Skip to content
Permalink
Browse files

tests: timer_api: Fix timer synchronization

The test_timer_periodicity waits for first timer expiration
in order to extract timer firing time. The wait is performed
using k_timer_status_sync() API call, which blocks thread
until timer expiration. However if the timer expired before
call the this function, it will return immediately, triggering
test failure.

This commit adds the second call to the k_timer_status_sync()
to ensure that the following part of the test will be executed
as soon as possible after timer expiration.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
  • Loading branch information...
pizi-nordic authored and nashif committed Jun 3, 2019
1 parent 2fb19fc commit a45ce52253d32f710fe280810bfa2d92b2c8ab82
Showing with 5 additions and 1 deletion.
  1. +5 −1 tests/kernel/timer/timer_api/src/main.c
@@ -245,9 +245,13 @@ void test_timer_periodicity(void)
k_timer_start(&periodicity_timer, 0, PERIOD);

/* clear the expiration that would have happenned due to
* whatever duration that was set.
* whatever duration that was set. Since timer is likely
* to fire before call to k_timer_status_sync(), we have
* to synchronize twice to ensure that the timestamp will
* be fetched as soon as possible after timer firing.
*/
k_timer_status_sync(&periodicity_timer);
k_timer_status_sync(&periodicity_timer);
tdata.timestamp = k_uptime_get();

for (int i = 0; i < EXPIRE_TIMES; i++) {

0 comments on commit a45ce52

Please sign in to comment.
You can’t perform that action at this time.