Note that there are some explanatory texts on larger screens.

plurals
  1. POBOOST Unit Test stack overflow
    text
    copied!<p>I am now using <a href="http://www.boost.org/doc/libs/1_35_0/libs/test/doc/components/utf/index.html" rel="nofollow noreferrer">Boost Unit Test</a> to perform unit test for my project. Every time I run the unit test, I got a memory stack problem. I debug into the source code of BOOST library, and I find that the problem comes from invoking the following codes in unit_test_suite.hpp file:</p> <pre><code>void traverse_test_tree( test_unit_id id, test_tree_visitor&amp; V ) { global_i = global_i + 1; std::cout&lt;&lt;global_i&lt;&lt;std::endl; if( ut_detail::test_id_2_unit_type( id ) == tut_case ) traverse_test_tree( framework::get&lt;test_case&gt;( id ), V ); else traverse_test_tree( framework::get&lt;test_suite&gt;( id ), V ); } </code></pre> <p>The error information I have obtained from VC10 is:</p> <pre><code>Unhandled exception at 0x779815de in TestApplication.exe: 0xC00000FD: Stack overflow. </code></pre> <p>I was wondering what's wrong with the test program. Thanks!</p> <p><strong>EDIT</strong> Based on the suggestions I looked through my codes, and very strange things happen: if the test suite is defined in same program with main(), it works; however, if the test suite is from a .dll, the error will occur. I list the following codes to illustrate my problem:</p> <pre><code>boost::unit_test::test_suite* main_global_test_suite; void Hellotestdll() { int i= 1; int j= 2; BOOST_CHECK(i == j); } boost::unit_test::test_suite* get_abc_test_suite() { test_suite* ts = BOOST_TEST_SUITE( "unit_geometric" ); ts-&gt;add( BOOST_TEST_CASE( &amp;Hellotestdll ) ); return ts; } int main( int argc, char* argv[] ) { try { /** * Step 1. obtain options */ char* optionLine[1024]; int len; len = obtain_options(optionLine, argc, argv); /** * Step 2. perform unit test based on user's options */ int test_status=0; main_global_test_suite = get_abc_test_suite(); test_status = unit_test_main(run_global_test_suite, len, optionLine); return test_status; } catch(std::exception&amp; e) { std::cout &lt;&lt; e.what() &lt;&lt; std::endl; return 1; } catch (const std::string&amp; s) { std::cout &lt;&lt; s &lt;&lt; std::endl; return 1; } catch (...) { return 1; } } </code></pre> <p>The above codes work very well. But if the test suite is from a .dll, for example:</p> <pre><code>// dll_header.h namespace abc { ABC_EXPORT boost::unit_test::test_suite* get_geometric_test_suite(); } // dll_header.cpp namespace abc { using namespace boost; using namespace boost::unit_test; void Hellotestdllabc() { int i= 1; int j= 2; BOOST_CHECK(i == j); } boost::unit_test::test_suite* get_abc_test_suite() { test_suite* ts = BOOST_TEST_SUITE( "unit_abc" ); ts-&gt;add( BOOST_TEST_CASE( &amp;Hellotestdllabc ) ); return ts; } } </code></pre> <p>Then if I invoke this test suite, with the following codes:</p> <pre><code> int main( int argc, char* argv[] ) { ............ /** * Step 2. perform unit test based on user's options */ int test_status=0; main_global_test_suite = abc::get_abc_test_suite(); test_status = unit_test_main(run_global_test_suite, len, optionLine); return test_status; } </code></pre> <p>The annoying stack overflow error will happen. </p> <p><strong>Summery of the Problems</strong></p> <pre><code> (1) boost dll with MDd (Succeed) </code></pre> <p>If I link the boost unit test library (with the definition <code>-DBOOST_ALL_DYN_LINK -DBOOST_TEST_NO_MAIN -DBOOST_TEST_DYN_LINK -DBOOST_ALL_NO_LIB</code>)and the running executable program with the same dynamic run-time library (Multi-thread Debug Dll (MDd)), it will work.</p> <pre><code>(2) boost dll with MTd (Failed) </code></pre> <p>If the boost unit test library (with the definition <code>-DBOOST_ALL_DYN_LINK -DBOOST_TEST_NO_MAIN -DBOOST_TEST_DYN_LINK -DBOOST_ALL_NO_LIB</code>)and the running executable program are compiled and link with the same static run-time libray (Multi-thred Debu (MTd)), I will have a crash, but the crash is different from the one I reported above: <img src="https://i.stack.imgur.com/P3p87.png" alt="enter image description here"></p> <pre><code>(3) boost static lib with MDd (Failed) </code></pre> <p>If the boost is built as a static library (with the definition of <code>-DBOOST_TEST_NO_MAIN -DBOOST_ALL_NO_LIB</code>), and both the boost library and the executable program are built with the same dynamic run-time library (MDd). The following crash will happen: <img src="https://i.stack.imgur.com/kk7ot.png" alt="enter image description here"></p> <pre><code>(4) boost static lib with MTd (Failed) </code></pre> <p>If the boost is built as a static library (with the definition of <code>-DBOOST_TEST_NO_MAIN -DBOOST_ALL_NO_LIB</code>), and both the boost library and the executable program are built with the same static run-time library (MTd). The following crash will happen: <img src="https://i.stack.imgur.com/zR3jE.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload