Boost C++ Libraries: Ticket #10943: SIGSEGV in compiler_log_formatter::log_start https://svn.boost.org/trac10/ticket/10943 <h1 class="section" id="SIGSEGVinoutput::compiler_log_formatter::log_startcalltoostream::_M_insertunsignedlong">SIGSEGV in output::compiler_log_formatter::log_start() call to ostream::_M_insert&lt;unsigned long&gt;()</h1> <p> Hi! </p> <p> I'm trying to compile a code which uses the Boost.Test module, and while playing around with some of the parameters it seems to have broken: I now get a segmentation fault whenever I run the code, at the printout of the first line to the log file. The custom-named log file exists, but is empty, and no error message is emitted. </p> <p> My setup is done using the following code, after which a BOOST_GLOBAL_FIXTURE is initiallized (succesfully). If I understand the stack trace, the error seems to occur only when starting to traverse the test_unit tree. </p> <h2 class="section" id="Stacktrace:">Stack trace:</h2> <pre class="wiki"> Thread [1] 5624 [core: 6] (Suspended : Signal : SIGSEGV:Segmentation fault) std::ostream::sentry::sentry() at 0x3495a915b1 std::ostream&amp; std::ostream::_M_insert&lt;unsigned long&gt;() at 0x3495a95168 boost::unit_test::output::compiler_log_formatter::log_start() at compiler_log_formatter.ipp:50 0x45aaa3 boost::unit_test::unit_test_log_t::test_start() at unit_test_log.ipp:138 0x469ad5 boost::unit_test::ut_detail::test_start_caller::operator() at framework.ipp:71 0x489832 boost::unit_test::ut_detail::invoker&lt;int&gt;::invoke&lt;boost::unit_test::ut_detail::test_start_caller&gt;() at callback.hpp:42 0x4de998 boost::unit_test::ut_detail::callback0_impl_t&lt;int, boost::unit_test::ut_detail::test_start_caller&gt;::invoke() at callback.hpp:89 0x4db5a7 boost::unit_test::callback0&lt;int&gt;::operator() at callback.hpp:118 0x4a24ff boost::detail::do_invoke&lt;boost::scoped_ptr&lt;boost::detail::translate_exception_base&gt;, boost::unit_test::callback0&lt;int&gt; &gt;() at execution_monitor.ipp:244 0x497784 boost::execution_monitor::catch_signals() at execution_monitor.ipp:841 0x461918 boost::execution_monitor::execute() at execution_monitor.ipp:1,167 0x4619dc boost::unit_test::framework::run() at framework.ipp:418 0x45dc32 boost::unit_test::unit_test_main() at unit_test_main.ipp:185 0x46a85e main() at unit_test_main.ipp:237 0x46aa58 </pre><h2 class="section" id="LoadedbytheBOOST_GLOBAL_FIXTURE">Loaded by the BOOST_GLOBAL_FIXTURE</h2> <div class="wiki-code"><div class="code"><pre> <span class="k">static</span> <span class="k">const</span> <span class="kt">bool</span> <span class="n">TestingDefs</span><span class="o">::</span><span class="n">formatBoostTestForJenkins</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span> <span class="c1">/// Loaded by the BOOST_GLOBAL_FIXTURE</span> <span class="k">struct</span> <span class="n">BoostTestFlags</span> <span class="p">{</span> <span class="n">BoostTestFlags</span><span class="p">()</span> <span class="o">:</span> <span class="n">m_set</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> <span class="n">Func_Reporter</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">m_set</span><span class="p">)</span> <span class="n">m_set</span> <span class="o">=</span> <span class="n">set</span><span class="p">();</span> <span class="p">}</span> <span class="kt">bool</span> <span class="n">set</span><span class="p">()</span> <span class="p">{</span> <span class="n">m_sOFStreamDirName</span> <span class="o">=</span> <span class="n">GlobalLoggerSingleton</span><span class="o">::</span><span class="n">instance</span><span class="p">()</span><span class="o">-&gt;</span><span class="n">getFullFilePath</span><span class="p">();</span> <span class="n">m_sOFStreamFileName</span> <span class="o">=</span> <span class="n">m_sOFStreamDirName</span> <span class="o">+</span> <span class="n">string</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="n">string</span><span class="p">(</span><span class="s">&quot;BoostTests_&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="n">to_iso_string</span><span class="p">(</span><span class="n">second_clock</span><span class="o">::</span><span class="n">local_time</span><span class="p">());</span> <span class="n">m_sOFStreamFileName</span> <span class="o">+=</span> <span class="s">&quot;.&quot;</span><span class="p">;</span> <span class="c1">///&lt; add filename extension according to filetype, TBD later on.</span> <span class="n">BETIS_LOGMSG</span><span class="p">((</span><span class="n">LM_INFO</span><span class="p">,</span><span class="s">&quot;Boost.Test output will be written to %s&quot;</span><span class="p">,</span><span class="n">m_sOFStreamFileName</span><span class="p">.</span><span class="n">c_str</span><span class="p">()));</span> <span class="k">if</span> <span class="p">(</span><span class="n">TestingDefs</span><span class="o">::</span><span class="n">formatBoostTestForJenkins</span><span class="p">)</span> <span class="p">{</span> <span class="n">m_sOFStreamFileName</span> <span class="o">+=</span> <span class="s">&quot;xml&quot;</span><span class="p">;</span> <span class="n">m_oFStreamBoostTests</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">m_sOFStreamFileName</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span><span class="o">::</span><span class="n">out</span> <span class="o">|</span> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span><span class="o">::</span><span class="n">trunc</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">m_oFStreamBoostTests</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span> <span class="n">BETIS_LOGMSG</span><span class="p">((</span><span class="n">LM_ERROR</span><span class="p">,</span><span class="s">&quot;BoostTestFlags::BoostTestFlags() Could not open output file stream for writing!&quot;</span><span class="p">));</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span> <span class="p">}</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_stream</span><span class="p">(</span><span class="n">m_oFStreamBoostTests</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_format</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">output_format</span><span class="p">)</span> <span class="n">XML</span><span class="p">);</span> <span class="c1">///&lt; --output_format=XML</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_threshold_level</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">log_level</span><span class="p">)</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">///&lt; --log_level=all</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">results_reporter</span><span class="o">::</span><span class="n">set_level</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">report_level</span><span class="p">(</span><span class="n">NO_REPORT</span><span class="p">));</span> <span class="c1">///&lt; --report_level=no</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">results_reporter</span><span class="o">::</span><span class="n">set_format</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">output_format</span><span class="p">)</span> <span class="n">XML</span><span class="p">);</span> <span class="p">}</span> <span class="k">else</span> <span class="c1">///&lt; Flags for human readability, verbose</span> <span class="p">{</span> <span class="n">m_sOFStreamFileName</span> <span class="o">+=</span> <span class="s">&quot;log&quot;</span><span class="p">;</span> <span class="n">m_oFStreamBoostTests</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">m_sOFStreamFileName</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span><span class="o">::</span><span class="n">out</span> <span class="o">|</span> <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span><span class="o">::</span><span class="n">trunc</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">m_oFStreamBoostTests</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span> <span class="n">BETIS_LOGMSG</span><span class="p">((</span><span class="n">LM_ERROR</span><span class="p">,</span><span class="s">&quot;BoostTestFlags::BoostTestFlags() Could not open output file stream for writing!&quot;</span><span class="p">));</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span> <span class="p">}</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_stream</span><span class="p">(</span><span class="n">m_oFStreamBoostTests</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_format</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">output_format</span><span class="p">)</span> <span class="n">CLF</span><span class="p">);</span> <span class="c1">///&lt; Compiler Log Format</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">unit_test_log</span><span class="p">.</span><span class="n">set_threshold_level</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">log_level</span><span class="p">)</span> <span class="mi">0</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">results_reporter</span><span class="o">::</span><span class="n">set_level</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">report_level</span><span class="p">(</span><span class="n">DETAILED_REPORT</span><span class="p">));</span> <span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">results_reporter</span><span class="o">::</span><span class="n">set_format</span><span class="p">((</span><span class="n">boost</span><span class="o">::</span><span class="n">unit_test</span><span class="o">::</span><span class="n">output_format</span><span class="p">)</span> <span class="n">CLF</span><span class="p">);</span> <span class="n">cout</span><span class="p">.</span><span class="n">setf</span><span class="p">(</span><span class="n">ios_base</span><span class="o">::</span><span class="n">unitbuf</span><span class="p">);</span> <span class="c1">///&lt; Turn off STDOUT buffering to improve accuracy of communication between Boost.Test and Tests Runner (since Boost.Test does not provide a way to flush the stream). @warning This costs in execution time. @see github.com/xgsa/cdt-tests-runner/wiki/Features#known-problems</span> <span class="p">}</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span> <span class="p">}</span> <span class="o">~</span><span class="n">BoostTestFlags</span><span class="p">()</span> <span class="p">{</span> <span class="n">Func_Reporter</span><span class="p">;</span> <span class="p">}</span> <span class="k">private</span><span class="o">:</span> <span class="n">ofstream</span> <span class="n">m_oFStreamBoostTests</span><span class="p">;</span> <span class="n">string</span> <span class="n">m_sOFStreamDirName</span><span class="p">;</span> <span class="n">string</span> <span class="n">m_sOFStreamFileName</span><span class="p">;</span> <span class="kt">bool</span> <span class="n">m_set</span><span class="p">;</span> <span class="p">};</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10943 Trac 1.4.3 anonymous Wed, 21 Jan 2015 07:42:50 GMT type, severity changed https://svn.boost.org/trac10/ticket/10943#comment:1 https://svn.boost.org/trac10/ticket/10943#comment:1 <ul> <li><strong>type</strong> <span class="trac-field-old">Support Requests</span> → <span class="trac-field-new">Bugs</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Cosmetic</span> </li> </ul> <p> <a class="ext-link" href="http://stackoverflow.com/a/28049426/3368225"><span class="icon">​</span>http://stackoverflow.com/a/28049426/3368225</a> </p> <p> After getting no help, and some desperate fiddling around, it seems to be working. I'm not sure how. </p> <p> Possible reasons for the original problem: </p> <ol><li>Invalid ofstream object (e.g. double open(), etc.). </li><li>Calling BOOST_TEST macros from within a BOOST_GLOBAL_FIXTURE, within init_unit_test_suite(). </li></ol><p> More informative output really should be given. For example, check the ofstream once before trying to insert into it, and maybe some more advanced sanity check to make sure any BOOST_TEST macro called prematurely is at least warned about. </p> Ticket anonymous Wed, 21 Jan 2015 10:23:32 GMT severity changed https://svn.boost.org/trac10/ticket/10943#comment:2 https://svn.boost.org/trac10/ticket/10943#comment:2 <ul> <li><strong>severity</strong> <span class="trac-field-old">Cosmetic</span> → <span class="trac-field-new">Problem</span> </li> </ul> <p> likewise, I get a segmentation fault in </p> <pre class="wiki">compiler_log_formatter::log_finish( std::ostream&amp; ostr ) { ostr.flush(); } </pre><p> with no explanation, after getting printouts from each of the test_units. The summary isn't printed to file. </p> Ticket Raffi Enficiaud Sat, 28 Mar 2015 01:16:49 GMT <link>https://svn.boost.org/trac10/ticket/10943#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10943#comment:3</guid> <description> <p> Hi, </p> <p> From the code above, the call to set() is successful, is it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Gennadiy Rozental</dc:creator> <pubDate>Tue, 07 Jul 2015 15:35:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10943#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10943#comment:4</guid> <description> <p> Can you please provide simple standalone example illustrating the issue? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 08 Jul 2015 06:43:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10943#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10943#comment:5</guid> <description> <p> Sorry, guys, no I can't because I've left the company where I wrote the code... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 08 Jul 2015 07:40:46 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10943#comment:6 https://svn.boost.org/trac10/ticket/10943#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> I am then closing the issue. </p> Ticket