diff --git a/components/libc/compilers/common/cstring.c b/components/libc/compilers/common/cstring.c index 59c516d273e..41f6c658ceb 100644 --- a/components/libc/compilers/common/cstring.c +++ b/components/libc/compilers/common/cstring.c @@ -13,13 +13,13 @@ #include #include +#ifndef RT_USING_PICOLIBC /** * @brief erases the data in the n bytes of the memory starting at the * location pointed to by s, by writing zeros (bytes containing '\0') to that area. * * @note The bzero() function is deprecated (marked as LEGACY in POSIX. 1-2001). */ -#ifndef RT_USING_PICOLIBC void bzero(void* s, size_t n) { rt_memset(s, 0, n); @@ -46,12 +46,12 @@ void explicit_bzero(void* s, size_t n) } } -char* index(const char* s, int c) +char *index(const char* s, int c) { return strchr(s, c); } -char* rindex(const char* s, int c) +char *rindex(const char* s, int c) { return strrchr(s, c); } @@ -99,7 +99,7 @@ int ffsll(long long i) * * @note This function is GNU extension, available since glibc 2.1.91. */ -void* memrchr(const void* ptr, int ch, size_t pos) +void *memrchr(const void* ptr, int ch, size_t pos) { char* end = (char*)ptr + pos - 1; while (end != ptr) @@ -118,7 +118,7 @@ size_t strnlen(const char *s, size_t maxlen) return sc - s; } -char* strchrnul(const char* s, int c) +char *strchrnul(const char* s, int c) { while (*s != '\0' && *s != c) s++; diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 45068f3f7de..d49eee1633f 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -191,7 +191,7 @@ static int utest_help(void) return 0; } -static void utest_run(const char *utest_name) +static void utest_do_run(const char *utest_name) { rt_size_t i; rt_uint32_t index; @@ -300,17 +300,38 @@ static void utest_run(const char *utest_name) } } -static void utest_thr_entry(const char *utest_name) +static void utest_thr_entry(void *para) { - /* see commit:0dc7b9a for details */ - rt_thread_mdelay(1000); + char *utest_name = (char *)para; + rt_thread_mdelay(1000); /* see commit:0dc7b9a for details */ + rt_kprintf("\n"); + utest_do_run(utest_name); +} - utest_run(utest_name); +static void utest_thread_create(const char *utest_name) +{ + rt_thread_t tid = RT_NULL; + tid = rt_thread_create("utest", + utest_thr_entry, (void *)utest_name, + UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10); + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } } -long utest_testcase_run(int argc, char** argv) +#ifdef RT_USING_CI_ACTION +static int utest_ci_action(void) { + tc_loop = 1; + utest_thread_create(RT_NULL); + return RT_EOK; +} +INIT_APP_EXPORT(utest_ci_action); +#endif /* RT_USING_CI_ACTION */ +int utest_testcase_run(int argc, char** argv) +{ static char utest_name[UTEST_NAME_MAX_LEN]; rt_memset(utest_name, 0x0, sizeof(utest_name)); @@ -318,27 +339,21 @@ long utest_testcase_run(int argc, char** argv) if (argc == 1) { - utest_run(RT_NULL); - return 0; + utest_thread_create(RT_NULL); } else if (argc == 2 || argc == 3 || argc == 4) { if (rt_strcmp(argv[1], "-thread") == 0) { - rt_thread_t tid = RT_NULL; if (argc == 3 || argc == 4) { rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1); - - if (argc == 4) tc_loop = atoi(argv[3]); - } - tid = rt_thread_create("utest", - (void (*)(void *))utest_thr_entry, utest_name, - UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10); - if (tid != NULL) - { - rt_thread_startup(tid); + if (argc == 4) + { + tc_loop = atoi(argv[3]); + } } + utest_thread_create(utest_name); } else if (rt_strcmp(argv[1], "-help") == 0) { @@ -347,8 +362,11 @@ long utest_testcase_run(int argc, char** argv) else { rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); - if (argc == 3) tc_loop = atoi(argv[2]); - utest_run(utest_name); + if (argc == 3) + { + tc_loop = atoi(argv[2]); + } + utest_do_run(utest_name); } } else @@ -356,7 +374,8 @@ long utest_testcase_run(int argc, char** argv) LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__); utest_help(); } - return 0; + + return RT_EOK; } MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]); diff --git a/components/utilities/utest/utest_log.h b/components/utilities/utest/utest_log.h index 6aa54386a8b..c25815dc638 100644 --- a/components/utilities/utest/utest_log.h +++ b/components/utilities/utest/utest_log.h @@ -18,7 +18,7 @@ #undef DBG_TAG #undef DBG_LVL -#define DBG_TAG "testcase" +#define DBG_TAG "utest" #ifdef UTEST_DEBUG #define DBG_LVL DBG_LOG #else diff --git a/src/Kconfig b/src/Kconfig index e7f2a5108b6..d4cad60d953 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -242,6 +242,8 @@ menuconfig RT_USING_DEBUG endif config RT_USING_CI_ACTION + bool "Enable CI Action build mode" + select RT_USING_UTEST default n help Identify that the environment is CI Action. diff --git a/src/klibc/Kconfig b/src/klibc/Kconfig index 0b00d10b8e8..e41e1cf6654 100644 --- a/src/klibc/Kconfig +++ b/src/klibc/Kconfig @@ -249,4 +249,10 @@ menu "klibc options" bool "Enable rt_strnlen to use user-defined version" default n endmenu # rt_strnlen options + + config RT_UTEST_TC_USING_KLIBC + bool "Enable klibc utest cases" + select RT_USING_UTEST + default n + endmenu diff --git a/src/klibc/utest/SConscript b/src/klibc/utest/SConscript new file mode 100644 index 00000000000..1b9bb9e18e2 --- /dev/null +++ b/src/klibc/utest/SConscript @@ -0,0 +1,10 @@ +from building import * + +src = [] + +if GetDepend('RT_USING_CI_ACTION') or GetDepend('RT_UTEST_TC_USING_KLIBC'): + src += Glob('tc_*.c') + +group = DefineGroup('utestcases', src, depend = ['']) + +Return('group') diff --git a/src/klibc/utest/tc_kstdlib.c b/src/klibc/utest/tc_kstdlib.c new file mode 100644 index 00000000000..207ff43ac2f --- /dev/null +++ b/src/klibc/utest/tc_kstdlib.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2019, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-12-21 Meco Man the first version + */ +#include +#include + +static rt_err_t utest_tc_init(void) +{ + return RT_EOK; +} + +static rt_err_t utest_tc_cleanup(void) +{ + return RT_EOK; +} + +static void tc_rt_memcpy_1(void) +{ + const char src[] = "Hello, memcpy!"; + char dest[20]; + rt_memcpy(dest, src, sizeof(src)); + uassert_true(rt_strcmp(src, dest) == 0); +} + +static void utest_do_tc(void) +{ + UTEST_UNIT_RUN(tc_rt_memcpy_1); +} + +UTEST_TC_EXPORT(utest_do_tc, "klibc.kstdlibc", utest_tc_init, utest_tc_cleanup, 1000);