tc_sample.c 1.2 KB

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