Skip to content
Open
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
15 changes: 9 additions & 6 deletions .github/workflows/utest_auto_run.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automation utest run script for the QEMU platform
# Generate the corresponding config configuration for CI based on the configuration file under examples/utest/configs.
# Generate the corresponding config configuration for CI based on the configuration file under .github/utest/configs.

name: utest_auto_run

Expand All @@ -9,8 +9,9 @@ on:
- master
paths:
- '.github/workflows/utest_auto_run.yml'
- '.github/utest/configs/**'
- 'Kconfig'
- 'Kconfig.utestcases'
- 'components/utilities/utest/Kconfig'
- 'bsp/qemu-vexpress-a9/**'
- 'bsp/qemu-virt64-aarch64/**'
- 'bsp/qemu-virt64-riscv/**'
Expand All @@ -28,8 +29,9 @@ on:
- master
paths:
- '.github/workflows/utest_auto_run.yml'
- '.github/utest/configs/**'
- 'Kconfig'
- 'Kconfig.utestcases'
- 'components/utilities/utest/Kconfig'
- 'bsp/qemu-vexpress-a9/**'
- 'bsp/qemu-virt64-aarch64/**'
- 'bsp/qemu-virt64-riscv/**'
Expand Down Expand Up @@ -155,6 +157,7 @@ jobs:
TEST_BSP_ROOT: ${{ matrix.platform.RTT_BSP }}
TEST_CONFIG_FILE: ${{ matrix.config_file }}
TEST_SD_FILE: ${{ matrix.platform.SD_FILE }}
UTEST_CONFIG_ROOT: .github/utest/configs
steps:
- uses: actions/checkout@main

Expand Down Expand Up @@ -266,16 +269,16 @@ jobs:
run: |
# Whether plan to run SMP?
if [[ "${{ matrix.platform.SMP_RUN }}" == "smp" ]]; then
cat examples/utest/configs/smp/smp.cfg >> $TEST_BSP_ROOT/.config
cat $UTEST_CONFIG_ROOT/smp/smp.cfg >> $TEST_BSP_ROOT/.config
fi

# Is the kernel rtsmart?
if [[ "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
cat examples/utest/configs/rtsmart/rtsmart.cfg >> $TEST_BSP_ROOT/.config
cat $UTEST_CONFIG_ROOT/rtsmart/rtsmart.cfg >> $TEST_BSP_ROOT/.config
fi

echo CONFIG_RT_USING_UTESTCASES=y >> $TEST_BSP_ROOT/.config
cat examples/utest/configs/$TEST_CONFIG_FILE >> $TEST_BSP_ROOT/.config
cat $UTEST_CONFIG_ROOT/$TEST_CONFIG_FILE >> $TEST_BSP_ROOT/.config
scons --pyconfig-silent -C $TEST_BSP_ROOT
scons -j$(nproc) --strict -C $TEST_BSP_ROOT

Expand Down
2 changes: 1 addition & 1 deletion Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rsource "src/Kconfig"
rsource "libcpu/Kconfig"
rsource "components/Kconfig"
rsource "Kconfig.utestcases"
rsource "components/utilities/utest/Kconfig"
35 changes: 0 additions & 35 deletions Kconfig.utestcases

This file was deleted.

3 changes: 3 additions & 0 deletions components/dfs/dfs_v2/filesystems/tmpfs/SConscript
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from building import *
import os

cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]

group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_TMPFS'], CPPPATH = CPPPATH)

group = group + SConscript(os.path.join('utest', 'SConscript'))

Return('group')
1 change: 1 addition & 0 deletions components/lwp/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ if not GetDepend(['LWP_USING_RUNTIME']):
group = DefineGroup('lwProcess', src, depend = ['RT_USING_SMART'], CPPPATH = CPPPATH)

group = group + SConscript(os.path.join('vdso', 'SConscript'))
group = group + SConscript(os.path.join('utest', 'SConscript'))
Return('group')
8 changes: 8 additions & 0 deletions components/lwp/utest/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
menu "LWP Testcase"

config RT_UTEST_LWP
bool "Enable LWP condvar test"
depends on RT_USING_SMART
default n

endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cwd = GetCurrentDir()
src = []
CPPPATH = [cwd]

if GetDepend(['UTEST_LWP_TC', 'RT_USING_SMART']):
if GetDepend(['RT_UTEST_LWP', 'RT_USING_SMART']):
src += ['condvar_timedwait_tc.c', 'condvar_broadcast_tc.c', 'condvar_signal_tc.c']

group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH)
Expand Down
2 changes: 2 additions & 0 deletions components/mm/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ if GetDepend('ARCH_ARM_CORTEX_A') or GetDepend('ARCH_ARMV8') or GetDepend('ARCH_

group = DefineGroup('Memm', src, depend = ['ARCH_MM_MMU'], CPPPATH = CPPPATH)

group = group + SConscript(os.path.join('utest', 'SConscript'))

Return('group')
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions components/utilities/utest/Kconfig
Original file line number Diff line number Diff line change
@@ -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
17 changes: 7 additions & 10 deletions examples/utest/README.md → components/utilities/utest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

为了保证某一部分代码的质量,通常可以通过编写测试用例的方式,验证此代码的功能。为了保证 RT-Thread 相关仓库的代码质量,我们基于 utest 框架搭建了一套简易的自动化测试环境。有兴趣,有精力的小伙伴可以利用这套机制完善自己的代码检查。如果有意愿让社区上更多的小伙伴受益,也可以在提交代码的时候,把对应的测试用例也提交上来。

## 目录结构
## 相关配置

| 目录 | 用途 |
| --------- | ------------------------------------------------------------ |
| configs | 配置文件集合(每一个目录代表一种功能集合,如:kernel,net等) |
| testcases | 测试用例源代码 |
自动化测试使用的配置文件维护在 [.github/utest/configs](../../../.github/utest/configs),每一个目录代表一种功能集合,如:kernel, net 等。

## 如何贡献

### 1. 编写测试用例

参考已有的测试用例在 [examples\utest\testcases](./testcases) 目录下添加自己的测试用例。测试用例的编写方法参考文档中心[《utest 测试框架》章节](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/utest/utest)。
参考已有的测试用例,在对应模块目录下添加 `utest` 目录并维护自己的测试用例,例如串口测试用例位于 `components/drivers/serial/utest`。测试用例的编写方法参考文档中心[《utest 测试框架》章节](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/utest/utest)。

### 2. 本地测试

Expand Down Expand Up @@ -54,7 +51,7 @@ msh />utest_run

### 3. 提交

1. 如果是对已有测试集合的完善,需要把添加的测试用例的配置项,以及对应的依赖项添加到对应测试集合的配置文件里,如:[examples\utest\configs\kernel\mem.conf](./configs/kernel/mem.conf)。
1. 如果是对已有测试集合的完善,需要把添加的测试用例的配置项,以及对应的依赖项添加到对应测试集合的配置文件里,如:[.github/utest/configs/kernel/mem.cfg](../../../.github/utest/configs/kernel/mem.cfg)。

```
CONFIG_RT_UTEST_MEMHEAP=y
Expand All @@ -63,11 +60,11 @@ CONFIG_RT_UTEST_MEMHEAP=y
CONFIG_RT_USING_MEMHEAP=y
```

2. 如果要添加新的测试集合,需要参考已有的测试集合,在 [examples\utest\configs](./configs) 目录下添加新的测试集合配置项。并更新 [.github\workflows\action_utest.yml](../../.github/workflows/action_utest.yml) 内的测试集合。
2. 如果要添加新的测试集合,需要参考已有的测试集合,在 [.github/utest/configs](../../../.github/utest/configs) 目录下添加新的测试集合配置项。并更新 [.github/workflows/utest_auto_run.yml](../../../.github/workflows/utest_auto_run.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"}
- 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 主仓库提交合并请求。
4 changes: 2 additions & 2 deletions documentation/6.components/utest/utest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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 <a href="https://github.com/RT-Thread/rt-thread/blob/master/src/klibc/utest/">"klibc"</a>.

15 changes: 0 additions & 15 deletions examples/utest/testcases/SConscript

This file was deleted.

6 changes: 0 additions & 6 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
variant_dir=kernel_vdir + '/components',
duplicate=0,
exports='remove_components'))
# include testcases
if os.path.isfile(os.path.join(Rtt_Root, 'examples/utest/testcases/SConscript')):
objs.extend(SConscript(Rtt_Root + '/examples/utest/testcases/SConscript',
variant_dir=kernel_vdir + '/examples/utest/testcases',
duplicate=0))

return objs

def PrepareModuleBuilding(env, root_directory, bsp_directory):
Expand Down
6 changes: 4 additions & 2 deletions tools/env_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')):
Expand All @@ -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)


Expand Down
9 changes: 7 additions & 2 deletions tools/mkdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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')
print('=> Distribution stripped successfully')
Loading