Answer the question
In order to leave comments, you need to log in
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
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;
}
(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
b *0x08048391
commands
return (int)43
continue
end
(gdb) run
Starting program: /root/a.out
Breakpoint 1, 0x08048391 in foo ()
43 <=== новое значение
[Inferior 1 (process 127) exited normally]
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question