smp_001_tc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024/9/12 zhujiale the first version
  9. * 2024/10/28 Shell Added more assertions
  10. */
  11. #include <rtdevice.h>
  12. #include <utest.h>
  13. #include <utest_assert.h>
  14. #include <smp_call.h>
  15. #define TEST_COUNT 10000
  16. static int pass_count = 0;
  17. static RT_DEFINE_SPINLOCK(_test_data_lock);
  18. static void _test_smp_cb(void *data)
  19. {
  20. int *maskp;
  21. int oncpu;
  22. if (!rt_hw_interrupt_is_disabled())
  23. {
  24. /* SYNC.004 */
  25. uassert_true(0);
  26. }
  27. rt_spin_lock(&_test_data_lock);
  28. oncpu = rt_hw_cpu_id();
  29. maskp = (int *)data;
  30. *maskp &= ~(1 << oncpu);
  31. rt_spin_unlock(&_test_data_lock);
  32. }
  33. static void _blocking_call(void)
  34. {
  35. volatile int cpu_mask;
  36. rt_ubase_t tested_cpus = 0;
  37. for (int i = 0; i < TEST_COUNT; i++)
  38. {
  39. cpu_mask = rand() % RT_ALL_CPU;
  40. tested_cpus |= cpu_mask;
  41. rt_smp_call_cpu_mask(cpu_mask, _test_smp_cb, (void *)&cpu_mask, SMP_CALL_WAIT_ALL);
  42. if (!cpu_mask)
  43. {
  44. pass_count++;
  45. }
  46. else
  47. {
  48. /* TARG.001, MP.001 */
  49. uassert_true(0);
  50. break;
  51. }
  52. }
  53. LOG_D("pass_count %d", pass_count);
  54. /* TARG.001 */
  55. uassert_true(pass_count == TEST_COUNT);
  56. /* TOP.001, TOP.002 */
  57. uassert_true(tested_cpus == RT_ALL_CPU);
  58. }
  59. static rt_err_t utest_tc_init(void)
  60. {
  61. pass_count = 0;
  62. srand(rt_tick_get());
  63. return RT_EOK;
  64. }
  65. static rt_err_t utest_tc_cleanup(void)
  66. {
  67. return RT_EOK;
  68. }
  69. static void _testcase(void)
  70. {
  71. UTEST_UNIT_RUN(_blocking_call);
  72. }
  73. UTEST_TC_EXPORT(_testcase, "testcase.smp.smoke.001", utest_tc_init, utest_tc_cleanup, 10);