From 1a8f9cb0b324a6dde08ee7a9f544b97d2cbc8a1b Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Thu, 1 Feb 2024 09:46:02 +0100 Subject: [PATCH] [nrf fromlist] tests: drivers: timer: grtc: Fix GRTC test The `z_nrf_grtc_timer_get_ticks()` function converts system ticks to GRTC ticks. It gets the current system tick to calculate an absolute GRTC value. The same does the test function to provide an argument to be converted. If the system tick occurs between those `sys_clock_tick_get()` calls the `z_nrf_grtc_timer_get_ticks()` will take into account the newer tick while the test estimate bases on the old tick value. Due to that the maximum result error is 1 system tick minus 1 GRTC tick which equals (`CYC_PER_TICK` - 1) for GRTC ticks. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/71688 Signed-off-by: Adam Kondraciuk --- tests/drivers/timer/nrf_grtc_timer/src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/drivers/timer/nrf_grtc_timer/src/main.c b/tests/drivers/timer/nrf_grtc_timer/src/main.c index e6621316666..f8d33d8c53a 100644 --- a/tests/drivers/timer/nrf_grtc_timer/src/main.c +++ b/tests/drivers/timer/nrf_grtc_timer/src/main.c @@ -24,6 +24,8 @@ ZTEST(nrf_grtc_timer, test_get_ticks) zassert_true((ticks >= exp_ticks) && (ticks <= (exp_ticks + GRTC_SLEW_TICKS)), "Unexpected result %" PRId64 " (expected: %" PRId64 ")", ticks, exp_ticks); + k_msleep(1); + for (uint32_t i = 0; i < NUMBER_OF_TRIES; i++) { /* Absolute timeout 1ms in the past */ t = Z_TIMEOUT_TICKS(Z_TICK_ABS(sys_clock_tick_get() - K_MSEC(1).ticks));