richardphibel / rpms / systemd

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