tests: drivers: counter: fix no_alarm use case

In the test scenario without alarms, it might
be the case that counter is already running and
it will not match the expected tick.
This adds a tick offset into the expected value
based on current counter reading.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
Sylvio Alves 2024-10-09 21:27:02 -03:00 committed by Henrik Brix Andersen
parent 7668a4d27e
commit 5a205518a6
1 changed files with 5 additions and 0 deletions

View File

@ -684,6 +684,7 @@ static void test_valid_function_without_alarm(const struct device *dev)
int err;
uint32_t ticks;
uint32_t ticks_expected;
uint32_t tick_current;
uint32_t ticks_tol;
uint32_t wait_for_us;
uint32_t freq = counter_get_frequency(dev);
@ -725,6 +726,10 @@ static void test_valid_function_without_alarm(const struct device *dev)
err = counter_start(dev);
zassert_equal(0, err, "%s: counter failed to start", dev->name);
/* counter might not start from 0, use current value as offset */
counter_get_value(dev, &tick_current);
ticks_expected += tick_current;
k_busy_wait(wait_for_us);
err = counter_get_value(dev, &ticks);