mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
10 files changed
+519
No files matched your search
@@ -0,0 +1,43 @@
|
||||
name: AutoTestCI
|
||||
|
||||
# Controls when the action will run. Triggers the workflow on push or pull request
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
name: ${{ matrix.legs.UTEST }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
legs:
|
||||
- {UTEST: "kernel/ipc", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
|
||||
- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
|
||||
|
||||
env:
|
||||
TEST_BSP_ROOT: ${{ matrix.legs.RTT_BSP }}
|
||||
TEST_CONFIG_FILE: ${{ matrix.legs.CONFIG_FILE }}
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Prepare env
|
||||
run: |
|
||||
sudo apt-get update > /dev/null
|
||||
sudo apt-get -yqq install scons qemu-system-arm git
|
||||
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
|
||||
sudo tar xjf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 -C /opt
|
||||
- name: Build bsp
|
||||
run: |
|
||||
export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update/bin
|
||||
/opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc --version
|
||||
cp $TEST_CONFIG_FILE $TEST_BSP_ROOT/rtconfig.h
|
||||
scons -j$(nproc) -C $TEST_BSP_ROOT
|
||||
- name: Start test
|
||||
run: |
|
||||
git clone https://github.com/armink/UtestRunner.git
|
||||
pushd $TEST_BSP_ROOT
|
||||
dd if=/dev/zero of=sd.bin bs=1024 count=65536
|
||||
popd
|
||||
pushd UtestRunner
|
||||
python3 qemu_runner.py --elf ../$TEST_BSP_ROOT/rtthread.elf --sd ../$TEST_BSP_ROOT/sd.bin
|
||||
cat rtt_console.log
|
||||
popd
|
||||
@@ -1,3 +1,4 @@
|
||||
source "$RTT_DIR/src/Kconfig"
|
||||
source "$RTT_DIR/libcpu/Kconfig"
|
||||
source "$RTT_DIR/components/Kconfig"
|
||||
source "$RTT_DIR/examples/utest/testcases/Kconfig"
|
||||
@@ -0,0 +1,79 @@
|
||||
# RT-Thread 测试用例集合
|
||||
|
||||
## 简介
|
||||
|
||||
为了保证某一部分代码的质量,通常可以通过编写测试用例的方式,验证此代码的功能。为了保证 RT-Thread 相关仓库的代码质量,我们基于 utest 框架搭建了一套简易的自动化测试环境。有兴趣,有精力的小伙伴可以利用这套机制完善自己的代码检查。如果有意愿让社区上更多的小伙伴收益,也可以在提交代码的时候,把对应的测试用例也提交上来。
|
||||
|
||||
## 目录结构
|
||||
|
||||
| 目录 | 用途 |
|
||||
| --------- | ------------------------------------------------------------ |
|
||||
| configs | 配置文件集合(每一个目录代表一种功能集合,如:kernel,net等) |
|
||||
| testcases | 测试用例源代码 |
|
||||
|
||||
## 如何贡献
|
||||
|
||||
### 1. 编写测试用例
|
||||
|
||||
参考已有的测试用例在 [examples\utest\testcases](./testcases) 目录下添加自己的测试用例。测试用例的编写方法参考文档中心《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\utest_self\config.h](./configs/utest_self/config.h)。
|
||||
|
||||
```
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
#define RT_USING_UTESTCASES
|
||||
|
||||
/* Utest Self Testcase */
|
||||
|
||||
#define UTEST_SELF_PASS_TC
|
||||
|
||||
/* xxx Testcase */
|
||||
#define UTEST_XXX_TC
|
||||
```
|
||||
|
||||
2. 如果要添加新的测试集合,需要参考已有的测试集合,在 [examples\utest\configs](./configs) 目录下添加新的测试集合配置项。并更新 [.github\workflows\action_utest.yml](../../.github/workflows/action_utest.yml) 内的测试集合。
|
||||
|
||||
```
|
||||
- {UTEST: "kernel/ipc", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
|
||||
- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
|
||||
```
|
||||
|
||||
3. 向 RT-Thread 主仓库提交合并请求。
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
||||
menu "RT-Thread Utestcases"
|
||||
|
||||
config RT_USING_UTESTCASES
|
||||
bool "RT-Thread Utestcases"
|
||||
default n
|
||||
select RT_USING_UTEST
|
||||
|
||||
if RT_USING_UTESTCASES
|
||||
|
||||
source "$RTT_DIR/examples/utest/testcases/utest/Kconfig"
|
||||
|
||||
endif
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,15 @@
|
||||
# RT-Thread building script for bridge
|
||||
|
||||
import os
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
@@ -0,0 +1,7 @@
|
||||
menu "Utest Self Testcase"
|
||||
|
||||
config UTEST_SELF_PASS_TC
|
||||
bool "Pass test"
|
||||
default y
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,13 @@
|
||||
Import('rtconfig')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Split('''
|
||||
pass_tc.c
|
||||
''')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('utestcases', src, depend = ['UTEST_SELF_PASS_TC'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2019, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-01-16 MurphyZhao the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "utest.h"
|
||||
|
||||
static void test_assert_pass(void)
|
||||
{
|
||||
uassert_true(1);
|
||||
uassert_false(0);
|
||||
|
||||
uassert_null(RT_NULL);
|
||||
uassert_not_null(!RT_NULL);
|
||||
|
||||
uassert_int_equal(1, 1);
|
||||
uassert_int_not_equal(1, 2);
|
||||
|
||||
uassert_str_equal("Hello RT-Thread!", "Hello RT-Thread!");
|
||||
uassert_str_not_equal("Hello RT-Thread!", "Hello");
|
||||
|
||||
uassert_in_range(2048, 1024, 4096);
|
||||
uassert_not_in_range(0, 1024, 4096);
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_assert_pass);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10);
|
||||
@@ -447,6 +447,10 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
||||
variant_dir=kernel_vdir + '/components',
|
||||
duplicate=0,
|
||||
exports='remove_components'))
|
||||
# include testcases
|
||||
objs.extend(SConscript(Rtt_Root + '/examples/utest/testcases/SConscript',
|
||||
variant_dir=kernel_vdir + '/examples/utest/testcases',
|
||||
duplicate=0))
|
||||
|
||||
return objs
|
||||
|
||||
|
||||
Reference in new issue
Block a user