]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
the tests execution time is measured
authorasl <asl@opencascade.com>
Thu, 7 Sep 2017 04:53:47 +0000 (07:53 +0300)
committerasl <asl@opencascade.com>
Thu, 7 Sep 2017 04:53:47 +0000 (07:53 +0300)
src/HYDRO_tests/TestLib_Listener.cxx
src/HYDRO_tests/TestLib_Listener.h
src/HYDRO_tests/test_HYDROData_Main.cxx

index e2586dcea120ab716ee2aeba88ce92a78fc345d9..593c8d6e29b3404c4531c09bbf312c39fb9692e8 100644 (file)
 #include <cppunit/Test.h>
 #include <iostream>
 
+#ifdef WIN32
+  #include <windows.h>
+#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 )
 {
 }
 
@@ -39,6 +85,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 +109,7 @@ void TestLib_Listener::startTest( CppUnit::Test* theTest )
     aName = theTest->getName();
 
   std::cout << aName << "...";
+  myStart = GetTimeForCurrentThreadInMs();
 }
 
 /**
@@ -60,7 +118,10 @@ 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;
 }
 
 /**
index b8e125d1cc904152fdfbf972a99936185f067222..8953a29d7e1b4ea21c18987cd047ed0bd4105ccf 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <cppunit/TestListener.h>
 
+typedef long long INT64;   ///< the cross-platform type definition for 64-bits integer
+
 /**
   \class TestLib_Listener
   \brief Implementation of the custom listener printing the time of test execution
@@ -31,7 +33,8 @@ public:
   virtual ~TestLib_Listener();
 
   void Clear();
-
+  INT64 GetCompleteTimeInMS() const;
+    
   virtual void startTest( CppUnit::Test* );
   virtual void endTest( CppUnit::Test* );
 
@@ -39,5 +42,9 @@ public:
   virtual void endSuite( CppUnit::Test* );
 
   virtual void addFailure( const CppUnit::TestFailure& );
+
+private:
+  INT64 myStart; ///< start time in milliseconds
+  INT64 myComplete; ///< complete time of all tests execution in milliseconds
 };
 
index 05f6b9b8f8cb7140b5c208f3b962cdb14bc07f0b..fe430bfd81b4adc37c7563918399081407e70e58 100644 (file)
@@ -95,5 +95,9 @@ int main( int argc, char* argv[] )
   aSession.closeSession();
   anApp.exit(!isOK);
   DEBTRACE("--- TODO: exception on exit..."); // TODO: exception on exit...
+
+  int ms = progress.GetCompleteTimeInMS();
+  printf( "COMPLETE TESTS TIME: %i ms\n", ms );
+
   return result.wasSuccessful() ? 0 : 1;
 }