diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh deleted file mode 100755 index 5bc41386b56..00000000000 --- a/test/TEST-07-ISSUE-1981/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/1981" -TEST_NO_QEMU=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -NSPAWN_TIMEOUT=30 - -do_test "$@" diff --git a/test/TEST-07-ISSUE-1981/Makefile b/test/TEST-07-PID1/Makefile similarity index 100% rename from test/TEST-07-ISSUE-1981/Makefile rename to test/TEST-07-PID1/Makefile diff --git a/test/TEST-07-PID1/test.sh b/test/TEST-07-PID1/test.sh new file mode 100755 index 00000000000..1c3d7137feb --- /dev/null +++ b/test/TEST-07-PID1/test.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -e + +TEST_DESCRIPTION="Tests for core PID1 functionality" + +# shellcheck source=test/test-functions +. "${TEST_BASE_DIR:?}/test-functions" + +test_append_files() { + local workspace="${1:?}" + + # Collecting coverage slows this particular test quite a bit, causing + # it to fail with the default settings (20 triggers per 2 secs). + # Let's help it a bit in such case. + if get_bool "$IS_BUILT_WITH_COVERAGE"; then + mkdir -p "$workspace/etc/systemd/system/issue2467.socket.d" + printf "[Socket]\nTriggerLimitIntervalSec=10\n" >"$workspace/etc/systemd/system/issue2467.socket.d/coverage-override.conf" + fi + + # Issue: https://github.com/systemd/systemd/issues/2730 + mkdir -p "$workspace/etc/systemd/system/" + cat >"$workspace/etc/systemd/system/issue2730.mount" <"${initdir:?}/etc/systemd/system/test10.socket.d/coverage-override.conf" - fi - ) -} - -do_test "$@" diff --git a/test/TEST-11-ISSUE-3166/Makefile b/test/TEST-11-ISSUE-3166/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-11-ISSUE-3166/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-11-ISSUE-3166/test.sh b/test/TEST-11-ISSUE-3166/test.sh deleted file mode 100755 index 12dabd704d7..00000000000 --- a/test/TEST-11-ISSUE-3166/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3166" -TEST_NO_NSPAWN=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-12-ISSUE-3171/Makefile b/test/TEST-12-ISSUE-3171/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-12-ISSUE-3171/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh deleted file mode 100755 index 977e04ee3f3..00000000000 --- a/test/TEST-12-ISSUE-3171/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3171" -TEST_NO_QEMU=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-20-MAINPIDGAMES/Makefile b/test/TEST-20-MAINPIDGAMES/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-20-MAINPIDGAMES/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-20-MAINPIDGAMES/test.sh b/test/TEST-20-MAINPIDGAMES/test.sh deleted file mode 100755 index b663201efb0..00000000000 --- a/test/TEST-20-MAINPIDGAMES/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="test changing main PID" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-47-ISSUE-14566/Makefile b/test/TEST-47-ISSUE-14566/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-47-ISSUE-14566/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-47-ISSUE-14566/test.sh b/test/TEST-47-ISSUE-14566/test.sh deleted file mode 100755 index 8bdbe14b97a..00000000000 --- a/test/TEST-47-ISSUE-14566/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="Test that KillMode=mixed does not leave left over processes with ExecStopPost=" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-51-ISSUE-16115/Makefile b/test/TEST-51-ISSUE-16115/Makefile deleted file mode 120000 index e9f93b1104c..00000000000 --- a/test/TEST-51-ISSUE-16115/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-51-ISSUE-16115/test.sh b/test/TEST-51-ISSUE-16115/test.sh deleted file mode 100755 index 7b306fa57b9..00000000000 --- a/test/TEST-51-ISSUE-16115/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="Test ExecCondition= does not restart on abnormal or failure" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/meson.build b/test/meson.build index f53971416ec..48f837cee52 100644 --- a/test/meson.build +++ b/test/meson.build @@ -15,9 +15,11 @@ if install_tests 'testsuite-03.units', 'testsuite-04.units', 'testsuite-06.units', + 'testsuite-07.units', 'testsuite-10.units', 'testsuite-11.units', 'testsuite-16.units', + 'testsuite-23.units', 'testsuite-28.units', 'testsuite-30.units', 'testsuite-52.units', @@ -32,18 +34,6 @@ if install_tests install_data(kbd_model_map, install_dir : testdata_dir + '/test-keymap-util') - testsuite08_dir = testdata_dir + '/testsuite-08.units' - install_data('testsuite-08.units/-.mount', - install_dir : testsuite08_dir) - install_data('testsuite-08.units/systemd-remount-fs.service', - install_dir : testsuite08_dir) - meson.add_install_script(meson_make_symlink, - './-.mount', - testsuite08_dir + '/root.mount') - meson.add_install_script(meson_make_symlink, - '../-.mount', - testsuite08_dir + '/local-fs.target.wants/-.mount') - if conf.get('HAVE_ZSTD') == 1 and efi_arch != '' install_subdir('test-bcd', exclude_files : '.gitattributes', diff --git a/test/units/testsuite-47-repro.service b/test/testsuite-07.units/issue14566-repro.service similarity index 66% rename from test/units/testsuite-47-repro.service rename to test/testsuite-07.units/issue14566-repro.service index 1508ac62424..56805963b41 100644 --- a/test/units/testsuite-47-repro.service +++ b/test/testsuite-07.units/issue14566-repro.service @@ -3,6 +3,6 @@ Description=Issue 14566 Repro [Service] -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +ExecStart=/usr/lib/systemd/tests/testdata/testsuite-07.units/%N.sh ExecStopPost=/bin/true KillMode=mixed diff --git a/test/units/testsuite-47-repro.sh b/test/testsuite-07.units/issue14566-repro.sh similarity index 100% rename from test/units/testsuite-47-repro.sh rename to test/testsuite-07.units/issue14566-repro.sh diff --git a/test/units/testsuite-51-repro-1.service b/test/testsuite-07.units/issue16115-repro-1.service similarity index 100% rename from test/units/testsuite-51-repro-1.service rename to test/testsuite-07.units/issue16115-repro-1.service diff --git a/test/units/testsuite-51-repro-2.service b/test/testsuite-07.units/issue16115-repro-2.service similarity index 100% rename from test/units/testsuite-51-repro-2.service rename to test/testsuite-07.units/issue16115-repro-2.service diff --git a/test/units/testsuite-51-repro-3.service b/test/testsuite-07.units/issue16115-repro-3.service similarity index 100% rename from test/units/testsuite-51-repro-3.service rename to test/testsuite-07.units/issue16115-repro-3.service diff --git a/test/testsuite-10.units/test10.service b/test/testsuite-07.units/issue2467.service similarity index 90% rename from test/testsuite-10.units/test10.service rename to test/testsuite-07.units/issue2467.service index fc8fad93279..99d886f0252 100644 --- a/test/testsuite-10.units/test10.service +++ b/test/testsuite-07.units/issue2467.service @@ -1,6 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Unit] -Requires=test10.socket +Requires=issue2467.socket ConditionPathExistsGlob=/tmp/nonexistent # Make sure we hit the socket trigger limit in the test and not the service start limit. StartLimitInterval=1000 diff --git a/test/testsuite-10.units/test10.socket b/test/testsuite-07.units/issue2467.socket similarity index 100% rename from test/testsuite-10.units/test10.socket rename to test/testsuite-07.units/issue2467.socket diff --git a/test/testsuite-11.units/fail-on-restart.service b/test/testsuite-07.units/issue3166-fail-on-restart.service similarity index 100% rename from test/testsuite-11.units/fail-on-restart.service rename to test/testsuite-07.units/issue3166-fail-on-restart.service diff --git a/test/testsuite-08.units/-.mount b/test/testsuite-08.units/-.mount deleted file mode 100644 index 66f29afab98..00000000000 --- a/test/testsuite-08.units/-.mount +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Before=local-fs.target - -[Mount] -What=/dev/sda1 -Where=/ -Options=noatime - -[Install] -WantedBy=local-fs.target -Alias=root.mount diff --git a/test/testsuite-08.units/local-fs.target.wants/-.mount b/test/testsuite-08.units/local-fs.target.wants/-.mount deleted file mode 120000 index 5566fceaa3c..00000000000 --- a/test/testsuite-08.units/local-fs.target.wants/-.mount +++ /dev/null @@ -1 +0,0 @@ -../-.mount \ No newline at end of file diff --git a/test/testsuite-08.units/root.mount b/test/testsuite-08.units/root.mount deleted file mode 120000 index fd8c47d1b0b..00000000000 --- a/test/testsuite-08.units/root.mount +++ /dev/null @@ -1 +0,0 @@ --.mount \ No newline at end of file diff --git a/test/testsuite-08.units/systemd-remount-fs.service b/test/testsuite-08.units/systemd-remount-fs.service deleted file mode 100644 index c7fdf2f68e0..00000000000 --- a/test/testsuite-08.units/systemd-remount-fs.service +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -DefaultDependencies=no -Conflicts=shutdown.target -After=systemd-fsck-root.service -Before=local-fs-pre.target local-fs.target shutdown.target -Wants=local-fs-pre.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/systemctl reload / diff --git a/test/units/testsuite-23-binds-to.service b/test/testsuite-23.units/testsuite-23-binds-to.service similarity index 100% rename from test/units/testsuite-23-binds-to.service rename to test/testsuite-23.units/testsuite-23-binds-to.service diff --git a/test/units/testsuite-23-bound-by.service b/test/testsuite-23.units/testsuite-23-bound-by.service similarity index 100% rename from test/units/testsuite-23-bound-by.service rename to test/testsuite-23.units/testsuite-23-bound-by.service diff --git a/test/units/testsuite-23-fail.service b/test/testsuite-23.units/testsuite-23-fail.service similarity index 100% rename from test/units/testsuite-23-fail.service rename to test/testsuite-23.units/testsuite-23-fail.service diff --git a/test/units/testsuite-23-prop-stop-one.service b/test/testsuite-23.units/testsuite-23-prop-stop-one.service similarity index 100% rename from test/units/testsuite-23-prop-stop-one.service rename to test/testsuite-23.units/testsuite-23-prop-stop-one.service diff --git a/test/units/testsuite-23-prop-stop-two.service b/test/testsuite-23.units/testsuite-23-prop-stop-two.service similarity index 100% rename from test/units/testsuite-23-prop-stop-two.service rename to test/testsuite-23.units/testsuite-23-prop-stop-two.service diff --git a/test/units/testsuite-23-retry-fail.service b/test/testsuite-23.units/testsuite-23-retry-fail.service similarity index 100% rename from test/units/testsuite-23-retry-fail.service rename to test/testsuite-23.units/testsuite-23-retry-fail.service diff --git a/test/units/testsuite-23-retry-upheld.service b/test/testsuite-23.units/testsuite-23-retry-upheld.service similarity index 100% rename from test/units/testsuite-23-retry-upheld.service rename to test/testsuite-23.units/testsuite-23-retry-upheld.service diff --git a/test/units/testsuite-23-retry-uphold.service b/test/testsuite-23.units/testsuite-23-retry-uphold.service similarity index 100% rename from test/units/testsuite-23-retry-uphold.service rename to test/testsuite-23.units/testsuite-23-retry-uphold.service diff --git a/test/units/testsuite-23-short-lived.service b/test/testsuite-23.units/testsuite-23-short-lived.service similarity index 100% rename from test/units/testsuite-23-short-lived.service rename to test/testsuite-23.units/testsuite-23-short-lived.service diff --git a/test/units/testsuite-23-success.service b/test/testsuite-23.units/testsuite-23-success.service similarity index 100% rename from test/units/testsuite-23-success.service rename to test/testsuite-23.units/testsuite-23-success.service diff --git a/test/units/testsuite-23-uphold.service b/test/testsuite-23.units/testsuite-23-uphold.service similarity index 100% rename from test/units/testsuite-23-uphold.service rename to test/testsuite-23.units/testsuite-23-uphold.service diff --git a/test/units/test-control.sh b/test/units/test-control.sh new file mode 100644 index 00000000000..dd28939cbf5 --- /dev/null +++ b/test/units/test-control.sh @@ -0,0 +1,126 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck shell=bash + +if [[ "${BASH_SOURCE[0]}" -ef "$0" ]]; then + echo >&2 "This file should not be executed directly" + exit 1 +fi + +declare -i CHILD_PID=0 +PASSED_TESTS=() +FAILED_TESTS=() + +# Like trap, but passes the signal name as the first argument +trap_with_sig() { + local fun="${1:?}" + local sig + shift + + for sig in "$@"; do + # shellcheck disable=SC2064 + trap "$fun $sig" "$sig" + done +} + +# Propagate the caught signal to the current child process +handle_signal() { + local sig="${1:?}" + + if [[ $CHILD_PID -gt 0 ]]; then + echo "Propagating signal $sig to child process $CHILD_PID" + kill -s "$sig" "$CHILD_PID" + fi +} + +# 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:?}" + + while kill -0 "$pid" &>/dev/null; do + wait "$pid" || : + done + + wait "$pid" +} + +# Like run_subtests, but propagate specified signals to the subtest script +run_subtests_with_signals() { + local subtests=("${0%.sh}".*.sh) + local subtest + + if [[ "${#subtests[@]}" -eq 0 ]]; then + echo >&2 "No subtests found for file $0" + exit 1 + fi + + if [[ "$#" -eq 0 ]]; then + echo >&2 "No signals to propagate were specified" + exit 1 + fi + + trap_with_sig handle_signal "$@" + + for subtest in "${subtests[@]}"; do + : "--- $subtest BEGIN ---" + "./$subtest" & + CHILD_PID=$! + wait_harder "$CHILD_PID" && PASSED_TESTS+=("$subtest") || FAILED_TESTS+=("$subtest") + : "--- $subtest END ---" + done + + show_summary +} + +run_subtests() { + local subtests=("${0%.sh}".*.sh) + local subtest + + if [[ "${#subtests[@]}" -eq 0 ]]; then + echo >&2 "No subtests found for file $0" + exit 1 + fi + + for subtest in "${subtests[@]}"; do + : "--- $subtest BEGIN ---" + "./$subtest" && PASSED_TESTS+=("$subtest") || FAILED_TESTS+=("$subtest") + : "--- $subtest END ---" + done + + show_summary +} + +show_summary() {( + set +x + + if [[ ${#PASSED_TESTS[@]} -eq 0 && ${#FAILED_TESTS[@]} -eq 0 ]]; then + echo >&2 "No tests were executed, this is most likely an error" + exit 1 + fi + + printf "PASSED TESTS: %3d:\n" "${#PASSED_TESTS[@]}" + echo "------------------" + for t in "${PASSED_TESTS[@]}"; do + echo "$t" + done + + if [[ "${#FAILED_TESTS[@]}" -ne 0 ]]; then + printf "FAILED TESTS: %3d:\n" "${#FAILED_TESTS[@]}" + echo "------------------" + for t in "${FAILED_TESTS[@]}"; do + echo "$t" + done + fi + + [[ "${#FAILED_TESTS[@]}" -eq 0 ]] +)} diff --git a/test/units/testsuite-07.issue-14566.sh b/test/units/testsuite-07.issue-14566.sh new file mode 100755 index 00000000000..e17c3934c1d --- /dev/null +++ b/test/units/testsuite-07.issue-14566.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Test that KillMode=mixed does not leave left over processes with ExecStopPost= +# Issue: https://github.com/systemd/systemd/issues/14566 + +if [[ -n "${ASAN_OPTIONS:-}" ]]; then + # Temporarily skip this test when running with sanitizers due to a deadlock + # See: https://bugzilla.redhat.com/show_bug.cgi?id=2098125 + echo "Sanitizers detected, skipping the test..." + exit 0 +fi + +systemd-analyze log-level debug + +systemctl start issue14566-repro +sleep 4 +systemctl status issue14566-repro + +leaked_pid=$(cat /leakedtestpid) + +systemctl stop issue14566-repro +sleep 4 + +# Leaked PID will still be around if we're buggy. +# I personally prefer to see 42. +ps -p "$leaked_pid" && exit 42 + +systemd-analyze log-level info diff --git a/test/units/testsuite-07.issue-16115.sh b/test/units/testsuite-07.issue-16115.sh new file mode 100755 index 00000000000..8f638269cd1 --- /dev/null +++ b/test/units/testsuite-07.issue-16115.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Test ExecCondition= does not restart on abnormal or failure +# Issue: https://github.com/systemd/systemd/issues/16115 + +systemctl start issue16115-repro-1 +systemctl start issue16115-repro-2 +systemctl start issue16115-repro-3 +sleep 5 # wait a bit in case there are restarts so we can count them below + +[[ "$(systemctl show issue16115-repro-1 -P NRestarts)" == "0" ]] +[[ "$(systemctl show issue16115-repro-2 -P NRestarts)" == "0" ]] +[[ "$(systemctl show issue16115-repro-3 -P NRestarts)" == "0" ]] diff --git a/test/units/testsuite-07.issue-1981.sh b/test/units/testsuite-07.issue-1981.sh new file mode 100755 index 00000000000..6eb802c93fb --- /dev/null +++ b/test/units/testsuite-07.issue-1981.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Segmentation fault in timer_enter_waiting while masking a unit +# Issue: https://github.com/systemd/systemd/issues/1981 + +at_exit() { + set +e + + systemctl stop my.timer my.service + rm -f /run/systemd/system/my.{service,timer} + systemctl daemon-reload +} + +trap at_exit EXIT + +mkdir -p /run/systemd/system + +cat >/run/systemd/system/my.service <<\EOF +[Service] +Type=oneshot +ExecStartPre=sh -c 'test "$TRIGGER_UNIT" = my.timer' +ExecStartPre=sh -c 'test -n "$TRIGGER_TIMER_REALTIME_USEC"' +ExecStartPre=sh -c 'test -n "$TRIGGER_TIMER_MONOTONIC_USEC"' +ExecStart=/bin/echo Timer runs me +EOF + +cat >/run/systemd/system/my.timer </run/systemd/system/my.timer.d/override.conf <$U </run/systemd/system/issue-3171@.service </tmp/test-mainpid.sh </tmp/test-mainpid.sh <<\EOF #!/usr/bin/env bash set -eux @@ -65,20 +69,26 @@ sleep infinity & disown sleep infinity & -MAINPID=\$! +MAINPID=$! disown sleep infinity & disown -echo \$MAINPID >/run/mainpidsh/pid +echo $MAINPID >/run/mainpidsh/pid EOF chmod +x /tmp/test-mainpid.sh -systemd-run --unit=test-mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/test-mainpid.sh +systemd-run --unit=test-mainpidsh.service \ + -p StandardOutput=tty \ + -p StandardError=tty \ + -p Type=forking \ + -p RuntimeDirectory=mainpidsh \ + -p PIDFile=/run/mainpidsh/pid \ + /tmp/test-mainpid.sh test "$(systemctl show -P MainPID test-mainpidsh.service)" -eq "$(cat /run/mainpidsh/pid)" -cat >/tmp/test-mainpid2.sh </tmp/test-mainpid2.sh <<\EOF #!/usr/bin/env bash set -eux @@ -89,18 +99,24 @@ sleep infinity & disown sleep infinity & -MAINPID=\$! +MAINPID=$! disown sleep infinity & disown -echo \$MAINPID >/run/mainpidsh2/pid +echo $MAINPID >/run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF chmod +x /tmp/test-mainpid2.sh -systemd-run --unit=test-mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/test-mainpid2.sh +systemd-run --unit=test-mainpidsh2.service \ + -p StandardOutput=tty \ + -p StandardError=tty \ + -p Type=forking \ + -p RuntimeDirectory=mainpidsh2 \ + -p PIDFile=/run/mainpidsh2/pid \ + /tmp/test-mainpid2.sh test "$(systemctl show -P MainPID test-mainpidsh2.service)" -eq "$(cat /run/mainpidsh2/pid)" cat >/dev/shm/test-mainpid3.sh </testok - -exit 0 diff --git a/test/units/testsuite-07.service b/test/units/testsuite-07.service index c478e123608..cc0a747a884 100644 --- a/test/units/testsuite-07.service +++ b/test/units/testsuite-07.service @@ -3,6 +3,11 @@ Description=TEST-07-ISSUE-1981 [Service] +Type=oneshot ExecStartPre=rm -f /failed /testok ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot +NotifyAccess=all +# Issue: https://github.com/systemd/systemd/issues/2691 +ExecStop=sh -c 'kill -SEGV $$$$' +RemainAfterExit=yes +TimeoutStopSec=270s diff --git a/test/units/testsuite-07.sh b/test/units/testsuite-07.sh index 95ebe3876ff..58d278e1f1f 100755 --- a/test/units/testsuite-07.sh +++ b/test/units/testsuite-07.sh @@ -3,37 +3,16 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh + : >/failed -cat >/lib/systemd/system/my.service </lib/systemd/system/my.timer </etc/systemd/system/my.timer.d/override.conf </testok; systemctl poweroff' -Type=oneshot diff --git a/test/units/testsuite-09.service b/test/units/testsuite-09.service deleted file mode 100644 index 6f6cd9c5227..00000000000 --- a/test/units/testsuite-09.service +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-09-ISSUE-2691 - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=sh -c '>/testok' -ExecStop=sh -c 'kill -SEGV $$$$' -Type=oneshot -RemainAfterExit=yes -TimeoutStopSec=270s diff --git a/test/units/testsuite-10.service b/test/units/testsuite-10.service deleted file mode 100644 index 9fcfd673c66..00000000000 --- a/test/units/testsuite-10.service +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-10-ISSUE-2467 - -[Service] -ExecStartPre=rm -f /failed /testok -Type=oneshot -ExecStart=rm -f /tmp/nonexistent -ExecStart=systemctl start test10.socket -ExecStart=-nc -w20 -U /run/test.ctl -# TriggerLimitIntervalSec= by default is set to 2s. A "sleep 10" should give -# systemd enough time even on slower machines, to reach the trigger limit. -ExecStart=sleep 10 -ExecStart=sh -x -c 'test "$(systemctl show test10.socket -P ActiveState)" = failed' -ExecStart=sh -x -c 'test "$(systemctl show test10.socket -P Result)" = trigger-limit-hit' -ExecStart=sh -x -c 'echo OK >/testok' diff --git a/test/units/testsuite-11.service b/test/units/testsuite-11.service deleted file mode 100644 index 5dfcf50e3f9..00000000000 --- a/test/units/testsuite-11.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-11-ISSUE-3166 - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-11.sh b/test/units/testsuite-11.sh deleted file mode 100755 index 7e1391d8eab..00000000000 --- a/test/units/testsuite-11.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux -set -o pipefail - -systemctl --no-block start fail-on-restart.service -active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) -while [[ "$active_state" == "activating" || "$active_state" =~ ^(in)?active$ ]]; do - sleep .5 - active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) -done -systemctl is-failed fail-on-restart.service || exit 1 -[[ "$(systemctl show --value --property NRestarts fail-on-restart.service)" -le 3 ]] || exit 1 -touch /testok diff --git a/test/units/testsuite-12.service b/test/units/testsuite-12.service deleted file mode 100644 index b26cfa575de..00000000000 --- a/test/units/testsuite-12.service +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-12-ISSUE-3171 -After=multi-user.target - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-12.sh b/test/units/testsuite-12.sh deleted file mode 100755 index 8c22a8b0312..00000000000 --- a/test/units/testsuite-12.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux -set -o pipefail - -echo "g adm - - -" | systemd-sysusers - - -U=/run/systemd/system/test12.socket -cat >$U </run/systemd/system/test12@.service </failed udevadm settle -for t in "${0%.sh}".*.sh; do - echo "Running $t"; ./"$t" -done +run_subtests touch /testok rm /failed diff --git a/test/units/testsuite-20.service b/test/units/testsuite-20.service deleted file mode 100644 index 4228d0b875e..00000000000 --- a/test/units/testsuite-20.service +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-20-MAINPIDGAMES -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 -NotifyAccess=all diff --git a/test/units/testsuite-22.sh b/test/units/testsuite-22.sh index 43823f1d466..5a07e7b78c2 100755 --- a/test/units/testsuite-22.sh +++ b/test/units/testsuite-22.sh @@ -3,11 +3,12 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh + : >/failed -for t in "${0%.sh}".*.sh; do - echo "Running $t"; ./"$t" -done +run_subtests touch /testok rm /failed diff --git a/test/units/testsuite-23.sh b/test/units/testsuite-23.sh index 34899070f17..3be645e20ae 100755 --- a/test/units/testsuite-23.sh +++ b/test/units/testsuite-23.sh @@ -5,62 +5,11 @@ set -o pipefail : >/failed -declare -i CHILD_PID=0 +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh -# Note: all the signal shenanigans are necessary for the Upholds= tests - -# Like trap, but passes the signal name as the first argument -trap_with_sig() { - local fun="${1:?}" - local sig - shift - - for sig in "$@"; do - # shellcheck disable=SC2064 - trap "$fun $sig" "$sig" - done -} - -# Propagate the caught signal to the current child process -handle_signal() { - local sig="${1:?}" - - if [[ $CHILD_PID -gt 0 ]]; then - echo "Propagating signal $sig to child process $CHILD_PID" - kill -s "$sig" "$CHILD_PID" - fi -} - -# 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:?}" - - while kill -0 "$pid" &>/dev/null; do - wait "$pid" || : - done - - wait "$pid" -} - -trap_with_sig handle_signal SIGUSR1 SIGUSR2 SIGRTMIN+1 - -for script in "${0%.sh}".*.sh; do - echo "Running $script" - "./$script" & - CHILD_PID=$! - wait_harder "$CHILD_PID" -done +# Note: the signal shenanigans are necessary for the Upholds= tests +run_subtests_with_signals SIGUSR1 SIGUSR2 SIGRTMIN+1 touch /testok rm /failed diff --git a/test/units/testsuite-47.service b/test/units/testsuite-47.service deleted file mode 100644 index d5ad4801085..00000000000 --- a/test/units/testsuite-47.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-47-ISSUE-14566 - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-47.sh b/test/units/testsuite-47.sh deleted file mode 100755 index 529e9617a58..00000000000 --- a/test/units/testsuite-47.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux -set -o pipefail - -systemd-analyze log-level debug - -systemctl start testsuite-47-repro -sleep 4 -systemctl status testsuite-47-repro - -leaked_pid=$(cat /leakedtestpid) - -systemctl stop testsuite-47-repro -sleep 4 - -# Leaked PID will still be around if we're buggy. -# I personally prefer to see 42. -ps -p "$leaked_pid" && exit 42 - -systemd-analyze log-level info - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-51.service b/test/units/testsuite-51.service deleted file mode 100644 index c241262c277..00000000000 --- a/test/units/testsuite-51.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-51-ISSUE-16115 - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-51.sh b/test/units/testsuite-51.sh deleted file mode 100755 index e603d953a4f..00000000000 --- a/test/units/testsuite-51.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux -set -o pipefail - -systemctl start testsuite-51-repro-1 -systemctl start testsuite-51-repro-2 -systemctl start testsuite-51-repro-3 -sleep 5 # wait a bit in case there are restarts so we can count them below - -[[ "$(systemctl show testsuite-51-repro-1 -P NRestarts)" == "0" ]] -[[ "$(systemctl show testsuite-51-repro-2 -P NRestarts)" == "0" ]] -[[ "$(systemctl show testsuite-51-repro-3 -P NRestarts)" == "0" ]] - -touch /testok diff --git a/test/units/testsuite-74.sh b/test/units/testsuite-74.sh index 13c767e490e..5a07e7b78c2 100755 --- a/test/units/testsuite-74.sh +++ b/test/units/testsuite-74.sh @@ -3,12 +3,12 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh + : >/failed -for script in "${0%.sh}".*.sh; do - echo "Running $script" - "./$script" -done +run_subtests touch /testok rm /failed diff --git a/test/units/testsuite-81.sh b/test/units/testsuite-81.sh index 13c767e490e..5a07e7b78c2 100755 --- a/test/units/testsuite-81.sh +++ b/test/units/testsuite-81.sh @@ -3,12 +3,12 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh + : >/failed -for script in "${0%.sh}".*.sh; do - echo "Running $script" - "./$script" -done +run_subtests touch /testok rm /failed