the Compartmented Robust Posix C++ Unit Test system |
|
---|
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.10.1 vanilla) 7.10.1 Copyright (C) 2015 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". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://bugs.gentoo.org/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ../test/assert_eq_fails...done. (gdb) break assert_eq_fails::test() Breakpoint 1 at 0x40894d: file /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp, line 44. (gdb) run -s assert_eq_fails Starting program: /var/tmp/build/test/assert_eq_fails -s assert_eq_fails [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1, assert_eq_fails::test (this=0x7fffffffc260) at /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp:44 44 { (gdb) n 45 a val1(3); (gdb) n 46 int val2 = 4; (gdb) print val1 $1 = {n = 3} (gdb) print val2 - 2 $2 = -1710857332 (gdb) quit A debugging session is active. Inferior 1 [process 7807] will be killed. Quit anyway? (y or n)
When run with -s
/ --single-shot
,
failed assertions leads to a call to abort
.
Note | |
---|---|
Deadlines are neither asserted, nor even monitored, when
a test is run with
-s / --single-shot .
|