Hi, all!
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 got 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.
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.
I opened up a ticket on the boost TRAC: https://svn.boost.org/trac/boost/ticket/10943, but it has not even been assigned...
I am running CentOS 6.5, so my boost version is 1.41
Thread [1] 5624 [core: 6] (Suspended : Signal : SIGSEGV:Segmentation fault)
std::ostream::sentry::sentry() at 0x3495a915b1
std::ostream& std::ostream::_M_insert<unsigned long>() 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<int>::invoke<boost::unit_test::ut_detail::test_start_caller>() at callback.hpp:42 0x4de998
boost::unit_test::ut_detail::callback0_impl_t<int, boost::unit_test::ut_detail::test_start_caller>::invoke() at callback.hpp:89 0x4db5a7
boost::unit_test::callback0<int>::operator() at callback.hpp:118 0x4a24ff
boost::detail::do_invoke<boost::scoped_ptr<boost::detail::translate_exception_base>, boost::unit_test::callback0<int> >() 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
The ostream is, I guess, optimized out -- all my Eclipse GDB gives me is an address which may be funky:
std::ostream & unit_test_log_t::test_start::s_log_impl().stream() = @0x7fffffffc9a0
Taken from the fourth stack frame (passed as argument to the third frame).
static const bool TestingDefs::formatBoostTestForJenkins = false;
/// Loaded by the BOOST_GLOBAL_FIXTURE
struct BoostTestFlags
{
BoostTestFlags() :
m_set(false)
{
Func_Reporter;
if (!m_set)
m_set = set();
}
bool set()
{
m_sOFStreamDirName = GlobalLoggerSingleton::instance()->getFullFilePath();
m_sOFStreamFileName = m_sOFStreamDirName + string("/") + string("BoostTests_") + to_iso_string(second_clock::local_time());
m_sOFStreamFileName += "."; ///< add filename extension according to filetype, TBD later on.
BETIS_LOGMSG((LM_INFO,"Boost.Test output will be written to %s",m_sOFStreamFileName.c_str()));
if (TestingDefs::formatBoostTestForJenkins)
{
m_sOFStreamFileName += "xml";
m_oFStreamBoostTests.open(m_sOFStreamFileName.c_str(), std::ofstream::out | std::ofstream::trunc);
if (!m_oFStreamBoostTests.is_open())
{
BETIS_LOGMSG((LM_ERROR,"BoostTestFlags::BoostTestFlags() Could not open output file stream for writing!"));
return false;
}
boost::unit_test::unit_test_log.set_stream(m_oFStreamBoostTests);
boost::unit_test::unit_test_log.set_format((boost::unit_test::output_format) XML); ///< --output_format=XML
boost::unit_test::unit_test_log.set_threshold_level((boost::unit_test::log_level) 0); ///< --log_level=all
boost::unit_test::results_reporter::set_level(boost::unit_test::report_level(NO_REPORT)); ///< --report_level=no
boost::unit_test::results_reporter::set_format((boost::unit_test::output_format) XML);
}
else ///< Flags for human readability, verbose
{
m_sOFStreamFileName += "log";
m_oFStreamBoostTests.open(m_sOFStreamFileName.c_str(), std::ofstream::out | std::ofstream::trunc);
if (!m_oFStreamBoostTests.is_open())
{
BETIS_LOGMSG((LM_ERROR,"BoostTestFlags::BoostTestFlags() Could not open output file stream for writing!"));
return false;
}
boost::unit_test::unit_test_log.set_stream(m_oFStreamBoostTests);
boost::unit_test::unit_test_log.set_format((boost::unit_test::output_format) CLF); ///< Compiler Log Format
boost::unit_test::unit_test_log.set_threshold_level((boost::unit_test::log_level) 0);
boost::unit_test::results_reporter::set_level(boost::unit_test::report_level(DETAILED_REPORT));
boost::unit_test::results_reporter::set_format((boost::unit_test::output_format) CLF);
cout.setf(ios_base::unitbuf); ///< 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
}
return true;
}
~BoostTestFlags()
{
Func_Reporter;
}
private:
ofstream m_oFStreamBoostTests;
string m_sOFStreamDirName;
string m_sOFStreamFileName;
bool m_set;
};
After moving some BOOST_TEST macros out of init_test_suite(), I now get a segmentation fault in
compiler_log_formatter::log_finish( std::ostream& ostr )
{
ostr.flush();
}
with no explanation, after getting printouts from each of the test_units. The summary isn't printed to file.
After getting no help, and some desperate fiddling around, it seems to be working. I'm not sure how.
Possible reasons for the original problem: