Skip to content

Commit

Permalink
[utest][klibc] add rt_sprintf family functions test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Dec 23, 2024
1 parent f31a879 commit c9ed784
Show file tree
Hide file tree
Showing 6 changed files with 1,093 additions and 7 deletions.
6 changes: 6 additions & 0 deletions bsp/stm32/stm32l475-atk-pandora/board/linker_scripts/link.lds
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ SECTIONS
KEEP(*(VSymTab))
__vsymtab_end = .;

/* section information for utest */
. = ALIGN(4);
__rt_utest_tc_tab_start = .;
KEEP(*(UtestTcTab))
__rt_utest_tc_tab_end = .;

/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
Expand Down
2 changes: 1 addition & 1 deletion src/klibc/Kconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
menu "klibc options"
menu "rt_vsnprintf options"
config RT_KLIBC_USING_LIBC_VSNPRINTF
bool "Enable rt_vsnprintf to use libc vsscanf"
bool "Enable rt_vsnprintf to use libc vsnprintf"
default n

config RT_KLIBC_USING_VSNPRINTF_LONGLONG
Expand Down
2 changes: 1 addition & 1 deletion src/klibc/rt_vsnprintf_tiny.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
s = va_arg(args, char *);
if (!s)
{
s = "(NULL)";
s = "(null)";
}

for (len = 0; (len != field_width) && (s[len] != '\0'); len++);
Expand Down
2 changes: 1 addition & 1 deletion src/klibc/utest/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from building import *
src = []

if GetDepend('RT_USING_CI_ACTION') or GetDepend('RT_UTEST_TC_USING_KLIBC'):
src += Glob('tc_*.c')
src += Glob('TC_*.c')

group = DefineGroup('utestcases', src, depend = [''])

Expand Down
9 changes: 5 additions & 4 deletions src/klibc/utest/tc_kstdlib.c → src/klibc/utest/TC_kstdlib.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2006-2019, RT-Thread Development Team
* Copyright (c) 2006-2024, 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>

Expand All @@ -20,17 +21,17 @@ static rt_err_t utest_tc_cleanup(void)
return RT_EOK;
}

static void tc_rt_memcpy_1(void)
static void TC_rt_memcpy_1(void)
{
const char src[] = "Hello, memcpy!";
char dest[20];
char dest[20] = {0};
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_UNIT_RUN(TC_rt_memcpy_1);
}

UTEST_TC_EXPORT(utest_do_tc, "klibc.kstdlibc", utest_tc_init, utest_tc_cleanup, 1000);
Loading

0 comments on commit c9ed784

Please sign in to comment.