Previous: Running the unit tests, Up: Unit testing


8.2.6 Using gdb to debug check tests

The check testing framework uses fork calls in order to create the processes used to run the single tests. This makes possible to catch unexpected process terminations such as a segmentation fault or a division by zero.

Sometimes we want to debug those failure conditions using gdb. Unfortunately the GNU debugger cannot catch the unexpected termination of the child processess.

The check implementor foresaw this and provides a workaround: to define the CK_FORK environment variable to "no" and launch the debugger.

The test driver torture/unit/runtests is a shell script generated by libtool. This means that it is not possible to run it invoking gdb from the command line, as in:

     $ gdb torture/unit/runtests

A solution for this problem is to edit the torture/unit/runtests and hack it so it will call gdb instead of the program in .libs/. Just find the line containing something like:

     exec "$progdir/$program" ${1+"$@"}

and change it to something like:

     exec "gdb $progdir/$program"

The second alternative is to run gdb on the real binary using:

     $ LD_LIBRARY_PATH=/path/to/libgnupdf/src/.libs:$LD_LIBRARY_PATH gdb torture/unit/.libs/runtests