To measure and validate response time in real-time systems, use the following macros:
Name | Details |
---|---|
CppTest_Time CppTest_TimeInit(CPPTEST_INTEGER seconds, CPPTEST_INTEGER nanoseconds); | Initializes the CppTest_Time structure with the given values.Nanoseconds should be between -999999999 and 999999999 |
CppTest_Time CppTest_TimeCurrent(); | Initializes the Time is stored as number of seconds (and nanoseconds) since 00:00:00 UTC, January 1, 1970. Accuracy depends on platform used. |
CppTest_Time CppTest_TimeDiff(CppTest_Time t1, CppTest_Time t2); | Returns the difference between t1 and t2 . |
int CppTest_TimeCompare(CppTest_Time t1, CppTest_Time t2); | Compares two Returns:
|
Here is an example of how to use these macros to measure and report time:
... /* Collect start time */ CppTest_Time start = CppTest_TimeCurrent(); /* Tested function call */ int _return = ::foo(); /* Compute time diff */ CppTest_Time stop = CppTest_TimeCurrent(); CppTest_Time diff = CppTest_TimeDiff(stop, start); /* Report time diff (assuming positive values) */ CPPTEST_MESSAGE(cpptestFormat("Call time for foo(): %d.%09d", diff.seconds, diff.nanoseconds)); ...
Here is an example of how to use these macros to check and compare time:
... /* Verify execution time */ CppTest_Time limit5ms = CppTest_TimeInit(0, 5000000); CPPTEST_ASSERT(CppTest_TimeCompare(diff, limit5ms) < 0) ...