From a1d21ca69bf471b06ebaad6ce2ec74a9b32724ef Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 9 Mar 2023 21:38:48 -0500 Subject: [PATCH] tests: timer_behavior: don't fail the test with timer wrap-arounds If the timer driver only implements sys_clock_cycle_get_32() (meaning CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER=n) and the hardware clock is high enough then the reported cycle count may wrap an uint32_t during the test. This makes validating the total test duration pointless as it cannot be measured. Just print a warning instead of failing the test in that case. Signed-off-by: Nicolas Pitre --- .../kernel/timer/timer_behavior/src/jitter_drift.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/kernel/timer/timer_behavior/src/jitter_drift.c b/tests/kernel/timer/timer_behavior/src/jitter_drift.c index a8c132cd48b..b1b6f818361 100644 --- a/tests/kernel/timer/timer_behavior/src/jitter_drift.c +++ b/tests/kernel/timer/timer_behavior/src/jitter_drift.c @@ -96,7 +96,7 @@ static uint64_t periodic_diff(uint64_t later, uint64_t earlier) { /* Timer wrap around, will be ignored in statistics */ if (later < earlier) { - TC_ERROR("Caught a timer wrap around which isn't handled!\n"); + TC_PRINT("WARNING: Caught a timer wrap-around !\n"); return 0; } @@ -249,9 +249,14 @@ static void do_test_using(void (*sample_collection_fn)(void)) zassert_true(stddev_us < (double)CONFIG_TIMER_TEST_MAX_STDDEV, "Standard deviation (in microseconds) outside expected bound"); - /* Validate the timer drift (accuracy over time) is within a configurable bound */ - zassert_true(abs(time_diff_us) < CONFIG_TIMER_TEST_MAX_DRIFT, - "Drift (in microseconds) outside expected bound"); + if (periodic_rollovers != 0) { + TC_PRINT("WARNING: the total time is bogus due to timer " + "rollovers and canot be validated\n"); + } else { + /* Validate the timer drift (accuracy over time) is within a configurable bound */ + zassert_true(abs(time_diff_us) < CONFIG_TIMER_TEST_MAX_DRIFT, + "Drift (in microseconds) outside expected bound"); + } } ZTEST(timer_jitter_drift, test_jitter_drift_timer_period)