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 <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2023-03-09 21:38:48 -05:00 committed by Anas Nashif
parent e982bf71c5
commit a1d21ca69b

View file

@ -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)