Navigation Menu

Skip to content

Commit

Permalink
tests: timer_api: Fix timer synchronization
Browse files Browse the repository at this point in the history
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 6, 2019
1 parent 2fb19fc commit a45ce52
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/kernel/timer/timer_api/src/main.c
Expand Up @@ -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++) {
Expand Down

0 comments on commit a45ce52

Please sign in to comment.