From 6fc2da644a22faba1ffff4d597ec91b97f3b2610 Mon Sep 17 00:00:00 2001 From: Peter Morrow Date: Mon, 22 Nov 2021 16:21:43 +0000 Subject: [PATCH] tests: add test to cover service exit status propagation Various tests to cover MONITOR_METADATA setup for OnFailure= and OnSuccess= dependencies. --- test/TEST-68-PROPAGATE-EXIT-STATUS/Makefile | 1 + test/TEST-68-PROPAGATE-EXIT-STATUS/test.sh | 11 + test/units/testsuite-68.service | 7 + test/units/testsuite-68.sh | 230 ++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 120000 test/TEST-68-PROPAGATE-EXIT-STATUS/Makefile create mode 100755 test/TEST-68-PROPAGATE-EXIT-STATUS/test.sh create mode 100644 test/units/testsuite-68.service create mode 100755 test/units/testsuite-68.sh diff --git a/test/TEST-68-PROPAGATE-EXIT-STATUS/Makefile b/test/TEST-68-PROPAGATE-EXIT-STATUS/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-68-PROPAGATE-EXIT-STATUS/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-68-PROPAGATE-EXIT-STATUS/test.sh b/test/TEST-68-PROPAGATE-EXIT-STATUS/test.sh new file mode 100755 index 0000000000..eecd56959f --- /dev/null +++ b/test/TEST-68-PROPAGATE-EXIT-STATUS/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -e + +TEST_DESCRIPTION="Test propagation of exit status to On{Failure,Success}= dependencies" +TEST_NO_QEMU=1 + +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" + +do_test "$@" diff --git a/test/units/testsuite-68.service b/test/units/testsuite-68.service new file mode 100644 index 0000000000..2d86e1fedc --- /dev/null +++ b/test/units/testsuite-68.service @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Unit] +Description=TEST-68-PROPAGATE-EXIT-STATUS + +[Service] +Type=oneshot +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh diff --git a/test/units/testsuite-68.sh b/test/units/testsuite-68.sh new file mode 100755 index 0000000000..1ac244bc5f --- /dev/null +++ b/test/units/testsuite-68.sh @@ -0,0 +1,230 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -ex +set -o pipefail + +# Wait for a service to enter a state within a timeout period, if it doesn't +# enter the desired state within the timeout period then this function will +# exit the test case with a non zero exit code. +wait_on_state_or_fail () { + service=$1 + expected_state=$2 + timeout=$3 + + state=$(systemctl show "$service" --property=ActiveState --value) + while [ "$state" != "$expected_state" ]; do + if [ "$timeout" = "0" ]; then + systemd-analyze log-level info + exit 1 + fi + timeout=$((timeout - 1)) + sleep 1 + state=$(systemctl show "$service" --property=ActiveState --value) + done +} + +systemd-analyze log-level debug +systemd-analyze log-target console + +# Trigger testservice-failure-exit-handler-68.service +cat >/run/systemd/system/testservice-failure-68.service </run/systemd/system/testservice-failure-68-additional.service </run/systemd/system/testservice-success-68.service </run/systemd/system/testservice-success-68-additional.service <= 1 service +# details since jobs may merge. +cat >/tmp/check_on_success.sh </run/systemd/system/testservice-success-exit-handler-68.service <=1 service +# details since jobs may merge. +cat >/tmp/check_on_failure.sh </run/systemd/system/testservice-failure-exit-handler-68.service </testok + +exit 0