irq_tc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-08-15 supperthomas add irq_test
  9. */
  10. #include <rtthread.h>
  11. #include "utest.h"
  12. #include "rthw.h"
  13. #define UTEST_NAME "irq_tc"
  14. static volatile uint32_t irq_count = 0;
  15. static volatile uint32_t max_get_nest_count = 0;
  16. static void irq_callback()
  17. {
  18. if(rt_interrupt_get_nest() > max_get_nest_count)
  19. {
  20. max_get_nest_count = rt_interrupt_get_nest();
  21. }
  22. irq_count ++;
  23. }
  24. static void irq_test(void)
  25. {
  26. irq_count = 0;
  27. rt_interrupt_enter_sethook(irq_callback);
  28. rt_interrupt_leave_sethook(irq_callback);
  29. rt_thread_mdelay(2);
  30. LOG_D("%s test irq_test! irq_count %d max_get_nest_count %d\n", UTEST_NAME, irq_count, max_get_nest_count);
  31. uassert_int_not_equal(0, irq_count);
  32. uassert_int_not_equal(0, max_get_nest_count);
  33. rt_interrupt_enter_sethook(RT_NULL);
  34. rt_interrupt_leave_sethook(RT_NULL);
  35. LOG_D("irq_test OK!\n");
  36. }
  37. static rt_err_t utest_tc_init(void)
  38. {
  39. irq_count = 0;
  40. max_get_nest_count = 0;
  41. return RT_EOK;
  42. }
  43. static rt_err_t utest_tc_cleanup(void)
  44. {
  45. return RT_EOK;
  46. }
  47. static void interrupt_test(void)
  48. {
  49. rt_base_t level;
  50. uint32_t i = 1000;
  51. rt_interrupt_enter_sethook(irq_callback);
  52. rt_interrupt_leave_sethook(irq_callback);
  53. irq_count = 0;
  54. level = rt_hw_interrupt_disable();
  55. while(i)
  56. {
  57. i --;
  58. }
  59. uassert_int_equal(0, irq_count);
  60. rt_hw_interrupt_enable(level);
  61. rt_interrupt_enter_sethook(RT_NULL);
  62. rt_interrupt_leave_sethook(RT_NULL);
  63. }
  64. static void testcase(void)
  65. {
  66. UTEST_UNIT_RUN(irq_test);
  67. UTEST_UNIT_RUN(interrupt_test);
  68. }
  69. UTEST_TC_EXPORT(testcase, "testcases.kernel.irq_tc", utest_tc_init, utest_tc_cleanup, 10);