提交 d28cdf68 编写于 作者: B bernard.xiong@gmail.com

update testcase for kernel.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1849 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 212d828d
...@@ -31,9 +31,9 @@ timer_timeout.c ...@@ -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')
...@@ -67,6 +67,7 @@ void tc_thread_entry(void* parameter) ...@@ -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);
} }
......
#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
...@@ -20,9 +20,20 @@ static void thread1_entry(void* parameter) ...@@ -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) ...@@ -37,19 +48,29 @@ static void thread2_entry(void* parameter)
* 队列 * 队列
*/ */
rt_thread_delete(tid1); rt_thread_delete(tid1);
tid1 = RT_NULL;
/* /*
* 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程 * 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
* 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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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
......
...@@ -91,6 +91,9 @@ static void _tc_cleanup() ...@@ -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() ...@@ -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);
......
...@@ -28,7 +28,7 @@ static void thread2_entry(void* parameter) ...@@ -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);
......
...@@ -25,6 +25,17 @@ static void thread1_entry(void* parameter) ...@@ -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) ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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);
......
...@@ -34,6 +34,7 @@ static void thread2_entry(void* parameter) ...@@ -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()
......
...@@ -86,7 +86,7 @@ int _tc_thread_yield() ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册