Skip to content
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
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.adc", utest_tc_init, utest_tc_cleanup, 100);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.gpio", utest_tc_init, utest_tc_cleanup, 100);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_gpio_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.gpio_irq", utest_tc_init, utest_tc_cleanup, 100);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_pdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(pwm_testcase, "bsp.k230.drivers.pwm", utest_tc_init, utest_tc_cleanup, 10);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(hw_timer_testcase, "bsp.k230.drivers.timer", utest_tc_init, utest_tc_cleanup, 10);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(testcase, "bsp.k230.drivers.ts", utest_tc_init, utest_tc_cleanup, 100);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(uart_testcase, "bsp.k230.drivers.uart", utest_tc_init, utest_tc_cleanup, 10);
2 changes: 1 addition & 1 deletion bsp/k230/drivers/utest/test_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ static rt_err_t utest_init(void)
return RT_EOK;
}

UTEST_TC_EXPORT(test_wdt, "wdt", utest_init, NULL, 10);
UTEST_TC_EXPORT(test_wdt, "bsp.k230.drivers.wdt", utest_init, NULL, 10);
2 changes: 1 addition & 1 deletion components/drivers/audio/utest/tc_audio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UTEST_TC_EXPORT(testcase, "components.drivers.audio.tc_audio_main", utest_tc_init, utest_tc_cleanup, 10);
2 changes: 1 addition & 1 deletion components/utilities/utest/utest/TC_uassert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
35 changes: 31 additions & 4 deletions documentation/6.components/utest/utest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_memmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/klibc/utest/TC_rt_sscanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);