tests: timestamp: minor cleanup

Minor cleanup and fixes.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-08-18 20:07:46 -04:00 committed by Maureen Helm
commit 6f729383a8
2 changed files with 11 additions and 11 deletions

View file

@ -23,7 +23,7 @@
#endif #endif
#define TICK_SYNCH() k_sleep(K_MSEC(1)) #define TICK_SYNCH() k_sleep(K_TICKS(1))
#define OS_GET_TIME() k_cycle_get_32() #define OS_GET_TIME() k_cycle_get_32()
@ -59,27 +59,27 @@ static inline void bench_test_init(void)
/* timestamp for checks */ /* timestamp for checks */
static int64_t tCheck; static int64_t timestamp_check;
/* /*
* Routines are invoked before and after the benchmark and check * Routines are invoked before and after the benchmark and check
* if penchmarking code took less time than necessary for the * if benchmarking code took less time than necessary for the
* high precision timer register overflow. * high precision timer register overflow.
* Functions modify the tCheck global variable. * Functions modify the timestamp_check global variable.
*/ */
static inline void bench_test_start(void) static inline void bench_test_start(void)
{ {
tCheck = 0; timestamp_check = 0;
/* before reading time we synchronize to the start of the timer tick */ /* before reading time we synchronize to the start of the timer tick */
TICK_SYNCH(); TICK_SYNCH();
tCheck = k_uptime_delta(&tCheck); timestamp_check = k_uptime_delta(&timestamp_check);
} }
/* returns 0 if the completed within a second and -1 if not */ /* returns 0 if the completed within a second and -1 if not */
static inline int bench_test_end(void) static inline int bench_test_end(void)
{ {
tCheck = k_uptime_delta(&tCheck); timestamp_check = k_uptime_delta(&timestamp_check);
/* Flag an error if the test ran for more than a second. /* Flag an error if the test ran for more than a second.
* (Note: Existing benchmarks have CONFIG_SYS_CLOCK_TICKS_PER_SEC=1 set, * (Note: Existing benchmarks have CONFIG_SYS_CLOCK_TICKS_PER_SEC=1 set,
@ -87,7 +87,7 @@ static inline int bench_test_end(void)
* timer tick interrupt overheads too are getting accounted towards * timer tick interrupt overheads too are getting accounted towards
* benchmark time) * benchmark time)
*/ */
if (tCheck >= MSEC_PER_SEC) { if (timestamp_check >= MSEC_PER_SEC) {
return -1; return -1;
} }
return 0; return 0;
@ -104,7 +104,7 @@ static inline int high_timer_overflow(void)
/* Check if the time elapsed in msec is sufficient to trigger an /* Check if the time elapsed in msec is sufficient to trigger an
* overflow of the high precision timer * overflow of the high precision timer
*/ */
if (tCheck >= (k_cyc_to_ns_floor64(UINT_MAX) / if (timestamp_check >= (k_cyc_to_ns_floor64(UINT_MAX) /
(NSEC_PER_USEC * USEC_PER_MSEC))) { (NSEC_PER_USEC * USEC_PER_MSEC))) {
return -1; return -1;
} }

View file

@ -44,7 +44,7 @@ void begin_test(void)
{ {
/* /*
* Invoke bench_test_start in order to be able to use * Invoke bench_test_start in order to be able to use
* tCheck static variable. * timestamp_check static variable.
*/ */
bench_test_start(); bench_test_start();
} }
@ -61,7 +61,7 @@ void begin_test(void)
int check_result(int i, uint32_t t) int check_result(int i, uint32_t t)
{ {
/* /*
* bench_test_end checks tCheck static variable. * bench_test_end checks timestamp_check static variable.
* bench_test_start modifies it * bench_test_start modifies it
*/ */
if (bench_test_end() != 0) { if (bench_test_end() != 0) {