]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: merge unit file related tests into TEST-23-UNIT-FILE
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 8 May 2023 20:38:34 +0000 (22:38 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 May 2023 17:39:12 +0000 (02:39 +0900)
Rename TEST-23-TYPE-EXEC to TEST-23-UNIT-FILE and merge it with
following tests:
  - TEST-37-RUNTIMEDIRECTORYPRESERV
  - TEST-40-EXEC-COMMAND-EX
  - TEST-41-ONESHOT-RESTART
  - TEST-42-EXECSTOPPOST
  - TEST-57-ONSUCCESS-UPHOLD

44 files changed:
test/TEST-23-UNIT-FILE/Makefile [moved from test/TEST-23-TYPE-EXEC/Makefile with 100% similarity]
test/TEST-23-UNIT-FILE/test.sh [moved from test/TEST-23-TYPE-EXEC/test.sh with 74% similarity]
test/TEST-37-RUNTIMEDIRECTORYPRESERVE/Makefile [deleted symlink]
test/TEST-37-RUNTIMEDIRECTORYPRESERVE/test.sh [deleted file]
test/TEST-39-EXECRELOAD/Makefile [deleted symlink]
test/TEST-39-EXECRELOAD/test.sh [deleted file]
test/TEST-40-EXEC-COMMAND-EX/Makefile [deleted symlink]
test/TEST-40-EXEC-COMMAND-EX/deny-list-ubuntu-ci-arm64 [deleted file]
test/TEST-40-EXEC-COMMAND-EX/test.sh [deleted file]
test/TEST-41-ONESHOT-RESTART/Makefile [deleted symlink]
test/TEST-41-ONESHOT-RESTART/test.sh [deleted file]
test/TEST-42-EXECSTOPPOST/Makefile [deleted symlink]
test/TEST-42-EXECSTOPPOST/test.sh [deleted file]
test/TEST-57-ONSUCCESS-UPHOLD/Makefile [deleted symlink]
test/TEST-57-ONSUCCESS-UPHOLD/test.sh [deleted file]
test/units/testsuite-23-binds-to.service [moved from test/units/testsuite-57-binds-to.service with 74% similarity]
test/units/testsuite-23-bound-by.service [moved from test/units/testsuite-57-bound-by.service with 100% similarity]
test/units/testsuite-23-fail.service [moved from test/units/testsuite-57-fail.service with 74% similarity]
test/units/testsuite-23-prop-stop-one.service [new file with mode: 0644]
test/units/testsuite-23-prop-stop-two.service [moved from test/units/testsuite-57-prop-stop-two.service with 100% similarity]
test/units/testsuite-23-retry-fail.service [moved from test/units/testsuite-57-retry-fail.service with 72% similarity]
test/units/testsuite-23-retry-upheld.service [moved from test/units/testsuite-57-retry-upheld.service with 64% similarity]
test/units/testsuite-23-retry-uphold.service [moved from test/units/testsuite-57-retry-uphold.service with 74% similarity]
test/units/testsuite-23-short-lived.service [moved from test/units/testsuite-57-short-lived.service with 79% similarity]
test/units/testsuite-23-short-lived.sh [new file with mode: 0755]
test/units/testsuite-23-success.service [moved from test/units/testsuite-57-success.service with 75% similarity]
test/units/testsuite-23-uphold.service [moved from test/units/testsuite-57-uphold.service with 74% similarity]
test/units/testsuite-23.ExecReload.sh [moved from test/units/testsuite-39.sh with 98% similarity]
test/units/testsuite-23.ExecStopPost.sh [moved from test/units/testsuite-42.sh with 98% similarity]
test/units/testsuite-23.RuntimeDirectoryPreserve.sh [moved from test/units/testsuite-37.sh with 92% similarity]
test/units/testsuite-23.Upholds.sh [new file with mode: 0755]
test/units/testsuite-23.exec-command-ex.sh [moved from test/units/testsuite-40.sh with 97% similarity]
test/units/testsuite-23.oneshot-restart.sh [moved from test/units/testsuite-41.sh with 76% similarity]
test/units/testsuite-23.sh
test/units/testsuite-23.type-exec.sh [new file with mode: 0755]
test/units/testsuite-37.service [deleted file]
test/units/testsuite-39.service [deleted file]
test/units/testsuite-40.service [deleted file]
test/units/testsuite-41.service [deleted file]
test/units/testsuite-42.service [deleted file]
test/units/testsuite-57-prop-stop-one.service [deleted file]
test/units/testsuite-57-short-lived.sh [deleted file]
test/units/testsuite-57.service [deleted file]
test/units/testsuite-57.sh [deleted file]

similarity index 74%
rename from test/TEST-23-TYPE-EXEC/test.sh
rename to test/TEST-23-UNIT-FILE/test.sh
index 7268cde8371e53bbe9ad99a3c33200f66899e5d4..335f2fdd2b8e0999744f96fa779e6f1318122d95 100755 (executable)
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
-TEST_DESCRIPTION="test Type=exec"
+TEST_DESCRIPTION="Tests for various unit file settings"
 
 # shellcheck source=test/test-functions
 . "${TEST_BASE_DIR:?}/test-functions"
diff --git a/test/TEST-37-RUNTIMEDIRECTORYPRESERVE/Makefile b/test/TEST-37-RUNTIMEDIRECTORYPRESERVE/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-37-RUNTIMEDIRECTORYPRESERVE/test.sh b/test/TEST-37-RUNTIMEDIRECTORYPRESERVE/test.sh
deleted file mode 100755 (executable)
index 2f65908..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-# -*- 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="test RuntimeDirectoryPreserve=yes"
-
-# shellcheck source=test/test-functions
-. "${TEST_BASE_DIR:?}/test-functions"
-
-do_test "$@"
diff --git a/test/TEST-39-EXECRELOAD/Makefile b/test/TEST-39-EXECRELOAD/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-39-EXECRELOAD/test.sh b/test/TEST-39-EXECRELOAD/test.sh
deleted file mode 100755 (executable)
index c7565c6..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
-
-TEST_DESCRIPTION="Test ExecReload= (PR #13098)"
-
-# shellcheck source=test/test-functions
-. "${TEST_BASE_DIR:?}/test-functions"
-
-do_test "$@"
diff --git a/test/TEST-40-EXEC-COMMAND-EX/Makefile b/test/TEST-40-EXEC-COMMAND-EX/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-40-EXEC-COMMAND-EX/deny-list-ubuntu-ci-arm64 b/test/TEST-40-EXEC-COMMAND-EX/deny-list-ubuntu-ci-arm64
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/test/TEST-40-EXEC-COMMAND-EX/test.sh b/test/TEST-40-EXEC-COMMAND-EX/test.sh
deleted file mode 100755 (executable)
index 6101f2c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
-
-TEST_DESCRIPTION="test ExecXYZEx= service unit dbus hookups"
-
-# shellcheck source=test/test-functions
-. "${TEST_BASE_DIR:?}/test-functions"
-
-do_test "$@"
diff --git a/test/TEST-41-ONESHOT-RESTART/Makefile b/test/TEST-41-ONESHOT-RESTART/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-41-ONESHOT-RESTART/test.sh b/test/TEST-41-ONESHOT-RESTART/test.sh
deleted file mode 100755 (executable)
index 2e1879a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
-
-TEST_DESCRIPTION="Test oneshot unit restart on failure"
-
-# shellcheck source=test/test-functions
-. "${TEST_BASE_DIR:?}/test-functions"
-
-do_test "$@"
diff --git a/test/TEST-42-EXECSTOPPOST/Makefile b/test/TEST-42-EXECSTOPPOST/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-42-EXECSTOPPOST/test.sh b/test/TEST-42-EXECSTOPPOST/test.sh
deleted file mode 100755 (executable)
index 9d75bac..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
-
-TEST_DESCRIPTION="test that ExecStopPost= is always run"
-
-# shellcheck source=test/test-functions
-. "${TEST_BASE_DIR:?}/test-functions"
-
-do_test "$@"
diff --git a/test/TEST-57-ONSUCCESS-UPHOLD/Makefile b/test/TEST-57-ONSUCCESS-UPHOLD/Makefile
deleted file mode 120000 (symlink)
index e9f93b1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../TEST-01-BASIC/Makefile
\ No newline at end of file
diff --git a/test/TEST-57-ONSUCCESS-UPHOLD/test.sh b/test/TEST-57-ONSUCCESS-UPHOLD/test.sh
deleted file mode 100755 (executable)
index 8181ac5..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
-
-TEST_DESCRIPTION="test OnSuccess= + Uphold= + PropagatesStopTo= + BindsTo="
-# shellcheck source=test/test-functions
-. "$TEST_BASE_DIR/test-functions"
-
-do_test "$@" 57
similarity index 74%
rename from test/units/testsuite-57-binds-to.service
rename to test/units/testsuite-23-binds-to.service
index c542896d941cd1f50a634dc54852c7fc3c5c3721..d81676a8c354984e81fe3948264157e9f5399771 100644 (file)
@@ -1,10 +1,10 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Unit with BindsTo=
-BindsTo=testsuite-57-bound-by.service
-After=testsuite-57-bound-by.service
+BindsTo=testsuite-23-bound-by.service
+After=testsuite-23-bound-by.service
 
 [Service]
 ExecStart=/bin/sleep infinity
 # --kill-who= (no 'm') to check that the short form is accepted
-ExecStopPost=systemctl kill --kill-who=main -sRTMIN+1 testsuite-57.service
+ExecStopPost=systemctl kill --kill-who=main -sRTMIN+1 testsuite-23.service
similarity index 74%
rename from test/units/testsuite-57-fail.service
rename to test/units/testsuite-23-fail.service
index 54d2330742e1f71448c8e224cd5f19a4081a35dc..36f8baa6ba4b589e8e916ef057e23b041f14b93d 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Failing unit
-OnFailure=testsuite-57-uphold.service
+OnFailure=testsuite-23-uphold.service
 
 [Service]
 ExecStart=/bin/false
diff --git a/test/units/testsuite-23-prop-stop-one.service b/test/units/testsuite-23-prop-stop-one.service
new file mode 100644 (file)
index 0000000..f068daf
--- /dev/null
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Unit]
+Description=Stop Propagation Receiver
+Wants=testsuite-23-prop-stop-two.service
+After=testsuite-23-prop-stop-two.service
+StopPropagatedFrom=testsuite-23-prop-stop-two.service
+
+[Service]
+ExecStart=/bin/sleep infinity
+ExecStopPost=systemctl kill --kill-whom=main -sUSR2 testsuite-23.service
similarity index 72%
rename from test/units/testsuite-57-retry-fail.service
rename to test/units/testsuite-23-retry-fail.service
index 67f34079d5f2db798db6dec5073194d2a3d42706..0fc27c41fee0128b607b9c4aafc5309ae7fe6bda 100644 (file)
@@ -5,5 +5,5 @@ Description=Failed Dependency Unit
 [Service]
 Type=oneshot
 RemainAfterExit=yes
-ExecStart=/bin/sh -c "if [ -f /tmp/testsuite-57-retry-fail ]; then exit 0; else exit 1; fi"
+ExecStart=/bin/sh -c "if [ -f /tmp/testsuite-23-retry-fail ]; then exit 0; else exit 1; fi"
 Restart=no
similarity index 64%
rename from test/units/testsuite-57-retry-upheld.service
rename to test/units/testsuite-23-retry-upheld.service
index 2f718a61fa6d0ed0b4f362ad0a00dbca3373990a..0426d76a54649eb2f745d94ae95b36c8c1f4005d 100644 (file)
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Upheld Unit
-Requires=testsuite-57-retry-fail.service
-After=testsuite-57-retry-fail.service
+Requires=testsuite-23-retry-fail.service
+After=testsuite-23-retry-fail.service
 
 [Service]
 Type=oneshot
similarity index 74%
rename from test/units/testsuite-57-retry-uphold.service
rename to test/units/testsuite-23-retry-uphold.service
index a01b131ed5b1ebf4b93abc134b00bb29b8b443cc..f35e8424de8ece0c04c6e33f233d7f0286ca240b 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Upholding Unit
-Upholds=testsuite-57-retry-upheld.service
+Upholds=testsuite-23-retry-upheld.service
 
 [Service]
 ExecStart=/bin/sleep infinity
similarity index 79%
rename from test/units/testsuite-57-short-lived.service
rename to test/units/testsuite-23-short-lived.service
index cd8b51477f2de6f979aa74f20206e896edf76f53..2dcb2ae228ea9819bcd89c5a7d57eb30541368e9 100644 (file)
@@ -8,4 +8,4 @@ StartLimitBurst=15
 StartLimitIntervalSec=1h
 
 [Service]
-ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-57-short-lived.sh
+ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-23-short-lived.sh
diff --git a/test/units/testsuite-23-short-lived.sh b/test/units/testsuite-23-short-lived.sh
new file mode 100755 (executable)
index 0000000..4a12c7f
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -ex
+
+if [ -f /tmp/testsuite-23.counter ] ; then
+    read -r counter < /tmp/testsuite-23.counter
+    counter=$((counter + 1))
+else
+    counter=0
+fi
+
+echo "$counter" >/tmp/testsuite-23.counter
+
+if [ "$counter" -eq 5 ] ; then
+    systemctl kill --kill-whom=main -sUSR1 testsuite-23.service
+fi
+
+exec sleep 1.5
similarity index 75%
rename from test/units/testsuite-57-success.service
rename to test/units/testsuite-23-success.service
index ae1f46f30cad98e2a9309839cdbc8444dbf6ea6d..410d4f83c3468e099fd2be347cb1d677de045595 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Succeeding unit
-OnSuccess=testsuite-57-fail.service
+OnSuccess=testsuite-23-fail.service
 
 [Service]
 ExecStart=/bin/true
similarity index 74%
rename from test/units/testsuite-57-uphold.service
rename to test/units/testsuite-23-uphold.service
index eba97f509d06aa6065a0d04ef6eb7b390f01109f..3549d6a8f50691a206696a55ec03889ed3784278 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 [Unit]
 Description=Upholding Unit
-Upholds=testsuite-57-short-lived.service
+Upholds=testsuite-23-short-lived.service
 
 [Service]
 ExecStart=/bin/sleep infinity
similarity index 98%
rename from test/units/testsuite-39.sh
rename to test/units/testsuite-23.ExecReload.sh
index dbeb1df8947f4a028ac4a925adc38d12335fdc2b..b497f73dfe53b1eaebdbe269a4e3c6a77f178c44 100755 (executable)
@@ -3,6 +3,8 @@
 set -eux
 set -o pipefail
 
+# Test ExecReload= (PR #13098)
+
 systemd-analyze log-level debug
 
 export SYSTEMD_PAGER=
@@ -57,7 +59,3 @@ systemctl status "$SERVICE_NAME"
 systemctl stop "$SERVICE_NAME"
 
 systemd-analyze log-level info
-
-echo OK >/testok
-
-exit 0
similarity index 98%
rename from test/units/testsuite-42.sh
rename to test/units/testsuite-23.ExecStopPost.sh
index b78d5b7a435ade2b8b5cc58c473e072116b44252..aeaf3aa3829182a16d2abff88cd303f804b8aba8 100755 (executable)
@@ -2,6 +2,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -eux
 
+# Test that ExecStopPost= is always run
+
 systemd-analyze log-level debug
 
 systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple \
@@ -100,7 +102,3 @@ test -f /run/idle1
 test -f /run/idle2
 
 systemd-analyze log-level info
-
-echo OK >/testok
-
-exit 0
similarity index 92%
rename from test/units/testsuite-37.sh
rename to test/units/testsuite-23.RuntimeDirectoryPreserve.sh
index 1aec383c0c4ecf050bda7d370ed62e974d55706a..b60b612d82f637391389aa7c12be8ac141270777 100755 (executable)
@@ -5,6 +5,8 @@
 set -eux
 set -o pipefail
 
+# Test RuntimeDirectoryPreserve=yes
+
 systemd-mount -p RuntimeDirectory=hoge -p RuntimeDirectoryPreserve=yes -t tmpfs tmpfs /tmp/aaa
 
 touch /run/hoge/foo
@@ -14,7 +16,3 @@ systemctl restart tmp-aaa.mount
 
 test -e /run/hoge/foo
 test ! -e /tmp/aaa/bbb
-
-echo OK >/testok
-
-exit 0
diff --git a/test/units/testsuite-23.Upholds.sh b/test/units/testsuite-23.Upholds.sh
new file mode 100755 (executable)
index 0000000..21db258
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+set -eux
+set -o pipefail
+
+# Test OnSuccess= + Uphold= + PropagatesStopTo= + BindsTo=
+
+systemd-analyze log-level debug
+systemd-analyze log-target journal
+
+# Idea is this:
+#    1. we start testsuite-23-success.service
+#    2. which through OnSuccess= starts testsuite-23-fail.service,
+#    3. which through OnFailure= starts testsuite-23-uphold.service,
+#    4. which through Uphold= starts/keeps testsuite-23-short-lived.service running,
+#    5. which will sleep 1s when invoked, and on the 5th invocation send us a SIGUSR1
+#    6. once we got that we finish cleanly
+
+sigusr1=0
+trap sigusr1=1 SIGUSR1
+
+trap -p SIGUSR1
+
+systemctl start testsuite-23-success.service
+
+while [ "$sigusr1" -eq 0 ] ; do
+    sleep .5
+done
+
+systemctl stop testsuite-23-uphold.service
+
+# Idea is this:
+#    1. we start testsuite-23-retry-uphold.service
+#    2. which through Uphold= starts testsuite-23-retry-upheld.service
+#    3. which through Requires= starts testsuite-23-retry-fail.service
+#    4. which fails as /tmp/testsuite-23-retry-fail does not exist, so testsuite-23-retry-upheld.service
+#       is no longer restarted
+#    5. we create /tmp/testsuite-23-retry-fail
+#    6. now testsuite-23-retry-upheld.service will be restarted since upheld, and its dependency will
+#       be satisfied
+
+rm -f /tmp/testsuite-23-retry-fail
+systemctl start testsuite-23-retry-uphold.service
+
+while ! systemctl is-failed testsuite-23-retry-fail.service ; do
+    sleep .5
+done
+
+systemctl is-active testsuite-23-retry-upheld.service && { echo 'unexpected success'; exit 1; }
+
+touch /tmp/testsuite-23-retry-fail
+
+while ! systemctl is-active testsuite-23-retry-upheld.service ; do
+    sleep .5
+done
+
+systemctl stop testsuite-23-retry-uphold.service testsuite-23-retry-fail.service testsuite-23-retry-upheld.service
+
+# Idea is this:
+#    1. we start testsuite-23-prop-stop-one.service
+#    2. which through Wants=/After= pulls in testsuite-23-prop-stop-two.service as well
+#    3. testsuite-23-prop-stop-one.service then sleeps indefinitely
+#    4. testsuite-23-prop-stop-two.service sleeps a short time and exits
+#    5. the StopPropagatedFrom= dependency between the two should ensure *both* will exit as result
+#    6. an ExecStopPost= line on testsuite-23-prop-stop-one.service will send us a SIGUSR2
+#    7. once we got that we finish cleanly
+
+sigusr2=0
+trap sigusr2=1 SIGUSR2
+
+systemctl start testsuite-23-prop-stop-one.service
+
+while [ "$sigusr2" -eq 0 ] ; do
+    sleep .5
+done
+
+
+# Idea is this:
+#    1. we start testsuite-23-binds-to.service
+#    2. which through BindsTo=/After= pulls in testsuite-23-bound-by.service as well
+#    3. testsuite-23-bound-by.service suddenly dies
+#    4. testsuite-23-binds-to.service should then also be pulled down (it otherwise just hangs)
+#    6. an ExecStopPost= line on testsuite-23-binds-to.service will send us a SIGRTMIN1+1
+#    7. once we got that we finish cleanly
+
+sigrtmin1=0
+trap sigrtmin1=1 SIGRTMIN+1
+
+systemctl start testsuite-23-binds-to.service
+
+while [ "$sigrtmin1" -eq 0 ] ; do
+    sleep .5
+done
+
+systemd-analyze log-level info
similarity index 97%
rename from test/units/testsuite-40.sh
rename to test/units/testsuite-23.exec-command-ex.sh
index cec1fd3a7aa41f211b2d347dfe9d4e42d2965045..f926e7dea87351f7212336dc3730b79fad888364 100755 (executable)
@@ -3,6 +3,8 @@
 set -eux
 set -o pipefail
 
+# Test ExecXYZEx= service unit dbus hookups
+
 systemd-analyze log-level debug
 
 declare -A property
@@ -40,7 +42,3 @@ for c in "${!property_ex[@]}"; do
 done
 
 systemd-analyze log-level info
-
-echo OK >/testok
-
-exit 0
similarity index 76%
rename from test/units/testsuite-41.sh
rename to test/units/testsuite-23.oneshot-restart.sh
index a6ae7bc0107db6d3991b7d8fbd9eda29adfe5c30..433cd698187351b4064e52e423474a3bc49b399d 100755 (executable)
@@ -3,19 +3,21 @@
 set -eux
 set -o pipefail
 
+# Test oneshot unit restart on failure
+
 # wait this many secs for each test service to succeed in what is being tested
 MAX_SECS=60
 
 systemd-analyze log-level debug
 
 # 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=oneshot-restart-one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1")
 
 for ((secs = 0; secs < MAX_SECS; secs++)); do
-    [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]] || break
+    [[ "$(systemctl show oneshot-restart-one.service -P NRestarts)" -le 0 ]] || break
     sleep 1
 done
-if [[ "$(systemctl show one.service -P NRestarts)" -le 0 ]]; then
+if [[ "$(systemctl show oneshot-restart-one.service -P NRestarts)" -le 0 ]]; then
     exit 1
 fi
 
@@ -25,7 +27,7 @@ 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 \
+(! systemd-run --unit=oneshot-restart-two \
         -p StartLimitIntervalSec=120 \
         -p StartLimitBurst=3 \
         -p Type=oneshot \
@@ -48,7 +50,3 @@ if [[ $(cat $TMP_FILE) != "aaa" ]]; then
 fi
 
 systemd-analyze log-level info
-
-echo OK >/testok
-
-exit 0
index 4ce205fae6863bc5ce0a625b68817fd5eae9a7d0..a6b8da34c9ae3640a628115d86946f2efc1300bc 100755 (executable)
@@ -3,63 +3,64 @@
 set -eux
 set -o pipefail
 
-systemd-analyze log-level debug
+: >/failed
 
-# Create a binary for which execve() will fail
-touch /tmp/brokenbinary
-chmod +x /tmp/brokenbinary
+declare -i CHILD_PID=0
 
-# These three commands should succeed.
-systemd-run --unit=one -p Type=simple /bin/sleep infinity
-systemd-run --unit=two -p Type=simple -p User=idontexist /bin/sleep infinity
-systemd-run --unit=three -p Type=simple /tmp/brokenbinary
+# Note: all the signal shenanigans are necessary for the Upholds= tests
 
-# And now, do the same with Type=exec, where the latter two should fail
-systemd-run --unit=four -p Type=exec /bin/sleep infinity
-(! systemd-run --unit=five -p Type=exec -p User=idontexist /bin/sleep infinity)
-(! systemd-run --unit=six -p Type=exec /tmp/brokenbinary)
+# Like trap, but passes the signal name as the first argument
+trap_with_sig() {
+    local fun="${1:?}"
+    local sig
+    shift
 
-systemd-run --unit=seven -p KillSignal=SIGTERM -p RestartKillSignal=SIGINT -p Type=exec /bin/sleep infinity
-# Both TERM and SIGINT happen to have the same number on all architectures
-test "$(systemctl show --value -p KillSignal seven.service)" -eq 15
-test "$(systemctl show --value -p RestartKillSignal seven.service)" -eq 2
+    for sig in "$@"; do
+        # shellcheck disable=SC2064
+        trap "$fun $sig" "$sig"
+    done
+}
 
-systemctl restart seven.service
-systemctl stop seven.service
+# Propagate the caught signal to the current child process
+handle_signal() {
+    local sig="${1:?}"
 
-# For issue #20933
+    if [[ $CHILD_PID -gt 0 ]]; then
+        echo "Propagating signal $sig to child process $CHILD_PID"
+        kill -s "$sig" "$CHILD_PID"
+    fi
+}
 
-# Should work normally
-busctl call \
-    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
-    org.freedesktop.systemd1.Manager StartTransientUnit \
-    "ssa(sv)a(sa(sv))" test-20933-ok.service replace 1 \
-      ExecStart "a(sasb)" 1 \
-        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
-    0
+# In order to make the handle_signal() stuff above work, we have to execute
+# each script asynchronously, since bash won't execute traps until the currently
+# executed command finishes. This, however, introduces another issue regarding
+# how bash's wait works. Quoting:
+#
+#   When bash is waiting for an asynchronous command via the wait builtin,
+#   the reception of a signal for which a trap has been set will cause the wait
+#   builtin to return immediately with an exit status greater than 128,
+#   immediately after which the trap is executed.
+#
+# In other words - every time we propagate a signal, wait returns with
+# 128+signal, so we have to wait again - repeat until the process dies.
+wait_harder() {
+    local pid="${1:?}"
 
-# DBus call should fail but not crash systemd
-(! busctl call \
-    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
-    org.freedesktop.systemd1.Manager StartTransientUnit \
-    "ssa(sv)a(sa(sv))" test-20933-bad.service replace 1 \
-      ExecStart "a(sasb)" 1 \
-        /usr/bin/sleep 0 true \
-    0)
+    while kill -0 "$pid"; do
+        wait "$pid" || :
+    done
 
-# Same but with the empty argv in the middle
-(! busctl call \
-    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
-    org.freedesktop.systemd1.Manager StartTransientUnit \
-    "ssa(sv)a(sa(sv))" test-20933-bad-middle.service replace 1 \
-      ExecStart "a(sasb)" 3 \
-        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
-        /usr/bin/sleep 0                  true \
-        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
-    0)
+    wait "$pid"
+}
 
-systemd-analyze log-level info
+trap_with_sig handle_signal SIGUSR1 SIGUSR2 SIGRTMIN+1
 
-echo OK >/testok
+for script in "${0%.sh}".*.sh; do
+    echo "Running $script"
+    "./$script" &
+    CHILD_PID=$!
+    wait_harder "$CHILD_PID"
+done
 
-exit 0
+touch /testok
+rm /failed
diff --git a/test/units/testsuite-23.type-exec.sh b/test/units/testsuite-23.type-exec.sh
new file mode 100755 (executable)
index 0000000..87f32cc
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+# Test Type=exec
+
+systemd-analyze log-level debug
+
+# Create a binary for which execve() will fail
+touch /tmp/brokenbinary
+chmod +x /tmp/brokenbinary
+
+# These three commands should succeed.
+systemd-run --unit=exec-one -p Type=simple /bin/sleep infinity
+systemd-run --unit=exec-two -p Type=simple -p User=idontexist /bin/sleep infinity
+systemd-run --unit=exec-three -p Type=simple /tmp/brokenbinary
+
+# And now, do the same with Type=exec, where the latter two should fail
+systemd-run --unit=exec-four -p Type=exec /bin/sleep infinity
+(! systemd-run --unit=exec-five -p Type=exec -p User=idontexist /bin/sleep infinity)
+(! systemd-run --unit=exec-six -p Type=exec /tmp/brokenbinary)
+
+systemd-run --unit=exec-seven -p KillSignal=SIGTERM -p RestartKillSignal=SIGINT -p Type=exec /bin/sleep infinity
+# Both TERM and SIGINT happen to have the same number on all architectures
+test "$(systemctl show --value -p KillSignal exec-seven.service)" -eq 15
+test "$(systemctl show --value -p RestartKillSignal exec-seven.service)" -eq 2
+
+systemctl restart exec-seven.service
+systemctl stop exec-seven.service
+
+# For issue #20933
+
+# Should work normally
+busctl call \
+    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
+    org.freedesktop.systemd1.Manager StartTransientUnit \
+    "ssa(sv)a(sa(sv))" test-20933-ok.service replace 1 \
+      ExecStart "a(sasb)" 1 \
+        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
+    0
+
+# DBus call should fail but not crash systemd
+(! busctl call \
+    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
+    org.freedesktop.systemd1.Manager StartTransientUnit \
+    "ssa(sv)a(sa(sv))" test-20933-bad.service replace 1 \
+      ExecStart "a(sasb)" 1 \
+        /usr/bin/sleep 0 true \
+    0)
+
+# Same but with the empty argv in the middle
+(! busctl call \
+    org.freedesktop.systemd1 /org/freedesktop/systemd1 \
+    org.freedesktop.systemd1.Manager StartTransientUnit \
+    "ssa(sv)a(sa(sv))" test-20933-bad-middle.service replace 1 \
+      ExecStart "a(sasb)" 3 \
+        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
+        /usr/bin/sleep 0                  true \
+        /usr/bin/sleep 2 /usr/bin/sleep 1 true \
+    0)
+
+systemd-analyze log-level info
diff --git a/test/units/testsuite-37.service b/test/units/testsuite-37.service
deleted file mode 100644 (file)
index ccad5e2..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-37-RUNTIMEDIRECTORYPRESERVE
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-39.service b/test/units/testsuite-39.service
deleted file mode 100644 (file)
index 1567dfa..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-39-EXECRELOAD
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-40.service b/test/units/testsuite-40.service
deleted file mode 100644 (file)
index eec4ddc..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-40-EXEC-COMMAND-EX
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-41.service b/test/units/testsuite-41.service
deleted file mode 100644 (file)
index bbd8a72..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-41-ONESHOT-RESTART
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-42.service b/test/units/testsuite-42.service
deleted file mode 100644 (file)
index f57e616..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-42-EXECSTOPPOST
-Before=getty-pre.target
-Wants=getty-pre.target
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-57-prop-stop-one.service b/test/units/testsuite-57-prop-stop-one.service
deleted file mode 100644 (file)
index a942b52..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=Stop Propagation Receiver
-Wants=testsuite-57-prop-stop-two.service
-After=testsuite-57-prop-stop-two.service
-StopPropagatedFrom=testsuite-57-prop-stop-two.service
-
-[Service]
-ExecStart=/bin/sleep infinity
-ExecStopPost=systemctl kill --kill-whom=main -sUSR2 testsuite-57.service
diff --git a/test/units/testsuite-57-short-lived.sh b/test/units/testsuite-57-short-lived.sh
deleted file mode 100755 (executable)
index e596392..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -ex
-
-if [ -f /tmp/testsuite-57.counter ] ; then
-    read -r counter < /tmp/testsuite-57.counter
-    counter=$((counter + 1))
-else
-    counter=0
-fi
-
-echo "$counter" >/tmp/testsuite-57.counter
-
-if [ "$counter" -eq 5 ] ; then
-    systemctl kill --kill-whom=main -sUSR1 testsuite-57.service
-fi
-
-exec sleep 1.5
diff --git a/test/units/testsuite-57.service b/test/units/testsuite-57.service
deleted file mode 100644 (file)
index d3ec955..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1-or-later
-[Unit]
-Description=TEST-57-ONSUCCESS-UPHOLD
-
-[Service]
-ExecStartPre=rm -f /failed /testok
-ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
-Type=oneshot
diff --git a/test/units/testsuite-57.sh b/test/units/testsuite-57.sh
deleted file mode 100755 (executable)
index 24040c3..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-set -eux
-set -o pipefail
-
-systemd-analyze log-level debug
-systemd-analyze log-target journal
-
-# Idea is this:
-#    1. we start testsuite-57-success.service
-#    2. which through OnSuccess= starts testsuite-57-fail.service,
-#    3. which through OnFailure= starts testsuite-57-uphold.service,
-#    4. which through Uphold= starts/keeps testsuite-57-short-lived.service running,
-#    5. which will sleep 1s when invoked, and on the 5th invocation send us a SIGUSR1
-#    6. once we got that we finish cleanly
-
-sigusr1=0
-trap sigusr1=1 SIGUSR1
-
-systemctl start testsuite-57-success.service
-
-while [ "$sigusr1" -eq 0 ] ; do
-    sleep .5
-done
-
-systemctl stop testsuite-57-uphold.service
-
-# Idea is this:
-#    1. we start testsuite-57-retry-uphold.service
-#    2. which through Uphold= starts testsuite-57-retry-upheld.service
-#    3. which through Requires= starts testsuite-57-retry-fail.service
-#    4. which fails as /tmp/testsuite-57-retry-fail does not exist, so testsuite-57-retry-upheld.service
-#       is no longer restarted
-#    5. we create /tmp/testsuite-57-retry-fail
-#    6. now testsuite-57-retry-upheld.service will be restarted since upheld, and its dependency will
-#       be satisfied
-
-rm -f /tmp/testsuite-57-retry-fail
-systemctl start testsuite-57-retry-uphold.service
-
-while ! systemctl is-failed testsuite-57-retry-fail.service ; do
-    sleep .5
-done
-
-systemctl is-active testsuite-57-retry-upheld.service && { echo 'unexpected success'; exit 1; }
-
-touch /tmp/testsuite-57-retry-fail
-
-while ! systemctl is-active testsuite-57-retry-upheld.service ; do
-    sleep .5
-done
-
-systemctl stop testsuite-57-retry-uphold.service testsuite-57-retry-fail.service testsuite-57-retry-upheld.service
-
-# Idea is this:
-#    1. we start testsuite-57-prop-stop-one.service
-#    2. which through Wants=/After= pulls in testsuite-57-prop-stop-two.service as well
-#    3. testsuite-57-prop-stop-one.service then sleeps indefinitely
-#    4. testsuite-57-prop-stop-two.service sleeps a short time and exits
-#    5. the StopPropagatedFrom= dependency between the two should ensure *both* will exit as result
-#    6. an ExecStopPost= line on testsuite-57-prop-stop-one.service will send us a SIGUSR2
-#    7. once we got that we finish cleanly
-
-sigusr2=0
-trap sigusr2=1 SIGUSR2
-
-systemctl start testsuite-57-prop-stop-one.service
-
-while [ "$sigusr2" -eq 0 ] ; do
-    sleep .5
-done
-
-
-# Idea is this:
-#    1. we start testsuite-57-binds-to.service
-#    2. which through BindsTo=/After= pulls in testsuite-57-bound-by.service as well
-#    3. testsuite-57-bound-by.service suddenly dies
-#    4. testsuite-57-binds-to.service should then also be pulled down (it otherwise just hangs)
-#    6. an ExecStopPost= line on testsuite-57-binds-to.service will send us a SIGRTMIN1+1
-#    7. once we got that we finish cleanly
-
-sigrtmin1=0
-trap sigrtmin1=1 SIGRTMIN+1
-
-systemctl start testsuite-57-binds-to.service
-
-while [ "$sigrtmin1" -eq 0 ] ; do
-    sleep .5
-done
-
-systemd-analyze log-level info
-
-echo OK >/testok
-
-exit 0