X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2FTestLib_Listener.cxx;h=7c79e858d763a15bd30a16b5719844002e3920ab;hb=1ad3406d04aa81800693d6811c7c36e87e0c95c1;hp=e2586dcea120ab716ee2aeba88ce92a78fc345d9;hpb=6527cd5d3063b2724b60b3f87ed1105244b74cb3;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/TestLib_Listener.cxx b/src/HYDRO_tests/TestLib_Listener.cxx index e2586dce..7c79e858 100644 --- a/src/HYDRO_tests/TestLib_Listener.cxx +++ b/src/HYDRO_tests/TestLib_Listener.cxx @@ -18,12 +18,61 @@ #include #include +#include +#include #include +#include + +#ifdef WIN32 + #include +#endif + +#ifdef WIN32 +/** + Convert the given time structure to milliseconds number + @param theTime the time structure to convert + @return the calculated number of milliseconds +*/ +INT64 GetMilliseconds( const FILETIME& theTime ) +{ + SYSTEMTIME aTime; + FileTimeToSystemTime( &theTime, &aTime ); + INT64 aRes = 0; + aRes += aTime.wHour * ( 3600 * 1000 ); + aRes += aTime.wMinute * ( 60 * 1000 ); + aRes += aTime.wSecond * ( 1000 ); + aRes += aTime.wMilliseconds; + return aRes; +} +#endif + +/** + Calculate the complete execution time for the current thread + @return the calculated time as the number of milliseconds +*/ +INT64 GetTimeForCurrentThreadInMs() +{ +#ifdef WIN32 + FILETIME aCreationTime, anExitTime, aKernelTime, aUserTime; + GetThreadTimes( GetCurrentThread(), &aCreationTime, &anExitTime, &aKernelTime, &aUserTime ); + INT64 aKernelMs = GetMilliseconds( aKernelTime ); + INT64 aUserMs = GetMilliseconds( aUserTime ); + return aKernelMs + aUserMs; +#else + struct timespec aTime; + clock_gettime( CLOCK_MONOTONIC, &aTime ); + INT64 aSec = aTime.tv_sec; + aSec *= 1000; + aSec += aTime.tv_nsec / 1000000; + return aSec; +#endif +} /** \brief Constructor */ TestLib_Listener::TestLib_Listener() +: myStart( 0 ), myComplete( 0 ), myNbTests( 0 ), myNbSuites( 0 ) { } @@ -39,6 +88,17 @@ TestLib_Listener::~TestLib_Listener() */ void TestLib_Listener::Clear() { + myStart = 0; + myComplete = 0; +} + +/** + Get complete time of all tests execution in milliseconds + @return complete time in milliseconds +*/ +INT64 TestLib_Listener::GetCompleteTimeInMS() const +{ + return myComplete; } /** @@ -52,6 +112,7 @@ void TestLib_Listener::startTest( CppUnit::Test* theTest ) aName = theTest->getName(); std::cout << aName << "..."; + myStart = GetTimeForCurrentThreadInMs(); } /** @@ -60,7 +121,22 @@ void TestLib_Listener::startTest( CppUnit::Test* theTest ) */ void TestLib_Listener::endTest( CppUnit::Test* theTest ) { - std::cout << std::endl; + INT64 aCurTime = GetTimeForCurrentThreadInMs(); + INT64 anExecTimeMS = aCurTime - myStart; + myComplete += anExecTimeMS; + std::cout << " " << anExecTimeMS << " ms" << std::endl; + + myNbTests++; +} + +int TestLib_Listener::GetNbTests() const +{ + return myNbTests; +} + +int TestLib_Listener::GetNbSuites() const +{ + return myNbSuites; } /** @@ -77,6 +153,7 @@ void TestLib_Listener::startSuite( CppUnit::Test* theTest ) */ void TestLib_Listener::endSuite( CppUnit::Test* theTest ) { + myNbSuites++; } /** @@ -85,5 +162,27 @@ void TestLib_Listener::endSuite( CppUnit::Test* theTest ) */ void TestLib_Listener::addFailure( const CppUnit::TestFailure& theFailure ) { + std::string failedTest = theFailure.failedTest()->getName(); + CppUnit::SourceLine failedLocation = theFailure.sourceLine(); + + QString aFile = QString::fromStdString( failedLocation.fileName() ); + aFile.replace( '\\', '/' ); + QStringList parts = aFile.split( '/' ); + aFile = parts.last(); + std::string cFile = aFile.toStdString(); + + int aLine = failedLocation.lineNumber(); + + static char aBuf[1024]; + sprintf( aBuf, "Failed %s: %s : %i", failedTest.c_str(), cFile.c_str(), aLine ); + + myFailures.push_back( aBuf ); } +void TestLib_Listener::DumpFailures() +{ + int n = (int)myFailures.size(); + printf( "FAILED TESTS: %i\n", n ); + for( int i=0; i