Skip to content

add demo of new utest cases #9815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions components/libc/compilers/common/cstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include <rtthread.h>
#include <stdlib.h>

#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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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++;
Expand Down
61 changes: 40 additions & 21 deletions components/utilities/utest/utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -300,45 +300,60 @@ 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));

tc_loop = 1;

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)
{
Expand All @@ -347,16 +362,20 @@ 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
{
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]);

Expand Down
2 changes: 1 addition & 1 deletion components/utilities/utest/utest_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/klibc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/klibc/utest/SConscript
Original file line number Diff line number Diff line change
@@ -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')
36 changes: 36 additions & 0 deletions src/klibc/utest/tc_kstdlib.c
Original file line number Diff line number Diff line change
@@ -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 <rtklibc.h>
#include <utest.h>

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);
Loading