richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
8f24f2
From d153f9ff573b191076b843118e825f71227dbc01 Mon Sep 17 00:00:00 2001
8f24f2
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
8f24f2
Date: Thu, 8 Apr 2021 01:27:33 +0200
8f24f2
Subject: [PATCH] TEST-*: make failure tests actually fail on failure
8f24f2
8f24f2
Here the intent was actually correct, and the tests still pass when the check
8f24f2
is made effective.
8f24f2
8f24f2
(cherry picked from commit 4e20fe27950e14e8a082a74515f347546a9371d0)
8f24f2
8f24f2
Related: #2087152
8f24f2
---
8f24f2
 test/TEST-03-JOBS/test-jobs.sh          |  8 ++++----
8f24f2
 test/TEST-04-JOURNAL/test-journal.sh    |  4 ++--
8f24f2
 test/TEST-18-FAILUREACTION/testsuite.sh |  2 +-
8f24f2
 test/TEST-20-MAINPIDGAMES/testsuite.sh  | 14 ++++++++++++--
8f24f2
 test/TEST-23-TYPE-EXEC/testsuite.sh     |  4 ++--
8f24f2
 5 files changed, 21 insertions(+), 11 deletions(-)
8f24f2
8f24f2
diff --git a/test/TEST-03-JOBS/test-jobs.sh b/test/TEST-03-JOBS/test-jobs.sh
8f24f2
index 42190cf478..4ff53e0ade 100755
8f24f2
--- a/test/TEST-03-JOBS/test-jobs.sh
8f24f2
+++ b/test/TEST-03-JOBS/test-jobs.sh
8f24f2
@@ -18,7 +18,7 @@ systemctl start --job-mode=ignore-dependencies hello
8f24f2
 END_SEC=$(date -u '+%s')
8f24f2
 ELAPSED=$(($END_SEC-$START_SEC))
8f24f2
 
8f24f2
-[ "$ELAPSED" -lt 3 ]
8f24f2
+test "$ELAPSED" -lt 3
8f24f2
 
8f24f2
 # sleep should still be running, hello not.
8f24f2
 systemctl list-jobs > /root/list-jobs.txt
8f24f2
@@ -27,11 +27,11 @@ grep 'hello\.service' /root/list-jobs.txt && exit 1
8f24f2
 systemctl stop sleep.service hello-after-sleep.target
8f24f2
 
8f24f2
 # Some basic testing that --show-transaction does something useful
8f24f2
-! systemctl is-active systemd-importd
8f24f2
+systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; }
8f24f2
 systemctl -T start systemd-importd
8f24f2
 systemctl is-active systemd-importd
8f24f2
 systemctl --show-transaction stop systemd-importd
8f24f2
-! systemctl is-active systemd-importd
8f24f2
+systemctl is-active systemd-importd && { echo 'unexpected success'; exit 1; }
8f24f2
 
8f24f2
 # Test for a crash when enqueuing a JOB_NOP when other job already exists
8f24f2
 systemctl start --no-block hello-after-sleep.target
8f24f2
@@ -79,7 +79,7 @@ ELAPSED=$(($END_SEC-$START_SEC))
8f24f2
 
8f24f2
 # wait5fail fails, so systemctl should fail
8f24f2
 START_SEC=$(date -u '+%s')
8f24f2
-! systemctl start --wait wait2.service wait5fail.service || exit 1
8f24f2
+systemctl start --wait wait2.service wait5fail.service && { echo 'unexpected success'; exit 1; }
8f24f2
 END_SEC=$(date -u '+%s')
8f24f2
 ELAPSED=$(($END_SEC-$START_SEC))
8f24f2
 [[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1
8f24f2
diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh
8f24f2
index 52a6ee84d1..a3db1a7472 100755
8f24f2
--- a/test/TEST-04-JOURNAL/test-journal.sh
8f24f2
+++ b/test/TEST-04-JOURNAL/test-journal.sh
8f24f2
@@ -60,8 +60,8 @@ journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MES
8f24f2
 grep -q '^__CURSOR=' /output
8f24f2
 grep -q '^MESSAGE=foo$' /output
8f24f2
 grep -q '^PRIORITY=6$' /output
8f24f2
-! grep -q '^FOO=' /output
8f24f2
-! grep -q '^SYSLOG_FACILITY=' /output
8f24f2
+grep '^FOO=' /output && { echo 'unexpected success'; exit 1; }
8f24f2
+grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; }
8f24f2
 
8f24f2
 # https://github.com/systemd/systemd/issues/13708
8f24f2
 ID=$(journalctl --new-id128 | sed -n 2p)
8f24f2
diff --git a/test/TEST-18-FAILUREACTION/testsuite.sh b/test/TEST-18-FAILUREACTION/testsuite.sh
8f24f2
index 1867cc3c47..21b055d6ef 100755
8f24f2
--- a/test/TEST-18-FAILUREACTION/testsuite.sh
8f24f2
+++ b/test/TEST-18-FAILUREACTION/testsuite.sh
8f24f2
@@ -5,7 +5,7 @@ set -ex
8f24f2
 set -o pipefail
8f24f2
 
8f24f2
 systemd-run --wait -p FailureAction=poweroff true
8f24f2
-! systemd-run --wait -p SuccessAction=poweroff false
8f24f2
+systemd-run --wait -p SuccessAction=poweroff false && { echo 'unexpected success'; exit 1; }
8f24f2
 
8f24f2
 if test -f /firstphase ; then
8f24f2
     echo OK > /firstphase
8f24f2
diff --git a/test/TEST-20-MAINPIDGAMES/testsuite.sh b/test/TEST-20-MAINPIDGAMES/testsuite.sh
8f24f2
index 0e1a116b07..d1bfdd7a2d 100755
8f24f2
--- a/test/TEST-20-MAINPIDGAMES/testsuite.sh
8f24f2
+++ b/test/TEST-20-MAINPIDGAMES/testsuite.sh
8f24f2
@@ -128,8 +128,18 @@ test -f /run/mainpidsh3/pid
8f24f2
 EOF
8f24f2
 chmod 755 /dev/shm/mainpid3.sh
8f24f2
 
8f24f2
-# 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
8f24f2
-! systemd-run --unit=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/mainpid3.sh
8f24f2
+# This has to fail, as we shouldn't accept the dangerous PID file, and then
8f24f2
+# inotify-wait on it to be corrected which we never do.
8f24f2
+systemd-run --unit=mainpidsh3.service \
8f24f2
+            -p StandardOutput=tty \
8f24f2
+            -p StandardError=tty \
8f24f2
+            -p Type=forking \
8f24f2
+            -p RuntimeDirectory=mainpidsh3 \
8f24f2
+            -p PIDFile=/run/mainpidsh3/pid \
8f24f2
+            -p DynamicUser=1 \
8f24f2
+            -p TimeoutStartSec=2s \
8f24f2
+            /dev/shm/mainpid3.sh \
8f24f2
+    && { echo 'unexpected success'; exit 1; }
8f24f2
 
8f24f2
 # Test that this failed due to timeout, and not some other error
8f24f2
 test `systemctl show -p Result --value mainpidsh3.service` = timeout
8f24f2
diff --git a/test/TEST-23-TYPE-EXEC/testsuite.sh b/test/TEST-23-TYPE-EXEC/testsuite.sh
8f24f2
index e0c34cfd04..beb7fd2e38 100755
8f24f2
--- a/test/TEST-23-TYPE-EXEC/testsuite.sh
8f24f2
+++ b/test/TEST-23-TYPE-EXEC/testsuite.sh
8f24f2
@@ -18,8 +18,8 @@ systemd-run --unit=three -p Type=simple /tmp/brokenbinary
8f24f2
 
8f24f2
 # And now, do the same with Type=exec, where the latter two should fail
8f24f2
 systemd-run --unit=four -p Type=exec /bin/sleep infinity
8f24f2
-! systemd-run --unit=five -p Type=exec -p User=idontexist /bin/sleep infinity
8f24f2
-! systemd-run --unit=six -p Type=exec /tmp/brokenbinary
8f24f2
+systemd-run --unit=five -p Type=exec -p User=idontexist /bin/sleep infinity && { echo 'unexpected success'; exit 1; }
8f24f2
+systemd-run --unit=six -p Type=exec /tmp/brokenbinary && { echo 'unexpected success'; exit 1; }
8f24f2
 
8f24f2
 # For issue #20933
8f24f2