dcavalca / rpms / systemd

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