Skip to content

Commit 3906f3b

Browse files
committed
[add] auto test ci.
1 parent 5102c32 commit 3906f3b

File tree

10 files changed

+517
-0
lines changed

10 files changed

+517
-0
lines changed

.github/workflows/action_utest.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: AutoTestCI
2+
on: push
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
name: ${{ matrix.legs.UTEST }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
legs:
11+
- {UTEST: "kernel/ipc", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
12+
- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
13+
14+
env:
15+
TEST_BSP_ROOT: ${{ matrix.legs.RTT_BSP }}
16+
TEST_CONFIG_FILE: ${{ matrix.legs.CONFIG_FILE }}
17+
steps:
18+
- uses: actions/checkout@v1
19+
- name: Prepare env
20+
run: |
21+
sudo apt-get update > /dev/null
22+
sudo apt-get -yqq install scons qemu-system-arm git
23+
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/arm-2017q2-v6/gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2
24+
sudo tar xjf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 -C /opt
25+
- name: Build bsp
26+
run: |
27+
export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update/bin
28+
/opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc --version
29+
cp $TEST_CONFIG_FILE $TEST_BSP_ROOT/rtconfig.h
30+
scons -j$(nproc) -C $TEST_BSP_ROOT
31+
- name: Start test
32+
run: |
33+
git clone https://github.com/armink/UtestRunner.git
34+
pushd $TEST_BSP_ROOT
35+
dd if=/dev/zero of=sd.bin bs=1024 count=65536
36+
popd
37+
pushd UtestRunner
38+
python3 qemu_runner.py --elf ../$TEST_BSP_ROOT/rtthread.elf --sd ../$TEST_BSP_ROOT/sd.bin
39+
cat rtt_console.log
40+
popd

Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
source "$RTT_DIR/src/Kconfig"
22
source "$RTT_DIR/libcpu/Kconfig"
33
source "$RTT_DIR/components/Kconfig"
4+
source "$RTT_DIR/examples/utest/testcases/Kconfig"

examples/utest/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# RT-Thread 测试用例集合
2+
3+
## 简介
4+
5+
为了保证某一部分代码的质量,通常可以通过编写测试用例的方式,验证此代码的功能。为了保证 RT-Thread 的代码质量,我们搭建了一套简易的自动化测试环境。每当向 RT-Thread 提交代码时,都应该编写对应的测试用例,来保证提交的代码能够正常工作。
6+
7+
## 目录结构
8+
9+
| 目录 | 用途 |
10+
| --------- | ------------------------------------------------------------ |
11+
| configs | 配置文件集合(每一个目录代表一种功能集合,如:kernel,net等) |
12+
| testcases | 测试用例源代码 |
13+
14+
## 如何贡献
15+
16+
### 1. 编写测试用例
17+
18+
参考已有的测试用例在 examples\utest\testcases 目录下添加自己的测试用例。测试用例的编写方法参考文档中心《utest 测试框架》章节。
19+
20+
### 2. 本地测试
21+
22+
1. 在 bsp\qemu-vexpress-a9 目录下打开 menuconfig,使能对应的测试用例,如下:
23+
24+
```
25+
RT-Thread Utestcases --->
26+
[*] RT-Thread Utestcases
27+
Utest Self Testcase --->
28+
[*] Pass test
29+
```
30+
31+
2. 保存并退出,输入 scons 编译当前 bsp。
32+
33+
3. 输入 .\qemu.bat 运行当前 bsp,在 msh 环境下执行 utest_run 命令,验证代码运行是否正常。
34+
35+
```
36+
msh />utest_run
37+
[I/utest] [==========] [ utest ] loop 1/1
38+
[I/utest] [==========] [ utest ] started
39+
[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) started
40+
[D/utest] [ OK ] [ unit ] (test_assert_pass:16) is passed
41+
[D/utest] [ OK ] [ unit ] (test_assert_pass:17) is passed
42+
[D/utest] [ OK ] [ unit ] (test_assert_pass:19) is passed
43+
[D/utest] [ OK ] [ unit ] (test_assert_pass:20) is passed
44+
[D/utest] [ OK ] [ unit ] (test_assert_pass:22) is passed
45+
[D/utest] [ OK ] [ unit ] (test_assert_pass:23) is passed
46+
[D/utest] [ OK ] [ unit ] (test_assert_pass:25) is passed
47+
[D/utest] [ OK ] [ unit ] (test_assert_pass:26) is passed
48+
[D/utest] [ OK ] [ unit ] (test_assert_pass:28) is passed
49+
[D/utest] [ OK ] [ unit ] (test_assert_pass:29) is passed
50+
[I/utest] [ PASSED ] [ result ] testcase (testcases.utest.pass_tc)
51+
[I/utest] [----------] [ testcase ] (testcases.utest.pass_tc) finished
52+
[I/utest] [==========] [ utest ] finished
53+
```
54+
55+
### 3. 提交
56+
57+
1. 如果是对已有测试集合的完善,需要把添加的测试用例的配置项添加到对应测试集合的配置文件里,如:`examples\utest\configs\utest_self\config.h`
58+
59+
```
60+
/* RT-Thread Utestcases */
61+
62+
#define RT_USING_UTESTCASES
63+
64+
/* Utest Self Testcase */
65+
66+
#define UTEST_SELF_PASS_TC
67+
68+
/* xxx Testcase */
69+
#define UTEST_XXX_TC
70+
```
71+
72+
2. 如果要添加新的测试集合,需要参考已有的测试集合,在 `examples\utest\configs` 目录下添加新的测试集合配置项。并更新 `.github\workflows\action_utest.yml` 内的测试集合。
73+
74+
```
75+
- {UTEST: "kernel/ipc", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
76+
- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
77+
```
78+
79+
3. 向 RT-Thread 主仓库提交合并请求。

0 commit comments

Comments
 (0)