summaryrefslogtreecommitdiff
path: root/examples/kernel/tc_comm.c
diff options
context:
space:
mode:
authorgeniusgogo <[email protected]>2013-12-22 21:31:12 +0800
committergeniusgogo <[email protected]>2013-12-22 21:31:12 +0800
commit4c463f27cbcb5e97099edea89b854831bb47bf30 (patch)
tree7143a798176fba7b5f1ceead99065a7a7d04476c /examples/kernel/tc_comm.c
parent7442414a74a909c4e60874c96eded1c739129778 (diff)
parent8b1b64567a090ae2df28ae677c896b14241780c2 (diff)
Merge branch 'master' into SQLite_on_ARMCC
Diffstat (limited to 'examples/kernel/tc_comm.c')
-rw-r--r--examples/kernel/tc_comm.c224
1 files changed, 119 insertions, 105 deletions
diff --git a/examples/kernel/tc_comm.c b/examples/kernel/tc_comm.c
index 60d843171f..c944755279 100644
--- a/examples/kernel/tc_comm.c
+++ b/examples/kernel/tc_comm.c
@@ -4,8 +4,8 @@
#endif
#ifdef RT_USING_TC
-#define TC_PRIORITY 25
-#define TC_STACK_SIZE 0x400
+#define TC_PRIORITY 25
+#define TC_STACK_SIZE 0x400
static rt_uint8_t _tc_stat;
static struct rt_semaphore _tc_sem;
@@ -20,156 +20,170 @@ FINSH_VAR_EXPORT(_tc_scale, finsh_type_int, the testcase timer timeout scale)
void tc_thread_entry(void* parameter)
{
- struct finsh_syscall* index;
+ unsigned int fail_count = 0;
+ struct finsh_syscall* index;
- /* create tc semaphore */
- rt_sem_init(&_tc_sem, "tc", 0, RT_IPC_FLAG_FIFO);
+ /* create tc semaphore */
+ rt_sem_init(&_tc_sem, "tc", 0, RT_IPC_FLAG_FIFO);
- while (_tc_stat & TC_STAT_RUNNING)
- {
- for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index))
- {
- /* search testcase */
- if (rt_strstr(index->name, _tc_prefix) == index->name)
- {
- long tick;
+ while (_tc_stat & TC_STAT_RUNNING)
+ {
+ for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index))
+ {
+ /* search testcase */
+ if (rt_strstr(index->name, _tc_prefix) == index->name)
+ {
+ long tick;
- _tc_current = index->name + 4;
- rt_kprintf("Run TestCase: %s\n", _tc_current);
- _tc_stat = TC_STAT_PASSED | TC_STAT_RUNNING;
- tick = index->func();
- if (tick > 0)
- {
- rt_sem_take(&_tc_sem, tick * _tc_scale);
+ _tc_current = index->name + 4;
+ rt_kprintf("Run TestCase: %s\n", _tc_current);
+ _tc_stat = TC_STAT_PASSED | TC_STAT_RUNNING;
+ tick = index->func();
+ if (tick > 0)
+ {
+ /* Make sure we are going to be blocked. */
+ rt_sem_control(&_tc_sem, RT_IPC_CMD_RESET, 0);
+ rt_sem_take(&_tc_sem, tick * _tc_scale);
+ }
- if (_tc_cleanup != RT_NULL)
- {
- /* perform testcase cleanup */
- _tc_cleanup();
- _tc_cleanup = RT_NULL;
- }
+ if (_tc_cleanup != RT_NULL)
+ {
+ /* perform testcase cleanup */
+ _tc_cleanup();
+ _tc_cleanup = RT_NULL;
+ }
- rt_sem_trytake(&_tc_sem);/* by nl1031 */
+ if (_tc_stat & TC_STAT_RUNNING)
+ {
+ rt_kprintf("TestCase[%s] exit with stat TC_STAT_RUNNING."
+ " Please fix the TC.\n",
+ _tc_current);
+ /* If the TC forgot to clear the flag, we do it. */
+ _tc_stat &= ~TC_STAT_RUNNING;
+ }
- if (_tc_stat & TC_STAT_FAILED)
- rt_kprintf("TestCase[%s] failed\n", _tc_current);
- else
- rt_kprintf("TestCase[%s] passed\n", _tc_current);
- }
- else
- {
- if (_tc_cleanup != RT_NULL)
- {
- /* perform testcase cleanup */
- _tc_cleanup();
- _tc_cleanup = RT_NULL;
- }
- }
- }
- }
- }
+ if (_tc_stat & TC_STAT_FAILED)
+ {
+ rt_kprintf("TestCase[%s] failed\n", _tc_current);
+ fail_count++;
+ }
+ else
+ {
+ rt_kprintf("TestCase[%s] passed\n", _tc_current);
+ }
+ }
+ }
+ }
- rt_kprintf("RT-Thread TestCase Running Done!\n");
- /* detach tc semaphore */
- rt_sem_detach(&_tc_sem);
+ rt_kprintf("RT-Thread TestCase Running Done!\n");
+ if (fail_count)
+ {
+ rt_kprintf("%d tests failed\n", fail_count);
+ }
+ else
+ {
+ rt_kprintf("All tests passed\n");
+ }
+ /* detach tc semaphore */
+ rt_sem_detach(&_tc_sem);
}
void tc_stop()
{
- _tc_stat &= ~TC_STAT_RUNNING;
+ _tc_stat &= ~TC_STAT_RUNNING;
- rt_thread_delay(RT_TICK_PER_SECOND/2);
- if (_tc_thread.stat != RT_THREAD_INIT)
- {
- /* lock scheduler */
- rt_enter_critical();
+ rt_thread_delay(RT_TICK_PER_SECOND/2);
+ if (_tc_thread.stat != RT_THREAD_INIT)
+ {
+ /* lock scheduler */
+ rt_enter_critical();
- /* detach old tc thread */
- rt_thread_detach(&_tc_thread);
- rt_sem_detach(&_tc_sem);
+ /* detach old tc thread */
+ rt_thread_detach(&_tc_thread);
+ rt_sem_detach(&_tc_sem);
- /* unlock scheduler */
- rt_exit_critical();
- }
- rt_thread_delay(RT_TICK_PER_SECOND/2);
+ /* unlock scheduler */
+ rt_exit_critical();
+ }
+ rt_thread_delay(RT_TICK_PER_SECOND/2);
}
FINSH_FUNCTION_EXPORT(tc_stop, stop testcase thread);
void tc_done(rt_uint8_t stat)
{
- _tc_stat |= stat;
- _tc_stat &= ~TC_STAT_RUNNING;
+ _tc_stat |= stat;
+ _tc_stat &= ~TC_STAT_RUNNING;
- /* release semaphore */
- rt_sem_release(&_tc_sem);
+ /* release semaphore */
+ rt_sem_release(&_tc_sem);
}
void tc_stat(rt_uint8_t stat)
{
- if (stat & TC_STAT_FAILED)
- {
- rt_kprintf("TestCases[%s] failed\n", _tc_current);
- }
- _tc_stat |= stat;
+ if (stat & TC_STAT_FAILED)
+ {
+ rt_kprintf("TestCases[%s] failed\n", _tc_current);
+ }
+ _tc_stat |= stat;
}
void tc_cleanup(void (*cleanup)())
{
- _tc_cleanup = cleanup;
+ _tc_cleanup = cleanup;
}
void tc_start(const char* tc_prefix)
{
- rt_err_t result;
+ rt_err_t result;
- /* tesecase prefix is null */
- if (tc_prefix == RT_NULL)
- {
- rt_kprintf("TestCase Usage: tc_start(prefix)\n\n");
- rt_kprintf("list_tc() can list all testcases.\n");
- return ;
- }
+ /* tesecase prefix is null */
+ if (tc_prefix == RT_NULL)
+ {
+ rt_kprintf("TestCase Usage: tc_start(prefix)\n\n");
+ rt_kprintf("list_tc() can list all testcases.\n");
+ return ;
+ }
- /* init tc thread */
- if (_tc_stat & TC_STAT_RUNNING)
- {
- /* stop old tc thread */
- tc_stop();
- }
+ /* init tc thread */
+ if (_tc_stat & TC_STAT_RUNNING)
+ {
+ /* stop old tc thread */
+ tc_stop();
+ }
- rt_memset(_tc_prefix, 0, sizeof(_tc_prefix));
- rt_snprintf(_tc_prefix, sizeof(_tc_prefix), "_tc_%s", tc_prefix);
+ rt_memset(_tc_prefix, 0, sizeof(_tc_prefix));
+ rt_snprintf(_tc_prefix, sizeof(_tc_prefix), "_tc_%s", tc_prefix);
- result = rt_thread_init(&_tc_thread, "tc",
- tc_thread_entry, RT_NULL,
- &_tc_stack[0], sizeof(_tc_stack),
- TC_PRIORITY - 3, 5);
+ result = rt_thread_init(&_tc_thread, "tc",
+ tc_thread_entry, RT_NULL,
+ &_tc_stack[0], sizeof(_tc_stack),
+ TC_PRIORITY - 3, 5);
- /* set tc stat */
- _tc_stat = TC_STAT_RUNNING | TC_STAT_FAILED;
+ /* set tc stat */
+ _tc_stat = TC_STAT_RUNNING | TC_STAT_FAILED;
- if (result == RT_EOK)
- rt_thread_startup(&_tc_thread);
+ if (result == RT_EOK)
+ rt_thread_startup(&_tc_thread);
}
FINSH_FUNCTION_EXPORT(tc_start, start testcase with testcase prefix or name);
void list_tc()
{
- struct finsh_syscall* index;
+ struct finsh_syscall* index;
- rt_kprintf("TestCases List:\n");
- for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index))
- {
- /* search testcase */
- if (rt_strstr(index->name, "_tc_") == index->name)
- {
+ rt_kprintf("TestCases List:\n");
+ for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index))
+ {
+ /* search testcase */
+ if (rt_strstr(index->name, "_tc_") == index->name)
+ {
#ifdef FINSH_USING_DESCRIPTION
- rt_kprintf("%-16s -- %s\n", index->name + 4, index->desc);
+ rt_kprintf("%-16s -- %s\n", index->name + 4, index->desc);
#else
- rt_kprintf("%s\n", index->name + 4);
+ rt_kprintf("%s\n", index->name + 4);
#endif
- }
- }
+ }
+ }
}
FINSH_FUNCTION_EXPORT(list_tc, list all testcases);
#endif