diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-12-09 18:56:13 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-28 11:46:47 +0100 |
commit | fe85f2bb9c11fd0c3787cc28caa7ea6420553db8 (patch) | |
tree | c3cca97d05169472a34481dd1f99a0f14445c17d | |
parent | test: allow overriding EFI_MOUNT like other variables (diff) | |
download | systemd-fe85f2bb9c11fd0c3787cc28caa7ea6420553db8.tar.xz systemd-fe85f2bb9c11fd0c3787cc28caa7ea6420553db8.zip |
test: move TEST-01-BASIC setup to static files
After this commit, only tests that were converted will work, because the
interface to test_run() changed.
-rwxr-xr-x | test/TEST-01-BASIC/test.sh | 15 | ||||
-rw-r--r-- | test/test-functions | 62 | ||||
-rw-r--r-- | test/units/end.service | 2 | ||||
-rw-r--r-- | test/units/testsuite-01.service | 7 |
4 files changed, 47 insertions, 39 deletions
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 0eaa8f991a..e07e1f3771 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -14,21 +14,8 @@ test_setup() { eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) setup_basic_environment - - # setup the testsuite service - cat >$initdir/etc/systemd/system/testsuite.service <<EOF -[Unit] -Description=Testsuite service -After=multi-user.target - -[Service] -ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; systemctl daemon-reload ; echo OK > /testok' -Type=oneshot -EOF - - setup_testsuite ) setup_nspawn_root } -do_test "$@" +do_test "$@" 01 diff --git a/test/test-functions b/test/test-functions index 690a4a8236..673685ea6b 100644 --- a/test/test-functions +++ b/test/test-functions @@ -204,6 +204,13 @@ run_qemu() { PARAMS+="ro" fi + local _end + if [[ ! "$INTERACTIVE_DEBUG" ]]; then + _end="systemd.wants=end.service" + else + _end="" + fi + KERNEL_APPEND="$PARAMS \ root=/dev/sda1 \ raid=noautodetect \ @@ -213,6 +220,9 @@ init=$PATH_TO_INIT \ console=$CONSOLE \ selinux=0 \ $_cgroup_args \ +SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/units: \ +systemd.unit=testsuite.target \ +systemd.wants=testsuite-$1.service ${_end} $KERNEL_APPEND \ " @@ -253,24 +263,41 @@ $QEMU_OPTIONS \ run_nspawn() { [[ -d /run/systemd/system ]] || return 1 - local _nspawn_cmd="$SYSTEMD_NSPAWN $NSPAWN_ARGUMENTS --register=no --kill-signal=SIGKILL --directory=$TESTDIR/$1 $PATH_TO_INIT $KERNEL_APPEND" + local _nspawn_cmd=( + --register=no + --kill-signal=SIGKILL + --directory=$TESTDIR/$1 + --setenv=SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/units: + $PATH_TO_INIT + $KERNEL_APPEND + systemd.unit=testsuite.target + systemd.wants=testsuite-$2.service + ) + + if [[ ! "$INTERACTIVE_DEBUG" ]]; then + _nspawn_cmd+=( systemd.wants=end.service ) + fi + + local _nspawn_pre if [[ "$NSPAWN_TIMEOUT" != "infinity" ]]; then - _nspawn_cmd="timeout --foreground $NSPAWN_TIMEOUT $_nspawn_cmd" + _nspawn_pre=(timeout --foreground $NSPAWN_TIMEOUT) + else + _nspawn_pre=() fi if [[ "$UNIFIED_CGROUP_HIERARCHY" = "hybrid" ]]; then dwarn "nspawn doesn't support SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=hybrid, skipping" exit elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" || "$UNIFIED_CGROUP_HIERARCHY" = "no" ]]; then - _nspawn_cmd="env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY $_nspawn_cmd" + _nspawn_pre=("${nspawn_pre[@]}" env SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=$UNIFIED_CGROUP_HIERARCHY) elif [[ "$UNIFIED_CGROUP_HIERARCHY" = "default" ]]; then - _nspawn_cmd="env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY $_nspawn_cmd" + _nspawn_pre=("${nspawn_pre[@]}" env --unset=UNIFIED_CGROUP_HIERARCHY --unset=SYSTEMD_NSPAWN_UNIFIED_HIERARCHY) else dfatal "Unknown UNIFIED_CGROUP_HIERARCHY. Got $UNIFIED_CGROUP_HIERARCHY, expected [yes|no|hybrid|default]" exit 1 fi - (set -x; $_nspawn_cmd) + (set -x; "${_nspawn_pre[@]}" "$SYSTEMD_NSPAWN" $NSPAWN_ARGUMENTS "${_nspawn_cmd[@]}") rc=$? if [ "$rc" = 124 ] && [ "$NSPAWN_TIMEOUT" != "infinity" ]; then derror "test timed out after $NSPAWN_TIMEOUT s" @@ -475,7 +502,7 @@ unset_ld_preload() { } unset_ld_preload systemd-remount-fs -unset_ld_preload testsuite +unset_ld_preload testsuite- export ASAN_OPTIONS=\$DEFAULT_ASAN_OPTIONS:log_path=/systemd.asan.log UBSAN_OPTIONS=\$DEFAULT_UBSAN_OPTIONS exec $ROOTLIBDIR/systemd "\$@" @@ -929,19 +956,6 @@ enable_user_manager() { install_user_dbus } -setup_testsuite() { - cp $TEST_BASE_DIR/testsuite.target $initdir/etc/systemd/system/ - cp $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/ - - mkdir -p $initdir/etc/systemd/system/testsuite.target.wants - ln -fs $TEST_BASE_DIR/testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service - # Don't shutdown the machine after running the test when INTERACTIVE_DEBUG is set - [[ -z $INTERACTIVE_DEBUG ]] && ln -fs $TEST_BASE_DIR/end.service $initdir/etc/systemd/system/testsuite.target.wants/end.service - - # make the testsuite the default target - ln -fs testsuite.target $initdir/etc/systemd/system/default.target -} - setup_nspawn_root() { rm -fr $TESTDIR/nspawn-root ddebug "cp -ar $initdir $TESTDIR/nspawn-root" @@ -1786,21 +1800,21 @@ test_cleanup() { test_run() { if [ -z "$TEST_NO_QEMU" ]; then - if run_qemu; then + if run_qemu "$1"; then check_result_qemu || return 1 else dwarn "can't run QEMU, skipping" fi fi if [ -z "$TEST_NO_NSPAWN" ]; then - if run_nspawn "nspawn-root"; then + if run_nspawn "nspawn-root" "$1"; then check_result_nspawn "nspawn-root" || return 1 else dwarn "can't run systemd-nspawn, skipping" fi if [[ "$RUN_IN_UNPRIVILEGED_CONTAINER" = "yes" ]]; then - if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "unprivileged-nspawn-root"; then + if NSPAWN_ARGUMENTS="-U --private-network $NSPAWN_ARGUMENTS" run_nspawn "unprivileged-nspawn-root" "$1"; then check_result_nspawn "unprivileged-nspawn-root" || return 1 else dwarn "can't run systemd-nspawn, skipping" @@ -1834,7 +1848,7 @@ do_test() { case $1 in --run) echo "TEST RUN: $TEST_DESCRIPTION" - test_run + test_run "$2" ret=$? if (( $ret == 0 )); then echo "TEST RUN: $TEST_DESCRIPTION [OK]" @@ -1857,7 +1871,7 @@ do_test() { ( test_setup test_setup_cleanup - test_run + test_run "$2" ) </dev/null >"$TESTLOG" 2>&1 || ret=$? test_cleanup if [ $ret -eq 0 ]; then diff --git a/test/units/end.service b/test/units/end.service index 6e1996fd02..e7ed75ef05 100644 --- a/test/units/end.service +++ b/test/units/end.service @@ -1,6 +1,6 @@ [Unit] Description=End the test -After=testsuite.service +After=testsuite.target OnFailure=poweroff.target OnFailureJobMode=replace-irreversibly diff --git a/test/units/testsuite-01.service b/test/units/testsuite-01.service new file mode 100644 index 0000000000..8112a85c18 --- /dev/null +++ b/test/units/testsuite-01.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-01-BASIC +After=multi-user.target + +[Service] +ExecStart=sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok' +Type=oneshot |