Skip to content
Browse files

tests/cmsis_rtos_v1: Correct timing assumptions

This test was written to assume that k_busy_wait() and CMSIS
osKernelSysTick() (which is just k_cycle_get_32()) were perfectly
synchronized.  On nRF, they aren't (one is the 32 kHz RTC timer, the
other is a calibrated spin loop using the CPU frequency).

When ticks were being reported at 100 Hz granularity, there wasn't
enough precision to detect the mismatch.  Now there is.  Rework the
test to require that the clocks match to within 1%.

Signed-off-by: Andy Ross <>
  • Loading branch information...
andyross authored and nashif committed Jun 16, 2019
1 parent ffb9e09 commit 33c64c2578d13bd5f63a777077f85a44f966d86e
Showing with 11 additions and 2 deletions.
  1. +11 −2 tests/cmsis_rtos_v1/src/kernel_apis.c
@@ -39,7 +39,7 @@ void test_kernel_start(void)
void test_kernel_systick(void)
u32_t start_time, stop_time, diff;
u32_t start_time, stop_time, diff, max, min;

start_time = osKernelSysTick();
@@ -48,5 +48,14 @@ void test_kernel_systick(void)
diff = SYS_CLOCK_HW_CYCLES_TO_NS(stop_time -
start_time) / NSEC_PER_USEC;

zassert_true(diff >= WAIT_TIME_US, NULL);
/* Check that it's within 1%. On some Zephyr platforms
* (e.g. nRF5x) the busy wait loop and the system timer are
* based on different mechanisms and may not align perfectly.
max = WAIT_TIME_US + (WAIT_TIME_US / 100);
min = WAIT_TIME_US - (WAIT_TIME_US / 100);

zassert_true(diff < max && diff > min,
"start %d stop %d (diff %d) wait %d\n",
start_time, stop_time, diff, WAIT_TIME_US);

0 comments on commit 33c64c2

Please sign in to comment.
You can’t perform that action at this time.