update testcase for kernel.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1849 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2011-12-19 07:08:06 +00:00
parent 212d828d3f
commit d28cdf68d9
9 changed files with 130 additions and 12 deletions

View File

@ -31,9 +31,9 @@ timer_timeout.c
heap_malloc.c heap_malloc.c
heap_realloc.c heap_realloc.c
memp_simple.c memp_simple.c
tc_sample.c
""") """)
CPPDEFINES = ['RT_USING_TC']
group = DefineGroup('examples', src, depend = [''], CPPDEFINES = CPPDEFINES) group = DefineGroup('examples', src, depend = ['RT_USING_TC'])
Return('group') Return('group')

View File

@ -67,6 +67,7 @@ void tc_thread_entry(void* parameter)
} }
} }
rt_kprintf("RT-Thread TestCase Running Done!\n");
/* detach tc semaphore */ /* detach tc semaphore */
rt_sem_detach(&_tc_sem); rt_sem_detach(&_tc_sem);
} }

View File

@ -0,0 +1,62 @@
#include <rtthread.h>
#include "tc_comm.h"
static rt_thread_t tid = RT_NULL;
static void sample_thread(void* parameter)
{
rt_kprintf("I'm sample!\n");
}
static void sample_thread_cleanup(struct rt_thread *p)
{
tid = RT_NULL;
tc_done(TC_STAT_PASSED);
}
int sample_init()
{
tid = rt_thread_create("t",
sample_thread, RT_NULL,
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid != RT_NULL)
{
rt_thread_startup(tid);
tid->cleanup = sample_thread_cleanup;
}
else
tc_stat(TC_STAT_END | TC_STAT_FAILED);
return 0;
}
#ifdef RT_USING_TC
static void _tc_cleanup()
{
/* lock scheduler */
rt_enter_critical();
/* delete thread */
if (tid != RT_NULL)
{
rt_kprintf("tid1 is bad\n");
tc_stat(TC_STAT_FAILED);
}
/* unlock scheduler */
rt_exit_critical();
}
int _tc_sample()
{
/* set tc cleanup */
tc_cleanup(_tc_cleanup);
sample_init();
return 25;
}
FINSH_FUNCTION_EXPORT(_tc_sample, a thread testcase example);
#else
int rt_application_init()
{
sample_init();
return 0;
}
#endif

View File

@ -20,9 +20,20 @@ static void thread1_entry(void* parameter)
while (1) while (1)
{ {
/* 线程1采用低优先级运行一直打印计数值 */ /* 线程1采用低优先级运行一直打印计数值 */
rt_kprintf("thread count: %d\n", count ++); // rt_kprintf("thread count: %d\n", count ++);
count ++;
} }
} }
static void thread1_cleanup(struct rt_thread *tid)
{
if (tid != tid1)
{
tc_stat(TC_STAT_END | TC_STAT_FAILED);
return ;
}
rt_kprintf("thread1 end\n");
tid1 = RT_NULL;
}
/* 线程2的入口函数 */ /* 线程2的入口函数 */
static void thread2_entry(void* parameter) static void thread2_entry(void* parameter)
@ -37,19 +48,29 @@ static void thread2_entry(void* parameter)
* *
*/ */
rt_thread_delete(tid1); rt_thread_delete(tid1);
tid1 = RT_NULL;
/* /*
* 线210OS Tick然后退出线2idle线程 * 线210OS Tick然后退出线2idle线程
* idle线程将执行真正的线程1控制块和线程栈的删除 * idle线程将执行真正的线程1控制块和线程栈的删除
*/ */
rt_thread_delay(10); rt_thread_delay(10);
}
static void thread2_cleanup(struct rt_thread *tid)
{
/* /*
* 线2(线线idle线 * 线2(线线idle线
* ) * )
*/ */
if (tid != tid2)
{
tc_stat(TC_STAT_END | TC_STAT_FAILED);
return ;
}
rt_kprintf("thread2 end\n");
tid2 = RT_NULL; tid2 = RT_NULL;
tc_done(TC_STAT_PASSED);
} }
/* 线程删除示例的初始化 */ /* 线程删除示例的初始化 */
@ -60,7 +81,10 @@ int thread_delete_init()
thread1_entry, RT_NULL, /* 入口是thread1_entry参数是RT_NULL */ thread1_entry, RT_NULL, /* 入口是thread1_entry参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid1 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */ if (tid1 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */
{
tid1->cleanup = thread1_cleanup;
rt_thread_startup(tid1); rt_thread_startup(tid1);
}
else else
tc_stat(TC_STAT_END | TC_STAT_FAILED); tc_stat(TC_STAT_END | TC_STAT_FAILED);
@ -69,7 +93,10 @@ int thread_delete_init()
thread2_entry, RT_NULL, /* 入口是thread2_entry参数是RT_NULL */ thread2_entry, RT_NULL, /* 入口是thread2_entry参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE); THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
if (tid2 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */ if (tid2 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */
{
tid2->cleanup = thread2_cleanup;
rt_thread_startup(tid2); rt_thread_startup(tid2);
}
else else
tc_stat(TC_STAT_END | TC_STAT_FAILED); tc_stat(TC_STAT_END | TC_STAT_FAILED);
@ -83,10 +110,16 @@ static void _tc_cleanup()
rt_enter_critical(); rt_enter_critical();
/* delete thread */ /* delete thread */
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE) if (tid1 != RT_NULL)
{
rt_kprintf("tid1 is bad\n");
tc_stat(TC_STAT_FAILED); tc_stat(TC_STAT_FAILED);
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE) }
if (tid2 != RT_NULL)
{
rt_kprintf("tid2 is bad\n");
tc_stat(TC_STAT_FAILED); tc_stat(TC_STAT_FAILED);
}
/* unlock scheduler */ /* unlock scheduler */
rt_exit_critical(); rt_exit_critical();
@ -98,7 +131,7 @@ int _tc_thread_delete()
tc_cleanup(_tc_cleanup); tc_cleanup(_tc_cleanup);
thread_delete_init(); thread_delete_init();
return 100; return 25;
} }
FINSH_FUNCTION_EXPORT(_tc_thread_delete, a thread delete example); FINSH_FUNCTION_EXPORT(_tc_thread_delete, a thread delete example);
#else #else

View File

@ -91,6 +91,9 @@ static void _tc_cleanup()
/* 调度器解锁 */ /* 调度器解锁 */
rt_exit_critical(); rt_exit_critical();
/* 设置TestCase状态 */
tc_done(TC_STAT_PASSED);
} }
int _tc_thread_detach() int _tc_thread_detach()
@ -100,7 +103,7 @@ int _tc_thread_detach()
thread_detach_init(); thread_detach_init();
/* 返回TestCase运行的最长时间 */ /* 返回TestCase运行的最长时间 */
return 100; return 25;
} }
/* 输出函数命令到finsh shell中 */ /* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_detach, a static thread example); FINSH_FUNCTION_EXPORT(_tc_thread_detach, a static thread example);

View File

@ -28,7 +28,7 @@ static void thread2_entry(void* parameter)
tick = rt_tick_get(); tick = rt_tick_get();
while (1) while (1)
{ {
if (rt_tick_get() - tick >= 100) if (rt_tick_get() - tick >= 50)
{ {
if (count == 0) if (count == 0)
tc_done(TC_STAT_FAILED); tc_done(TC_STAT_FAILED);

View File

@ -25,6 +25,17 @@ static void thread1_entry(void* parameter)
/* 当线程1被唤醒时 */ /* 当线程1被唤醒时 */
rt_kprintf("thread1 resumed\n"); rt_kprintf("thread1 resumed\n");
} }
static void thread_cleanup(rt_thread_t tid)
{
if (tid == tid1)
{
tid1 = RT_NULL;
}
if (tid == tid2)
{
tid = RT_NULL;
}
}
/* 线程2入口 */ /* 线程2入口 */
static void thread2_entry(void* parameter) static void thread2_entry(void* parameter)
@ -34,6 +45,7 @@ static void thread2_entry(void* parameter)
/* 唤醒线程1 */ /* 唤醒线程1 */
rt_thread_resume(tid1); rt_thread_resume(tid1);
rt_kprintf("thread2: to resume thread1\n");
/* 延时10个OS Tick */ /* 延时10个OS Tick */
rt_thread_delay(10); rt_thread_delay(10);
@ -48,7 +60,10 @@ int thread_resume_init()
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */ thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid1 != RT_NULL) if (tid1 != RT_NULL)
{
tid1->cleanup = thread_cleanup;
rt_thread_startup(tid1); rt_thread_startup(tid1);
}
else else
tc_stat(TC_STAT_END | TC_STAT_FAILED); tc_stat(TC_STAT_END | TC_STAT_FAILED);
@ -57,7 +72,10 @@ int thread_resume_init()
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */ thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE); THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
if (tid2 != RT_NULL) if (tid2 != RT_NULL)
{
tid2->cleanup = thread_cleanup;
rt_thread_startup(tid2); rt_thread_startup(tid2);
}
else else
tc_stat(TC_STAT_END | TC_STAT_FAILED); tc_stat(TC_STAT_END | TC_STAT_FAILED);
@ -90,7 +108,7 @@ int _tc_thread_resume()
thread_resume_init(); thread_resume_init();
/* 返回TestCase运行的最长时间 */ /* 返回TestCase运行的最长时间 */
return 100; return 25;
} }
/* 输出函数命令到finsh shell中 */ /* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_resume, a thread resume example); FINSH_FUNCTION_EXPORT(_tc_thread_resume, a thread resume example);

View File

@ -34,6 +34,7 @@ static void thread2_entry(void* parameter)
rt_thread_delay(10); rt_thread_delay(10);
/* 线程2自动退出 */ /* 线程2自动退出 */
tid2 = RT_NULL;
} }
int thread_suspend_init() int thread_suspend_init()

View File

@ -86,7 +86,7 @@ int _tc_thread_yield()
thread_yield_init(); thread_yield_init();
/* 返回TestCase运行的最长时间 */ /* 返回TestCase运行的最长时间 */
return 100; return 30;
} }
/* 输出函数命令到finsh shell中 */ /* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_yield, a thread yield example); FINSH_FUNCTION_EXPORT(_tc_thread_yield, a thread yield example);