P
P
Pavel K2018-10-27 00:17:23
Qt
Pavel K, 2018-10-27 00:17:23

Tested by "errors", or how to emulate them when debugging and debugging?

Greetings!
There is a big project on Qt (C++). There are errors from the category of elusive Joe.
There are usual functional tests (by means of Qt), but this is not enough. I would like to emulate errors in functions (for example, some variable returned an unexpected value within the function itself) and see what happens. Now I do it in the debugger, manually changing the values, but it's tedious, I want automation (yes, it would be possible to stumble on defines, but in my opinion this is a crutch solution). What can you think of in such a situation to run the tests automatically, but what if, like in a debugger, there would be a simple opportunity to change the value of a variable?
PS Yes, I assume that the main problem here is in the architecture itself, etc. It's in the process of being corrected as bugs are found.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
4
4rtzel, 2018-10-27
@PavelK

You can look towards the fault injection concept. They are used as an additional step in program testing to check how the code behaves when errors occur. The downside of all this is that it requires additional modification of the code (which in your case may be too expensive and redundant), but there are also external tools for modifying the code on the fly.
As another option, write a script for the debugger, which would set breakpoints on retq (if it is necessary for the function body to be executed) instructions at the start of the program and execute a custom return with an erroneous value.
Example (gdb):
File:

int my_function() {
  return 42;
}
 
int main(void) {
  int a = my_function();
  printf("%d\n", a);
  return 0;
}

Find the address ret(q):
(gdb) disassemble my_function
Dump of assembler code for function my_function:
   0x08048388 <+0>:     push   %ebp
   0x08048389 <+1>:     mov    %esp,%ebp
   0x0804838b <+3>:     mov    $0x2a,%eax
   0x08048390 <+8>:     pop    %ebp
   0x08048391 <+9>:     ret

In the .gdbinit file:
b *0x08048391
commands
return (int)43
continue
end

We launch:
(gdb) run
Starting program: /root/a.out
Breakpoint 1, 0x08048391 in foo ()
43             <=== новое значение
[Inferior 1 (process 127) exited normally]

B
bogolt, 2018-12-07
@bogolt

Write logs of all actions performed by the program. for example

2018-11-01 15:12:12.123 Menu 'Open file' activated
2018-11-01 15:12:12.223 Opening file '/home/user/abc.txt
' with system error: Permission denied

A sufficiently detailed log with the necessary values ​​of variables (database passwords and other dangerous things should be replaced with asterisks in the log) can be analyzed and reproduced later (and then the bug can be fixed). Logs can be asked to be sent from the machine on which the bug happened, if for example it is not reproduced on your hardware.
Just keep in mind that the logs should not grow indefinitely, and that at each start of the program you need to add to the existing log without resetting the old file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question