boost :: unit_test :: output :: compiler_log_formatter中的SIGSEGV开始和结束

时间:2015-01-20 07:43:53

标签: boost-test

boost :: unit_test :: output :: compiler_log_formatter :: log_start()中的

SIGSEGV调用ostream :: _ M_insert()

大家好!

我正在尝试编译一个使用Boost.Test模块的代码,并且在使用某些参数时它似乎已经破坏了:每当我运行代码时,我都会遇到分段错误第一行到日志文件。自定义命名的日志文件存在,但为空,并且不会发出错误消息。

我的设置使用以下代码完成,之后初始化BOOST_GLOBAL_FIXTURE(成功)。如果我理解堆栈跟踪,则只有在开始遍历test_unit树时才会出现错误。

我在提升TRAC上打开了一张票:https://svn.boost.org/trac/boost/ticket/10943,但它甚至没有分配......

我正在运行CentOS 6.5,所以我的升级版本是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   

调试信息

我想,ostream是优化出来的 - 我所有的Eclipse GDB都给了我一个可能很时髦的地址:

std::ostream & unit_test_log_t::test_start::s_log_impl().stream() = @0x7fffffffc9a0

取自第四个堆栈帧(作为参数传递给第三个帧)。

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

Epilog:仍然开放(截至2月22日)!

将一些BOOST_TEST宏从init_test_suite()中移出后,我现在在

中出现了分段错误
compiler_log_formatter::log_finish( std::ostream& ostr )
{
    ostr.flush();
}
在获得每个test_units的打印输出后,没有任何解释。摘要不会打印到文件。

1 个答案:

答案 0 :(得分:0)

在没有得到任何帮助之后,一些绝望的摆弄,它似乎工作。我不知道怎么做。

原始问题的可能原因:

  1. 无效的流对象(例如,double open()等)。谢谢@sehe @。
  2. 在init_unit_test_suite()中的BOOST_GLOBAL_FIXTURE中调用BOOST_TEST宏。