Opened 8 years ago

Closed 7 years ago

#10943 closed Bugs (invalid)

SIGSEGV in compiler_log_formatter::log_start

Reported by: InonShar@… Owned by: Gennadiy Rozental
Milestone: To Be Determined Component: test
Version: Boost 1.41.0 Severity: Problem
Keywords: Cc:

Description

SIGSEGV in output::compiler_log_formatter::log_start() call to ostream::_M_insert<unsigned long>()

Hi!

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.

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.

Stack trace:

        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

Loaded by the BOOST_GLOBAL_FIXTURE

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;
};

Change History (6)

comment:1 by anonymous, 8 years ago

Severity: ProblemCosmetic
Type: Support RequestsBugs

http://stackoverflow.com/a/28049426/3368225

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:

  1. Invalid ofstream object (e.g. double open(), etc.).
  2. Calling BOOST_TEST macros from within a BOOST_GLOBAL_FIXTURE, within init_unit_test_suite().

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.

comment:2 by anonymous, 8 years ago

Severity: CosmeticProblem

likewise, I 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.

comment:3 by Raffi Enficiaud, 8 years ago

Hi,

From the code above, the call to set() is successful, is it?

comment:4 by Gennadiy Rozental, 7 years ago

Can you please provide simple standalone example illustrating the issue?

comment:5 by anonymous, 7 years ago

Sorry, guys, no I can't because I've left the company where I wrote the code...

comment:6 by Raffi Enficiaud, 7 years ago

Resolution: invalid
Status: newclosed

I am then closing the issue.

Note: See TracTickets for help on using tickets.