diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-05-11 16:48:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-11 16:48:13 +0900 |
commit | 531a6233d1d7978af005bffd59b0c703889d9b1c (patch) | |
tree | 4903a79c5ce92c5c8d886ae2da2fa35daedcdf28 /test | |
parent | 43a221473c9b24815a5a0a30d2464f307728e7f5 (diff) | |
parent | 15bbc0c1071c439d83e711ef7786d401b6c0a0d4 (diff) | |
download | systemd-531a6233d1d7978af005bffd59b0c703889d9b1c.tar.gz |
Merge pull request #27603 from mrc0mmand/more-test-shenanigans
test: merge PID1-related tests into TEST-07-PID1
Diffstat (limited to 'test')
70 files changed, 415 insertions, 464 deletions
diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh deleted file mode 100755 index 5bc41386b5..0000000000 --- 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 index e9f93b1104..e9f93b1104 120000 --- a/test/TEST-07-ISSUE-1981/Makefile +++ b/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 0000000000..1c3d7137fe --- /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" <<EOF +[Mount] +What=tmpfs +Where=/issue2730 +Type=tmpfs + +[Install] +WantedBy=local-fs.target +Alias=issue2730-alias.mount +EOF + "${SYSTEMCTL:?}" enable --root="$workspace" issue2730.mount + ln -svrf "$workspace/etc/systemd/system/issue2730.mount" "$workspace/etc/systemd/system/issue2730-alias.mount" +} + +do_test "$@" diff --git a/test/TEST-08-ISSUE-2730/Makefile b/test/TEST-08-ISSUE-2730/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-08-ISSUE-2730/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh deleted file mode 100755 index 0564314a86..0000000000 --- a/test/TEST-08-ISSUE-2730/test.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730" -IMAGE_NAME="test08" -TEST_NO_NSPAWN=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -TEST_FORCE_NEWIMAGE=1 - -do_test "$@" diff --git a/test/TEST-09-ISSUE-2691/Makefile b/test/TEST-09-ISSUE-2691/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-09-ISSUE-2691/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-09-ISSUE-2691/test.sh b/test/TEST-09-ISSUE-2691/test.sh deleted file mode 100755 index 3fc243cc55..0000000000 --- a/test/TEST-09-ISSUE-2691/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/2691" -TEST_NO_NSPAWN=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-10-ISSUE-2467/Makefile b/test/TEST-10-ISSUE-2467/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-10-ISSUE-2467/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh deleted file mode 100755 index 8dabf3f2b6..0000000000 --- a/test/TEST-10-ISSUE-2467/test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -test_append_files() { - ( - # Collecting coverage slows this particular test quite a bit, causing - # it to fail with the default settings (20 triggers per 2 secs) - # to trip over the default limit. Let's help it a bit in such case. - if get_bool "$IS_BUILT_WITH_COVERAGE"; then - mkdir -p "${initdir:?}/etc/systemd/system/test10.socket.d" - printf "[Socket]\nTriggerLimitIntervalSec=10\n" >"${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 e9f93b1104..0000000000 --- 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 12dabd704d..0000000000 --- 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 e9f93b1104..0000000000 --- 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 977e04ee3f..0000000000 --- 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 e9f93b1104..0000000000 --- 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 b663201efb..0000000000 --- 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 e9f93b1104..0000000000 --- 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 8bdbe14b97..0000000000 --- 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 e9f93b1104..0000000000 --- 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 7b306fa57b..0000000000 --- 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 f53971416e..48f837cee5 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 index 1508ac6242..56805963b4 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 index 74fa7605e7..74fa7605e7 100755 --- a/test/units/testsuite-47-repro.sh +++ b/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 index 90252b388a..90252b388a 100644 --- a/test/units/testsuite-51-repro-1.service +++ b/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 index 7c65691029..7c65691029 100644 --- a/test/units/testsuite-51-repro-2.service +++ b/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 index c68f93d11d..c68f93d11d 100644 --- a/test/units/testsuite-51-repro-3.service +++ b/test/testsuite-07.units/issue16115-repro-3.service diff --git a/test/testsuite-10.units/test10.service b/test/testsuite-07.units/issue2467.service index fc8fad9327..99d886f025 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 index af1317b409..af1317b409 100644 --- a/test/testsuite-10.units/test10.socket +++ b/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 index b8695d8446..b8695d8446 100644 --- a/test/testsuite-11.units/fail-on-restart.service +++ b/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 66f29afab9..0000000000 --- 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 5566fceaa3..0000000000 --- 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 fd8c47d1b0..0000000000 --- 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 c7fdf2f68e..0000000000 --- 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 index d81676a8c3..d81676a8c3 100644 --- a/test/units/testsuite-23-binds-to.service +++ b/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 index a2df5a1954..a2df5a1954 100644 --- a/test/units/testsuite-23-bound-by.service +++ b/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 index 36f8baa6ba..36f8baa6ba 100644 --- a/test/units/testsuite-23-fail.service +++ b/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 index f068daf2b3..f068daf2b3 100644 --- a/test/units/testsuite-23-prop-stop-one.service +++ b/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 index 2bcd209e16..2bcd209e16 100644 --- a/test/units/testsuite-23-prop-stop-two.service +++ b/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 index 0fc27c41fe..0fc27c41fe 100644 --- a/test/units/testsuite-23-retry-fail.service +++ b/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 index 0426d76a54..0426d76a54 100644 --- a/test/units/testsuite-23-retry-upheld.service +++ b/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 index f35e8424de..f35e8424de 100644 --- a/test/units/testsuite-23-retry-uphold.service +++ b/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 index 2dcb2ae228..2dcb2ae228 100644 --- a/test/units/testsuite-23-short-lived.service +++ b/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 index 410d4f83c3..410d4f83c3 100644 --- a/test/units/testsuite-23-success.service +++ b/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 index 3549d6a8f5..3549d6a8f5 100644 --- a/test/units/testsuite-23-uphold.service +++ b/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 0000000000..dd28939cbf --- /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 0000000000..e17c3934c1 --- /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 0000000000..8f638269cd --- /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 0000000000..6eb802c93f --- /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 <<EOF +[Timer] +OnBootSec=10s +OnUnitInactiveSec=1h +EOF + +systemctl unmask my.timer +systemctl start my.timer + +mkdir -p /run/systemd/system/my.timer.d/ +cat >/run/systemd/system/my.timer.d/override.conf <<EOF +[Timer] +OnBootSec=10s +OnUnitInactiveSec=1h +EOF + +systemctl daemon-reload +systemctl mask my.timer diff --git a/test/units/testsuite-07.issue-2467.sh b/test/units/testsuite-07.issue-2467.sh new file mode 100755 index 0000000000..a5dcfd55dd --- /dev/null +++ b/test/units/testsuite-07.issue-2467.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Don't start services every few ms if condition fails +# Issue: https://github.com/systemd/systemd/issues/2467 + +rm -f /tmp/nonexistent +systemctl start issue2467.socket +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. +# shellcheck disable=SC2016 +timeout 10 bash -c 'while ! [[ "$(systemctl show issue2467.socket -P ActiveState)" == failed ]]; do sleep .5; done' +[[ "$(systemctl show issue2467.socket -P Result)" == trigger-limit-hit ]] diff --git a/test/units/testsuite-07.issue-3166.sh b/test/units/testsuite-07.issue-3166.sh new file mode 100755 index 0000000000..6677901358 --- /dev/null +++ b/test/units/testsuite-07.issue-3166.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Service doesn't enter the "failed" state +# Issue: https://github.com/systemd/systemd/issues/3166 + +systemctl --no-block start issue3166-fail-on-restart.service +active_state="$(systemctl show --value --property ActiveState issue3166-fail-on-restart.service)" +while [[ "$active_state" == "activating" || "$active_state" =~ ^(in)?active$ ]]; do + sleep .5 + active_state="$(systemctl show --value --property ActiveState issue3166-fail-on-restart.service)" +done +systemctl is-failed issue3166-fail-on-restart.service || exit 1 +[[ "$(systemctl show --value --property NRestarts issue3166-fail-on-restart.service)" -le 3 ]] || exit 1 diff --git a/test/units/testsuite-07.issue-3171.sh b/test/units/testsuite-07.issue-3171.sh new file mode 100755 index 0000000000..db17c25f90 --- /dev/null +++ b/test/units/testsuite-07.issue-3171.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# SocketGroup lost on daemon-reload with unit moving away temporarily +# Issue: https://github.com/systemd/systemd/issues/3171 + +echo "g adm - - -" | systemd-sysusers - + +U=/run/systemd/system/issue-3171.socket +cat >$U <<EOF +[Unit] +Description=Test 12 socket +[Socket] +Accept=yes +ListenStream=/run/issue-3171.socket +SocketGroup=adm +SocketMode=0660 +EOF + +cat >/run/systemd/system/issue-3171@.service <<EOF +[Unit] +Description=Test service +[Service] +StandardInput=socket +ExecStart=/bin/sh -x -c cat +EOF + +systemctl start issue-3171.socket +systemctl is-active issue-3171.socket +[[ "$(stat --format='%G' /run/issue-3171.socket)" == adm ]] +echo A | nc -w1 -U /run/issue-3171.socket + +mv $U ${U}.disabled +systemctl daemon-reload +systemctl is-active issue-3171.socket +[[ "$(stat --format='%G' /run/issue-3171.socket)" == adm ]] +echo B | nc -w1 -U /run/issue-3171.socket && exit 1 + +mv ${U}.disabled $U +systemctl daemon-reload +systemctl is-active issue-3171.socket +echo C | nc -w1 -U /run/issue-3171.socket && exit 1 +[[ "$(stat --format='%G' /run/issue-3171.socket)" == adm ]] + +systemctl restart issue-3171.socket +systemctl is-active issue-3171.socket +echo D | nc -w1 -U /run/issue-3171.socket +[[ "$(stat --format='%G' /run/issue-3171.socket)" == adm ]] diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-07.main-PID-change.sh index 6ce992f41a..da23032d1e 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-07.main-PID-change.sh @@ -3,9 +3,13 @@ set -eux set -o pipefail +# Test changing the main PID + systemd-analyze log-level debug -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +# The main service PID should be the parent bash process +MAINPID="${PPID:?}" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Start a test process inside of our own cgroup sleep infinity & @@ -18,43 +22,43 @@ EXTERNALPID="$(systemctl show -P MainPID test-sleep.service)" # Update our own main PID to the external test PID, this should work systemd-notify MAINPID="$EXTERNALPID" -test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$EXTERNALPID" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$EXTERNALPID" # Update our own main PID to the internal test PID, this should work, too systemd-notify MAINPID=$INTERNALPID -test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$INTERNALPID" # Update it back to our own PID, this should also work -systemd-notify MAINPID=$$ -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +systemd-notify MAINPID="$MAINPID" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Try to set it to PID 1, which it should ignore, because that's the manager systemd-notify MAINPID=1 -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Try to set it to PID 0, which is invalid and should be ignored systemd-notify MAINPID=0 -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Try to set it to a valid but non-existing PID, which should be ignored. (Note # that we set the PID to a value well above any known /proc/sys/kernel/pid_max, # which means we can be pretty sure it doesn't exist by coincidence) systemd-notify MAINPID=1073741824 -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Change it again to the external PID, without privileges this time. This should be ignored, because the PID is from outside of our cgroup and we lack privileges. systemd-notify --uid=1000 MAINPID="$EXTERNALPID" -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" # Change it again to the internal PID, without privileges this time. This should work, as the process is on our cgroup, and that's enough even if we lack privileges. systemd-notify --uid=1000 MAINPID="$INTERNALPID" -test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$INTERNALPID" # Update it back to our own PID, this should also work -systemd-notify --uid=1000 MAINPID=$$ -test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ +systemd-notify --uid=1000 MAINPID="$MAINPID" +test "$(systemctl show -P MainPID testsuite-07.service)" -eq "$MAINPID" -cat >/tmp/test-mainpid.sh <<EOF +cat >/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 <<EOF +cat >/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 <<EOF @@ -136,6 +152,8 @@ chmod 755 /dev/shm/test-mainpid3.sh -p RuntimeDirectory=mainpidsh3 \ -p PIDFile=/run/mainpidsh3/pid \ -p DynamicUser=1 \ + `# Make sanitizers happy when DynamicUser=1 pulls in instrumented systemd NSS modules` \ + -p EnvironmentFile=-/usr/lib/systemd/systemd-asan-env \ -p TimeoutStartSec=2s \ /dev/shm/test-mainpid3.sh) @@ -159,7 +177,3 @@ runas testuser systemd-run --scope --user --unit test-true.scope /bin/true test "$(systemctl show -P Result test-true.scope)" = success systemd-analyze log-level info - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-07.service b/test/units/testsuite-07.service index c478e12360..cc0a747a88 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 95ebe3876f..58d278e1f1 100755 --- a/test/units/testsuite-07.sh +++ b/test/units/testsuite-07.sh @@ -3,37 +3,16 @@ set -eux set -o pipefail -: >/failed - -cat >/lib/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 >/lib/systemd/system/my.timer <<EOF -[Timer] -OnBootSec=10s -OnUnitInactiveSec=1h -EOF +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh -systemctl unmask my.timer - -systemctl start my.timer - -mkdir -p /etc/systemd/system/my.timer.d/ -cat >/etc/systemd/system/my.timer.d/override.conf <<EOF -[Timer] -OnBootSec=10s -OnUnitInactiveSec=1h -EOF +: >/failed -systemctl daemon-reload +# Issue: https://github.com/systemd/systemd/issues/2730 +# See TEST-07-PID1/test.sh for the first "half" of the test +mountpoint /issue2730 -systemctl mask my.timer +run_subtests touch /testok rm /failed diff --git a/test/units/testsuite-08.service b/test/units/testsuite-08.service deleted file mode 100644 index d6937663e2..0000000000 --- a/test/units/testsuite-08.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-08-ISSUE-2730 - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=sh -x -c 'mount -o remount,rw /dev/sda1 && echo OK >/testok; systemctl poweroff' -Type=oneshot diff --git a/test/units/testsuite-09.service b/test/units/testsuite-09.service deleted file mode 100644 index 6f6cd9c522..0000000000 --- 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 9fcfd673c6..0000000000 --- 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 5dfcf50e3f..0000000000 --- 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 7e1391d8ea..0000000000 --- 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 b26cfa575d..0000000000 --- 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 8c22a8b031..0000000000 --- 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 <<EOF -[Unit] -Description=Test 12 socket -[Socket] -Accept=yes -ListenStream=/run/test12.socket -SocketGroup=adm -SocketMode=0660 -EOF - -cat >/run/systemd/system/test12@.service <<EOF -[Unit] -Description=Test service -[Service] -StandardInput=socket -ExecStart=/bin/sh -x -c cat -EOF - -systemctl start test12.socket -systemctl is-active test12.socket -[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] -echo A | nc -w1 -U /run/test12.socket - -mv $U ${U}.disabled -systemctl daemon-reload -systemctl is-active test12.socket -[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] -echo B | nc -w1 -U /run/test12.socket && exit 1 - -mv ${U}.disabled $U -systemctl daemon-reload -systemctl is-active test12.socket -echo C | nc -w1 -U /run/test12.socket && exit 1 -[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] - -systemctl restart test12.socket -systemctl is-active test12.socket -echo D | nc -w1 -U /run/test12.socket -[[ "$(stat --format='%G' /run/test12.socket)" == adm ]] - -touch /testok diff --git a/test/units/testsuite-17.sh b/test/units/testsuite-17.sh index b389875ef1..72040f69d8 100755 --- a/test/units/testsuite-17.sh +++ b/test/units/testsuite-17.sh @@ -3,13 +3,14 @@ set -eux set -o pipefail +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh + : >/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 4228d0b875..0000000000 --- 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 43823f1d46..5a07e7b78c 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 34899070f1..3be645e20a 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 d5ad480108..0000000000 --- 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 529e9617a5..0000000000 --- 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 c241262c27..0000000000 --- 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 e603d953a4..0000000000 --- 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 13c767e490..5a07e7b78c 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 13c767e490..5a07e7b78c 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 |