From bb4aace00f49ea89d0888d1d4af65142fc82c469 Mon Sep 17 00:00:00 2001 From: CYFS <2805686936@qq.com> Date: Thu, 11 Jun 2026 15:51:46 +0800 Subject: utest: move utestcases Kconfig to utest component Signed-off-by: CYFS <2805686936@qq.com> --- Kconfig | 2 +- Kconfig.utestcases | 35 --------------- components/utilities/utest/Kconfig | 35 +++++++++++++++ components/utilities/utest/README.md | 70 ++++++++++++++++++++++++++++++ documentation/6.components/utest/utest.md | 4 +- examples/utest/README.md | 72 ------------------------------- tools/env_utility.py | 6 ++- tools/mkdist.py | 9 +++- 8 files changed, 119 insertions(+), 114 deletions(-) delete mode 100644 Kconfig.utestcases create mode 100644 components/utilities/utest/Kconfig create mode 100644 components/utilities/utest/README.md delete mode 100644 examples/utest/README.md diff --git a/Kconfig b/Kconfig index a7a7758f67..ac6a1d6310 100644 --- a/Kconfig +++ b/Kconfig @@ -1,4 +1,4 @@ rsource "src/Kconfig" rsource "libcpu/Kconfig" rsource "components/Kconfig" -rsource "Kconfig.utestcases" +rsource "components/utilities/utest/Kconfig" diff --git a/Kconfig.utestcases b/Kconfig.utestcases deleted file mode 100644 index de283e5e81..0000000000 --- a/Kconfig.utestcases +++ /dev/null @@ -1,35 +0,0 @@ -menu "RT-Thread Utestcases" - - config RT_USING_UTESTCASES - bool "RT-Thread Utestcases" - default n - select RT_USING_UTEST - select RT_USING_DEBUG if !RT_USING_ULOG - - if RT_USING_UTESTCASES - - rsource "src/utest/Kconfig" - - menu "Kernel Components" - - menu "Drivers" - rsource "components/drivers/core/utest/Kconfig" - rsource "components/drivers/audio/utest/Kconfig" - rsource "components/drivers/ipc/utest/Kconfig" - rsource "components/drivers/serial/utest/Kconfig" - rsource "components/drivers/smp_call/utest/Kconfig" - endmenu - - rsource "components/dfs/utest/Kconfig" - rsource "components/dfs/dfs_v2/filesystems/tmpfs/utest/Kconfig" - rsource "components/libc/cplusplus/utest/Kconfig" - rsource "components/lwp/utest/Kconfig" - rsource "components/mm/utest/Kconfig" - rsource "components/net/utest/Kconfig" - rsource "components/utilities/utest/utest/Kconfig" - - endmenu - -endif - -endmenu diff --git a/components/utilities/utest/Kconfig b/components/utilities/utest/Kconfig new file mode 100644 index 0000000000..2b7bf55a54 --- /dev/null +++ b/components/utilities/utest/Kconfig @@ -0,0 +1,35 @@ +menu "RT-Thread Utestcases" + + config RT_USING_UTESTCASES + bool "RT-Thread Utestcases" + default n + select RT_USING_UTEST + select RT_USING_DEBUG if !RT_USING_ULOG + + if RT_USING_UTESTCASES + + rsource "../../../src/utest/Kconfig" + + menu "Kernel Components" + + menu "Drivers" + rsource "../../../components/drivers/core/utest/Kconfig" + rsource "../../../components/drivers/audio/utest/Kconfig" + rsource "../../../components/drivers/ipc/utest/Kconfig" + rsource "../../../components/drivers/serial/utest/Kconfig" + rsource "../../../components/drivers/smp_call/utest/Kconfig" + endmenu + + rsource "../../../components/dfs/utest/Kconfig" + rsource "../../../components/dfs/dfs_v2/filesystems/tmpfs/utest/Kconfig" + rsource "../../../components/libc/cplusplus/utest/Kconfig" + rsource "../../../components/lwp/utest/Kconfig" + rsource "../../../components/mm/utest/Kconfig" + rsource "../../../components/net/utest/Kconfig" + rsource "../../../components/utilities/utest/utest/Kconfig" + + endmenu + +endif + +endmenu diff --git a/components/utilities/utest/README.md b/components/utilities/utest/README.md new file mode 100644 index 0000000000..3d3dd7c8e8 --- /dev/null +++ b/components/utilities/utest/README.md @@ -0,0 +1,70 @@ +# RT-Thread 测试用例集合 + +## 简介 + +为了保证某一部分代码的质量,通常可以通过编写测试用例的方式,验证此代码的功能。为了保证 RT-Thread 相关仓库的代码质量,我们基于 utest 框架搭建了一套简易的自动化测试环境。有兴趣,有精力的小伙伴可以利用这套机制完善自己的代码检查。如果有意愿让社区上更多的小伙伴受益,也可以在提交代码的时候,把对应的测试用例也提交上来。 + +## 相关配置 + +自动化测试使用的配置文件维护在 [examples/utest/configs](../../../examples/utest/configs),每一个目录代表一种功能集合,如:kernel, net 等。 + +## 如何贡献 + +### 1. 编写测试用例 + +参考已有的测试用例,在对应模块目录下添加 `utest` 目录并维护自己的测试用例,例如串口测试用例位于 `components/drivers/serial/utest`。测试用例的编写方法参考文档中心[《utest 测试框架》章节](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/utest/utest)。 + +### 2. 本地测试 + +1. 在 `bsp\qemu-vexpress-a9` 目录下打开 `menuconfig`,使能对应的测试用例,如下: + +``` +RT-Thread Utestcases ---> + [*] RT-Thread Utestcases + Utest Self Testcase ---> + [*] Pass test +``` + +2. 保存并退出,输入 scons 编译当前 bsp。 + +3. 输入 .\qemu.bat 运行当前 bsp,在 msh 环境下执行 utest_run 命令,验证代码运行是否正常。 + +``` +msh />utest_run +[I/utest] [==========] [ utest ] loop 1/1 +[I/utest] [==========] [ utest ] started +[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) started +[D/utest] [ OK ] [ unit ] (test_assert_pass:16) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:17) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:19) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:20) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:22) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:23) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:25) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:26) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:28) is passed +[D/utest] [ OK ] [ unit ] (test_assert_pass:29) is passed +[I/utest] [ PASSED ] [ result ] testcase (testcases.utest.pass_tc) +[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) finished +[I/utest] [==========] [ utest ] finished +``` + +### 3. 提交 + +1. 如果是对已有测试集合的完善,需要把添加的测试用例的配置项,以及对应的依赖项添加到对应测试集合的配置文件里,如:[examples/utest/configs/kernel/mem.cfg](../../../examples/utest/configs/kernel/mem.cfg)。 + +``` +CONFIG_RT_UTEST_MEMHEAP=y + +# dependencies +CONFIG_RT_USING_MEMHEAP=y +``` + +2. 如果要添加新的测试集合,需要参考已有的测试集合,在 [examples/utest/configs](../../../examples/utest/configs) 目录下添加新的测试集合配置项。并更新 [.github/workflows/utest_auto_run.yml](../../../.github/workflows/utest_auto_run.yml) 内的测试集合。 + +``` +- platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", SMP_RUN: "" } + config_file: "kernel/mem.cfg" +``` + +3. 向 RT-Thread 主仓库提交合并请求。 diff --git a/documentation/6.components/utest/utest.md b/documentation/6.components/utest/utest.md index aa70ee96df..aae598523c 100644 --- a/documentation/6.components/utest/utest.md +++ b/documentation/6.components/utest/utest.md @@ -308,7 +308,7 @@ The utest_run tool now supports dynamic auto-completion for test case names. Aft # 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. +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 `components/utilities/utest/Kconfig` 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. For each module, you can maintain unit testcases in a unified manner in the following way: @@ -322,7 +322,7 @@ For each module, you can maintain unit testcases in a unified manner in the foll - `SConscript` file, when adding src files, you need to rely on `RT_UTEST_XXXX`. -After completing the above steps, rsource the path of the Kconfig file of utest of this module to the file `Kconfig.utestcases`. +After completing the above steps, rsource the path of the Kconfig file of utest of this module to the file `components/utilities/utest/Kconfig`. You can find a good example in "klibc". diff --git a/examples/utest/README.md b/examples/utest/README.md deleted file mode 100644 index f21884b5b7..0000000000 --- a/examples/utest/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# RT-Thread 测试用例集合 - -## 简介 - -为了保证某一部分代码的质量,通常可以通过编写测试用例的方式,验证此代码的功能。为了保证 RT-Thread 相关仓库的代码质量,我们基于 utest 框架搭建了一套简易的自动化测试环境。有兴趣,有精力的小伙伴可以利用这套机制完善自己的代码检查。如果有意愿让社区上更多的小伙伴受益,也可以在提交代码的时候,把对应的测试用例也提交上来。 - -## 目录结构 - -| 目录 | 用途 | -| --------- | ------------------------------------------------------------ | -| configs | 配置文件集合(每一个目录代表一种功能集合,如:kernel,net等) | - -## 如何贡献 - -### 1. 编写测试用例 - -参考已有的测试用例,在对应模块目录下添加 `utest` 目录并维护自己的测试用例,例如串口测试用例位于 `components/drivers/serial/utest`。测试用例的编写方法参考文档中心[《utest 测试框架》章节](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/utest/utest)。 - -### 2. 本地测试 - -1. 在 `bsp\qemu-vexpress-a9` 目录下打开 `menuconfig`,使能对应的测试用例,如下: - -``` -RT-Thread Utestcases ---> - [*] RT-Thread Utestcases - Utest Self Testcase ---> - [*] Pass test -``` - -2. 保存并退出,输入 scons 编译当前 bsp。 - -3. 输入 .\qemu.bat 运行当前 bsp,在 msh 环境下执行 utest_run 命令,验证代码运行是否正常。 - -``` -msh />utest_run -[I/utest] [==========] [ utest ] loop 1/1 -[I/utest] [==========] [ utest ] started -[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) started -[D/utest] [ OK ] [ unit ] (test_assert_pass:16) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:17) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:19) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:20) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:22) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:23) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:25) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:26) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:28) is passed -[D/utest] [ OK ] [ unit ] (test_assert_pass:29) is passed -[I/utest] [ PASSED ] [ result ] testcase (testcases.utest.pass_tc) -[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) finished -[I/utest] [==========] [ utest ] finished -``` - -### 3. 提交 - -1. 如果是对已有测试集合的完善,需要把添加的测试用例的配置项,以及对应的依赖项添加到对应测试集合的配置文件里,如:[examples\utest\configs\kernel\mem.conf](./configs/kernel/mem.conf)。 - -``` -CONFIG_RT_UTEST_MEMHEAP=y - -# dependencies -CONFIG_RT_USING_MEMHEAP=y -``` - -2. 如果要添加新的测试集合,需要参考已有的测试集合,在 [examples\utest\configs](./configs) 目录下添加新的测试集合配置项。并更新 [.github\workflows\action_utest.yml](../../.github/workflows/action_utest.yml) 内的测试集合。 - -``` -- {UTEST: "kernel/mem", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", CONFIG_FILE: "kernel/mem.conf", SD_FILE: "sd.bin"} -- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", CONFIG_FILE: "utest_self/self.conf", SD_FILE: "sd.bin"} -``` - -3. 向 RT-Thread 主仓库提交合并请求。 diff --git a/tools/env_utility.py b/tools/env_utility.py index d7904ff005..639ab530b7 100644 --- a/tools/env_utility.py +++ b/tools/env_utility.py @@ -327,7 +327,9 @@ def get_file_md5(file): # Exclude utestcases def exclude_utestcases(RTT_ROOT): - if os.path.isfile(os.path.join(RTT_ROOT, 'Kconfig.utestcases')): + utestcases_kconfig = os.path.join(RTT_ROOT, 'components', 'utilities', 'utest', 'Kconfig') + + if os.path.isfile(utestcases_kconfig): return if not os.path.isfile(os.path.join(RTT_ROOT, 'Kconfig')): @@ -337,7 +339,7 @@ def exclude_utestcases(RTT_ROOT): data = f.readlines() with open(os.path.join(RTT_ROOT, 'Kconfig'), 'w') as f: for line in data: - if line.find('Kconfig.utestcases') == -1: + if line.find('components/utilities/utest/Kconfig') == -1: f.write(line) diff --git a/tools/mkdist.py b/tools/mkdist.py index 838ae15ad5..ddbbc3dc51 100644 --- a/tools/mkdist.py +++ b/tools/mkdist.py @@ -110,6 +110,11 @@ def bsp_update_sconstruct(dist_dir): f.write(line) def bsp_update_kconfig_testcases(dist_dir): + utestcases_kconfig = os.path.join(dist_dir, 'rt-thread/components/utilities/utest/Kconfig') + + if os.path.isfile(utestcases_kconfig): + return + # delete testcases in rt-thread/Kconfig if not os.path.isfile(os.path.join(dist_dir, 'rt-thread/Kconfig')): return @@ -118,7 +123,7 @@ def bsp_update_kconfig_testcases(dist_dir): data = f.readlines() with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'w') as f: for line in data: - if line.find('Kconfig.utestcases') == -1: + if line.find('components/utilities/utest/Kconfig') == -1: f.write(line) def bsp_update_kconfig(dist_dir): @@ -336,4 +341,4 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, env, project_name, project_path=No if project_path is None: zip_dist(dist_dir, project_name) print("Distribution package created: {}.zip".format(dist_dir)) - print('=> Distribution stripped successfully') \ No newline at end of file + print('=> Distribution stripped successfully') -- cgit v1.3.1