TC: more tolerate for tick in TC thread

This commit is contained in:
Grissiom 2013-12-21 13:18:09 +08:00
parent f7b1421880
commit f6bf69f233
3 changed files with 17 additions and 13 deletions

View File

@ -27,9 +27,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_detach(&sem);
return;

View File

@ -14,7 +14,7 @@ static void thread_entry(void* parameter)
rt_kprintf("thread delay 10 tick\n");
tick = rt_tick_get();
rt_thread_delay(10);
if (rt_tick_get() - tick > 10)
if (rt_tick_get() - tick > 11)
{
tc_done(TC_STAT_FAILED);
return;
@ -23,7 +23,7 @@ static void thread_entry(void* parameter)
rt_kprintf("thread delay 15 tick\n");
tick = rt_tick_get();
rt_thread_delay(15);
if (rt_tick_get() - tick > 15)
if (rt_tick_get() - tick > 16)
{
tc_done(TC_STAT_FAILED);
return;

View File

@ -45,21 +45,21 @@ int thread_priority_init()
rt_err_t result;
result = rt_thread_init(&thread1,
"t1",
thread1_entry, RT_NULL,
&thread1_stack[0], sizeof(thread1_stack),
THREAD_PRIORITY - 1, THREAD_TIMESLICE);
"t1",
thread1_entry, RT_NULL,
&thread1_stack[0], sizeof(thread1_stack),
THREAD_PRIORITY - 1, THREAD_TIMESLICE);
if (result == RT_EOK)
rt_thread_startup(&thread1);
else
tc_stat(TC_STAT_FAILED);
rt_thread_init(&thread2,
"t2",
thread2_entry, RT_NULL,
&thread2_stack[0], sizeof(thread2_stack),
THREAD_PRIORITY + 1, THREAD_TIMESLICE);
"t2",
thread2_entry, RT_NULL,
&thread2_stack[0], sizeof(thread2_stack),
THREAD_PRIORITY + 1, THREAD_TIMESLICE);
if (result == RT_EOK)
rt_thread_startup(&thread2);