Boost test, segmentation fault.
Hello all, First of all: I'm building an application and with that I use Boost test for unit testing. This helped me already to fix some obscure bugs. (I am very happy with boost test) I have the Master suite test setup in one file and the normal test suites each in one file. This worked very well. Now I have the following test suite which gives me a segmentation fault and I have no idea why: BOOST_AUTO_TEST_SUITE(ProgramOptions) BOOST_AUTO_TEST_CASE(ProgramOptions_Valid_Options) { // Output boost::test_tools::output_test_stream output("misc/ProgramOptions_01.output", true); // Save output buffer std::streambuf *strmbuffer; strmbuffer = std::cout.rdbuf(); // Redirect the output. std::cout.rdbuf(output.rdbuf()); // Redirect output stream so we can do some checks. printSomething(); BOOST_REQUIRE(output.match_pattern()); // Now lets process some arguments. printSomething(); BOOST_REQUIRE(output.match_pattern()); // Restore output buffer std::cout.rdbuf(strmbuffer); } BOOST_AUTO_TEST_SUITE_END() The function that gets tested: void printSomething() { std::cout << "Test output" << std::endl; } If I put the same content 'Test output' in the ProgramOptions_01.output file then everything is fine and executes ok. When putting different content in that file it goes wrong. I have also a gdb backtrace if that is interesting: (gdb) r Starting program: /home/matthijs/Projects/cppcms/trunk/cmsapp_test [Thread debugging using libthread_db enabled] Running 10 test cases... Program received signal SIGSEGV, Segmentation fault. 0xb7f6f9e8 in vtable for boost::unit_test::progress_monitor_t () from /usr/lib/libboost_unit_test_framework.so.1.42.0 (gdb) bt full #0 0xb7f6f9e8 in vtable for boost::unit_test::progress_monitor_t () from /usr/lib/libboost_unit_test_framework.so.1.42.0 No symbol table info available. #1 0xb7e5b77f in std::ostream::flush() () from /usr/lib/libstdc++.so.6 No symbol table info available. #2 0xb7f0a13d in boost::unit_test::output::compiler_log_formatter::log_finish(std::ostream&) () from /usr/lib/libboost_unit_test_framework.so.1.42.0 No symbol table info available. #3 0xb7f2e492 in boost::unit_test::unit_test_log_t::test_finish() () from /usr/lib/libboost_unit_test_framework.so.1.42.0 No symbol table info available. #4 0xb7f1a593 in boost::unit_test::framework::run(unsigned long, bool) () from /usr/lib/libboost_unit_test_framework.so.1.42.0 No symbol table info available. #5 0xb7f2f469 in boost::unit_test::unit_test_main(bool (*)(), int, char**) () from /usr/lib/libboost_unit_test_framework.so.1.42.0 No symbol table info available. #6 0x08062133 in main (argc=1, argv=0xbffff824) at /usr/include/boost/test/unit_test.hpp:59 No locals. Hopefully someone with some insight in boost.test can help me out here... Regards, Matthijs Möhlmann
AMDG Matthijs Mohlmann wrote:
First of all: I'm building an application and with that I use Boost test for unit testing. This helped me already to fix some obscure bugs. (I am very happy with boost test)
I have the Master suite test setup in one file and the normal test suites each in one file. This worked very well. Now I have the following test suite which gives me a segmentation fault and I have no idea why:
BOOST_AUTO_TEST_SUITE(ProgramOptions)
BOOST_AUTO_TEST_CASE(ProgramOptions_Valid_Options) {
// Output boost::test_tools::output_test_stream output("misc/ProgramOptions_01.output", true);
// Save output buffer std::streambuf *strmbuffer; strmbuffer = std::cout.rdbuf();
// Redirect the output. std::cout.rdbuf(output.rdbuf());
// Redirect output stream so we can do some checks. printSomething(); BOOST_REQUIRE(output.match_pattern());
// Now lets process some arguments. printSomething(); BOOST_REQUIRE(output.match_pattern());
// Restore output buffer std::cout.rdbuf(strmbuffer); }
BOOST_AUTO_TEST_SUITE_END()
The function that gets tested: void printSomething() { std::cout << "Test output" << std::endl; }
If I put the same content 'Test output' in the ProgramOptions_01.output file then everything is fine and executes ok. When putting different content in that file it goes wrong.
The problem is that when BOOST_REQUIRE fails, the test case immediately aborts, the output buffer is not restored, the output_test_stream is destroyed, and std::cout is left with a dangling pointer. In Christ, Steven Watanabe
On Aug 27, 2010, at 12:09 AM, Steven Watanabe wrote:
AMDG
Matthijs Mohlmann wrote:
First of all: I'm building an application and with that I use Boost test for unit testing. This helped me already to fix some obscure bugs. (I am very happy with boost test)
I have the Master suite test setup in one file and the normal test suites each in one file. This worked very well. Now I have the following test suite which gives me a segmentation fault and I have no idea why:
BOOST_AUTO_TEST_SUITE(ProgramOptions)
BOOST_AUTO_TEST_CASE(ProgramOptions_Valid_Options) {
// Output boost::test_tools::output_test_stream output("misc/ProgramOptions_01.output", true);
// Save output buffer std::streambuf *strmbuffer; strmbuffer = std::cout.rdbuf();
// Redirect the output. std::cout.rdbuf(output.rdbuf());
// Redirect output stream so we can do some checks. printSomething(); BOOST_REQUIRE(output.match_pattern());
// Now lets process some arguments. printSomething(); BOOST_REQUIRE(output.match_pattern());
// Restore output buffer std::cout.rdbuf(strmbuffer); }
BOOST_AUTO_TEST_SUITE_END()
The function that gets tested: void printSomething() { std::cout << "Test output" << std::endl; }
If I put the same content 'Test output' in the ProgramOptions_01.output file then everything is fine and executes ok. When putting different content in that file it goes wrong.
The problem is that when BOOST_REQUIRE fails, the test case immediately aborts, the output buffer is not restored, the output_test_stream is destroyed, and std::cout is left with a dangling pointer.
In Christ, Steven Watanabe
Right, why couldn't I think of that? Regards, Matthijs Möhlmann
participants (2)
-
Matthijs Mohlmann
-
Steven Watanabe