Note: Each condition is encapsulated into a separate function, and these execution branches execute only one at a time.
Automating Testing
Ideas
Do not try to modify the existing code.
Construct the conditions required to execute each handler at runtime. For example, to handler called normally requires all its pre-condition to be modified to true.
Can do this with GDB.
Using GDB to modify function return values at runtime
ethanol@ethanol:~/Desktop/automating_test$ gdb -q ./main GEF for linux ready, type `gef' to start, `gef config' to configure 96 commands loaded for GDB 9.2 using Python engine 3.8 Reading symbols from ./main... gef➤ b condition1 Breakpoint 1 at 0x11a9: file main.cpp, line 8. gef➤ b condition2 Breakpoint 2 at 0x11b9: file main.cpp, line 12. gef➤ b condition3 Breakpoint 3 at 0x11c9: file main.cpp, line 16. gef➤ b condition4
1 2 3 4 5 6 7 8 9 10 11 12 13
gef➤ c gef➤ return 2 gef➤ c gef➤ return 3 gef➤ c gef➤ returnfalse gef➤ c gef➤ returntrue gef➤ c Continuing. handler1() is called [Inferior 1 (process 20873) exited normally] gef➤
We can put manually executed commands into a file cmd_test.gdb.
define test_handler1 b condition1 b condition2 b condition3 b condition4 b *handler1 c return 2 c return 3 c returnfalse c returntrue c set$next_actual = $pc set$next_expected = &handler1 if$next_actual == $next_expected echo test_handler1[SUCCESS]\n else echo test_handler1[FAILURE]\n end c end test_handler1
Note: If you want to get the first instruction of a class member function - set $expected =(int) 'test.cpp' ::Test::Handler1.
Test: class name.
Handler1: member function name.
Other issues
Breakpoint cleanup between test cases - d.
Test case results statistics.
Turn on gdb logging function.
Write scripts that analyze the output logs of gdb and count which test cases passed and which failed.