Browse Source

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>
pull/79775/head
Sylvio Alves 9 months ago committed by Henrik Brix Andersen
parent
commit
5a205518a6
  1. 5
      tests/drivers/counter/counter_basic_api/src/test_counter.c

5
tests/drivers/counter/counter_basic_api/src/test_counter.c

@ -684,6 +684,7 @@ static void test_valid_function_without_alarm(const struct device *dev) @@ -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) @@ -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);

Loading…
Cancel
Save