0

在清理阶段从 main 返回时,CPPUNIT 在执行我的程序后崩溃。TestWrapping 的 dtor 调用 TestSuite 的 dtor,然后调用 deleteContents 触发测试用例清理。

奇怪的是 TestSuite 的 dtor 被调用了两次?这是在成功执行 6 个测试用例之后。关于如何避免这种情况的任何想法?

    Program terminated with signal 11, Segmentation fault.
#0  0x0000000000000045 in ?? ()
(gdb) bt
#0  0x0000000000000045 in ?? ()
#1  0x0000000000000001 in ?? ()
#2  0x0000000001004f2d in CppUnit::TestSuite::~TestSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at TestSuite.cpp:18
#3  0x0000000001004ebd in CppUnit::TestSuite::deleteContents (this=0x7fe7bc001040) at TestSuite.cpp:28
#4  0x000000000100500d in CppUnit::TestSuite::~TestSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at TestSuite.cpp:18
#5  0x0000000001004c50 in CppUnit::TestRunner::WrappingSuite::~WrappingSuite (this=0x7fe7bc005820, __in_chrg=<optimized out>) at ../../include/cppunit/TestRunner.h:101
#6  0x000000000040b72a in main (argc=0, argv=0x7fff8198bf08) at /project/EAB3_EMC/BRF/lmcgupe/brf/build/../software/brfc_test/BrfcTestMain.cc:447


Code exercising this:
(from main)
    CppUnit::TextUi::TestRunner runner;
    CPPUNIT_NS::TestResult controller;
    CPPUNIT_NS::TestResultCollector result;
    controller.addListener( &result );

    // Show a message as each test starts
    //
    CppUnit::BriefTestProgressListener listener;
    runner.eventManager().addListener(&listener);
    controller.addListener( &listener );

    // Specify XML output and inform the runner of this format
    //
    std::ofstream xmlout("test_result.xml");
    CppUnit::XmlOutputter* outputter = new CppUnit::XmlOutputter(
            &result, xmlout);
    runner.setOutputter(outputter);


    CppUnit::TextOutputter consoleOutputter(&result , std::cout);

    runner.addTest(CreateAlarmBackupSuite::suite());
    runner.run( controller );

from class CreateAlarmBackupSuite: public CppUnit::TestFixture

    static CppUnit::Test *suite()
    {

        // Create the Test Suite
        //
        CppUnit::TestSuite *suite = new CppUnit::TestSuite("CreateAlarmBackupSuite");

        // Add the test cases

        //Crt_Syst_07
        suite->addTest(new CppUnit::TestCaller<CreateAlarmBackupSuite>(
                       "07_Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Persistent_ManualDelNotClear",
                &CreateAlarmBackupSuite::Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Persistent_ManualDelNotClear));



        //Crt_Syst_09
        suite->addTest(new CppUnit::TestCaller<CreateAlarmBackupSuite>(
                "09_Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Transient_NoRetry",
                &CreateAlarmBackupSuite::Crt_ScheduledBackup_ScheduledSingleEvent_SystemDataBackup_Non_Successful_Create_Transient_NoRetry));

return suite;
}
4

1 回答 1

0

我希望您的代码没有显式调用这些对象的析构函数,而是调用delete指向它们的指针,或者它们超出范围并且编译器会自动调用它们的析构函数。假设您没有明确调用析构函数.....

看起来您的 TestSuite 对象要么执行 a ,要么delete this包含指向自身的指针(或在 deleteContents() 中以某种方式获得指向自身的指针),然后调用delete该指针。你还没有发布你的TestSuite类的源代码(特别是它的deleteContents()方法),但这是我的猜测,没有看到代码。

于 2013-01-09T18:11:07.687 回答