From a45ce52253d32f710fe280810bfa2d92b2c8ab82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Zi=C4=99cik?= Date: Mon, 3 Jun 2019 17:39:43 +0200 Subject: [PATCH] tests: timer_api: Fix timer synchronization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/kernel/timer/timer_api/src/main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/kernel/timer/timer_api/src/main.c b/tests/kernel/timer/timer_api/src/main.c index ffa7ba76619082..633a853136f359 100644 --- a/tests/kernel/timer/timer_api/src/main.c +++ b/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++) {