From 4e20fe27950e14e8a082a74515f347546a9371d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 8 Apr 2021 01:27:33 +0200 Subject: [PATCH] TEST-*: make failure tests actually fail on failure Here the intent was actually correct, and the tests still pass when the check is made effective. --- test/units/testsuite-03.sh | 8 ++++---- test/units/testsuite-04.sh | 4 ++-- test/units/testsuite-18.sh | 2 +- test/units/testsuite-20.sh | 14 ++++++++++++-- test/units/testsuite-22.03.sh | 28 ++++++++++++++-------------- test/units/testsuite-22.08.sh | 6 ++++-- test/units/testsuite-23.sh | 4 ++-- test/units/testsuite-25.sh | 16 ++++++++-------- test/units/testsuite-26.sh | 4 ++-- test/units/testsuite-33.sh | 8 ++++---- test/units/testsuite-34.sh | 9 ++++++--- test/units/testsuite-39.sh | 4 ++-- test/units/testsuite-41.sh | 11 +++++++++-- test/units/testsuite-42.sh | 18 ++++++++++++------ test/units/testsuite-54.sh | 10 ++++++---- test/units/testsuite-56.sh | 12 ++++++++---- 16 files changed, 96 insertions(+), 62 deletions(-) diff --git a/test/units/testsuite-03.sh b/test/units/testsuite-03.sh index 85efeeb741..ec731aa11b 100755 --- a/test/units/testsuite-03.sh +++ b/test/units/testsuite-03.sh @@ -19,7 +19,7 @@ systemctl start --job-mode=ignore-dependencies hello END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) -[ "$ELAPSED" -lt 3 ] +test "$ELAPSED" -lt 3 # sleep should still be running, hello not. systemctl list-jobs > /root/list-jobs.txt @@ -28,11 +28,11 @@ grep 'hello\.service' /root/list-jobs.txt && exit 1 systemctl stop sleep.service hello-after-sleep.target # Some basic testing that --show-transaction does something useful -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } systemctl -T start systemd-importd systemctl is-active systemd-importd systemctl --show-transaction stop systemd-importd -! systemctl is-active systemd-importd +systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; } # Test for a crash when enqueuing a JOB_NOP when other job already exists systemctl start --no-block hello-after-sleep.target @@ -80,7 +80,7 @@ ELAPSED=$(($END_SEC-$START_SEC)) # wait5fail fails, so systemctl should fail START_SEC=$(date -u '+%s') -! systemctl start --wait wait2.service wait5fail.service || exit 1 +systemctl start --wait wait2.service wait5fail.service && { echo 'unexpected success'; exit 1; } END_SEC=$(date -u '+%s') ELAPSED=$(($END_SEC-$START_SEC)) [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 3dce73b778..f464f61a36 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -59,8 +59,8 @@ journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MES grep -q '^__CURSOR=' /output grep -q '^MESSAGE=foo$' /output grep -q '^PRIORITY=6$' /output -! grep -q '^FOO=' /output -! grep -q '^SYSLOG_FACILITY=' /output +grep '^FOO=' /output && { echo 'unexpected success'; exit 1; } +grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; } # `-b all` negates earlier use of -b (-b and -m are otherwise exclusive) journalctl -b -1 -b all -m > /dev/null diff --git a/test/units/testsuite-18.sh b/test/units/testsuite-18.sh index e471cda51b..d3c2df8101 100755 --- a/test/units/testsuite-18.sh +++ b/test/units/testsuite-18.sh @@ -3,7 +3,7 @@ set -ex set -o pipefail systemd-run --wait -p FailureAction=poweroff true -! systemd-run --wait -p SuccessAction=poweroff false +systemd-run --wait -p SuccessAction=poweroff false && { echo 'unexpected success'; exit 1; } if ! test -f /firstphase ; then echo OK > /firstphase diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index d94f6b2afb..0e0feded39 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -126,8 +126,18 @@ test -f /run/mainpidsh3/pid EOF chmod 755 /dev/shm/test20-mainpid3.sh -# This has to fail, as we shouldn't accept the dangerous PID file, and then inotify-wait on it to be corrected which we never do -! systemd-run --unit=test20-mainpidsh3.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh3 -p PIDFile=/run/mainpidsh3/pid -p DynamicUser=1 -p TimeoutStartSec=2s /dev/shm/test20-mainpid3.sh +# This has to fail, as we shouldn't accept the dangerous PID file, and then +# inotify-wait on it to be corrected which we never do. +systemd-run --unit=test20-mainpidsh3.service \ + -p StandardOutput=tty \ + -p StandardError=tty \ + -p Type=forking \ + -p RuntimeDirectory=mainpidsh3 \ + -p PIDFile=/run/mainpidsh3/pid \ + -p DynamicUser=1 \ + -p TimeoutStartSec=2s \ + /dev/shm/test20-mainpid3.sh \ + && { echo 'unexpected success'; exit 1; } # Test that this failed due to timeout, and not some other error test `systemctl show -P Result test20-mainpidsh3.service` = timeout diff --git a/test/units/testsuite-22.03.sh b/test/units/testsuite-22.03.sh index 5e3b1ead19..c905784bee 100755 --- a/test/units/testsuite-22.03.sh +++ b/test/units/testsuite-22.03.sh @@ -39,7 +39,7 @@ test $(stat -c %U:%G:%a /tmp/f/1) = "daemon:daemon:666" mkfifo /tmp/f/fifo chmod 644 /tmp/f/fifo -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - </tmp/F/rw-fs/foo -! systemd-tmpfiles --create - < fails. -! systemd-tmpfiles --create - < /testok diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index 89c0937c8d..22bd22c2b0 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -22,8 +22,8 @@ systemctl show-environment | grep -q '^FOO=BAR$' systemctl unset-environment FOO PATH # Check that one is gone and the other reverted to the built-in -! (systemctl show-environment | grep -q '^FOO=$') -! (systemctl show-environment | grep -q '^PATH=.*testaddition$') +systemctl show-environment | grep '^FOO=$' && exit 1 +systemctl show-environment | grep '^PATH=.*testaddition$' && exit 1 systemctl show-environment | grep -q '^PATH=' echo OK > /testok diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-33.sh index 3618bee7fb..d79d054fcd 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-33.sh @@ -32,7 +32,7 @@ test -d /var/lib/testservice test -d /var/cache/testservice test -d /var/log/testservice -! systemctl clean testservice +systemctl clean testservice && { echo 'unexpected success'; exit 1; } systemctl stop testservice @@ -107,7 +107,7 @@ test -L /var/lib/testservice test -L /var/cache/testservice test -L /var/log/testservice -! systemctl clean testservice +systemctl clean testservice && { echo 'unexpected success'; exit 1; } systemctl stop testservice @@ -196,7 +196,7 @@ test -d /var/lib/hoge test -d /var/cache/hoge test -d /var/log/hoge -! systemctl clean tmp-hoge.mount +systemctl clean tmp-hoge.mount && { echo 'unexpected success'; exit 1; } test -d /etc/hoge test -d /run/hoge @@ -272,7 +272,7 @@ test -d /var/lib/testsocket test -d /var/cache/testsocket test -d /var/log/testsocket -! systemctl clean testservice.socket +systemctl clean testservice.socket && { echo 'unexpected success'; exit 1; } systemctl stop testservice.socket diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 596fc15ee8..827eafc433 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -9,7 +9,8 @@ systemd-analyze log-target console systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz touch /var/lib/zzz/test systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz test ! -L /var/lib/zzz @@ -20,7 +21,8 @@ test ! -f /var/lib/zzz/test-missing # Convert to DynamicUser=1 systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=1 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -L /var/lib/zzz test -d /var/lib/private/zzz @@ -31,7 +33,8 @@ test ! -f /var/lib/zzz/test-missing # Convert back systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test -! systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing +systemd-run --wait -p DynamicUser=0 -p StateDirectory=zzz test -f /var/lib/zzz/test-missing \ + && { echo 'unexpected success'; exit 1; } test -d /var/lib/zzz test ! -L /var/lib/zzz diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index eb7363fa6a..0b0cfc5aa5 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -21,7 +21,7 @@ systemctl daemon-reload systemctl start $SERVICE_NAME systemctl status $SERVICE_NAME # The reload SHOULD fail but SHOULD NOT affect the service state -! systemctl reload $SERVICE_NAME +systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } systemctl status $SERVICE_NAME systemctl stop $SERVICE_NAME @@ -39,7 +39,7 @@ systemctl daemon-reload systemctl start $SERVICE_NAME systemctl status $SERVICE_NAME # The reload SHOULD fail but SHOULD NOT affect the service state -! systemctl reload $SERVICE_NAME +systemctl reload $SERVICE_NAME && { echo 'unexpected success'; exit 1; } systemctl status $SERVICE_NAME systemctl stop $SERVICE_NAME diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 81fa1716f1..7caf99be24 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -9,7 +9,8 @@ systemd-analyze log-level debug systemd-analyze log-target console # test one: Restart=on-failure should restart the service -! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" +systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" \ + && { echo 'unexpected success'; exit 1; } for ((secs=0; secs<$MAX_SECS; secs++)); do [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break @@ -25,7 +26,13 @@ TMP_FILE="/tmp/test-41-oneshot-restart-test" # test two: make sure StartLimitBurst correctly limits the number of restarts # and restarts execution of the unit from the first ExecStart= -! systemd-run --unit=two -p StartLimitIntervalSec=120 -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" +systemd-run --unit=two \ + -p StartLimitIntervalSec=120 \ + -p StartLimitBurst=3 \ + -p Type=oneshot \ + -p Restart=on-failure \ + -p ExecStart="/bin/bash -c \"printf a >> $TMP_FILE\"" /bin/bash -c "exit 1" \ + && { echo 'unexpected success'; exit 1; } # wait for at least 3 restarts for ((secs=0; secs<$MAX_SECS; secs++)); do diff --git a/test/units/testsuite-42.sh b/test/units/testsuite-42.sh index 087e2cb294..155c3c7384 100755 --- a/test/units/testsuite-42.sh +++ b/test/units/testsuite-42.sh @@ -6,13 +6,15 @@ systemd-analyze log-level debug systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple1' true test -f /run/simple1 -! systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false +systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false \ + && { echo 'unexpected success'; exit 1; } test -f /run/simple2 systemd-run --unit=exec1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec1' sleep 1 test -f /run/exec1 -! systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' +systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec2' sh -c 'sleep 1; false' \ + && { echo 'unexpected success'; exit 1; } test -f /run/exec2 cat > /tmp/forking1.sh <