diff --git a/bsp/k230/drivers/utest/test_adc.c b/bsp/k230/drivers/utest/test_adc.c index d4df2443286..10ba7e3416d 100644 --- a/bsp/k230/drivers/utest/test_adc.c +++ b/bsp/k230/drivers/utest/test_adc.c @@ -115,4 +115,4 @@ static void testcase(void) { UTEST_UNIT_RUN(test_read); } -UTEST_TC_EXPORT(testcase, "adc", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file +UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.adc", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_gpio.c b/bsp/k230/drivers/utest/test_gpio.c index de8a9c83438..20b69b9d46c 100644 --- a/bsp/k230/drivers/utest/test_gpio.c +++ b/bsp/k230/drivers/utest/test_gpio.c @@ -102,4 +102,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(testcase, "gpio", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file +UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.gpio", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_gpio_irq.c b/bsp/k230/drivers/utest/test_gpio_irq.c index 759166ca896..10510b6976c 100644 --- a/bsp/k230/drivers/utest/test_gpio_irq.c +++ b/bsp/k230/drivers/utest/test_gpio_irq.c @@ -130,4 +130,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(testcase, "gpio_irq", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file +UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.gpio_irq", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_pdma.c b/bsp/k230/drivers/utest/test_pdma.c index 5ac30ab9da6..f6787dfcaef 100644 --- a/bsp/k230/drivers/utest/test_pdma.c +++ b/bsp/k230/drivers/utest/test_pdma.c @@ -296,4 +296,4 @@ void test_pdma() UTEST_UNIT_RUN(test_pdma_rx); } -UTEST_TC_EXPORT(test_pdma, "pdma", utest_tc_init, utest_tc_cleanup, 10); +UTEST_TC_EXPORT(test_pdma, "bsp.k230.drivers.pdma", utest_tc_init, utest_tc_cleanup, 10); diff --git a/bsp/k230/drivers/utest/test_pwm.c b/bsp/k230/drivers/utest/test_pwm.c index 8d9be04af63..9b76fdd74ac 100644 --- a/bsp/k230/drivers/utest/test_pwm.c +++ b/bsp/k230/drivers/utest/test_pwm.c @@ -117,4 +117,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(pwm_testcase, "pwm", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file +UTEST_TC_EXPORT(pwm_testcase, "bsp.k230.drivers.pwm", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_timer.c b/bsp/k230/drivers/utest/test_timer.c index 30db354783b..50a5578a70b 100644 --- a/bsp/k230/drivers/utest/test_timer.c +++ b/bsp/k230/drivers/utest/test_timer.c @@ -150,4 +150,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(hw_timer_testcase, "timer", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file +UTEST_TC_EXPORT(hw_timer_testcase, "bsp.k230.drivers.timer", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_ts.c b/bsp/k230/drivers/utest/test_ts.c index 0452499440a..53825bdc7e2 100644 --- a/bsp/k230/drivers/utest/test_ts.c +++ b/bsp/k230/drivers/utest/test_ts.c @@ -130,4 +130,4 @@ static void testcase(void) UTEST_UNIT_RUN(test_ts_read); UTEST_UNIT_RUN(test_ts_control); } -UTEST_TC_EXPORT(testcase, "ts", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file +UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.ts", utest_tc_init, utest_tc_cleanup, 100); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_uart.c b/bsp/k230/drivers/utest/test_uart.c index 9ab5654df71..206905f36aa 100644 --- a/bsp/k230/drivers/utest/test_uart.c +++ b/bsp/k230/drivers/utest/test_uart.c @@ -162,4 +162,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(uart_testcase, "uart", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file +UTEST_TC_EXPORT(uart_testcase, "bsp.k230.drivers.uart", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file diff --git a/bsp/k230/drivers/utest/test_wdt.c b/bsp/k230/drivers/utest/test_wdt.c index 61837cbab60..026d4eb0162 100644 --- a/bsp/k230/drivers/utest/test_wdt.c +++ b/bsp/k230/drivers/utest/test_wdt.c @@ -143,4 +143,4 @@ static rt_err_t utest_init(void) return RT_EOK; } -UTEST_TC_EXPORT(test_wdt, "wdt", utest_init, NULL, 10); \ No newline at end of file +UTEST_TC_EXPORT(test_wdt, "bsp.k230.drivers.wdt", utest_init, NULL, 10); \ No newline at end of file diff --git a/components/drivers/audio/utest/tc_audio_main.c b/components/drivers/audio/utest/tc_audio_main.c index 969b714f4ae..7e326dda241 100644 --- a/components/drivers/audio/utest/tc_audio_main.c +++ b/components/drivers/audio/utest/tc_audio_main.c @@ -306,4 +306,4 @@ static rt_err_t utest_tc_cleanup(void) return RT_EOK; } -UTEST_TC_EXPORT(testcase, "audio.tc_audio_main", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file +UTEST_TC_EXPORT(testcase, "components.drivers.audio.tc_audio_main", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file diff --git a/components/utilities/utest/utest/TC_uassert.c b/components/utilities/utest/utest/TC_uassert.c index 0599dff6ef8..1d5ed1a67e9 100644 --- a/components/utilities/utest/utest/TC_uassert.c +++ b/components/utilities/utest/utest/TC_uassert.c @@ -86,4 +86,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_uassert_in_range); } -UTEST_TC_EXPORT(utest_do_tc, "utest", RT_NULL, RT_NULL, 10); +UTEST_TC_EXPORT(utest_do_tc, "components.utilities.utest.uassert", RT_NULL, RT_NULL, 10); diff --git a/documentation/6.components/utest/utest.md b/documentation/6.components/utest/utest.md index dffff285351..9cc63b6b81d 100644 --- a/documentation/6.components/utest/utest.md +++ b/documentation/6.components/utest/utest.md @@ -62,18 +62,45 @@ UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout) | Parameters | Description | | :----- | :------ | | testcase | Test case main-bearing function (**specifies** using a function called *static void testcase(void)* | -| name | Test case name (uniqueness). Specifies the naming format for connecting relative names of test cases relative to `testcases directory` with `.` | +| name | Test case name (uniqueness). Detailed requirements see below **Test case naming requirements:** | | init | the initialization function before Test case startup | | cleanup | Cleanup function after the end of the test case | | timeout | Test case expected test time (in seconds) | **Test case naming requirements:** -Test cases need to be named in the prescribed format. Specifies the naming format for the connection of the current test case relative to the `testcases directory ` linked with `.` . The name contains the file name of the current test case file (the file name except the suffix name). +To ensure unique unit-testcase names throughout the RT-Thread source code repository, the full name consists of two parts: + +**Module-Prefix.Test-Function** + +- **Module-Prefix**: Use the path of the *module's utest directory* relative to the source code repository root (excluding utest), connected by a dot ("."). For more information on *module's utest directory*, see section **How-to add utest cases into RT-Thread for your module**. + +- **Test-Function**: Define your own name, ensuring it's unique within the same **Module-Prefix** (it doesn't have to match the test case file name). **Test case naming example:** -Assuming that there is a `testcases\components\filesystem\dfs\dfs_api_tc.c` test case file in the test case `testcases` directory, the test case name in the `dfs_api_tc.c` is named `components.filesystem.dfs.dfs_api_tc`. +Assuming that there is a *module's utest directory*: `components/dfs/utest`, which contains utest source files for module "DFS". We can define the testcase in file `components/dfs/utest/tc_dfs_api.c` as below: + +```c +static void testcase(void) +{ + /* Skip filesystem mount test for now due to mutex issues */ + UTEST_UNIT_RUN(test_mkfs); + // ...... +} + +UTEST_TC_EXPORT(testcase, "components.dfs.fs_dfs_api_tc", utest_tc_init, utest_tc_cleanup, 10); +``` + +Here, the global unique unit-testcase name is "components.dfs.fs_dfs_api_tc". Of this name, **Module-Prefix** is "components.dfs", which corresponds to the path name `components/dfs`; **Test-Function** is `fs_dfs_api_tc`, which uniquely identifies a suite of cases which will be run in the function `testcase()`, and note that the `fs_dfs_api_tc` need not be the same as the file name of `tc_dfs_api.c`. + +Particularly, for modules in the `src` directory, since the name `src` is ambiguous, it is recommended to replace it with `core` to contrast it with `components`. This indicates that the code in `src` is the kernel's *core* code module relative to `components`. + +For example: The utest case in `src/klibc/utest/TC_rt_memcmp.c` can be written as: + +```c +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_memcmp", RT_NULL, RT_NULL, 1000); +``` ## Test Case LOG Output Interface @@ -273,7 +300,7 @@ From the above flow chart you can get the following: - A test case implementation can only export a test body function (testcase function) using `UTEST_TC_EXPORT` - Write a `README.md` document for the your test case to guide the user through configuring the test environment. -# How-to add utest cases into RT-Thread for your module. +# How-to add utest cases into RT-Thread for your module The source code of utest cases is recommended to be placed in each module for maintenance, but the entry of Kconfig should all be placed(rsourced) in `Kconfig.utestcases` for unified maintenance. In this way, when executing menuconfig, people can enter and configure from one place, avoiding searching for utest configuration switches scattering in the menuconfig interface. diff --git a/src/klibc/utest/TC_rt_memcmp.c b/src/klibc/utest/TC_rt_memcmp.c index 45d4d756ccc..c89fe3123f0 100644 --- a/src/klibc/utest/TC_rt_memcmp.c +++ b/src/klibc/utest/TC_rt_memcmp.c @@ -158,4 +158,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_rt_memcmp_large_array); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_memcmp", RT_NULL, RT_NULL, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_memcmp", RT_NULL, RT_NULL, 1000); diff --git a/src/klibc/utest/TC_rt_memcpy.c b/src/klibc/utest/TC_rt_memcpy.c index c02ccd5c96d..7c53bea6e18 100644 --- a/src/klibc/utest/TC_rt_memcpy.c +++ b/src/klibc/utest/TC_rt_memcpy.c @@ -105,4 +105,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_rt_memcpy_align); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_memcpy", utest_tc_init, utest_tc_cleanup, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_memcpy", utest_tc_init, utest_tc_cleanup, 1000); diff --git a/src/klibc/utest/TC_rt_memmove.c b/src/klibc/utest/TC_rt_memmove.c index 22f80214b21..ecb916cb275 100644 --- a/src/klibc/utest/TC_rt_memmove.c +++ b/src/klibc/utest/TC_rt_memmove.c @@ -105,4 +105,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_rt_memmove_empty_string); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_memmove", RT_NULL, RT_NULL, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_memmove", RT_NULL, RT_NULL, 1000); diff --git a/src/klibc/utest/TC_rt_memset.c b/src/klibc/utest/TC_rt_memset.c index afe705df4b6..94c2269e095 100644 --- a/src/klibc/utest/TC_rt_memset.c +++ b/src/klibc/utest/TC_rt_memset.c @@ -99,4 +99,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_rt_memcpy_input); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_memset", utest_tc_init, utest_tc_cleanup, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_memset", utest_tc_init, utest_tc_cleanup, 1000); diff --git a/src/klibc/utest/TC_rt_sprintf.c b/src/klibc/utest/TC_rt_sprintf.c index a6a248a7e33..d8bba42c08c 100644 --- a/src/klibc/utest/TC_rt_sprintf.c +++ b/src/klibc/utest/TC_rt_sprintf.c @@ -1062,4 +1062,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(SPRINTF_TEST_CASE_NAME(misc)); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_sprintf", RT_NULL, RT_NULL, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_sprintf", RT_NULL, RT_NULL, 1000); diff --git a/src/klibc/utest/TC_rt_sscanf.c b/src/klibc/utest/TC_rt_sscanf.c index b82be049729..8468acd9656 100644 --- a/src/klibc/utest/TC_rt_sscanf.c +++ b/src/klibc/utest/TC_rt_sscanf.c @@ -247,4 +247,4 @@ static void utest_do_tc(void) UTEST_UNIT_RUN(TC_rt_sscanf_issue_9853); } -UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_sscanf", RT_NULL, RT_NULL, 1000); +UTEST_TC_EXPORT(utest_do_tc, "core.klibc.rt_sscanf", RT_NULL, RT_NULL, 1000);