diff options
Diffstat (limited to 'examples/kernel')
| -rw-r--r-- | examples/kernel/SConscript | 4 | ||||
| -rw-r--r-- | examples/kernel/tc_comm.c | 1 | ||||
| -rw-r--r-- | examples/kernel/tc_sample.c | 62 | ||||
| -rw-r--r-- | examples/kernel/thread_delete.c | 45 | ||||
| -rw-r--r-- | examples/kernel/thread_detach.c | 5 | ||||
| -rw-r--r-- | examples/kernel/thread_priority.c | 2 | ||||
| -rw-r--r-- | examples/kernel/thread_resume.c | 20 | ||||
| -rw-r--r-- | examples/kernel/thread_suspend.c | 1 | ||||
| -rw-r--r-- | examples/kernel/thread_yield.c | 2 |
9 files changed, 130 insertions, 12 deletions
diff --git a/examples/kernel/SConscript b/examples/kernel/SConscript index f07ccbb84b..3610085157 100644 --- a/examples/kernel/SConscript +++ b/examples/kernel/SConscript @@ -31,9 +31,9 @@ timer_timeout.c heap_malloc.c
heap_realloc.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')
diff --git a/examples/kernel/tc_comm.c b/examples/kernel/tc_comm.c index 47d3435932..de9bb3ce31 100644 --- a/examples/kernel/tc_comm.c +++ b/examples/kernel/tc_comm.c @@ -67,6 +67,7 @@ void tc_thread_entry(void* parameter) }
}
+ rt_kprintf("RT-Thread TestCase Running Done!\n");
/* detach tc semaphore */
rt_sem_detach(&_tc_sem);
}
diff --git a/examples/kernel/tc_sample.c b/examples/kernel/tc_sample.c new file mode 100644 index 0000000000..ea77ccda39 --- /dev/null +++ b/examples/kernel/tc_sample.c @@ -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 diff --git a/examples/kernel/thread_delete.c b/examples/kernel/thread_delete.c index 994c5e84dd..a394f282d0 100644 --- a/examples/kernel/thread_delete.c +++ b/examples/kernel/thread_delete.c @@ -20,9 +20,20 @@ static void thread1_entry(void* parameter) while (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的入口函数 */
static void thread2_entry(void* parameter)
@@ -37,19 +48,29 @@ static void thread2_entry(void* parameter) * 队列
*/
rt_thread_delete(tid1);
- tid1 = RT_NULL;
/*
* 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
* idle线程将执行真正的线程1控制块和线程栈的删除
*/
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;
+ tc_done(TC_STAT_PASSED);
}
/* 线程删除示例的初始化 */
@@ -60,7 +81,10 @@ int thread_delete_init() thread1_entry, RT_NULL, /* 入口是thread1_entry,参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid1 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */
+ {
+ tid1->cleanup = thread1_cleanup;
rt_thread_startup(tid1);
+ }
else
tc_stat(TC_STAT_END | TC_STAT_FAILED);
@@ -69,7 +93,10 @@ int thread_delete_init() thread2_entry, RT_NULL, /* 入口是thread2_entry,参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
if (tid2 != RT_NULL) /* 如果获得线程控制块,启动这个线程 */
+ {
+ tid2->cleanup = thread2_cleanup;
rt_thread_startup(tid2);
+ }
else
tc_stat(TC_STAT_END | TC_STAT_FAILED);
@@ -83,10 +110,16 @@ static void _tc_cleanup() rt_enter_critical();
/* 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);
- if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
+ }
+ if (tid2 != RT_NULL)
+ {
+ rt_kprintf("tid2 is bad\n");
tc_stat(TC_STAT_FAILED);
+ }
/* unlock scheduler */
rt_exit_critical();
@@ -98,7 +131,7 @@ int _tc_thread_delete() tc_cleanup(_tc_cleanup);
thread_delete_init();
- return 100;
+ return 25;
}
FINSH_FUNCTION_EXPORT(_tc_thread_delete, a thread delete example);
#else
diff --git a/examples/kernel/thread_detach.c b/examples/kernel/thread_detach.c index ac7a92558e..84c85977fb 100644 --- a/examples/kernel/thread_detach.c +++ b/examples/kernel/thread_detach.c @@ -91,6 +91,9 @@ static void _tc_cleanup() /* 调度器解锁 */
rt_exit_critical();
+
+ /* 设置TestCase状态 */
+ tc_done(TC_STAT_PASSED);
}
int _tc_thread_detach()
@@ -100,7 +103,7 @@ int _tc_thread_detach() thread_detach_init();
/* 返回TestCase运行的最长时间 */
- return 100;
+ return 25;
}
/* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_detach, a static thread example);
diff --git a/examples/kernel/thread_priority.c b/examples/kernel/thread_priority.c index c64e329a6f..6d0692e4dc 100644 --- a/examples/kernel/thread_priority.c +++ b/examples/kernel/thread_priority.c @@ -28,7 +28,7 @@ static void thread2_entry(void* parameter) tick = rt_tick_get();
while (1)
{
- if (rt_tick_get() - tick >= 100)
+ if (rt_tick_get() - tick >= 50)
{
if (count == 0)
tc_done(TC_STAT_FAILED);
diff --git a/examples/kernel/thread_resume.c b/examples/kernel/thread_resume.c index 23dfcdc132..e0ed6fa5f7 100644 --- a/examples/kernel/thread_resume.c +++ b/examples/kernel/thread_resume.c @@ -25,6 +25,17 @@ static void thread1_entry(void* parameter) /* 当线程1被唤醒时 */
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入口 */
static void thread2_entry(void* parameter)
@@ -34,6 +45,7 @@ static void thread2_entry(void* parameter) /* 唤醒线程1 */
rt_thread_resume(tid1);
+ rt_kprintf("thread2: to resume thread1\n");
/* 延时10个OS Tick */
rt_thread_delay(10);
@@ -48,7 +60,10 @@ int thread_resume_init() thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid1 != RT_NULL)
+ {
+ tid1->cleanup = thread_cleanup;
rt_thread_startup(tid1);
+ }
else
tc_stat(TC_STAT_END | TC_STAT_FAILED);
@@ -57,7 +72,10 @@ int thread_resume_init() thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
if (tid2 != RT_NULL)
+ {
+ tid2->cleanup = thread_cleanup;
rt_thread_startup(tid2);
+ }
else
tc_stat(TC_STAT_END | TC_STAT_FAILED);
@@ -90,7 +108,7 @@ int _tc_thread_resume() thread_resume_init();
/* 返回TestCase运行的最长时间 */
- return 100;
+ return 25;
}
/* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_resume, a thread resume example);
diff --git a/examples/kernel/thread_suspend.c b/examples/kernel/thread_suspend.c index 2be237a2a5..b38cb8fdfb 100644 --- a/examples/kernel/thread_suspend.c +++ b/examples/kernel/thread_suspend.c @@ -34,6 +34,7 @@ static void thread2_entry(void* parameter) rt_thread_delay(10);
/* 线程2自动退出 */
+ tid2 = RT_NULL;
}
int thread_suspend_init()
diff --git a/examples/kernel/thread_yield.c b/examples/kernel/thread_yield.c index e9fb7f57f9..71244589b8 100644 --- a/examples/kernel/thread_yield.c +++ b/examples/kernel/thread_yield.c @@ -86,7 +86,7 @@ int _tc_thread_yield() thread_yield_init();
/* 返回TestCase运行的最长时间 */
- return 100;
+ return 30;
}
/* 输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT(_tc_thread_yield, a thread yield example);
|
