Skip to content

Commit

Permalink
tests/cmsis_rtos_v1: Correct timing assumptions
Browse files Browse the repository at this point in the history
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 <andrew.j.ross@intel.com>
  • Loading branch information
Andy Ross authored and nashif committed Jul 3, 2019
1 parent ffb9e09 commit 33c64c2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/cmsis_rtos_v1/src/kernel_apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
k_busy_wait(WAIT_TIME_US);
Expand All @@ -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.