summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorzhujiale <[email protected]>2024-08-29 16:21:19 +0800
committerRbb666 <[email protected]>2024-09-24 09:56:30 +0800
commitd1865d0d939cd1783112931589f83c984a671317 (patch)
tree049be70e6e0435747a2b06cb71d84147125f5501 /examples
parent79445b6773e5af42ab5a2f6627df8aa7fbbd6b8f (diff)
smp_call
Diffstat (limited to 'examples')
-rw-r--r--examples/utest/testcases/Kconfig1
-rw-r--r--examples/utest/testcases/smp/Kconfig6
-rw-r--r--examples/utest/testcases/smp/SConscript13
-rw-r--r--examples/utest/testcases/smp/smp.c55
4 files changed, 75 insertions, 0 deletions
diff --git a/examples/utest/testcases/Kconfig b/examples/utest/testcases/Kconfig
index cc13e4e70e..91b41d5aaa 100644
--- a/examples/utest/testcases/Kconfig
+++ b/examples/utest/testcases/Kconfig
@@ -15,6 +15,7 @@ rsource "drivers/ipc/Kconfig"
rsource "posix/Kconfig"
rsource "mm/Kconfig"
rsource "tmpfs/Kconfig"
+rsource "smp/Kconfig"
endif
endmenu
diff --git a/examples/utest/testcases/smp/Kconfig b/examples/utest/testcases/smp/Kconfig
new file mode 100644
index 0000000000..2e144c5b60
--- /dev/null
+++ b/examples/utest/testcases/smp/Kconfig
@@ -0,0 +1,6 @@
+menu "SMP Testcase"
+
+config UTEST_SMP_CALL_FUNC
+ bool "Call random cpu to run func"
+ default n
+endmenu
diff --git a/examples/utest/testcases/smp/SConscript b/examples/utest/testcases/smp/SConscript
new file mode 100644
index 0000000000..b3570fd040
--- /dev/null
+++ b/examples/utest/testcases/smp/SConscript
@@ -0,0 +1,13 @@
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+src = []
+CPPPATH = [cwd]
+
+if GetDepend(['RT_USING_SMP','UTEST_SMP_CALL_FUNC']):
+ src += ['smp.c']
+
+group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/examples/utest/testcases/smp/smp.c b/examples/utest/testcases/smp/smp.c
new file mode 100644
index 0000000000..099a9f7899
--- /dev/null
+++ b/examples/utest/testcases/smp/smp.c
@@ -0,0 +1,55 @@
+#include <rtdevice.h>
+#include "utest.h"
+#include "utest_assert.h"
+#include "smp.h"
+int pass_count = 0;
+int pass = 1000;
+struct rt_spinlock lock;
+
+void test_call(void *data)
+{
+ rt_spin_lock(&lock);
+ int *i = (int *)data;
+ int id = rt_hw_cpu_id();
+ *i &= ~(1 << id);
+ if(*i == 0)
+ pass_count++;
+ rt_spin_unlock(&lock);
+}
+
+
+void test()
+{
+ int cpu_mask = 0xf;
+ for(int i =0 ;i < 1000 ;i++)
+ {
+ cpu_mask = rand()% 0xf;
+ if (cpu_mask == 0)
+ pass--;
+ rt_smp_call_func_cond(cpu_mask,test_call, &cpu_mask);
+ if(i % 20 == 0)
+ rt_kprintf("#");
+ rt_thread_mdelay(1);
+ }
+ rt_kprintf("\n");
+}
+
+
+
+static rt_err_t utest_tc_init(void)
+{
+ rt_spin_lock_init(&lock);
+ return RT_EOK;
+}
+
+static rt_err_t utest_tc_cleanup(void)
+{
+ uassert_true(pass_count == pass);
+ return RT_EOK;
+}
+static void testcase(void)
+{
+ UTEST_UNIT_RUN(test);
+}
+
+UTEST_TC_EXPORT(testcase, "testcase.smp.smp", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file