diff options
| author | Shell <[email protected]> | 2024-01-09 20:37:47 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2024-01-16 00:59:18 +0800 |
| commit | f6fce5f8d76e26c2315a64de81ce07bd6e379394 (patch) | |
| tree | eec5650cafe081bdfff1933f0926c0cc1b6548a9 /examples | |
| parent | 447a22a21dc6da2bcbe7489ae08c9d0e18308511 (diff) | |
[kservice] MT-safe output support (kprintf/kputs)
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/utest/testcases/kernel/Kconfig | 4 | ||||
| -rw-r--r-- | examples/utest/testcases/kernel/SConscript | 3 | ||||
| -rw-r--r-- | examples/utest/testcases/kernel/mtsafe_kprint_tc.c | 68 |
3 files changed, 75 insertions, 0 deletions
diff --git a/examples/utest/testcases/kernel/Kconfig b/examples/utest/testcases/kernel/Kconfig index fc92292f0b..988f13f43f 100644 --- a/examples/utest/testcases/kernel/Kconfig +++ b/examples/utest/testcases/kernel/Kconfig @@ -65,4 +65,8 @@ config UTEST_HOOKLIST_TC select RT_USING_HOOKLIST default n +config UTEST_MTSAFE_KPRINT_TC + bool "mtsafe kprint test" + default n + endmenu diff --git a/examples/utest/testcases/kernel/SConscript b/examples/utest/testcases/kernel/SConscript index ea2780e4d7..598b92251a 100644 --- a/examples/utest/testcases/kernel/SConscript +++ b/examples/utest/testcases/kernel/SConscript @@ -47,6 +47,9 @@ if GetDepend(['UTEST_ATOMIC_TC']): if GetDepend(['UTEST_HOOKLIST_TC']): src += ['hooklist_tc.c'] +if GetDepend(['UTEST_MTSAFE_KPRINT_TC']): + src += ['mtsafe_kprint_tc.c'] + group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH) Return('group') diff --git a/examples/utest/testcases/kernel/mtsafe_kprint_tc.c b/examples/utest/testcases/kernel/mtsafe_kprint_tc.c new file mode 100644 index 0000000000..f6934e6b21 --- /dev/null +++ b/examples/utest/testcases/kernel/mtsafe_kprint_tc.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-12-25 Shell the first version + */ +#include <rtthread.h> +#include "utest.h" + +#define TEST_LOOP_TIMES 20 + +static struct rt_semaphore _thr_exit_sem; + +static void _thread_entry(void *param) +{ + for (size_t i = 0; i < TEST_LOOP_TIMES; i++) + { + rt_kprintf("This is thread %p\n", rt_thread_self()); + rt_thread_mdelay(1); + } + + rt_sem_release(&_thr_exit_sem); + return; +} + +#define TEST_THREAD_COUNT 16 + +static void mtsafe_kprint_tc(void) +{ + for (size_t i = 0; i < TEST_THREAD_COUNT; i++) + { + rt_thread_t new_thread = + rt_thread_create( + "test", + _thread_entry, + NULL, + UTEST_THR_STACK_SIZE, + UTEST_THR_PRIORITY, + 100); + rt_thread_startup(new_thread); + } + + for (size_t i = 0; i < TEST_THREAD_COUNT; i++) + { + rt_sem_take(&_thr_exit_sem, RT_WAITING_FOREVER); + } +} + +static rt_err_t utest_tc_init(void) +{ + rt_sem_init(&_thr_exit_sem, "test", 0, RT_IPC_FLAG_PRIO); + return RT_EOK; +} + +static rt_err_t utest_tc_cleanup(void) +{ + rt_sem_detach(&_thr_exit_sem); + return RT_EOK; +} + +static void testcase(void) +{ + UTEST_UNIT_RUN(mtsafe_kprint_tc); +} +UTEST_TC_EXPORT(testcase, "testcases.kernel.mtsafe_kprint", utest_tc_init, utest_tc_cleanup, 10); |
