-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utest: smp_call: add smoke test cases
Signed-off-by: Shell <[email protected]>
- Loading branch information
Showing
6 changed files
with
549 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2006-2024 RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024/9/12 zhujiale the first version | ||
* 2024/10/28 Shell Added more assertions | ||
*/ | ||
|
||
#include <rtdevice.h> | ||
#include <utest.h> | ||
#include <utest_assert.h> | ||
#include <smp.h> | ||
|
||
#define TEST_COUNT 10000 | ||
|
||
static int pass_count = 0; | ||
static RT_DEFINE_SPINLOCK(_test_data_lock); | ||
|
||
static void _test_smp_cb(void *data) | ||
{ | ||
int *maskp; | ||
int oncpu; | ||
|
||
if (!rt_hw_interrupt_is_disabled()) | ||
{ | ||
/* SYNC.004 */ | ||
uassert_true(0); | ||
} | ||
|
||
rt_spin_lock(&_test_data_lock); | ||
|
||
oncpu = rt_hw_cpu_id(); | ||
maskp = (int *)data; | ||
*maskp &= ~(1 << oncpu); | ||
|
||
rt_spin_unlock(&_test_data_lock); | ||
} | ||
|
||
static void _blocking_call(void) | ||
{ | ||
volatile int cpu_mask; | ||
rt_ubase_t tested_cpus = 0; | ||
|
||
for (int i = 0; i < TEST_COUNT; i++) | ||
{ | ||
cpu_mask = rand() % RT_ALL_CPU; | ||
tested_cpus |= cpu_mask; | ||
rt_smp_call_cpu_mask(cpu_mask, _test_smp_cb, (void *)&cpu_mask, SMP_CALL_WAIT_ALL); | ||
|
||
if (!cpu_mask) | ||
{ | ||
pass_count++; | ||
} | ||
else | ||
{ | ||
/* TARG.001, MP.001 */ | ||
uassert_true(0); | ||
break; | ||
} | ||
} | ||
LOG_D("pass_count %d", pass_count); | ||
|
||
/* TARG.001 */ | ||
uassert_true(pass_count == TEST_COUNT); | ||
|
||
/* TOP.001, TOP.002 */ | ||
uassert_true(tested_cpus == RT_ALL_CPU); | ||
} | ||
|
||
static rt_err_t utest_tc_init(void) | ||
{ | ||
pass_count = 0; | ||
srand(rt_tick_get()); | ||
return RT_EOK; | ||
} | ||
|
||
static rt_err_t utest_tc_cleanup(void) | ||
{ | ||
return RT_EOK; | ||
} | ||
|
||
static void _testcase(void) | ||
{ | ||
UTEST_UNIT_RUN(_blocking_call); | ||
} | ||
|
||
UTEST_TC_EXPORT(_testcase, "testcase.smp.smoke.001", utest_tc_init, utest_tc_cleanup, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2006-2024 RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024/10/28 Shell Added smp.smoke | ||
*/ | ||
|
||
#include <rtdevice.h> | ||
#include <utest.h> | ||
#include <utest_assert.h> | ||
#include <smp.h> | ||
|
||
#define PERCPU_TEST_COUNT 10000 | ||
#define NEWLINE_ON 80 | ||
|
||
static struct rt_semaphore _utestd_exited; | ||
static rt_thread_t _utestd[RT_CPUS_NR]; | ||
static rt_atomic_t _entry_counts[RT_CPUS_NR]; | ||
|
||
static void _logging_progress(void) | ||
{ | ||
static rt_atomic_t counts; | ||
rt_ubase_t old; | ||
|
||
rt_kputs("#"); | ||
old = rt_atomic_add(&counts, 1); | ||
if (old % NEWLINE_ON == 0) | ||
{ | ||
rt_kputs("\n"); | ||
} | ||
} | ||
|
||
static void _test_smp_cb(void *param) | ||
{ | ||
rt_ubase_t req_cpuid = (rt_ubase_t)param; | ||
|
||
if (!rt_hw_interrupt_is_disabled()) | ||
{ | ||
/* SYNC.004 */ | ||
uassert_true(0); | ||
} | ||
|
||
_logging_progress(); | ||
rt_atomic_add(&_entry_counts[req_cpuid], 1); | ||
} | ||
|
||
static void _utestd_entry(void *oncpu_param) | ||
{ | ||
rt_ubase_t oncpu = (rt_ubase_t)oncpu_param; | ||
volatile int cpu_mask; | ||
volatile int popcount = 0; | ||
rt_ubase_t tested_cpus = 0; | ||
|
||
if (rt_hw_cpu_id() != oncpu) | ||
{ | ||
/* SYNC.004 */ | ||
uassert_true(0); | ||
} | ||
|
||
for (size_t i = 0; i < PERCPU_TEST_COUNT; i++) | ||
{ | ||
cpu_mask = rand() % RT_ALL_CPU; | ||
tested_cpus |= cpu_mask; | ||
|
||
rt_smp_call_cpu_mask(cpu_mask, _test_smp_cb, oncpu_param, SMP_CALL_WAIT_ALL); | ||
popcount += __builtin_popcount(cpu_mask); | ||
} | ||
|
||
LOG_D("popcount %d, _entry_counts[%d] %d", popcount, oncpu, _entry_counts[oncpu]); | ||
|
||
/* TARG.001 */ | ||
uassert_true(popcount == rt_atomic_load(&_entry_counts[oncpu])); | ||
|
||
/* TOP.001, TOP.002 */ | ||
uassert_true(tested_cpus == RT_ALL_CPU); | ||
|
||
rt_sem_release(&_utestd_exited); | ||
} | ||
|
||
static void _blocking_mtsafe_call(void) | ||
{ | ||
rt_err_t error; | ||
for (size_t i = 0; i < RT_CPUS_NR; i++) | ||
{ | ||
error = rt_thread_startup(_utestd[i]); | ||
|
||
/* SYNC.001, SYNC.002, SYNC.003 */ | ||
uassert_true(!error); | ||
} | ||
|
||
for (size_t i = 0; i < RT_CPUS_NR; i++) | ||
{ | ||
rt_sem_take(&_utestd_exited, RT_WAITING_FOREVER); | ||
} | ||
} | ||
|
||
static rt_err_t utest_tc_init(void) | ||
{ | ||
for (size_t i = 0; i < RT_CPUS_NR; i++) | ||
{ | ||
rt_atomic_store(&_entry_counts[i], 0); | ||
_utestd[i] = rt_thread_create("utestd", _utestd_entry, (void *)i, | ||
UTEST_THR_STACK_SIZE, UTEST_THR_PRIORITY, | ||
20); | ||
rt_thread_control(_utestd[i], RT_THREAD_CTRL_BIND_CPU, (void *)i); | ||
|
||
/* SYNC.001, SYNC.002, SYNC.003 */ | ||
uassert_true(_utestd[i] != RT_NULL); | ||
} | ||
|
||
rt_sem_init(&_utestd_exited, "utestd", 0, RT_IPC_FLAG_PRIO); | ||
srand(rt_tick_get()); | ||
|
||
return RT_EOK; | ||
} | ||
|
||
static rt_err_t utest_tc_cleanup(void) | ||
{ | ||
rt_sem_detach(&_utestd_exited); | ||
|
||
return RT_EOK; | ||
} | ||
|
||
static void _testcase(void) | ||
{ | ||
UTEST_UNIT_RUN(_blocking_mtsafe_call); | ||
} | ||
|
||
UTEST_TC_EXPORT(_testcase, "testcase.smp.smoke.002", utest_tc_init, utest_tc_cleanup, 10); |
Oops, something went wrong.