1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

Merge pull request #27603 from mrc0mmand/more-test-shenanigans

test: merge PID1-related tests into TEST-07-PID1
This commit is contained in:
Yu Watanabe 2023-05-11 16:48:13 +09:00 committed by GitHub
commit 531a6233d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 415 additions and 464 deletions

View File

@ -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 "$@"

37
test/TEST-07-PID1/test.sh Executable file
View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -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 "$@"

View File

@ -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',

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1 +0,0 @@
../-.mount

View File

@ -1 +0,0 @@
-.mount

View File

@ -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 /

126
test/units/test-control.sh Normal file
View File

@ -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 ]]
)}

View File

@ -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

View File

@ -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" ]]

View File

@ -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

View File

@ -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 ]]

View File

@ -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

View File

@ -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 ]]

View File

@ -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

View File

@ -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

View File

@ -3,37 +3,16 @@
set -eux
set -o pipefail
# shellcheck source=test/units/test-control.sh
. "$(dirname "$0")"/test-control.sh
: >/failed
cat >/lib/systemd/system/my.service <<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
# Issue: https://github.com/systemd/systemd/issues/2730
# See TEST-07-PID1/test.sh for the first "half" of the test
mountpoint /issue2730
cat >/lib/systemd/system/my.timer <<EOF
[Timer]
OnBootSec=10s
OnUnitInactiveSec=1h
EOF
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
systemctl daemon-reload
systemctl mask my.timer
run_subtests
touch /testok
rm /failed

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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