From 3533162ce06945fe2bae8ddb4d0200e6b3e361c2 Mon Sep 17 00:00:00 2001
From: oh_thats_great <hexinyue1@huawei.com>
Date: Tue, 11 Jul 2023 16:37:43 +0800
Subject: [PATCH] test: support yum install sysmaster

---
 install.sh                                    | 30 +++++++------
 tests/common/docker_lib.sh                    | 45 ++++++++++++++++---
 tests/common/monitor.sh                       |  2 +-
 tests/common/util_lib.sh                      | 36 ++++++---------
 .../unit_config_test/action_001/action_001.sh |  1 -
 .../unit_config_test/assert_001/assert_001.sh |  1 -
 .../unit_config_test/condition_001/check.sh   |  2 +-
 .../condition_001/condition_001.sh            |  1 -
 .../unit_config_test/condition_002/check.sh   |  2 +-
 .../condition_002/condition_002.sh            |  1 -
 .../condition_003/condition_003.sh            |  1 -
 .../unit_config_test/dependency_001/check.sh  |  2 +-
 .../dependency_001/dependency_001.sh          |  1 -
 .../dependency_002/dependency_002.sh          |  1 -
 .../dependency_003/dependency_003.sh          |  1 -
 .../dependency_004/dependency_004.sh          |  1 -
 .../dependency_005/dependency_005.sh          |  1 -
 .../unit_config_test/env_001/env_001.sh       |  1 -
 .../unit_config_test/exec_001/exec_001.sh     |  1 -
 .../isolate_001/isolate_001.sh                |  1 -
 .../unit_config_test/kill_001/kill_001.sh     |  1 -
 .../unit_config_test/listen_001/check.sh      |  2 +-
 .../unit_config_test/listen_001/listen_001.sh |  1 -
 .../unit_config_test/refuse_001/refuse_001.sh |  1 -
 .../restart_001/restart_001.sh                |  1 -
 .../service_001/service_001.sh                |  1 -
 .../service_002/service_002.sh                |  1 -
 .../service_003/service_003.sh                |  1 -
 .../unit_config_test/service_004/check.sh     |  2 +-
 .../service_004/service_004.sh                |  1 -
 .../unit_config_test/socket_001/check.sh      |  2 +-
 .../unit_config_test/socket_001/socket_001.sh |  1 -
 .../startlimit_001/startlimit_001.sh          |  1 -
 .../timeout_001/timeout_001.sh                |  1 -
 .../timeout_002/timeout_002.sh                |  1 -
 .../docker_example_001/check.sh               |  3 +-
 tests/perf_test/cpu_time_001/check.sh         |  2 +-
 tests/test_frame.sh                           |  7 +--
 38 files changed, 84 insertions(+), 78 deletions(-)

diff --git a/install.sh b/install.sh
index 675c543..dc0e6da 100644
--- a/install.sh
+++ b/install.sh
@@ -7,19 +7,23 @@ install_dir=${work_dir}/target/install/usr/lib/sysmaster
 
 rm -rf "${work_dir}"/target/install
 
-install -Dm0755 -t ${work_dir}/target/install/usr/bin ${target_dir}/sctl || exit 1
-install -Dm0755 -t ${work_dir}/target/install/usr/bin ${target_dir}/init || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/sysmaster || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/fstab || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/sysmonitor || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/random_seed || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/rc-local-generator || exit 1
-install -Dm0755 -t ${install_dir} ${target_dir}/hostname_setup || exit 1
+install -Dm0550 -t ${work_dir}/target/install/usr/bin ${target_dir}/sctl || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/init || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/sysmaster || exit 1
+
+install -Dm0550 -t ${install_dir} ${target_dir}/fstab || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/sysmonitor || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/random_seed || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/rc-local-generator || exit 1
+install -Dm0550 -t ${install_dir} ${target_dir}/hostname_setup || exit 1
+
+install -Dm0640 -t ${install_dir} ${work_dir}/units/* || exit 1
+install -Dm0640 -t ${install_dir}/plugin ${target_dir}/conf/plugin.conf || exit 1
+install -Dm0640 -t ${work_dir}/target/install/etc/sysmaster ${target_dir}/conf/system.conf || exit 1
 
 strip ${target_dir}/lib*.so
 
-install -Dm0644 -t ${install_dir}/plugin ${target_dir}/libmount.so || exit 1
-install -Dm0644 -t ${install_dir}/plugin ${target_dir}/libservice.so || exit 1
-install -Dm0644 -t ${install_dir}/plugin ${target_dir}/libsocket.so || exit 1
-install -Dm0644 -t ${install_dir}/plugin ${target_dir}/libtarget.so || exit 1
-install -Dm0644 -t ${install_dir}/plugin ${target_dir}/conf/plugin.conf || exit 1
+install -Dm0750 -t ${install_dir}/plugin ${target_dir}/libmount.so || exit 1
+install -Dm0750 -t ${install_dir}/plugin ${target_dir}/libservice.so || exit 1
+install -Dm0750 -t ${install_dir}/plugin ${target_dir}/libsocket.so || exit 1
+install -Dm0750 -t ${install_dir}/plugin ${target_dir}/libtarget.so || exit 1
diff --git a/tests/common/docker_lib.sh b/tests/common/docker_lib.sh
index cc57e51..2ff96b6 100755
--- a/tests/common/docker_lib.sh
+++ b/tests/common/docker_lib.sh
@@ -43,15 +43,32 @@ function load_isula_img() {
 
 function build_base_img() {
     cp -arf ${BUILD_PATH}/target/install "${TMP_DIR}"
+    cp -arf /etc/yum.repos.d "${TMP_DIR}"
 
     pushd "${TMP_DIR}"
-    cat << EOF > Dockerfile
+    if yum list sysmaster; then
+        cat << EOF > Dockerfile
 FROM ${BASE_IMG} as ${SYSMST_BASE_IMG}
+
+RUN rm -rf /etc/yum.repos.d && mkdir /etc/yum.repos.d
+COPY yum.repos.d /etc/yum.repos.d/
+RUN yum install -y sysmaster util-linux shadow sudo passwd net-tools iproute nmap
+EOF
+    else
+        cat << EOF > Dockerfile
+FROM ${BASE_IMG} as ${SYSMST_BASE_IMG}
+
+RUN rm -rf /etc/yum.repos.d && mkdir /etc/yum.repos.d
+COPY yum.repos.d /etc/yum.repos.d/
+RUN yum install -y util-linux shadow sudo passwd net-tools iproute nmap
+
 COPY install/usr/bin/sctl /usr/bin/
-COPY install/usr/bin/init /usr/bin/
-RUN mkdir /usr/lib/sysmaster
+RUN mkdir /usr/lib/sysmaster /etc/sysmaster
 COPY install/usr/lib/sysmaster /usr/lib/sysmaster/
+COPY install/etc/sysmaster /etc/sysmaster/
+RUN sed -i '/LogTarget/ s/=.*/="console-syslog"/' /etc/sysmaster/system.conf
 EOF
+    fi
     cat Dockerfile
     if ! docker build -t "${SYSMST_BASE_IMG}:latest" .; then
         log_error "build ${SYSMST_BASE_IMG} image failed!"
@@ -69,13 +86,29 @@ function build_isula_img() {
 
     pushd "${TMP_DIR}"
     img_name=$(isula-build ctr-img images | grep "${BASE_IMG}" | head -n1 | awk '{print $1}')
-    cat << EOF > Dockerfile
+    if yum list sysmaster; then
+        cat << EOF > Dockerfile
 FROM ${img_name} as ${SYSMST_BASE_IMG}
+
+RUN rm -rf /etc/yum.repos.d && mkdir /etc/yum.repos.d
+COPY yum.repos.d /usr/lib/sysmaster/
+RUN yum install -y sysmaster util-linux shadow sudo passwd net-tools iproute nmap
+EOF
+    else
+        cat << EOF > Dockerfile
+FROM ${img_name} as ${SYSMST_BASE_IMG}
+
+RUN rm -rf /etc/yum.repos.d && mkdir /etc/yum.repos.d
+COPY yum.repos.d /usr/lib/sysmaster/
+RUN yum install -y util-linux shadow sudo passwd net-tools iproute nmap
+
 COPY install/usr/bin/sctl /usr/bin/
-COPY install/usr/bin/init /usr/bin/
-RUN mkdir /usr/lib/sysmaster
+RUN mkdir /usr/lib/sysmaster /etc/sysmaster
 COPY install/usr/lib/sysmaster /usr/lib/sysmaster/
+COPY install/etc/sysmaster /etc/sysmaster/
+RUN sed -i '/LogTarget/ s/=.*/="console-syslog"/' /etc/sysmaster/system.conf
 EOF
+    fi
     cat Dockerfile
     if ! isula-build ctr-img build -o isulad:"${SYSMST_BASE_IMG}:latest" -f Dockerfile .; then
         log_error "build ${SYSMST_BASE_IMG} image failed!"
diff --git a/tests/common/monitor.sh b/tests/common/monitor.sh
index 2fe790f..24b8e6a 100644
--- a/tests/common/monitor.sh
+++ b/tests/common/monitor.sh
@@ -2,7 +2,7 @@
 
 while ((1)); do
     time="$(date)"
-    init_data="$(ps aux | grep -v grep | grep '/usr/bin/init')"
+    init_data="$(ps aux | grep -v grep | grep '/usr/lib/sysmaster/init')"
     sysmst_data="$(ps aux | grep -v grep | grep '/usr/lib/sysmaster/sysmaster')"
 
     pid=$(echo ${init_data} | awk '{print $2}')
diff --git a/tests/common/util_lib.sh b/tests/common/util_lib.sh
index 18de448..2cf944a 100644
--- a/tests/common/util_lib.sh
+++ b/tests/common/util_lib.sh
@@ -5,6 +5,13 @@ export SYSMST_LIB_PATH='/usr/lib/sysmaster/system'
 export SYSMST_ETC_PATH='/etc/sysmaster/system'
 export SYSMST_RUN_PATH='/run/sysmaster/system'
 export SYSMST_LOG='/opt/sysmaster.log'
+[ "${DOCKER_TEST}" -ne 1 ] && SYSMST_LOG='/var/log/messages'
+if ! test -d /usr/lib/sysmaster/system; then
+    SYSMST_LIB_PATH='/usr/lib/sysmaster'
+    SYSMST_ETC_PATH='/etc/sysmaster'
+    SYSMST_RUN_PATH='/run/sysmaster'
+fi
+export SYSMST_PATH='/usr/lib/sysmaster'
 export RELIAB_SWITCH_PATH='/run/sysmaster/reliability'
 export RELIAB_SWITCH='switch.debug'
 export RELIAB_CLR='clear.debug'
@@ -12,7 +19,6 @@ export init_pid=''
 export sysmaster_pid=''
 export cond_fail_log='Starting failed .* condition test failed'
 export asst_fail_log='Starting failed .* assert test failed'
-export yum_proxy='proxy='
 
 # ================== log function ==================
 function log_info() {
@@ -127,14 +133,13 @@ function expect_str_eq() {
 function run_sysmaster() {
     local user="${1:-root}"
 
-    cp -arf "${work_dir}"/tmp_units/*.target ${SYSMST_LIB_PATH} || return 1
     if [ "${user}" = root ]; then
-        RUST_BACKTRACE=full /usr/bin/init &> "${SYSMST_LOG}" &
+        RUST_BACKTRACE=full "${SYSMST_PATH}"/init &> "${SYSMST_LOG}" &
     else
-        chmod 777 /usr/bin/init
-        chmod -R 777 /usr/lib/sysmaster /run
+        chmod 777 "${SYSMST_PATH}"/init
+        chmod -R 777 "${SYSMST_PATH}" /run
         chmod -R 777 "$(dirname "${SYSMST_LOG}")"
-        sudo -u "${user}" /usr/bin/init &> "${SYSMST_LOG}" &
+        sudo -u "${user}" "${SYSMST_PATH}"/init &> "${SYSMST_LOG}" &
     fi
     init_pid=$!
 
@@ -142,17 +147,17 @@ function run_sysmaster() {
     sleep 3
     for ((i = 0; i < 300; ++i)); do
         sleep 1
-        ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -w '/usr/lib/sysmaster/sysmaster' | grep ep_pol && break
+        ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -w "${SYSMST_PATH}"/sysmaster | grep ep_pol && break
     done
     # debug
     ps -elf | grep -v grep | grep -Ew 'sysmaster|init'
-    if ! ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -wq '/usr/lib/sysmaster/sysmaster'; then
+    if ! ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -wq "${SYSMST_PATH}"/sysmaster; then
         cat "${SYSMST_LOG}"
         return 1
     fi
 
     # get sysmaster pid
-    sysmaster_pid="$(ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -w '/usr/lib/sysmaster/sysmaster' | awk '{print $4}')"
+    sysmaster_pid="$(ps -elf | grep -v grep | grep " $(echo ${user} | cut -c1-7)" | grep -w "${SYSMST_PATH}"/sysmaster | awk '{print $4}')"
     echo > "${SYSMST_LOG}"
     return 0
 }
@@ -223,19 +228,6 @@ function get_pids() {
     sctl status "${service}" |& sed -n '/PID:/,$p' | sed 's/PID://' | awk '{print $1}'
 }
 
-# usage: install packages
-# input: packages names or files
-function install_pkg() {
-    if ! grep -rq 'proxy=' /etc/yum.repos.d; then
-        for file in /etc/yum.repos.d/*.repo; do
-            sed -i "/^baseurl=/a ${yum_proxy}" "${file}"
-        done
-        yum clean all
-        yum makecache
-    fi
-    yum install -y $@
-}
-
 # usage: check netstat
 # input: $1: path
 #        $2: type
diff --git a/tests/config_test/unit_config_test/action_001/action_001.sh b/tests/config_test/unit_config_test/action_001/action_001.sh
index 5f4d505..3d3d07b 100644
--- a/tests/config_test/unit_config_test/action_001/action_001.sh
+++ b/tests/config_test/unit_config_test/action_001/action_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{reboot.target,poweroff.target,exit.target} tmp_units
     popd
diff --git a/tests/config_test/unit_config_test/assert_001/assert_001.sh b/tests/config_test/unit_config_test/assert_001/assert_001.sh
index 60fc3c9..fe40ee3 100644
--- a/tests/config_test/unit_config_test/assert_001/assert_001.sh
+++ b/tests/config_test/unit_config_test/assert_001/assert_001.sh
@@ -12,7 +12,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/condition_001/check.sh b/tests/config_test/unit_config_test/condition_001/check.sh
index 0107bb6..9afb53b 100644
--- a/tests/config_test/unit_config_test/condition_001/check.sh
+++ b/tests/config_test/unit_config_test/condition_001/check.sh
@@ -165,7 +165,7 @@ function test03() {
     expect_eq $? 0 || return 1
 
     # ro mounted path
-    which mount || install_pkg /usr/bin/mount
+    which mount || yum install -y /usr/bin/mount
     expect_eq $? 0 || return 1
     dd if=/dev/zero of=/tmp/mountfile bs=1M count=10
     mkfs.ext4 /tmp/mountfile
diff --git a/tests/config_test/unit_config_test/condition_001/condition_001.sh b/tests/config_test/unit_config_test/condition_001/condition_001.sh
index 4deada6..e082880 100644
--- a/tests/config_test/unit_config_test/condition_001/condition_001.sh
+++ b/tests/config_test/unit_config_test/condition_001/condition_001.sh
@@ -14,7 +14,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/condition_002/check.sh b/tests/config_test/unit_config_test/condition_002/check.sh
index 1deabaa..3ad0455 100644
--- a/tests/config_test/unit_config_test/condition_002/check.sh
+++ b/tests/config_test/unit_config_test/condition_002/check.sh
@@ -86,7 +86,7 @@ function test04() {
     test_user_2="test2_${RANDOM}"
     user_pw_1="PW!test1_${RANDOM}"
     user_pw_2="PW!test2_${RANDOM}"
-    install_pkg shadow sudo
+    yum install -y shadow sudo
     expect_eq $? 0 || return 1
     useradd "${test_user_1}"
     useradd "${test_user_2}"
diff --git a/tests/config_test/unit_config_test/condition_002/condition_002.sh b/tests/config_test/unit_config_test/condition_002/condition_002.sh
index 3bc857c..207805d 100644
--- a/tests/config_test/unit_config_test/condition_002/condition_002.sh
+++ b/tests/config_test/unit_config_test/condition_002/condition_002.sh
@@ -12,7 +12,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/condition_003/condition_003.sh b/tests/config_test/unit_config_test/condition_003/condition_003.sh
index 54eb5be..af33bad 100644
--- a/tests/config_test/unit_config_test/condition_003/condition_003.sh
+++ b/tests/config_test/unit_config_test/condition_003/condition_003.sh
@@ -12,7 +12,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/dependency_001/check.sh b/tests/config_test/unit_config_test/dependency_001/check.sh
index 9259bab..e9d3774 100644
--- a/tests/config_test/unit_config_test/dependency_001/check.sh
+++ b/tests/config_test/unit_config_test/dependency_001/check.sh
@@ -11,7 +11,7 @@ function test01() {
     cp -arf "${work_dir}"/tmp_units/{conflicts.service,requires.service,wants.service,requisite.service,partof.service,bindsto.service} ${SYSMST_LIB_PATH} || return 1
     sctl daemon-reload
     sctl status base.service &> log
-    expect_eq $? 1
+    expect_ne $? 0
     check_log log 'Failed to show the status of base.service: NotExisted'
     expect_eq $? 0 || return 1
     rm -rf log
diff --git a/tests/config_test/unit_config_test/dependency_001/dependency_001.sh b/tests/config_test/unit_config_test/dependency_001/dependency_001.sh
index f29e2ee..393b4cd 100644
--- a/tests/config_test/unit_config_test/dependency_001/dependency_001.sh
+++ b/tests/config_test/unit_config_test/dependency_001/dependency_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,conflicts.service,requires.service,wants.service,requisite.service,partof.service,bindsto.service} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/dependency_002/dependency_002.sh b/tests/config_test/unit_config_test/dependency_002/dependency_002.sh
index b00be90..6f7758f 100644
--- a/tests/config_test/unit_config_test/dependency_002/dependency_002.sh
+++ b/tests/config_test/unit_config_test/dependency_002/dependency_002.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/dependency_003/dependency_003.sh b/tests/config_test/unit_config_test/dependency_003/dependency_003.sh
index f43d7f1..163b1d8 100644
--- a/tests/config_test/unit_config_test/dependency_003/dependency_003.sh
+++ b/tests/config_test/unit_config_test/dependency_003/dependency_003.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/dependency_004/dependency_004.sh b/tests/config_test/unit_config_test/dependency_004/dependency_004.sh
index a37b502..f11c8b5 100644
--- a/tests/config_test/unit_config_test/dependency_004/dependency_004.sh
+++ b/tests/config_test/unit_config_test/dependency_004/dependency_004.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/dependency_005/dependency_005.sh b/tests/config_test/unit_config_test/dependency_005/dependency_005.sh
index 01d76e8..6b71497 100644
--- a/tests/config_test/unit_config_test/dependency_005/dependency_005.sh
+++ b/tests/config_test/unit_config_test/dependency_005/dependency_005.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{fork.service,before.service,after.service} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/env_001/env_001.sh b/tests/config_test/unit_config_test/env_001/env_001.sh
index 9218e42..6e8f40b 100644
--- a/tests/config_test/unit_config_test/env_001/env_001.sh
+++ b/tests/config_test/unit_config_test/env_001/env_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/env.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/exec_001/exec_001.sh b/tests/config_test/unit_config_test/exec_001/exec_001.sh
index 666a154..90b3f74 100644
--- a/tests/config_test/unit_config_test/exec_001/exec_001.sh
+++ b/tests/config_test/unit_config_test/exec_001/exec_001.sh
@@ -12,7 +12,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,exec.service} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/isolate_001/isolate_001.sh b/tests/config_test/unit_config_test/isolate_001/isolate_001.sh
index 20bd545..8ee2127 100644
--- a/tests/config_test/unit_config_test/isolate_001/isolate_001.sh
+++ b/tests/config_test/unit_config_test/isolate_001/isolate_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,reboot.target} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/kill_001/kill_001.sh b/tests/config_test/unit_config_test/kill_001/kill_001.sh
index 259fa03..c781f80 100644
--- a/tests/config_test/unit_config_test/kill_001/kill_001.sh
+++ b/tests/config_test/unit_config_test/kill_001/kill_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/fork.service tmp_units
     gcc kill_mode.c -o kill_mode
     popd
diff --git a/tests/config_test/unit_config_test/listen_001/check.sh b/tests/config_test/unit_config_test/listen_001/check.sh
index 8891f99..c124a38 100644
--- a/tests/config_test/unit_config_test/listen_001/check.sh
+++ b/tests/config_test/unit_config_test/listen_001/check.sh
@@ -222,7 +222,7 @@ seed="1$((${RANDOM} % 1000))"
 test01_socket="/run/test01_${seed}.socket"
 test02_socket="/run/test02_${seed}.socket"
 test03_socket="/run/test03_${seed}.socket"
-install_pkg net-tools iproute || exit 1
+yum install -y net-tools iproute || exit 1
 
 run_sysmaster || return 1
 test01 || exit 1
diff --git a/tests/config_test/unit_config_test/listen_001/listen_001.sh b/tests/config_test/unit_config_test/listen_001/listen_001.sh
index c3f9f53..3539237 100644
--- a/tests/config_test/unit_config_test/listen_001/listen_001.sh
+++ b/tests/config_test/unit_config_test/listen_001/listen_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,base.socket} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/refuse_001/refuse_001.sh b/tests/config_test/unit_config_test/refuse_001/refuse_001.sh
index b43fae6..6157436 100644
--- a/tests/config_test/unit_config_test/refuse_001/refuse_001.sh
+++ b/tests/config_test/unit_config_test/refuse_001/refuse_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,requires.service} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/restart_001/restart_001.sh b/tests/config_test/unit_config_test/restart_001/restart_001.sh
index 93d1217..5dd1143 100644
--- a/tests/config_test/unit_config_test/restart_001/restart_001.sh
+++ b/tests/config_test/unit_config_test/restart_001/restart_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{restart_001.service,restart_002.service,restart_003.service,restart_004.service} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/service_001/service_001.sh b/tests/config_test/unit_config_test/service_001/service_001.sh
index da79e9c..1aac45f 100644
--- a/tests/config_test/unit_config_test/service_001/service_001.sh
+++ b/tests/config_test/unit_config_test/service_001/service_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/service_002/service_002.sh b/tests/config_test/unit_config_test/service_002/service_002.sh
index 5cf3d49..6ae0624 100644
--- a/tests/config_test/unit_config_test/service_002/service_002.sh
+++ b/tests/config_test/unit_config_test/service_002/service_002.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/fork.service tmp_units
     gcc fork_exec.c -o fork_exec
     popd
diff --git a/tests/config_test/unit_config_test/service_003/service_003.sh b/tests/config_test/unit_config_test/service_003/service_003.sh
index ccf6200..6c4fdd6 100644
--- a/tests/config_test/unit_config_test/service_003/service_003.sh
+++ b/tests/config_test/unit_config_test/service_003/service_003.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,base.socket} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/service_004/check.sh b/tests/config_test/unit_config_test/service_004/check.sh
index 387121f..7effdb4 100644
--- a/tests/config_test/unit_config_test/service_004/check.sh
+++ b/tests/config_test/unit_config_test/service_004/check.sh
@@ -34,7 +34,7 @@ function test01() {
     expect_eq $? 0 || return 1
 
     # user/group exist
-    install_pkg shadow
+    yum install -y shadow
     expect_eq $? 0 || return 1
     useradd "${test_user}"
     groupadd "${test_grp}"
diff --git a/tests/config_test/unit_config_test/service_004/service_004.sh b/tests/config_test/unit_config_test/service_004/service_004.sh
index 418f389..b2a8398 100644
--- a/tests/config_test/unit_config_test/service_004/service_004.sh
+++ b/tests/config_test/unit_config_test/service_004/service_004.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/socket_001/check.sh b/tests/config_test/unit_config_test/socket_001/check.sh
index e055532..9f28604 100644
--- a/tests/config_test/unit_config_test/socket_001/check.sh
+++ b/tests/config_test/unit_config_test/socket_001/check.sh
@@ -125,7 +125,7 @@ function test03() {
 seed="1$((${RANDOM} % 1000))"
 test_socket="/run/test_${seed}.socket"
 test_symlink="/dev/test_${seed}_link"
-install_pkg net-tools nmap || exit 1
+yum install -y net-tools nmap || exit 1
 
 run_sysmaster || exit 1
 test01 || exit 1
diff --git a/tests/config_test/unit_config_test/socket_001/socket_001.sh b/tests/config_test/unit_config_test/socket_001/socket_001.sh
index f3efb17..6fd74a3 100644
--- a/tests/config_test/unit_config_test/socket_001/socket_001.sh
+++ b/tests/config_test/unit_config_test/socket_001/socket_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{base.service,base.socket} tmp_units
     popd
 }
diff --git a/tests/config_test/unit_config_test/startlimit_001/startlimit_001.sh b/tests/config_test/unit_config_test/startlimit_001/startlimit_001.sh
index bd037e2..fc93149 100644
--- a/tests/config_test/unit_config_test/startlimit_001/startlimit_001.sh
+++ b/tests/config_test/unit_config_test/startlimit_001/startlimit_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{reboot.target,poweroff.target,exit.target} tmp_units
     popd
diff --git a/tests/config_test/unit_config_test/timeout_001/timeout_001.sh b/tests/config_test/unit_config_test/timeout_001/timeout_001.sh
index df2f52f..08d4512 100644
--- a/tests/config_test/unit_config_test/timeout_001/timeout_001.sh
+++ b/tests/config_test/unit_config_test/timeout_001/timeout_001.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/base.service tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/{reboot.target,poweroff.target,exit.target} tmp_units
     popd
diff --git a/tests/config_test/unit_config_test/timeout_002/timeout_002.sh b/tests/config_test/unit_config_test/timeout_002/timeout_002.sh
index 9cfb2a5..9ccf3c7 100644
--- a/tests/config_test/unit_config_test/timeout_002/timeout_002.sh
+++ b/tests/config_test/unit_config_test/timeout_002/timeout_002.sh
@@ -11,7 +11,6 @@ function test_pre() {
     pushd "${TEST_SCRIPT_PATH}"
     rm -rf tmp_units
     mkdir tmp_units
-    cp -arf "${TEST_PATH}"/test_units/{shutdown.target,sysinit.target} tmp_units
     cp -arf "${TEST_PATH}"/test_units/tests/timeout.service tmp_units
     popd
 }
diff --git a/tests/docker_example/docker_example_001/check.sh b/tests/docker_example/docker_example_001/check.sh
index 3db7629..3d89207 100755
--- a/tests/docker_example/docker_example_001/check.sh
+++ b/tests/docker_example/docker_example_001/check.sh
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
+
 ls -l /usr/lib/sysmaster || exit 1
-ls -l /usr/lib/sysmaster/plugin || exit 1
 ls -l /usr/bin/sctl || exit 1
diff --git a/tests/perf_test/cpu_time_001/check.sh b/tests/perf_test/cpu_time_001/check.sh
index a6e16a1..26f1dfd 100644
--- a/tests/perf_test/cpu_time_001/check.sh
+++ b/tests/perf_test/cpu_time_001/check.sh
@@ -6,7 +6,7 @@ source "${work_dir}"/util_lib.sh
 set +e
 max=1000
 
-install_pkg nginx
+yum install -y nginx
 expect_eq $? 0 || exit 1
 
 cp -arf "${work_dir}"/tmp_units/*.service ${SYSMST_LIB_PATH} || exit 1
diff --git a/tests/test_frame.sh b/tests/test_frame.sh
index e2eab7d..c734feb 100644
--- a/tests/test_frame.sh
+++ b/tests/test_frame.sh
@@ -12,7 +12,9 @@ TMP_DIR=''
 function test_setup() {
     setenforce 0
 
-    install_sysmaster || return 1
+    if ! yum list sysmaster; then
+        install_sysmaster || return 1
+    fi
 
     if [ "${DOCKER_TEST}" == '1' ]; then
         if which isula-build; then
@@ -57,9 +59,8 @@ function setup_isula() {
 
 function test_cleanup() {
     [ -n "${TMP_DIR}" ] && rm -rf "${TMP_DIR}"
-    rm -rf /usr/bin/sctl "${SYSMST_LIB_PATH}"
 
-    if [ "${DOCKER_TEST}" == '1' ]; then
+    if [ "${DOCKER_TEST}" == '1' ] && [ -n "${DOCKER_CMD}" ]; then
         cleanup_docker || return 1
     fi
 
-- 
2.33.0

