From 7e5b8d99e46f5be0dc76ba1318c329e165f87ae6 Mon Sep 17 00:00:00 2001 From: Yihao Wu Date: Thu, 5 May 2022 17:19:12 +0800 Subject: [PATCH] tests: add a test framework. run_test ---+--> prev_env |--> build_case (with test_1/patch) |--> test_1/assert |--> build_case (with test_2/patch) |--> test_2/assert |--> ... ./tests/run_test ci is the current available bundle. Signed-off-by: Yihao Wu --- tests/build_case | 14 ++++++++++++++ tests/bundles/ci | 1 + tests/libs/catch_error | 9 +++++++++ tests/libs/working_dir | 7 +++++++ tests/prep_env | 31 +++++++++++++++++++++++++++++++ tests/run_test | 13 +++++++++++++ tests/test_quick_start/assert | 10 ++++++++++ tests/test_quick_start/patch.diff | 16 ++++++++++++++++ 8 files changed, 101 insertions(+) create mode 100755 tests/build_case create mode 100644 tests/bundles/ci create mode 100755 tests/libs/catch_error create mode 100755 tests/libs/working_dir create mode 100755 tests/prep_env create mode 100755 tests/run_test create mode 100755 tests/test_quick_start/assert create mode 100644 tests/test_quick_start/patch.diff diff --git a/tests/build_case b/tests/build_case new file mode 100755 index 0000000..725b678 --- /dev/null +++ b/tests/build_case @@ -0,0 +1,14 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +source $(dirname "$0")/libs/working_dir +source libs/catch_error + +podman cp $1/patch.diff plugsched:/root/patch +podman exec -it plugsched patch -f -p1 -i patch +podman exec -it plugsched plugsched-cli build scheduler +podman exec -it plugsched patch -f -p1 -i patch -R +podman exec -it plugsched ls /usr/local/lib/plugsched/rpmbuild/RPMS/$(uname -i)/ +podman exec -it plugsched bash -c "cp /usr/local/lib/plugsched/rpmbuild/RPMS/$(uname -i)/scheduler-xxx-*.rpm /root" + diff --git a/tests/bundles/ci b/tests/bundles/ci new file mode 100644 index 0000000..d1666d4 --- /dev/null +++ b/tests/bundles/ci @@ -0,0 +1 @@ +quick_start diff --git a/tests/libs/catch_error b/tests/libs/catch_error new file mode 100755 index 0000000..3e8df7b --- /dev/null +++ b/tests/libs/catch_error @@ -0,0 +1,9 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +set -e +# keep track of the last executed command +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG +# echo an error message before exiting +trap 'echo "\"${last_command}\" command failed with exit code $?."' EXIT diff --git a/tests/libs/working_dir b/tests/libs/working_dir new file mode 100755 index 0000000..682b070 --- /dev/null +++ b/tests/libs/working_dir @@ -0,0 +1,7 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +TEST_PATH=$(realpath $(dirname "$0")) +cd ${TEST_PATH} +export PATH=$PATH:${TEST_PATH} diff --git a/tests/prep_env b/tests/prep_env new file mode 100755 index 0000000..946718a --- /dev/null +++ b/tests/prep_env @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +source $(dirname "$0")/libs/working_dir +source libs/catch_error + +arch=$(uname -i) +if [ "${arch}" = "x86_64" ]; then + # x86_64 is the default image + tag="latest" +else + tag="latest-${arch}" +fi + +uname_r=$(uname -r) +uname_noarch=${uname_r%.*} +yum install anolis-repos -y +yum install podman yum-utils kernel-debuginfo-${uname_r} kernel-devel-${uname_r} --enablerepo=Plus-debuginfo --enablerepo=Plus -y + +container=$(podman ps -a | awk '$NF=="plugsched"{print $1}') +if [ -n "$container" ]; then + podman rm -f ${container} +fi +podman run -itd --name=plugsched -w /root/ -v /tmp/work:/root -v /usr/src/kernels:/usr/src/kernels -v /usr/lib/debug/lib/modules:/usr/lib/debug/lib/modules plugsched/plugsched-sdk:${tag} /bin/bash +podman exec -it plugsched rm -rf /usr/local/lib/plugsched +podman cp .. plugsched:/usr/local/lib/plugsched +mkdir -p /tmp/work && cd /tmp/work +yumdownloader --source kernel-${uname_r} --enablerepo=Plus +podman exec -it plugsched plugsched-cli extract_src kernel-${uname_noarch}.src.rpm ./kernel +podman exec -it plugsched plugsched-cli init ${uname_r} ./kernel ./scheduler diff --git a/tests/run_test b/tests/run_test new file mode 100755 index 0000000..c15b317 --- /dev/null +++ b/tests/run_test @@ -0,0 +1,13 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +source $(dirname "$0")/libs/working_dir +source libs/catch_error + +tests=$(cat bundles/$1) +prep_env +for T in ${tests}; do + build_case test_$T + test_$T/assert +done diff --git a/tests/test_quick_start/assert b/tests/test_quick_start/assert new file mode 100755 index 0000000..488fa90 --- /dev/null +++ b/tests/test_quick_start/assert @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright 2019-2022 Alibaba Group Holding Limited. +# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +rpm -ivh /tmp/work/scheduler-xxx-*.rpm +if ! dmesg | grep "I am the new scheduler: __schedule"; then + 2>&1 echo "Failed to install the scheduler module" + exit 1 +fi +rpm -e scheduler-xxx diff --git a/tests/test_quick_start/patch.diff b/tests/test_quick_start/patch.diff new file mode 100644 index 0000000..b4be4f3 --- /dev/null +++ b/tests/test_quick_start/patch.diff @@ -0,0 +1,16 @@ +// Copyright 2019-2022 Alibaba Group Holding Limited. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause + +diff --git a/scheduler/kernel/sched/mod/core.c b/scheduler/kernel/sched/mod/core.c +index 9f16b72..21262fd 100644 +--- a/scheduler/kernel/sched/mod/core.c ++++ b/scheduler/kernel/sched/mod/core.c +@@ -3234,6 +3234,8 @@ static void __sched notrace __schedule(bool preempt) + struct rq *rq; + int cpu; + ++ printk_once("I am the new scheduler: __schedule\n"); ++ + cpu = smp_processor_id(); + rq = cpu_rq(cpu); + prev = rq->curr; -- Gitee