the Compartmented Robust Posix C++ Unit Test system

Debugging a test

The easiest way to debug a single test, is to run it with the -s / --single-shot command line parameter, which prevents it from being spawned as a separate process.

A break point can then be set on testcasename::test()

Example: To debug the test case assert_eq_fails in

     
     #include <crpcut.hpp>
     
     struct a {
       a(int val) : n(val) {}
       int n;
       operator int() const { return n; }
     };
     
     TEST(assert_eq_succeeds)
     {
       a val1(3);
       int val2 = 5;
       ASSERT_EQ(val1, val2 - 2);
     }
     
     TEST(assert_eq_fails)
     {
       a val1(3);
       int val2 = 4;
       ASSERT_EQ(val1, val2 - 2);
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

      

run


bash > gdb ./test/assert_eq_fails
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 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 "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /var/tmp/builld/test/assert_eq_fails...done.
(gdb) break assert_eq_fails::test()
Breakpoint 1 at 0x406d6d: file /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp, line 45.
(gdb) run -s assert_eq_fails
Starting program: /var/tmp/builld/test/assert_eq_fails -s assert_eq_fails
[Thread debugging using libthread_db enabled]

Breakpoint 1, assert_eq_fails::test (this=0x7fffffffcc80) at /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp:45
45	  a val1(3);
(gdb) n
46	  int val2 = 4;
(gdb) n
47	  ASSERT_EQ(val1, val2 - 2);
(gdb) print val1
$1 = {n = 3}
(gdb) print val2 - 2
$2 = 2
(gdb) quit
A debugging session is active.

	Inferior 1 [process 2446] will be killed.

Quit anyway? (y or n) 

      

When run with -s / --single-shot, failed assertions leads to a call to abort.

[Note]Note
Deadlines are neither asserted, nor even monitored, when a test is run with -s / --single-shot.