Skip to content

Commit 04e8d08

Browse files
nordic-krchkartben
authored andcommitted
tests: kernel: timer: timer_api: Tweak test_timer_remaining
Test test_timer_remaining is comparing time captured by k_busy_wait and k_timer_remaining_ticks. Test was accepting 1 tick difference between those two. If system clock frequency is low (e.g. 100 Hz) 1 tick is a long time but if system clock is high then 1 tick may not cover for processing latency. Instead of using fixed 1 tick test is now converting 100 us to ticks (ceiling) to cover for cases where system clock is high. 100 us processing latency time is an arbitrary value. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
1 parent 2e711aa commit 04e8d08

File tree

1 file changed

+11
-1
lines changed
  • tests/kernel/timer/timer_api/src

1 file changed

+11
-1
lines changed

tests/kernel/timer/timer_api/src/main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,20 @@ ZTEST_USER(timer_api, test_timer_remaining)
680680
uint32_t dur_ticks = k_ms_to_ticks_ceil32(DURATION);
681681
uint32_t target_rem_ticks = k_ms_to_ticks_ceil32(DURATION / 2);
682682
uint32_t rem_ms, rem_ticks, exp_ticks;
683+
uint32_t latency_ticks;
683684
int32_t delta_ticks;
684685
uint32_t slew_ticks;
685686
uint64_t now;
686687

688+
/* Test is running in a user space thread so there is an additional latency
689+
* involved in executing k_busy_wait and k_timer_remaining_ticks. Due
690+
* to that latency, returned ticks won't be exact as expected even if
691+
* k_busy_wait is running using the same clock source as the system clock.
692+
* If system clock frequency is low (e.g. 100Hz) 1 tick will be enough but
693+
* for cases where clock frequency is much higher we need to accept higher
694+
* deviation (in ticks). Arbitrary value of 100 us processing overhead is used.
695+
*/
696+
latency_ticks = k_us_to_ticks_ceil32(100);
687697

688698
init_timer_data();
689699
k_timer_start(&remain_timer, K_MSEC(DURATION), K_NO_WAIT);
@@ -713,7 +723,7 @@ ZTEST_USER(timer_api, test_timer_remaining)
713723
*/
714724
delta_ticks = (int32_t)(rem_ticks - target_rem_ticks);
715725
slew_ticks = BUSY_SLEW_THRESHOLD_TICKS(DURATION * USEC_PER_MSEC / 2U);
716-
zassert_true(abs(delta_ticks) <= MAX(slew_ticks, 1U),
726+
zassert_true(abs(delta_ticks) <= MAX(slew_ticks, latency_ticks),
717727
"tick/busy slew %d larger than test threshold %u",
718728
delta_ticks, slew_ticks);
719729

0 commit comments

Comments
 (0)