utest/utest: intergare testcases into utest framework (#10665)

* utest: move testcases of Utest from example to Utest folder

Create unit-test-cases for the Utest framework subsystem
according to "How to add utest cases into RT-Thread for your module." [1]

Link:
https://rt-thread.github.io/rt-thread/page_component_utest.html#autotoc_md804
[1]

The original `components/utilities/utest` directory already has unit
testcases, which are more comprehensive than the testcases in
`examples/utest/testcases/utest/`. Therefore, simply deleted
the test cases in `examples` and used the existing testcases
in the utest framework.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>

* utest/utest: rename name and add license text

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>

---------

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
This commit is contained in:
Chen Wang
2025-09-02 18:48:07 +08:00
committed by GitHub
parent c1e9403fba
commit c0142c786e
8 changed files with 31 additions and 68 deletions

View File

@@ -7,7 +7,7 @@ config RT_USING_UTESTCASES
if RT_USING_UTESTCASES
rsource "examples/utest/testcases/utest/Kconfig"
rsource "components/utilities/utest/utest/Kconfig"
rsource "examples/utest/testcases/kernel/Kconfig"
rsource "examples/utest/testcases/cpp11/Kconfig"
rsource "examples/utest/testcases/drivers/serial_v2/Kconfig"

View File

@@ -5,4 +5,9 @@ src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('UTest', src, depend = ['RT_USING_UTEST'], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

View File

@@ -0,0 +1,8 @@
menu "Utest Self Testcase"
config UTEST_SELF_PASS_TC
bool "UTEST Self-test"
select RT_USING_UTEST
default n
endmenu

View File

@@ -0,0 +1,10 @@
from building import *
src = []
if GetDepend('RT_UTEST_USING_ALL_CASES') or GetDepend('UTEST_SELF_PASS_TC'):
src += Glob('TC_*.c')
group = DefineGroup('utc_UTest', src, depend = [''])
Return('group')

View File

@@ -1,3 +1,9 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <rtthread.h>
#include "utest.h"
@@ -80,4 +86,4 @@ static void utest_do_tc(void)
UTEST_UNIT_RUN(TC_uassert_in_range);
}
UTEST_TC_EXPORT(utest_do_tc, "utest.uassert", RT_NULL, RT_NULL, 10);
UTEST_TC_EXPORT(utest_do_tc, "utest", RT_NULL, RT_NULL, 10);

View File

@@ -1,7 +0,0 @@
menu "Utest Self Testcase"
config UTEST_SELF_PASS_TC
bool "Pass test"
default y
endmenu

View File

@@ -1,13 +0,0 @@
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = Split('''
pass_tc.c
''')
CPPPATH = [cwd]
group = DefineGroup('utestcases', src, depend = ['UTEST_SELF_PASS_TC'], CPPPATH = CPPPATH)
Return('group')

View File

@@ -1,46 +0,0 @@
/*
* Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-01-16 MurphyZhao the first version
*/
#include <rtthread.h>
#include "utest.h"
static void test_assert_pass(void)
{
uassert_true(1);
uassert_false(0);
uassert_null(RT_NULL);
uassert_not_null(!RT_NULL);
uassert_int_equal(1, 1);
uassert_int_not_equal(1, 2);
uassert_str_equal("Hello RT-Thread!", "Hello RT-Thread!");
uassert_str_not_equal("Hello RT-Thread!", "Hello");
uassert_in_range(2048, 1024, 4096);
uassert_not_in_range(0, 1024, 4096);
}
static rt_err_t utest_tc_init(void)
{
return RT_EOK;
}
static rt_err_t utest_tc_cleanup(void)
{
return RT_EOK;
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_assert_pass);
}
UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10);