diff options
78 files changed, 521 insertions, 508 deletions
diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh deleted file mode 100755 index afaa4cfbc6..0000000000 --- a/test/TEST-14-MACHINE-ID/test.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="/etc/machine-id testing" -IMAGE_NAME="badid" -TEST_NO_NSPAWN=1 - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -test_append_files() { - printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >"${1:?}/etc/machine-id" -} - -do_test "$@" diff --git a/test/TEST-14-MACHINE-ID/Makefile b/test/TEST-19-CGROUP/Makefile index e9f93b1104..e9f93b1104 120000 --- a/test/TEST-14-MACHINE-ID/Makefile +++ b/test/TEST-19-CGROUP/Makefile diff --git a/test/TEST-19-DELEGATE/test.sh b/test/TEST-19-CGROUP/test.sh index 1b50ac3ae7..ba05b5ecdf 100755 --- a/test/TEST-19-DELEGATE/test.sh +++ b/test/TEST-19-CGROUP/test.sh @@ -2,8 +2,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later set -e -TEST_DESCRIPTION="test cgroup delegation in the unified hierarchy" -TEST_NO_NSPAWN=1 +TEST_DESCRIPTION="Various cgroup-related tests" # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" diff --git a/test/TEST-19-DELEGATE/Makefile b/test/TEST-19-DELEGATE/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-19-DELEGATE/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-27-STDOUTFILE/Makefile b/test/TEST-27-STDOUTFILE/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-27-STDOUTFILE/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-27-STDOUTFILE/test.sh b/test/TEST-27-STDOUTFILE/test.sh deleted file mode 100755 index 15229ba018..0000000000 --- a/test/TEST-27-STDOUTFILE/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 StandardOutput=file:" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-28-PERCENTJ-WANTEDBY/Makefile b/test/TEST-28-PERCENTJ-WANTEDBY/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-28-PERCENTJ-WANTEDBY/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-28-PERCENTJ-WANTEDBY/test.sh b/test/TEST-28-PERCENTJ-WANTEDBY/test.sh deleted file mode 100755 index ae935fa789..0000000000 --- a/test/TEST-28-PERCENTJ-WANTEDBY/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="Ensure %j Wants directives work" -RUN_IN_UNPRIVILEGED_CONTAINER=yes - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-33-CLEAN-UNIT/Makefile b/test/TEST-33-CLEAN-UNIT/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-33-CLEAN-UNIT/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-33-CLEAN-UNIT/test.sh b/test/TEST-33-CLEAN-UNIT/test.sh deleted file mode 100755 index dae72d98ef..0000000000 --- a/test/TEST-33-CLEAN-UNIT/test.sh +++ /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 CleanUnit" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-48-START-STOP-NO-RELOAD/Makefile b/test/TEST-48-START-STOP-NO-RELOAD/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-48-START-STOP-NO-RELOAD/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-48-START-STOP-NO-RELOAD/test.sh b/test/TEST-48-START-STOP-NO-RELOAD/test.sh deleted file mode 100755 index 0bece7d5b5..0000000000 --- a/test/TEST-48-START-STOP-NO-RELOAD/test.sh +++ /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 StartStopNoReload" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-49-RUNTIME-BIND-PATHS/Makefile b/test/TEST-49-RUNTIME-BIND-PATHS/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-49-RUNTIME-BIND-PATHS/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-49-RUNTIME-BIND-PATHS/test.sh b/test/TEST-49-RUNTIME-BIND-PATHS/test.sh deleted file mode 100755 index c9f33457b3..0000000000 --- a/test/TEST-49-RUNTIME-BIND-PATHS/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 adding new BindPaths while unit is already running" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -do_test "$@" diff --git a/test/TEST-56-EXIT-TYPE/Makefile b/test/TEST-56-EXIT-TYPE/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-56-EXIT-TYPE/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile
\ No newline at end of file diff --git a/test/TEST-56-EXIT-TYPE/test.sh b/test/TEST-56-EXIT-TYPE/test.sh deleted file mode 100755 index 37475e817e..0000000000 --- a/test/TEST-56-EXIT-TYPE/test.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -e - -TEST_DESCRIPTION="test ExitType=cgroup" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -if [[ "$(get_cgroup_hierarchy)" != unified ]]; then - echo "This test requires unified cgroup hierarchy, skipping..." - exit 0 -fi - -do_test "$@" diff --git a/test/TEST-74-AUX-UTILS/test.sh b/test/TEST-74-AUX-UTILS/test.sh index f422c89141..6b7c251049 100755 --- a/test/TEST-74-AUX-UTILS/test.sh +++ b/test/TEST-74-AUX-UTILS/test.sh @@ -7,4 +7,10 @@ TEST_DESCRIPTION="Tests for auxiliary utilities" # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" +test_append_files() { + local workspace="${1:?}" + + printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >"$workspace/etc/machine-id" +} + do_test "$@" diff --git a/test/units/testsuite-49-namespaced.service b/test/testsuite-23.units/testsuite-23-namespaced.service index 93abc31cdc..5f30b55e00 100644 --- a/test/units/testsuite-49-namespaced.service +++ b/test/testsuite-23.units/testsuite-23-namespaced.service @@ -7,7 +7,7 @@ Type=notify RemainAfterExit=yes MountAPIVFS=yes PrivateTmp=yes -BindPaths=/run/testservice-49-fixed:/tmp/testfile_fixed +BindPaths=/run/testsuite-23-marker-fixed:/tmp/testfile-marker-fixed InaccessiblePaths=/run/inaccessible -ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile_fixed -ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile_runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile_fixed' +ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile-marker-fixed +ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed' diff --git a/test/units/testsuite-49-non-namespaced.service b/test/testsuite-23.units/testsuite-23-non-namespaced.service index db4e8d975f..058ecb4769 100644 --- a/test/units/testsuite-49-non-namespaced.service +++ b/test/testsuite-23.units/testsuite-23-non-namespaced.service @@ -1,6 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Service] -RuntimeMaxSec=10 +RuntimeMaxSec=5 Type=notify RemainAfterExit=yes -ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile_runtime; do sleep 0.1; done; exit 0' +ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0' diff --git a/test/testsuite-28.units/specifier-j-depends-wants.service b/test/testsuite-23.units/testsuite-23-specifier-j-depends-wants.service index c39a8ba911..c45edd9b54 100644 --- a/test/testsuite-28.units/specifier-j-depends-wants.service +++ b/test/testsuite-23.units/testsuite-23-specifier-j-depends-wants.service @@ -1,7 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Unit] Description=Dependent service for percent-j specifier -After=testsuite-28-pre.service [Service] Type=oneshot diff --git a/test/testsuite-28.units/specifier-j-wants.service b/test/testsuite-23.units/testsuite-23-specifier-j-wants.service index 6067ba09ac..9abb257df4 100644 --- a/test/testsuite-28.units/specifier-j-wants.service +++ b/test/testsuite-23.units/testsuite-23-specifier-j-wants.service @@ -1,11 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1-or-later [Unit] Description=Wants with percent-j specifier -Wants=specifier-j-depends-%j.service -After=specifier-j-depends-%j.service -After=testsuite-28-pre.service +Wants=testsuite-23-specifier-j-depends-%j.service +After=testsuite-23-specifier-j-depends-%j.service [Service] Type=oneshot ExecStart=test -f /tmp/test-specifier-j-%j -ExecStart=sh -c 'echo OK >/testok' +ExecStart=touch /tmp/tetsuite-23-specifier-j-done diff --git a/test/testsuite-28.units/testsuite-28-pre.service b/test/testsuite-28.units/testsuite-28-pre.service deleted file mode 100644 index 0d77247cfd..0000000000 --- a/test/testsuite-28.units/testsuite-28-pre.service +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Service] -ExecStart=rm -f /failed /testok -Type=oneshot diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index 211bd10547..d8aaacb913 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -60,7 +60,7 @@ for task in "${TEST_LIST[@]}"; do if ! kill -0 "${running[$key]}" &>/dev/null; then # Task has finished, report its result and drop it from the queue wait "${running[$key]}" && ec=0 || ec=$? - report_result "$key" $ec + report_result "$key" "$ec" unset "running[$key]" # Break from inner for loop and outer while loop to skip # the sleep below when we find a free slot in the queue @@ -83,8 +83,8 @@ done # Wait for remaining running tasks for key in "${!running[@]}"; do echo "Waiting for test '$key' to finish" - wait ${running[$key]} && ec=0 || ec=$? - report_result "$key" $ec + wait "${running[$key]}" && ec=0 || ec=$? + report_result "$key" "$ec" unset "running[$key]" done diff --git a/test/units/testsuite-07.main-PID-change.sh b/test/units/testsuite-07.main-PID-change.sh index da23032d1e..6d302452af 100755 --- a/test/units/testsuite-07.main-PID-change.sh +++ b/test/units/testsuite-07.main-PID-change.sh @@ -5,6 +5,9 @@ set -o pipefail # Test changing the main PID +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + systemd-analyze log-level debug # The main service PID should be the parent bash process @@ -166,12 +169,6 @@ test "$(systemctl show -P Result test-true.scope)" = success # Test that user scope units work as well -runas() { - declare userid=$1 - shift - XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@" -} - systemctl start user@4711.service runas testuser systemd-run --scope --user --unit test-true.scope /bin/true test "$(systemctl show -P Result test-true.scope)" = success diff --git a/test/units/testsuite-14.service b/test/units/testsuite-14.service deleted file mode 100644 index 23644e53a7..0000000000 --- a/test/units/testsuite-14.service +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-14-MACHINE-ID - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; echo OK >/testok' -Type=oneshot diff --git a/test/units/testsuite-14.sh b/test/units/testsuite-14.sh deleted file mode 100755 index 54275910cf..0000000000 --- a/test/units/testsuite-14.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux -set -o pipefail - -function setup_root { - local _root="$1" - mkdir -p "$_root" - mount -t tmpfs tmpfs "$_root" - mkdir -p "$_root/etc" "$_root/run" -} - -function check { - printf "Expected\n" - cat "$1" - printf "\nGot\n" - cat "$2" - cmp "$1" "$2" -} - -r="$(pwd)/overwrite-broken-machine-id" -setup_root "$r" -systemd-machine-id-setup --print --root "$r" -echo abc >>"$r/etc/machine-id" -id="$(systemd-machine-id-setup --print --root "$r")" -echo "$id" >expected -check expected "$r/etc/machine-id" - -r="$PWD/transient-machine-id" -setup_root "$r" -systemd-machine-id-setup --print --root "$r" -echo abc >>"$r/etc/machine-id" -mount -o remount,ro "$r" -mount -t tmpfs tmpfs "$r/run" -transient_id="$(systemd-machine-id-setup --print --root "$r")" -mount -o remount,rw "$r" -commited_id="$(systemd-machine-id-setup --print --commit --root "$r")" -[[ "$transient_id" = "$commited_id" ]] -check "$r/etc/machine-id" "$r/run/machine-id" diff --git a/test/units/testsuite-17.02.sh b/test/units/testsuite-17.02.sh index 82f9fd1f62..f5b5f372d1 100755 --- a/test/units/testsuite-17.02.sh +++ b/test/units/testsuite-17.02.sh @@ -7,8 +7,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh mkdir -p /run/udev/rules.d/ @@ -100,6 +100,7 @@ timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /s # cleanup ip link del hoge +# shellcheck disable=SC2317 teardown_netif_renaming_conflict() { set +ex diff --git a/test/units/testsuite-17.03.sh b/test/units/testsuite-17.03.sh index 318afdcb5a..fafe9d186c 100755 --- a/test/units/testsuite-17.03.sh +++ b/test/units/testsuite-17.03.sh @@ -20,6 +20,7 @@ EOF systemctl restart systemd-udevd.service } +# shellcheck disable=SC2317 teardown() { set +e diff --git a/test/units/testsuite-17.07.sh b/test/units/testsuite-17.07.sh index b4dfd904e9..629393a56d 100755 --- a/test/units/testsuite-17.07.sh +++ b/test/units/testsuite-17.07.sh @@ -3,8 +3,8 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh wait_service_active() {( set +ex diff --git a/test/units/testsuite-17.08.sh b/test/units/testsuite-17.08.sh index a49a77dc44..e570c69e9f 100755 --- a/test/units/testsuite-17.08.sh +++ b/test/units/testsuite-17.08.sh @@ -3,8 +3,8 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh # This is a test for issue #24518. diff --git a/test/units/testsuite-17.09.sh b/test/units/testsuite-17.09.sh index 31fc9d6842..99931962d5 100755 --- a/test/units/testsuite-17.09.sh +++ b/test/units/testsuite-17.09.sh @@ -3,8 +3,8 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh # This is a test for issue #24987. diff --git a/test/units/testsuite-17.10.sh b/test/units/testsuite-17.10.sh index 073e3762ff..4d8b94f248 100755 --- a/test/units/testsuite-17.10.sh +++ b/test/units/testsuite-17.10.sh @@ -3,11 +3,12 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh # Coverage test for udevadm +# shellcheck disable=SC2317 cleanup_17_10() { set +e diff --git a/test/units/testsuite-17.11.sh b/test/units/testsuite-17.11.sh index ce6f58077f..f1897b6785 100755 --- a/test/units/testsuite-17.11.sh +++ b/test/units/testsuite-17.11.sh @@ -5,9 +5,10 @@ set -o pipefail # Test for udevadm verify. -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh +# shellcheck disable=SC2317 cleanup() { cd / rm -rf "${workdir}" diff --git a/test/units/testsuite-17.12.sh b/test/units/testsuite-17.12.sh index df74d356ee..ccc91bfe46 100755 --- a/test/units/testsuite-17.12.sh +++ b/test/units/testsuite-17.12.sh @@ -3,8 +3,8 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh create_link_file() { name=${1?} diff --git a/test/units/testsuite-19.ExitType-cgroup.sh b/test/units/testsuite-19.ExitType-cgroup.sh new file mode 100755 index 0000000000..cd221d74ef --- /dev/null +++ b/test/units/testsuite-19.ExitType-cgroup.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +set -eux + +# Test ExitType=cgroup + +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +if [[ "$(get_cgroup_hierarchy)" != unified ]]; then + echo "Skipping $0 as we're not running with the unified cgroup hierarchy" + exit 0 +fi + +systemd-analyze log-level debug + +# Multiple level process tree, parent process stays up +cat >/tmp/test19-exit-cgroup.sh <<EOF +#!/usr/bin/env bash +set -eux + +# process tree: systemd -> sleep +sleep infinity & +disown + +# process tree: systemd -> bash -> bash -> sleep +((sleep infinity); true) & + +systemd-notify --ready + +# Run the stop/kill command +\$1 & + +# process tree: systemd -> bash -> sleep +sleep infinity +EOF +chmod +x /tmp/test19-exit-cgroup.sh + +# service should be stopped cleanly +systemd-run --wait \ + --unit=one \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + /tmp/test19-exit-cgroup.sh 'systemctl stop one' + +# same thing with a truthy exec condition +systemd-run --wait \ + --unit=two \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + --property="ExecCondition=true" \ + /tmp/test19-exit-cgroup.sh 'systemctl stop two' + +# false exec condition: systemd-run should exit immediately with status code: 1 +(! systemd-run --wait \ + --unit=three \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + --property="ExecCondition=false" \ + /tmp/test19-exit-cgroup.sh) + +# service should exit uncleanly (main process exits with SIGKILL) +(! systemd-run --wait \ + --unit=four \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + /tmp/test19-exit-cgroup.sh 'systemctl kill --signal 9 four') + + +# Multiple level process tree, parent process exits quickly +cat >/tmp/test19-exit-cgroup-parentless.sh <<EOF +#!/usr/bin/env bash +set -eux + +# process tree: systemd -> sleep +sleep infinity & + +# process tree: systemd -> bash -> sleep +((sleep infinity); true) & + +systemd-notify --ready + +# Run the stop/kill command after this bash process exits +(sleep 1; \$1) & +EOF +chmod +x /tmp/test19-exit-cgroup-parentless.sh + +# service should be stopped cleanly +systemd-run --wait \ + --unit=five \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + /tmp/test19-exit-cgroup-parentless.sh 'systemctl stop five' + +# service should still exit cleanly despite SIGKILL (the main process already exited cleanly) +systemd-run --wait \ + --unit=six \ + --property="Type=notify" \ + --property="ExitType=cgroup" \ + /tmp/test19-exit-cgroup-parentless.sh 'systemctl kill --signal 9 six' + + +systemd-analyze log-level info diff --git a/test/units/testsuite-19.delegate.sh b/test/units/testsuite-19.delegate.sh new file mode 100755 index 0000000000..691913cb81 --- /dev/null +++ b/test/units/testsuite-19.delegate.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# Test cgroup delegation in the unified hierarchy + +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +if [[ "$(get_cgroup_hierarchy)" != unified ]]; then + echo "Skipping $0 as we're not running with the unified cgroup hierarchy" + exit 0 +fi + +at_exit() { + set +e + userdel -r test +} + +systemd-run --wait \ + --unit=test-0.service \ + --property="DynamicUser=1" \ + --property="Delegate=" \ + test -w /sys/fs/cgroup/system.slice/test-0.service/ -a \ + -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.procs -a \ + -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.subtree_control + +systemd-run --wait \ + --unit=test-1.service \ + --property="DynamicUser=1" \ + --property="Delegate=memory pids" \ + grep -q memory /sys/fs/cgroup/system.slice/test-1.service/cgroup.controllers + +systemd-run --wait \ + --unit=test-2.service \ + --property="DynamicUser=1" \ + --property="Delegate=memory pids" \ + grep -q pids /sys/fs/cgroup/system.slice/test-2.service/cgroup.controllers + +# "io" is not among the controllers enabled by default for all units, verify that +grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers + +# Run a service with "io" enabled, and verify it works +systemd-run --wait \ + --unit=test-3.service \ + --property="IOAccounting=yes" \ + --property="Slice=system-foo-bar-baz.slice" \ + grep -q io /sys/fs/cgroup/system.slice/system-foo.slice/system-foo-bar.slice/system-foo-bar-baz.slice/test-3.service/cgroup.controllers + +# We want to check if "io" is removed again from the controllers +# list. However, PID 1 (rightfully) does this asynchronously. In order +# to force synchronization on this, let's start a short-lived service +# which requires PID 1 to refresh the cgroup tree, so that we can +# verify that this all works. +systemd-run --wait --unit=test-4.service true + +# And now check again, "io" should have vanished +grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers + +# Check that unprivileged delegation works for scopes +useradd test ||: +systemd-run --uid=test \ + --property="User=test" \ + --property="Delegate=yes" \ + --slice workload.slice \ + --unit test-workload0.scope\ + --scope \ + test -w /sys/fs/cgroup/workload.slice/test-workload0.scope -a \ + -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.procs -a \ + -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.subtree_control + +# Verify that DelegateSubgroup= affects ownership correctly +unit="test-subgroup-$RANDOM.service" +systemd-run --wait \ + --unit="$unit" \ + --property="DynamicUser=1" \ + --property="Delegate=pids" \ + --property="DelegateSubgroup=foo" \ + test -w "/sys/fs/cgroup/system.slice/$unit" -a \ + -w "/sys/fs/cgroup/system.slice/$unit/foo" + +# Check that for the subgroup also attributes that aren't covered by +# regular (i.e. main cgroup) delegation ownership rules are delegated properly +if test -f /sys/fs/cgroup/cgroup.max.depth; then + unit="test-subgroup-$RANDOM.service" + systemd-run --wait \ + --unit="$unit" \ + --property="DynamicUser=1" \ + --property="Delegate=pids" \ + --property="DelegateSubgroup=zzz" \ + test -w "/sys/fs/cgroup/system.slice/$unit/zzz/cgroup.max.depth" +fi + +# Check that the invoked process itsel is also in the subgroup +unit="test-subgroup-$RANDOM.service" +systemd-run --wait \ + --unit="$unit" \ + --property="DynamicUser=1" \ + --property="Delegate=pids" \ + --property="DelegateSubgroup=bar" \ + grep -q -x -F "0::/system.slice/$unit/bar" /proc/self/cgroup diff --git a/test/units/testsuite-19.sh b/test/units/testsuite-19.sh index 93280993f1..34fe819c5e 100755 --- a/test/units/testsuite-19.sh +++ b/test/units/testsuite-19.sh @@ -3,70 +3,12 @@ set -eux set -o pipefail -test_scope_unpriv_delegation() { - useradd test ||: - trap "userdel -r test" RETURN +: >/failed - systemd-run --uid=test -p User=test -p Delegate=yes --slice workload.slice --unit test-workload0.scope --scope \ - test -w /sys/fs/cgroup/workload.slice/test-workload0.scope -a \ - -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.procs -a \ - -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.subtree_control -} +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh -if grep -q cgroup2 /proc/filesystems ; then - systemd-run --wait --unit=test-0.service -p "DynamicUser=1" -p "Delegate=" \ - test -w /sys/fs/cgroup/system.slice/test-0.service/ -a \ - -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.procs -a \ - -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.subtree_control +run_subtests - systemd-run --wait --unit=test-1.service -p "DynamicUser=1" -p "Delegate=memory pids" \ - grep -q memory /sys/fs/cgroup/system.slice/test-1.service/cgroup.controllers - - systemd-run --wait --unit=test-2.service -p "DynamicUser=1" -p "Delegate=memory pids" \ - grep -q pids /sys/fs/cgroup/system.slice/test-2.service/cgroup.controllers - - # "io" is not among the controllers enabled by default for all units, verify that - grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers - - # Run a service with "io" enabled, and verify it works - systemd-run --wait --unit=test-3.service -p "IOAccounting=yes" -p "Slice=system-foo-bar-baz.slice" \ - grep -q io /sys/fs/cgroup/system.slice/system-foo.slice/system-foo-bar.slice/system-foo-bar-baz.slice/test-3.service/cgroup.controllers - - # We want to check if "io" is removed again from the controllers - # list. However, PID 1 (rightfully) does this asynchronously. In order - # to force synchronization on this, let's start a short-lived service - # which requires PID 1 to refresh the cgroup tree, so that we can - # verify that this all works. - systemd-run --wait --unit=test-4.service true - - # And now check again, "io" should have vanished - grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers - - # Check that unprivileged delegation works for scopes - test_scope_unpriv_delegation - - # Verify that DelegateSubgroup= affects ownership correctly - U="test-subgroup-$RANDOM.service" - systemd-run --wait --unit="$U" -p "DynamicUser=1" -p "Delegate=pids" -p "DelegateSubgroup=foo" \ - test -w "/sys/fs/cgroup/system.slice/$U" -a \ - -w "/sys/fs/cgroup/system.slice/$U/foo" - - # Check that for the subgroup also attributes that aren't covered by - # regular (i.e. main cgroup) delegation ownership rules are delegated properly - if test -f /sys/fs/cgroup/cgroup.max.depth ; then - U="test-subgroup-$RANDOM.service" - systemd-run --wait --unit="$U" -p "DynamicUser=1" -p "Delegate=pids" -p "DelegateSubgroup=zzz" \ - test -w "/sys/fs/cgroup/system.slice/$U/zzz/cgroup.max.depth" - fi - - # Check that the invoked process itsel is also in the subgroup - U="test-subgroup-$RANDOM.service" - systemd-run --wait --unit="$U" -p "DynamicUser=1" -p "Delegate=pids" -p "DelegateSubgroup=bar" \ - grep -q -x -F "0::/system.slice/$U/bar" /proc/self/cgroup -else - echo "Skipping TEST-19-DELEGATE, as the kernel doesn't actually support cgroup v2" >&2 -fi - -echo OK >/testok - -exit 0 +touch /testok +rm /failed diff --git a/test/units/testsuite-22.16.sh b/test/units/testsuite-22.16.sh index 15387cddb8..555e07fec7 100755 --- a/test/units/testsuite-22.16.sh +++ b/test/units/testsuite-22.16.sh @@ -5,8 +5,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh rm -f /tmp/acl_exec touch /tmp/acl_exec diff --git a/test/units/testsuite-23.RuntimeDirectoryPreserve.sh b/test/units/testsuite-23.RuntimeDirectoryPreserve.sh index b60b612d82..ca57702cf1 100755 --- a/test/units/testsuite-23.RuntimeDirectoryPreserve.sh +++ b/test/units/testsuite-23.RuntimeDirectoryPreserve.sh @@ -7,6 +7,14 @@ set -o pipefail # Test RuntimeDirectoryPreserve=yes +at_exit() { + set +e + + rm -fr /run/hoge /tmp/aaa +} + +trap at_exit EXIT + systemd-mount -p RuntimeDirectory=hoge -p RuntimeDirectoryPreserve=yes -t tmpfs tmpfs /tmp/aaa touch /run/hoge/foo diff --git a/test/units/testsuite-27.sh b/test/units/testsuite-23.StandardOutput.sh index c0701f35c3..50b9ac2a2b 100755 --- a/test/units/testsuite-27.sh +++ b/test/units/testsuite-23.StandardOutput.sh @@ -3,9 +3,11 @@ set -eux set -o pipefail +# Test StandardOutput=file: + systemd-analyze log-level debug -systemd-run --wait --unit=test27-one \ +systemd-run --wait --unit=testsuite-23-standard-output-one \ -p StandardOutput=file:/tmp/stdout \ -p StandardError=file:/tmp/stderr \ -p Type=exec \ @@ -17,7 +19,7 @@ cmp /tmp/stderr <<EOF y EOF -systemd-run --wait --unit=test27-two \ +systemd-run --wait --unit=testsuite-23-standard-output-two \ -p StandardOutput=file:/tmp/stdout \ -p StandardError=file:/tmp/stderr \ -p Type=exec \ @@ -29,7 +31,7 @@ cmp /tmp/stderr <<EOF a EOF -systemd-run --wait --unit=test27-three \ +systemd-run --wait --unit=testsuite-23-standard-output-three \ -p StandardOutput=append:/tmp/stdout \ -p StandardError=append:/tmp/stderr \ -p Type=exec \ @@ -43,7 +45,7 @@ a c EOF -systemd-run --wait --unit=test27-four \ +systemd-run --wait --unit=testsuite-23-standard-output-four \ -p StandardOutput=truncate:/tmp/stdout \ -p StandardError=truncate:/tmp/stderr \ -p Type=exec \ @@ -56,7 +58,3 @@ b EOF systemd-analyze log-level info - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-33.sh b/test/units/testsuite-23.clean-unit.sh index d48bef73b4..a82b54fe9e 100755 --- a/test/units/testsuite-33.sh +++ b/test/units/testsuite-23.clean-unit.sh @@ -5,6 +5,19 @@ set -eux set -o pipefail +# Test unit configuration/state/cache/log/runtime data cleanup + +at_exit() { + set +e + + rm -fr /{etc,run,var/lib,var/cache,var/log}/test-service + rm -fr /{etc,run,var/lib,var/cache,var/log}/private/test-service + rm -fr /{etc,run,var/lib,var/cache,var/log}/hoge + rm -fr /{etc,run,var/lib,var/cache,var/log}/test-socket +} + +trap at_exit EXIT + cat >/run/systemd/system/test-service.service <<EOF [Service] ConfigurationDirectory=test-service @@ -314,7 +327,3 @@ test ! -e /run/test-socket test ! -e /var/lib/test-socket test ! -e /var/cache/test-socket test ! -e /var/log/test-socket - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-23.percentj-wantedby.sh b/test/units/testsuite-23.percentj-wantedby.sh new file mode 100755 index 0000000000..e9ffaba682 --- /dev/null +++ b/test/units/testsuite-23.percentj-wantedby.sh @@ -0,0 +1,15 @@ +#!/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 -eux +set -o pipefail + +# Ensure %j Wants directives work +systemd-run --wait \ + --property="Type=oneshot" \ + --property="Wants=testsuite-23-specifier-j-wants.service" \ + --property="After=testsuite-23-specifier-j-wants.service" \ + true + +test -f /tmp/tetsuite-23-specifier-j-done diff --git a/test/units/testsuite-23.runtime-bind-paths.sh b/test/units/testsuite-23.runtime-bind-paths.sh new file mode 100755 index 0000000000..c63586e1a2 --- /dev/null +++ b/test/units/testsuite-23.runtime-bind-paths.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck disable=SC2016 +set -eux +set -o pipefail + +# Test adding new BindPaths while unit is already running + +at_exit() { + set +e + + rm -f /run/testsuite-23-marker-{fixed,runtime} + rm -fr /run/inaccessible +} + +trap at_exit EXIT + +echo "MARKER_FIXED" >/run/testsuite-23-marker-fixed +mkdir /run/inaccessible + +systemctl start testsuite-23-namespaced.service + +# Ensure that inaccessible paths aren't bypassed by the runtime setup, +(! systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-fixed /run/inaccessible/testfile-marker-fixed) + +echo "MARKER_RUNTIME" >/run/testsuite-23-marker-runtime + +systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime + +timeout 10 sh -xec 'while [[ "$(systemctl show -P SubState testsuite-23-namespaced.service)" == running ]]; do sleep .5; done' +systemctl is-active testsuite-23-namespaced.service + +# Now test that systemctl bind fails when attempted on a non-namespaced unit +systemctl start testsuite-23-non-namespaced.service + +(! systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime) + +timeout 10 sh -xec 'while [[ "$(systemctl show -P SubState testsuite-23-non-namespaced.service)" == running ]]; do sleep .5; done' +(! systemctl is-active testsuite-23-non-namespaced.service) diff --git a/test/units/testsuite-48.sh b/test/units/testsuite-23.start-stop-no-reload.sh index 2b5b86f6e8..9c4f17d7a2 100755 --- a/test/units/testsuite-48.sh +++ b/test/units/testsuite-23.start-stop-no-reload.sh @@ -3,44 +3,55 @@ # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh set -eux +set -o pipefail -cat >/run/systemd/system/testservice-48.target <<EOF +# Test start & stop operations without daemon-reload + +at_exit() { + set +e + + rm -f /run/systemd/system/testsuite-23-no-reload.{service,target} +} + +trap at_exit EXIT + +cat >/run/systemd/system/testsuite-23-no-reload.target <<EOF [Unit] -Wants=testservice-48.service +Wants=testsuite-23-no-reload.service EOF systemctl daemon-reload -systemctl start testservice-48.target +systemctl start testsuite-23-no-reload.target # The filesystem on the test image, despite being ext4, seems to have a mtime # granularity of one second, which means the manager's unit cache won't be # marked as dirty when writing the unit file, unless we wait at least a full # second after the previous daemon-reload. # May 07 23:12:20 H testsuite-48.sh[30]: + cat -# May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testservice-48.service +# May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testsuite-23-no-reload.service # May 07 23:12:20 H testsuite-48.sh[52]: -rw-r--r-- 1 root root 50 2020-05-07 23:12:20.000000000 +0100 / -# May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testservice-48.servic +# May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testsuite-23-no-reload.servic # May 07 23:12:20 H testsuite-48.sh[53]: ef53 sleep 3.1 -cat >/run/systemd/system/testservice-48.service <<EOF +cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF [Service] ExecStart=/bin/sleep infinity EOF -systemctl start testservice-48.service +systemctl start testsuite-23-no-reload.service -systemctl is-active testservice-48.service +systemctl is-active testsuite-23-no-reload.service # Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/15992 -systemctl stop testservice-48.service -rm -f /run/systemd/system/testservice-48.service +systemctl stop testsuite-23-no-reload.service +rm -f /run/systemd/system/testsuite-23-no-reload.service systemctl daemon-reload sleep 3.1 -cat >/run/systemd/system/testservice-48.service <<EOF +cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF [Service] ExecStart=/bin/sleep infinity EOF @@ -48,39 +59,35 @@ EOF # Start a non-existing unit first, so that the cache is reloaded for an unrelated # reason. Starting the existing unit later should still work thanks to the check # for the last load attempt vs cache timestamp. -systemctl start testservice-48-nonexistent.service || true +systemctl start testsuite-23-no-reload-nonexistent.service || true -systemctl start testservice-48.service +systemctl start testsuite-23-no-reload.service -systemctl is-active testservice-48.service +systemctl is-active testsuite-23-no-reload.service # Stop and remove, and try again to exercise the transaction setup code path by # having the target pull in the unloaded but available unit -systemctl stop testservice-48.service testservice-48.target -rm -f /run/systemd/system/testservice-48.service /run/systemd/system/testservice-48.target +systemctl stop testsuite-23-no-reload.service testsuite-23-no-reload.target +rm -f /run/systemd/system/testsuite-23-no-reload.service /run/systemd/system/testsuite-23-no-reload.target systemctl daemon-reload sleep 3.1 -cat >/run/systemd/system/testservice-48.target <<EOF +cat >/run/systemd/system/testsuite-23-no-reload.target <<EOF [Unit] Conflicts=shutdown.target -Wants=testservice-48.service +Wants=testsuite-23-no-reload.service EOF systemctl daemon-reload -systemctl start testservice-48.target +systemctl start testsuite-23-no-reload.target -cat >/run/systemd/system/testservice-48.service <<EOF +cat >/run/systemd/system/testsuite-23-no-reload.service <<EOF [Service] ExecStart=/bin/sleep infinity EOF -systemctl restart testservice-48.target - -systemctl is-active testservice-48.service - -echo OK >/testok +systemctl restart testsuite-23-no-reload.target -exit 0 +systemctl is-active testsuite-23-no-reload.service diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh index dc8e1e47c6..45d044be66 100755 --- a/test/units/testsuite-26.sh +++ b/test/units/testsuite-26.sh @@ -4,8 +4,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh : >/failed diff --git a/test/units/testsuite-27.service b/test/units/testsuite-27.service deleted file mode 100644 index 454fde6108..0000000000 --- a/test/units/testsuite-27.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-27-STDOUTFILE - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-28.service b/test/units/testsuite-28.service deleted file mode 100644 index 222de00c32..0000000000 --- a/test/units/testsuite-28.service +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-28-PERCENTJ-WANTEDBY -# Testsuite: Ensure %j Wants directives work -Wants=specifier-j-wants.service -After=specifier-j-wants.service -Requires=testsuite-28-pre.service -After=testsuite-28-pre.service - -[Service] -ExecStart=true -Type=oneshot diff --git a/test/units/testsuite-33.service b/test/units/testsuite-33.service deleted file mode 100644 index 582cdb180c..0000000000 --- a/test/units/testsuite-33.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-33-CLEAN-UNIT - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index 76127102c4..8cb380d2fd 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh cleanup_test_user() ( set +ex @@ -468,7 +468,7 @@ test_lock_idle_action() { fi if loginctl --no-legend | grep -q logind-test-user; then - echo >&2 "Session of the \'logind-test-user\' is already present." + echo >&2 "Session of the 'logind-test-user' is already present." exit 1 fi diff --git a/test/units/testsuite-36.sh b/test/units/testsuite-36.sh index 9705f2db86..d242749b61 100755 --- a/test/units/testsuite-36.sh +++ b/test/units/testsuite-36.sh @@ -3,6 +3,7 @@ set -eux set -o pipefail +# shellcheck disable=SC2317 at_exit() { # shellcheck disable=SC2181 if [[ $? -ne 0 ]]; then diff --git a/test/units/testsuite-43.sh b/test/units/testsuite-43.sh index ae979d734b..f9819f2c05 100755 --- a/test/units/testsuite-43.sh +++ b/test/units/testsuite-43.sh @@ -3,13 +3,10 @@ set -eux set -o pipefail -systemd-analyze log-level debug +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh -runas() { - declare userid=$1 - shift - XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@" -} +systemd-analyze log-level debug runas testuser systemd-run --wait --user --unit=test-private-users \ -p PrivateUsers=yes -P echo hello diff --git a/test/units/testsuite-45.sh b/test/units/testsuite-45.sh index 74b3a2c6a9..b21b1105d7 100755 --- a/test/units/testsuite-45.sh +++ b/test/units/testsuite-45.sh @@ -4,8 +4,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh test_timedatectl() { timedatectl --no-pager --help diff --git a/test/units/testsuite-48.service b/test/units/testsuite-48.service deleted file mode 100644 index 74769563e3..0000000000 --- a/test/units/testsuite-48.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-48-START-STOP-NO-RELOAD - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-49.service b/test/units/testsuite-49.service deleted file mode 100644 index bd4e15558f..0000000000 --- a/test/units/testsuite-49.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-49-RUNTIME-BIND-PATHS - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-49.sh b/test/units/testsuite-49.sh deleted file mode 100755 index 1fa972552b..0000000000 --- a/test/units/testsuite-49.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -eux - -echo "MARKER_FIXED" >/run/testservice-49-fixed -mkdir -p /run/inaccessible - -systemctl start testsuite-49-namespaced.service - -# Ensure that inaccessible paths aren't bypassed by the runtime setup -set +e -systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-fixed /run/inaccessible/testfile_fixed && exit 1 -set -e - -echo "MARKER_RUNTIME" >/run/testservice-49-runtime - -systemctl bind --mkdir testsuite-49-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime - -while systemctl show -P SubState testsuite-49-namespaced.service | grep -q running -do - sleep 0.1 -done - -systemctl is-active testsuite-49-namespaced.service - -# Now test that systemctl bind fails when attempted on a non-namespaced unit -systemctl start testsuite-49-non-namespaced.service - -set +e -systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testservice-49-runtime /tmp/testfile_runtime && exit 1 -set -e - -while systemctl show -P SubState testsuite-49-non-namespaced.service | grep -q running -do - sleep 0.1 -done - -set +e -systemctl is-active testsuite-49-non-namespaced.service && exit 1 -set -e - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index 1b703dc18c..cdb7c0043b 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -7,6 +7,7 @@ set -o pipefail export SYSTEMD_LOG_LEVEL=debug +# shellcheck disable=SC2317 cleanup() {( set +ex diff --git a/test/units/testsuite-56.service b/test/units/testsuite-56.service deleted file mode 100644 index d8ad589ca0..0000000000 --- a/test/units/testsuite-56.service +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=TEST-56-EXIT-TYPE - -[Service] -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh deleted file mode 100755 index f81c6ddf1f..0000000000 --- a/test/units/testsuite-56.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash -set -eux - -systemd-analyze log-level debug - -# Multiple level process tree, parent process stays up -cat >/tmp/test56-exit-cgroup.sh <<EOF -#!/usr/bin/env bash -set -eux - -# process tree: systemd -> sleep -sleep infinity & -disown - -# process tree: systemd -> bash -> bash -> sleep -((sleep infinity); true) & - -systemd-notify --ready - -# Run the stop/kill command -\$1 & - -# process tree: systemd -> bash -> sleep -sleep infinity -EOF -chmod +x /tmp/test56-exit-cgroup.sh - -# service should be stopped cleanly -systemd-run --wait --unit=one -p Type=notify -p ExitType=cgroup \ - /tmp/test56-exit-cgroup.sh 'systemctl stop one' - -# same thing with a truthy exec condition -systemd-run --wait --unit=two -p Type=notify -p ExitType=cgroup \ - -p ExecCondition=true \ - /tmp/test56-exit-cgroup.sh 'systemctl stop two' - -# false exec condition: systemd-run should exit immediately with status code: 1 -(! systemd-run --wait --unit=three -p Type=notify -p ExitType=cgroup \ - -p ExecCondition=false \ - /tmp/test56-exit-cgroup.sh) - -# service should exit uncleanly (main process exits with SIGKILL) -(! systemd-run --wait --unit=four -p Type=notify -p ExitType=cgroup \ - /tmp/test56-exit-cgroup.sh 'systemctl kill --signal 9 four') - - -# Multiple level process tree, parent process exits quickly -cat >/tmp/test56-exit-cgroup-parentless.sh <<EOF -#!/usr/bin/env bash -set -eux - -# process tree: systemd -> sleep -sleep infinity & - -# process tree: systemd -> bash -> sleep -((sleep infinity); true) & - -systemd-notify --ready - -# Run the stop/kill command after this bash process exits -(sleep 1; \$1) & -EOF -chmod +x /tmp/test56-exit-cgroup-parentless.sh - -# service should be stopped cleanly -systemd-run --wait --unit=five -p Type=notify -p ExitType=cgroup \ - /tmp/test56-exit-cgroup-parentless.sh 'systemctl stop five' - -# service should still exit cleanly despite SIGKILL (the main process already exited cleanly) -systemd-run --wait --unit=six -p Type=notify -p ExitType=cgroup \ - /tmp/test56-exit-cgroup-parentless.sh 'systemctl kill --signal 9 six' - - -systemd-analyze log-level info - -echo OK >/testok - -exit 0 diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index 6cc699f151..ecb376476a 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -3,19 +3,16 @@ set -eux set -o pipefail -runas() { - declare userid=$1 - shift - XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@" -} +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh if ! command -v systemd-repart &>/dev/null; then echo "no systemd-repart" >/skipped exit 0 fi -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug export PAGER=cat diff --git a/test/units/testsuite-60.sh b/test/units/testsuite-60.sh index 5795d6bbeb..f51d3fdef9 100755 --- a/test/units/testsuite-60.sh +++ b/test/units/testsuite-60.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh teardown_test_dependencies() ( set +eux diff --git a/test/units/testsuite-61.sh b/test/units/testsuite-61.sh index 748e24a7ca..0b7b0116d3 100755 --- a/test/units/testsuite-61.sh +++ b/test/units/testsuite-61.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck disable=SC2317 set -eux set -o pipefail diff --git a/test/units/testsuite-62.sh b/test/units/testsuite-62.sh index 1b3b11adf1..8ba01f54d7 100755 --- a/test/units/testsuite-62.sh +++ b/test/units/testsuite-62.sh @@ -21,11 +21,11 @@ setup() { done } +# shellcheck disable=SC2317 teardown() { set +e - for i in {0..3}; - do + for i in {0..3}; do ip netns del "ns${i}" ip link del "veth${i}" done diff --git a/test/units/testsuite-63.sh b/test/units/testsuite-63.sh index 59a7b3208f..0be1f86d9c 100755 --- a/test/units/testsuite-63.sh +++ b/test/units/testsuite-63.sh @@ -3,8 +3,8 @@ set -ex set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh systemctl log-level debug diff --git a/test/units/testsuite-65.sh b/test/units/testsuite-65.sh index 2ad7b9a439..05673e7cc7 100755 --- a/test/units/testsuite-65.sh +++ b/test/units/testsuite-65.sh @@ -3,8 +3,8 @@ # shellcheck disable=SC2016 set -eux -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh systemctl log-level debug export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-71.sh b/test/units/testsuite-71.sh index d9663de158..fca1819b74 100755 --- a/test/units/testsuite-71.sh +++ b/test/units/testsuite-71.sh @@ -4,8 +4,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh restore_hostname() { if [[ -e /tmp/hostname.bak ]]; then diff --git a/test/units/testsuite-73.sh b/test/units/testsuite-73.sh index 8f33baf879..39992a844b 100755 --- a/test/units/testsuite-73.sh +++ b/test/units/testsuite-73.sh @@ -4,8 +4,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh enable_debug() { mkdir -p /run/systemd/system/systemd-localed.service.d diff --git a/test/units/testsuite-74.escape.sh b/test/units/testsuite-74.escape.sh index 8e6896cccf..584c7340b5 100755 --- a/test/units/testsuite-74.escape.sh +++ b/test/units/testsuite-74.escape.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh # Simple wrapper to check both escaping and unescaping of given strings # Arguments: diff --git a/test/units/testsuite-74.id128.sh b/test/units/testsuite-74.id128.sh index 6a9d2135c0..213333d9d1 100755 --- a/test/units/testsuite-74.id128.sh +++ b/test/units/testsuite-74.id128.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh systemd-id128 --help systemd-id128 help diff --git a/test/units/testsuite-74.machine-id-setup.sh b/test/units/testsuite-74.machine-id-setup.sh new file mode 100755 index 0000000000..a24f9d299e --- /dev/null +++ b/test/units/testsuite-74.machine-id-setup.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck disable=SC2064 +set -eux +set -o pipefail + +root_mock() { + local root="${1:?}" + + mkdir -p "$root" + # Put a tmpfs over the "root", so we're able to remount it as read-only + # when needed + mount -t tmpfs tmpfs "$root" + mkdir "$root/etc" "$root/run" +} + +root_cleanup() { + local root="${1:?}" + + umount --recursive "$root" + rm -fr "$root" +} + +testcase_sanity() { + systemd-machine-id-setup + systemd-machine-id-setup --help + systemd-machine-id-setup --version + systemd-machine-id-setup --print + systemd-machine-id-setup --root= --print + systemd-machine-id-setup --root=/ --print + + (! systemd-machine-id-setup "") + (! systemd-machine-id-setup --foo) +} + +testcase_invalid() { + local root machine_id + + root="$(mktemp -d)" + trap "root_cleanup $root" RETURN + root_mock "$root" + + systemd-machine-id-setup --print --root "$root" + echo abc >>"$root/etc/machine-id" + machine_id="$(systemd-machine-id-setup --print --root "$root")" + diff <(echo "$machine_id") "$root/etc/machine-id" +} + +testcase_transient() { + local root transient_id committed_id + + root="$(mktemp -d)" + trap "root_cleanup $root" RETURN + root_mock "$root" + + systemd-machine-id-setup --print --root "$root" + echo abc >>"$root/etc/machine-id" + mount -o remount,ro "$root" + mount -t tmpfs tmpfs "$root/run" + transient_id="$(systemd-machine-id-setup --print --root "$root")" + mount -o remount,rw "$root" + committed_id="$(systemd-machine-id-setup --print --commit --root "$root")" + [[ "$transient_id" == "$committed_id" ]] + diff "$root/etc/machine-id" "$root/run/machine-id" +} + +# Check if we correctly processed the invalid machine ID we set up in the respective +# test.sh file +systemctl --state=failed --no-legend --no-pager >/failed +test ! -s /failed + +# Create a list of all functions prefixed with testcase_ +mapfile -t TESTCASES < <(declare -F | awk '$3 ~ /^testcase_/ {print $3;}') + +if [[ "${#TESTCASES[@]}" -eq 0 ]]; then + echo >&2 "No test cases found, this is most likely an error" + exit 1 +fi + +for testcase in "${TESTCASES[@]}"; do + "$testcase" +done diff --git a/test/units/testsuite-74.mount.sh b/test/units/testsuite-74.mount.sh index bfe472bef7..c4ecfdcada 100755 --- a/test/units/testsuite-74.mount.sh +++ b/test/units/testsuite-74.mount.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh # We're going to play around with block/loop devices, so bail out early # if we're running in nspawn diff --git a/test/units/testsuite-74.path.sh b/test/units/testsuite-74.path.sh index 08ac9ca82c..79056a5b2b 100755 --- a/test/units/testsuite-74.path.sh +++ b/test/units/testsuite-74.path.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh USER_DIRS_CONF="/root/.config/user-dirs.dirs" diff --git a/test/units/testsuite-75.sh b/test/units/testsuite-75.sh index c5487555b6..24af11b589 100755 --- a/test/units/testsuite-75.sh +++ b/test/units/testsuite-75.sh @@ -11,8 +11,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh : >/failed diff --git a/test/units/testsuite-76.sh b/test/units/testsuite-76.sh index ef1eedf68b..855d0ef1f8 100755 --- a/test/units/testsuite-76.sh +++ b/test/units/testsuite-76.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-77-client.sh b/test/units/testsuite-77-client.sh index 0f88a6d835..0d9487ab96 100755 --- a/test/units/testsuite-77-client.sh +++ b/test/units/testsuite-77-client.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-77-run.sh b/test/units/testsuite-77-run.sh index 086044a2bc..fadd34d517 100755 --- a/test/units/testsuite-77-run.sh +++ b/test/units/testsuite-77-run.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-77.sh b/test/units/testsuite-77.sh index 61749fd0c8..2b85a8c565 100755 --- a/test/units/testsuite-77.sh +++ b/test/units/testsuite-77.sh @@ -3,8 +3,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh export SYSTEMD_LOG_LEVEL=debug diff --git a/test/units/testsuite-80.sh b/test/units/testsuite-80.sh index 7440b241be..592af9a132 100755 --- a/test/units/testsuite-80.sh +++ b/test/units/testsuite-80.sh @@ -4,8 +4,8 @@ set -eux set -o pipefail -# shellcheck source=test/units/assert.sh -. "$(dirname "$0")"/assert.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh : >/failed diff --git a/test/units/assert.sh b/test/units/util.sh index 2f4d93ab8c..d151c39965 100755 --- a/test/units/assert.sh +++ b/test/units/util.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later -# utility functions for shell tests +# Utility functions for shell tests assert_true() {( set +ex @@ -56,3 +56,27 @@ assert_rc() {( rc=$? assert_eq "$rc" "$exp" )} + +get_cgroup_hierarchy() { + case "$(stat -c '%T' -f /sys/fs/cgroup)" in + cgroup2fs) + echo "unified" + ;; + tmpfs) + if [[ -d /sys/fs/cgroup/unified && "$(stat -c '%T' -f /sys/fs/cgroup/unified)" == cgroup2fs ]]; then + echo "hybrid" + else + echo "legacy" + fi + ;; + *) + echo >&2 "Failed to determine host's cgroup hierarchy" + exit 1 + esac +} + +runas() { + local userid="${1:?}" + shift + XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@" +} |