summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2017-08-11 07:02:02 +0300
committerGitHub <noreply@github.com>2017-08-11 07:02:02 +0300
commit43ee6a8128dc751943e25c42a490a833904a58b9 (patch)
tree014be1cb4268a3980ae749b693df027eab817783
parent2935311ca4c0f77cde85307278bd84c1b57d8e71 (diff)
parent818567fce693519eda9d7550a9ae21a7fc974b3c (diff)
downloadsystemd-43ee6a8128dc751943e25c42a490a833904a58b9.tar.gz
systemd-43ee6a8128dc751943e25c42a490a833904a58b9.tar.bz2
systemd-43ee6a8128dc751943e25c42a490a833904a58b9.zip
Merge pull request #6475 from martinpitt/test-set-e
test: Run qemu/nspawn tests with "set -e"
-rwxr-xr-xtest/TEST-01-BASIC/test.sh1
-rwxr-xr-xtest/TEST-02-CRYPTSETUP/test.sh5
-rwxr-xr-xtest/TEST-03-JOBS/test-jobs.sh26
-rwxr-xr-xtest/TEST-03-JOBS/test.sh1
-rwxr-xr-xtest/TEST-04-JOURNAL/test.sh1
-rwxr-xr-xtest/TEST-05-RLIMITS/test.sh1
-rwxr-xr-xtest/TEST-06-SELINUX/test.sh1
-rwxr-xr-xtest/TEST-07-ISSUE-1981/test.sh1
-rwxr-xr-xtest/TEST-08-ISSUE-2730/test.sh1
-rwxr-xr-xtest/TEST-09-ISSUE-2691/test.sh1
-rwxr-xr-xtest/TEST-10-ISSUE-2467/test.sh1
-rwxr-xr-xtest/TEST-11-ISSUE-3166/test.sh1
-rwxr-xr-xtest/TEST-12-ISSUE-3171/test.sh1
-rwxr-xr-xtest/TEST-13-NSPAWN-SMOKE/test.sh1
-rwxr-xr-xtest/TEST-14-MACHINE-ID/test.sh1
-rwxr-xr-xtest/TEST-15-DROPIN/test.sh2
-rw-r--r--test/test-functions58
17 files changed, 61 insertions, 43 deletions
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
index b1d6e1931b..8b21ba05d3 100755
--- a/test/TEST-01-BASIC/test.sh
+++ b/test/TEST-01-BASIC/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="Basic systemd setup"
. $TEST_BASE_DIR/test-functions
diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh
index 31eced5809..1280148b58 100755
--- a/test/TEST-02-CRYPTSETUP/test.sh
+++ b/test/TEST-02-CRYPTSETUP/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="cryptsetup systemd setup"
TEST_NO_NSPAWN=1
@@ -78,9 +79,9 @@ EOF
}
test_cleanup() {
- umount $TESTDIR/root/var 2>/dev/null
+ [ -d $TESTDIR/root/var ] && mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var
[[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt
- umount $TESTDIR/root 2>/dev/null
+ umount $TESTDIR/root 2>/dev/null || true
[[ $LOOPDEV ]] && losetup -d $LOOPDEV
return 0
}
diff --git a/test/TEST-03-JOBS/test-jobs.sh b/test/TEST-03-JOBS/test-jobs.sh
index 48926290a6..4c954d0397 100755
--- a/test/TEST-03-JOBS/test-jobs.sh
+++ b/test/TEST-03-JOBS/test-jobs.sh
@@ -1,4 +1,4 @@
-#!/bin/bash -x
+#!/bin/bash -e
# Test merging of a --job-mode=ignore-dependencies job into a previously
# installed job.
@@ -10,7 +10,7 @@ while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
systemctl list-jobs > /root/list-jobs.txt
done
-grep 'hello\.service.*waiting' /root/list-jobs.txt || exit 1
+grep 'hello\.service.*waiting' /root/list-jobs.txt
# This is supposed to finish quickly, not wait for sleep to finish.
START_SEC=$(date -u '+%s')
@@ -18,36 +18,36 @@ systemctl start --job-mode=ignore-dependencies hello
END_SEC=$(date -u '+%s')
ELAPSED=$(($END_SEC-$START_SEC))
-[ "$ELAPSED" -lt 3 ] || exit 1
+[ "$ELAPSED" -lt 3 ]
# sleep should still be running, hello not.
systemctl list-jobs > /root/list-jobs.txt
-grep 'sleep\.service.*running' /root/list-jobs.txt || exit 1
+grep 'sleep\.service.*running' /root/list-jobs.txt
grep 'hello\.service' /root/list-jobs.txt && exit 1
-systemctl stop sleep.service hello-after-sleep.target || exit 1
+systemctl stop sleep.service hello-after-sleep.target
# Test for a crash when enqueuing a JOB_NOP when other job already exists
-systemctl start --no-block hello-after-sleep.target || exit 1
+systemctl start --no-block hello-after-sleep.target
# hello.service should still be waiting, so these try-restarts will collapse
# into NOPs.
-systemctl try-restart --job-mode=fail hello.service || exit 1
-systemctl try-restart hello.service || exit 1
-systemctl stop hello.service sleep.service hello-after-sleep.target || exit 1
+systemctl try-restart --job-mode=fail hello.service
+systemctl try-restart hello.service
+systemctl stop hello.service sleep.service hello-after-sleep.target
# TODO: add more job queueing/merging tests here.
# Test for irreversible jobs
-systemctl start unstoppable.service || exit 1
+systemctl start unstoppable.service
# This is expected to fail with 'job cancelled'
systemctl stop unstoppable.service && exit 1
# But this should succeed
-systemctl stop --job-mode=replace-irreversibly unstoppable.service || exit 1
+systemctl stop --job-mode=replace-irreversibly unstoppable.service
# We're going to shutdown soon. Let's see if it succeeds when
# there's an active service that tries to be unstoppable.
# Shutdown of the container/VM will hang if not.
-systemctl start unstoppable.service || exit 1
+systemctl start unstoppable.service
# Test waiting for a started unit(s) to terminate again
cat <<EOF > /run/systemd/system/wait2.service
@@ -65,7 +65,7 @@ EOF
# wait2 succeeds
START_SEC=$(date -u '+%s')
-systemctl start --wait wait2.service || exit 1
+systemctl start --wait wait2.service
END_SEC=$(date -u '+%s')
ELAPSED=$(($END_SEC-$START_SEC))
[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1
diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh
index a3755a7a7a..88bbf3cdac 100755
--- a/test/TEST-03-JOBS/test.sh
+++ b/test/TEST-03-JOBS/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="Job-related tests"
. $TEST_BASE_DIR/test-functions
diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh
index 66fc5af3d2..30e7b181b2 100755
--- a/test/TEST-04-JOURNAL/test.sh
+++ b/test/TEST-04-JOURNAL/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="Journal-related tests"
. $TEST_BASE_DIR/test-functions
diff --git a/test/TEST-05-RLIMITS/test.sh b/test/TEST-05-RLIMITS/test.sh
index e684b6dd2d..a1b855c5fb 100755
--- a/test/TEST-05-RLIMITS/test.sh
+++ b/test/TEST-05-RLIMITS/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="Resource limits-related tests"
. $TEST_BASE_DIR/test-functions
diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh
index ab4bb435dc..e0c4c10e1c 100755
--- a/test/TEST-06-SELINUX/test.sh
+++ b/test/TEST-06-SELINUX/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="SELinux tests"
TEST_NO_NSPAWN=1
diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh
index a55c691a62..88d143e479 100755
--- a/test/TEST-07-ISSUE-1981/test.sh
+++ b/test/TEST-07-ISSUE-1981/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/1981"
TEST_NO_QEMU=1
diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh
index f7f34007f9..68159c331f 100755
--- a/test/TEST-08-ISSUE-2730/test.sh
+++ b/test/TEST-08-ISSUE-2730/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730"
TEST_NO_NSPAWN=1
diff --git a/test/TEST-09-ISSUE-2691/test.sh b/test/TEST-09-ISSUE-2691/test.sh
index 1bd620a267..4c3e9496b4 100755
--- a/test/TEST-09-ISSUE-2691/test.sh
+++ b/test/TEST-09-ISSUE-2691/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2691"
TEST_NO_NSPAWN=1
diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh
index dfc7cbe52d..e7eb1cb303 100755
--- a/test/TEST-10-ISSUE-2467/test.sh
+++ b/test/TEST-10-ISSUE-2467/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467"
TEST_NO_NSPAWN=1
diff --git a/test/TEST-11-ISSUE-3166/test.sh b/test/TEST-11-ISSUE-3166/test.sh
index 12bf84252b..4602bdfc98 100755
--- a/test/TEST-11-ISSUE-3166/test.sh
+++ b/test/TEST-11-ISSUE-3166/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3166"
TEST_NO_NSPAWN=1
diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh
index 7837f639a1..559fa469cd 100755
--- a/test/TEST-12-ISSUE-3171/test.sh
+++ b/test/TEST-12-ISSUE-3171/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3171"
TEST_NO_QEMU=1
diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh
index 84a3af30a3..7f7380fd62 100755
--- a/test/TEST-13-NSPAWN-SMOKE/test.sh
+++ b/test/TEST-13-NSPAWN-SMOKE/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="systemd-nspawn smoke test"
TEST_NO_NSPAWN=1
SKIP_INITRD=yes
diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh
index c406205c51..b932060bc2 100755
--- a/test/TEST-14-MACHINE-ID/test.sh
+++ b/test/TEST-14-MACHINE-ID/test.sh
@@ -1,6 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
TEST_DESCRIPTION="Basic systemd setup"
TEST_NO_NSPAWN=1
SKIP_INITRD=yes
diff --git a/test/TEST-15-DROPIN/test.sh b/test/TEST-15-DROPIN/test.sh
index 536b379f64..b85bffafaf 100755
--- a/test/TEST-15-DROPIN/test.sh
+++ b/test/TEST-15-DROPIN/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
-
+set -e
TEST_DESCRIPTION="Dropin tests"
TEST_NO_QEMU=1
diff --git a/test/test-functions b/test/test-functions
index 61787b6d33..67fe5e19b8 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -4,9 +4,9 @@
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
-LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes)
-LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes)
-LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes)
+LOOKS_LIKE_DEBIAN=$(source /etc/os-release && [[ "$ID" = "debian" || "$ID_LIKE" = "debian" ]] && echo yes || true)
+LOOKS_LIKE_ARCH=$(source /etc/os-release && [[ "$ID" = "arch" ]] && echo yes || true)
+LOOKS_LIKE_SUSE=$(source /etc/os-release && [[ "$ID_LIKE" = "suse" ]] && echo yes || true)
KERNEL_VER=${KERNEL_VER-$(uname -r)}
KERNEL_MODS="/lib/modules/$KERNEL_VER/"
QEMU_TIMEOUT="${QEMU_TIMEOUT:-infinity}"
@@ -23,6 +23,10 @@ fi
BASICTOOLS="sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm"
DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
+STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"
+STATEFILE="$STATEDIR/.testdir"
+TESTLOG="$STATEDIR/test.log"
+
function find_qemu_bin() {
# SUSE and Red Hat call the binary qemu-kvm
# Debian and Gentoo call it kvm
@@ -423,7 +427,8 @@ install_execs() {
egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/{$systemdsystemunitdir,$systemduserunitdir}/*.service \
| while read i; do
i=${i##Exec*=}; i=${i##-}
- inst $i
+ # some {rc,halt}.local scripts and programs are okay to not exist, the rest should
+ inst $i || [ "${i%.local}" != "$i" ] || [ "${i%systemd-update-done}" != "$i" ]
done
)
}
@@ -458,15 +463,15 @@ install_ld_so_conf() {
}
install_config_files() {
- inst /etc/sysconfig/init
+ inst /etc/sysconfig/init || true
inst /etc/passwd
inst /etc/shadow
inst /etc/login.defs
inst /etc/group
inst /etc/shells
inst /etc/nsswitch.conf
- inst /etc/pam.conf
- inst /etc/securetty
+ inst /etc/pam.conf || true
+ inst /etc/securetty || true
inst /etc/os-release
inst /etc/localtime
# we want an empty environment
@@ -516,12 +521,12 @@ install_dbus() {
install_pam() {
(
- [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null && find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
- find \
- /etc/pam.d \
- /etc/security \
- /lib64/security \
- /lib/security -xtype f \
+ if [[ "$LOOKS_LIKE_DEBIAN" ]] && type -p dpkg-architecture &>/dev/null; then
+ find "/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security" -xtype f
+ else
+ find /lib*/security -xtype f
+ fi
+ find /etc/pam.d /etc/security -xtype f
) | while read file; do
inst $file
done
@@ -626,7 +631,6 @@ inst_libs() {
}
import_testdir() {
- STATEFILE=".testdir"
[[ -e $STATEFILE ]] && . $STATEFILE
if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX)
@@ -920,7 +924,7 @@ inst_library() {
# Create additional symlinks. See rev_symlinks description.
for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
- [[ ! -e $initdir/$_symlink ]] && {
+ [[ -e $initdir/$_symlink ]] || {
ddebug "Creating extra symlink: $_symlink"
inst_symlink $_symlink
}
@@ -1384,7 +1388,7 @@ setup_suse() {
# can be overridden in specific test
test_cleanup() {
umount $TESTDIR/root 2>/dev/null || true
- [[ $LOOPDEV ]] && losetup -d $LOOPDEV
+ [[ $LOOPDEV ]] && losetup -d $LOOPDEV || true
return 0
}
@@ -1421,6 +1425,8 @@ do_test() {
[[ -d $usrlibdir ]] && libdirs+=" $usrlibdir" && break
done
+ mkdir -p "$STATEDIR"
+
import_testdir
import_initdir
@@ -1428,9 +1434,7 @@ do_test() {
case $1 in
--run)
echo "TEST RUN: $TEST_DESCRIPTION"
- test_run
- ret=$?
- if [ $ret -eq 0 ]; then
+ if test_run; then
echo "TEST RUN: $TEST_DESCRIPTION [OK]"
else
echo "TEST RUN: $TEST_DESCRIPTION [FAILED]"
@@ -1439,30 +1443,30 @@ do_test() {
--setup)
echo "TEST SETUP: $TEST_DESCRIPTION"
test_setup
- exit $?;;
+ ;;
--clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION"
test_cleanup
rm -fr "$TESTDIR"
- rm -f .testdir
- exit $?;;
+ rm -f "$STATEFILE"
+ ;;
--all)
+ ret=0
echo -n "TEST: $TEST_DESCRIPTION ";
(
test_setup && test_run
ret=$?
test_cleanup
rm -fr "$TESTDIR"
- rm -f .testdir
+ rm -f "$STATEFILE"
exit $ret
- ) </dev/null >test.log 2>&1
- ret=$?
+ ) </dev/null >"$TESTLOG" 2>&1 || ret=$?
if [ $ret -eq 0 ]; then
- rm test.log
+ rm "$TESTLOG"
echo "[OK]"
else
echo "[FAILED]"
- echo "see $(pwd)/test.log"
+ echo "see $TESTLOG"
fi
exit $ret;;
*) break ;;