From ac0e10bb839eb1dc196a96ba7a09e03a2daf853e Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 21 Dec 2013 12:40:54 +0800 Subject: [PATCH] TC: more tolerate on the timeout tick in semaphore_dynamic With system that has RT_TICK_PER_SECOND is 1000, it's easy to get one tick error. --- examples/kernel/semaphore_dynamic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/kernel/semaphore_dynamic.c b/examples/kernel/semaphore_dynamic.c index 579d9daa9a..16c87a4240 100644 --- a/examples/kernel/semaphore_dynamic.c +++ b/examples/kernel/semaphore_dynamic.c @@ -25,9 +25,13 @@ static void thread_entry(void* parameter) result = rt_sem_take(sem, 10); if (result == -RT_ETIMEOUT) { - /* 判断是否刚好过去10个OS Tick */ - if (rt_tick_get() - tick != 10) + rt_tick_t new_tick = rt_tick_get(); + /* 可以有两个 tick 的误差 */ + if (new_tick - tick >= 12) { + rt_kprintf("tick error to large: expect: 10, get %d\n", + new_tick - tick); + /* 如果失败,则测试失败 */ tc_done(TC_STAT_FAILED); rt_sem_delete(sem);