This commit is contained in:
zhujiale
2024-09-24 09:56:30 +08:00
committed by Rbb666
parent 79445b6773
commit d1865d0d93
6 changed files with 122 additions and 64 deletions
+1
View File
@@ -15,6 +15,7 @@ rsource "drivers/ipc/Kconfig"
rsource "posix/Kconfig"
rsource "mm/Kconfig"
rsource "tmpfs/Kconfig"
rsource "smp/Kconfig"
endif
endmenu
+6
View File
@@ -0,0 +1,6 @@
menu "SMP Testcase"
config UTEST_SMP_CALL_FUNC
bool "Call random cpu to run func"
default n
endmenu
+13
View File
@@ -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')
+55
View File
@@ -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);