To measure and validate response time in real-time systems, use the following macros:
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 structure with the current time.
Time is stored as number of seconds (and nanoseconds) since 00:00:00 UTC, January 1, 1970.
Accuracy depends on platform used.
CppTest_TimeDiff(CppTest_Time t1, CppTest_Time t2);
|Returns the difference between |
int CppTest_TimeCompare(CppTest_Time t1, CppTest_Time t2);
- < 0: If
t1 is smaller/earlier than
- == 0: If
t2 are equal
- > 0: If
t1 is bigger/later than
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)