How to debug test cases

The test cases of ws4d-gsoap can be activated with the MAINTAINER_MODE and the BUILD_TESTING cmake options.

You can run the test with:

$ make test
Running tests...
Test project /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/Build-Debug
      Start  1: device_create_destroy
 1/11 Test  #1: device_create_destroy .....................   Passed    0.02 sec
      Start  2: device_create_destroy_two_times
 2/11 Test  #2: device_create_destroy_two_times ...........   Passed    0.02 sec
      Start  3: device_without_wsdl
 3/11 Test  #3: device_without_wsdl .......................   Passed    0.02 sec
      Start  4: double_dpws_done
 4/11 Test  #4: double_dpws_done ..........................   Passed    0.01 sec
      Start  5: dpws_init_invalid_host
 5/11 Test  #5: dpws_init_invalid_host ....................   Passed    0.01 sec
      Start  6: hosting_create_destroy
 6/11 Test  #6: hosting_create_destroy ....................   Passed    0.00 sec
      Start  7: hosting_add_and_delete_service
 7/11 Test  #7: hosting_add_and_delete_service ............   Passed    0.01 sec
      Start  8: hosting_activate_and_deactivate_service
 8/11 Test  #8: hosting_activate_and_deactivate_service ...   Passed    0.01 sec
      Start  9: stringlist_create_destroy
 9/11 Test  #9: stringlist_create_destroy .................   Passed    0.02 sec
      Start 10: stringlist_add_one_item
10/11 Test #10: stringlist_add_one_item ...................   Passed    0.01 sec
      Start 11: stringlist_add_several_items
11/11 Test #11: stringlist_add_several_items ..............   Passed    0.00 sec

100% tests passed, 0 tests failed out of 11

Total Test time (real) =   0.15 sec

If you test case fails, you can use the following steps to debug the test case with gdb:

Check which test case is failing?

The following ARGS parameter starts the test suite with a more verbose output:

$ make ARGS="-VV" test
[...]
11: Test command: /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/Build-Debug/bin/stringlist_test stringlist_add_several_items
11: Test timeout computed to be: 1500
11: Running suite(s): "stringlist"
11: 100%: Checks: 1, Failures: 0, Errors: 0
11: /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/test/api/stringlist_test.c:63:P:stringlist_add_several_items:function:0: Passed
11/11 Test #11: stringlist_add_several_items ..............   Passed    0.00 sec

Here you can see the test command.

Run the test command in gdb

$ gdb --args /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/Build-Debug/bin/stringlist_test stringlist_add_several_items
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/Build-Debug/bin/stringlist_test...done.
(gdb)

Set a breakpoint for the test case

If we want to debug the test case stringlist_add_several_items we should set a breakpoint for a function with the same name

(gdb) b stringlist_add_several_items
Breakpoint 1 at 0x804a8c9: file /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/test/api/stringlist_test.c, line 55.

Activate no fork mode

The ws4d-gsoap test suite is based on the  check tool. This runs tests in a separate process. This is hard to debug with gdb, so we want to disable this feature with the CK_FORK environment variable

(gdb) set environment CK_FORK=no

Debug the test case

Run the debugging session and wait for the test case to hit the breakpoint

(gdb) r
Starting program: /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/Build-Debug/bin/stringlist_test stringlist_add_several_items
Running suite(s): "stringlist"

Breakpoint 1, stringlist_add_several_items (_i=0)
    at /media/disk/elmex/EclipseWorkspace/ws4d-gsoap/test/api/stringlist_test.c:55
55	START_TEST (stringlist_add_several_items)
(gdb)