1 #include <rtthread.h> 2 #include "tc_comm.h" 3 4 static rt_thread_t tid = RT_NULL; 5 static void sample_thread(void* parameter) 6 { 7 rt_kprintf("I'm sample!\n"); 8 } 9 static void sample_thread_cleanup(struct rt_thread *p) 10 { 11 tid = RT_NULL; 12 tc_done(TC_STAT_PASSED); 13 } 14 15 int sample_init() 16 { 17 tid = rt_thread_create("t", 18 sample_thread, RT_NULL, 19 THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); 20 if (tid != RT_NULL) 21 { 22 rt_thread_startup(tid); 23 tid->cleanup = sample_thread_cleanup; 24 } 25 else 26 tc_stat(TC_STAT_END | TC_STAT_FAILED); 27 28 return 0; 29 } 30 31 #ifdef RT_USING_TC 32 static void _tc_cleanup() 33 { 34 /* lock scheduler */ 35 rt_enter_critical(); 36 /* delete thread */ 37 if (tid != RT_NULL) 38 { 39 rt_kprintf("tid1 is bad\n"); 40 tc_stat(TC_STAT_FAILED); 41 } 42 /* unlock scheduler */ 43 rt_exit_critical(); 44 } 45 46 int _tc_sample() 47 { 48 /* set tc cleanup */ 49 tc_cleanup(_tc_cleanup); 50 sample_init(); 51 52 return 25; 53 } 54 FINSH_FUNCTION_EXPORT(_tc_sample, a thread testcase example); 55 #else 56 int rt_application_init() 57 { 58 sample_init(); 59 60 return 0; 61 } 62 #endif 63