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 <andrew.j.ross@intel.com>
This commit is contained in:
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user