Z572's blog

learn mugen

by Z572 — Thu 09 March 2023

简单学习了一下 openEuler 的测试套件 mugen 并尝试给 mugen 加一个 gcc 测试.

在 conf/env.json 写入如下内容

{
  "NODE": [
    {
      "ID": 1,
      "LOCALTION": "local",
      "MACHINE": "kvm",
      "FRAME": "riscv64",
      "IPV4": "127.0.0.1",
      "MAC": "52:54:00:12:34:56",
      "NIC": "eth0",
      "USER": "root",
      "HOST_IP": "",
      "HOST_USER": "",
      "HOST_PASSWORD": "",
      "HOST_SSH_PORT": "",
      "PASSWORD": "openEuler12#$",
      "BMC_IP": "",
      "BMC_USER": "",
      "MBC_PASSWORD": "",
      "SSH_PORT": 22
    }
  ]
}

在 suite2cases 目录下 增加一个 gcc-10.3.1.json 文件

{
    "path": "$OET_PATH/testcases/cli-test/gcc",
     "cases": [
         {
             "name": "oe_test_gcc"
         }
     ]
}

在 testcases/cli-test/ 目录下增加一个 gcc 文件夹

testcases/cli-test/gcc/common/common_gcc.sh:

source "$OET_PATH/libs/locallibs/common_lib.sh"
work_dir="$(mktemp -d)"
function deploy_env() {
    DNF_INSTALL "gcc"
    cd $work_dir
}

function clear_env(){
    rm -rf $work_dir
    DNF_REMOVE
}

testcases/cli-test/gcc/common/main.c:

#include <stdio.h>
int main(void)
{
    printf("Hello World\n");
    return 0;
}

testcases/cli-test/gcc/oe_test_gcc/oe_test_gcc.sh:

source "../common/common_gcc.sh"

function pre_test(){
    LOG_INFO "Start to prepare the test environment."
    deploy_env
    LOG_INFO "Finish preparing the test environment."
}
function run_test(){
    LOG_INFO "Start to run test."
    gcc --help | grep -E "Usage|gcc \[options]\ file..."
    CHECK_RESULT $? 0 0 "Failed option: --help"
    gcc --version | grep -E "gcc \(GCC\)"
    CHECK_RESULT $? 0 0 "Failed option: --version"
    gcc $OET_PATH/testcases/cli-test/gcc/common/main.c -o hello-world
    CHECK_RESULT $? 0 0 "Failed option: -o, 'gcc -o hello-world'"
    test -f hello-world
    CHECK_RESULT $? 0 0 "Failed option: -o, if success, have a bin called 'hello-world'"
    ./hello-world | grep "Hello World"
    CHECK_RESULT $? 0 0 "gcc build failed"
    gcc $OET_PATH/testcases/cli-test/gcc/common/main.c -S
    test -f main.s
    CHECK_RESULT $? 0 0 "Failed option: -S, if success, have a .s file called 'main.s'"
}
function post_test(){
    LOG_INFO "Start to restore the test environment."
    clear_env
    LOG_INFO "Finish restoring the test environment."
}

main $@

DNF_INSTALL 用来安装 软件, DNF_REMOVER 用来移除

运行测试

# bash mugen.sh -f gcc-10.3.1
Thu Mar  9 16:15:01 2023 - INFO  - start to run testcase:oe_test_gcc.
Thu Mar  9 16:16:27 2023 - INFO  - The case exit by code 0.
Thu Mar  9 16:16:31 2023 - INFO  - End to run testcase:oe_test_gcc.
Thu Mar  9 16:16:34 2023 - INFO  - A total of 1 use cases were executed, with 1 successes and 0 failures.

如果成功, 则存在 results/gcc-10.3.1/succeed/oe_test_gcc 文件.

如果失败, 可以查看 logs/gcc-10.3.1/oe_test_gcc/ 下相应时间 log 文件.