2012-06-07 5 views
1

운영 체제 = 우분투.CPPUNIT_ASSERT_MESSAGE가 OpenMP에서 오류를 일으키는 이유는 무엇입니까?

bjam usage = TRUE.

OpenMP의 도움을 받아 단위 테스트 시스템을 최적화하고 싶습니다.

bjam 스크립트 파일 :

lib my_lib 
    : 
     [ glob sources/*.cpp ] 
    : 
     <link>static 
    ; 


    ... 

explicit my_project ; 
unit-test my_project 
    : 
     [ glob UnitTests/*.cpp ]   
     my_lib 
    : 
    <linkflags>-fopenmp 
    <cflags>-fopenmp 
    ; 

내 코드의 일부는 :

terminate called without an active exception 
Aborted 

내가 언급 라인 CPPUNIT_ASSERT_MESSAGE : 내 테스트 시스템을 시작하면

for(j = 0; j < AMOUNT; j++) 
    { 
     #pragma omp parallel for 
     for(i = 0; i < 0x10000; ++i) 
     { 
     ... 
     try 
     { 
      variable1 = func1(); 
      variable2 = func2(); 
     //variable1 and variable 2 must be equal 
      CPPUNIT_ASSERT_MESSAGE("OLOLO", variable1 == variable2); 

     } 
     catch (const std::logic_error& exception) 
     { 
      std::cerr << exception.what() << std::endl; 
      CPPUNIT_ASSERT_MESSAGE("OLOLO", 0); 
     } 
     catch (const std::runtime_error & exception) 
     { 
      std::cerr << exception.what() << std::endl; 
      CPPUNIT_ASSERT_MESSAGE("OLOLO", 0); 
     } 

     } 

    } 

이 오류와 함께 종료 :

for(j = 0; j < AMOUNT; j++) 
    { 
     #pragma omp parallel for 
     for(i = 0; i < 0x10000; ++i) 
     { 
     ... 
     try 
     { 
      variable1 = func1(); 
      variable2 = func2(); 
      //CPPUNIT_ASSERT_MESSAGE("OLOLO", variable1 == variable2); 

     } 
     catch (const std::logic_error& exception) 
     { 
      std::cerr << exception.what() << std::endl; 
      //CPPUNIT_ASSERT_MESSAGE("OLOLO", 0); 
     } 
     catch (const std::runtime_error & exception) 
     { 
      std::cerr << exception.what() << std::endl; 
      //CPPUNIT_ASSERT_MESSAGE("OLOLO", 0); 
     } 

     } 

    } 

그리고 내가 필요한 방식으로 작동합니다. 하지만 잘못된 결과가 발생할 경우 정보를 출력하려면 CPPUNIT_ASSERT_MESSAGE가 필요합니다. CPPUNIT_ASSERT_MESSAGE가 오류를 일으키는 이유와 이러한 오류를 제거하기 위해 무엇을해야합니까?

답변

1

CPPUNIT는 오류가 발생하면 프로그램을 중지하여 작동합니다. 프로그램을 중지하는 대신 잘못된 결과가 발생할 경우 정보를 출력하려면 XmlOutputter를 구성하고이를 사용하는 TestRunner를 만들어야합니다. 예를 들어

:

// Create the event manager and test controller 
CPPUNIT_NS::TestResult controller; 

// Add a listener that colllects test result 
CPPUNIT_NS::TestResultCollector result; 
controller.addListener(&result); 

// Add a listener that print dots as test run. 
CPPUNIT_NS::BriefTestProgressListener progress; 
controller.addListener(&progress); 

// Add the top suite to the test runner 
CPPUNIT_NS::TextUi::TestRunner runner; 
CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); 
runner.addTest(suite); 

runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), 
                 std::cerr)); 

runner.run(testPath, false, true, true); 

std::cout << "Test done" << std::endl; 
exit(result.wasSuccessful() ? 0 : 1); 

하면 테스트를 중지하는 대신 XML 스트림을 출력하는 테스트 실행이 그 방법.

희망 하시겠습니까?