set -eux
set -o pipefail
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
+
clear_unit () {
local UNIT_NAME="${1:?}"
systemctl stop "$UNIT_NAME" 2>/dev/null || :
! check_ok "$@"
}
-test_basic_dropins () {
+testcase_basic_dropins () {
echo "Testing basic dropins..."
echo "*** test a wants b wants c"
clear_units test15-{a,b,c,c1}.service
}
-test_linked_units () {
+testcase_linked_units () {
echo "Testing linked units..."
echo "*** test linked unit (same basename)"
clear_units test15-{a,b}.service
}
-test_template_alias() {
+testcase_template_alias() {
echo "Testing instance alias..."
echo "*** forward"
clear_units test15-{a,b}@.service
}
-test_hierarchical_service_dropins () {
+testcase_hierarchical_service_dropins () {
echo "Testing hierarchical service dropins..."
echo "*** test service.d/ top level drop-in"
create_services a-b-c
clear_units a-b-c.service
}
-test_hierarchical_slice_dropins () {
+testcase_hierarchical_slice_dropins () {
echo "Testing hierarchical slice dropins..."
echo "*** test slice.d/ top level drop-in"
# Slice units don't even need a fragment, so we test the defaults here
clear_units a-b-c.slice
}
-test_transient_service_dropins () {
+testcase_transient_service_dropins () {
echo "Testing dropins for a transient service..."
echo "*** test transient service drop-ins"
/etc/systemd/system/a-b-.service.d/drop3.conf
}
-test_transient_slice_dropins () {
+testcase_transient_slice_dropins () {
echo "Testing dropins for a transient slice..."
echo "*** test transient slice drop-ins"
/etc/systemd/system/a-b-.slice.d/drop3.conf
}
-test_template_dropins () {
+testcase_template_dropins () {
echo "Testing template dropins..."
create_services foo bar@ yup@
clear_units foo.service {bar,yup,bar-alias}@{,1,2,3}.service
}
-test_alias_dropins () {
+testcase_alias_dropins () {
echo "Testing alias dropins..."
echo "*** test a wants b1 alias of b"
clear_units test15-{a,x,y}.service
}
-test_masked_dropins () {
+testcase_masked_dropins () {
echo "Testing masked dropins..."
create_services test15-a test15-b
clear_units test15-{a,b}.service
}
-test_invalid_dropins () {
+testcase_invalid_dropins () {
echo "Testing invalid dropins..."
# Assertion failed on earlier versions, command exits unsuccessfully on later versions
systemctl cat nonexistent@.service || true
return 0
}
-test_symlink_dropin_directory () {
+testcase_symlink_dropin_directory () {
# For issue #21920.
echo "Testing symlink drop-in directory..."
create_services test15-a
clear_units test15-a.service
}
-test_basic_dropins
-test_linked_units
-test_template_alias
-test_hierarchical_service_dropins
-test_hierarchical_slice_dropins
-test_transient_service_dropins
-test_transient_slice_dropins
-test_template_dropins
-test_alias_dropins
-test_masked_dropins
-test_invalid_dropins
-test_symlink_dropin_directory
+run_testcases
touch /testok
set -eux
set -o pipefail
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
systemctl stop systemd-logind.service
}
-test_properties() {
+testcase_properties() {
mkdir -p /run/systemd/logind.conf.d
cat >/run/systemd/logind.conf.d/kill-user-processes.conf <<EOF
rm -rf /run/systemd/logind.conf.d
}
-test_started() {
+testcase_started() {
local pid
systemctl restart systemd-logind.service
return 0
)
-test_suspend_on_lid() {
+testcase_suspend_on_lid() {
local pid input_name lid_dev
if systemd-detect-virt --quiet --container; then
assert_eq "$(systemctl show systemd-logind.service -p ExecMainPID --value)" "$pid"
}
-test_shutdown() {
+testcase_shutdown() {
local pid
# save pid
assert_eq "$(loginctl --no-legend | awk '$3=="logind-test-user" { print $5 }')" "tty2"
}
-test_sanity_check() {
+testcase_sanity_check() {
# Exercise basic loginctl options
if [[ ! -c /dev/tty2 ]]; then
loginctl flush-devices
}
-test_session() {
+testcase_session() {
local dev
if systemd-detect-virt --quiet --container; then
return 0
)
-test_lock_idle_action() {
+testcase_lock_idle_action() {
local ts
if [[ ! -c /dev/tty2 ]]; then
fi
}
-test_session_properties() {
+testcase_session_properties() {
local s
if [[ ! -c /dev/tty2 ]]; then
/usr/lib/systemd/tests/unit-tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}"
}
-test_list_users_sessions() {
+testcase_list_users_sessions() {
if [[ ! -c /dev/tty2 ]]; then
echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
return
cleanup_session
)
-test_stop_idle_session() {
+testcase_stop_idle_session() {
local id ts
if [[ ! -c /dev/tty2 ]]; then
assert_eq "$(loginctl --no-legend | grep -c "logind-test-user")" 0
}
-test_ambient_caps() {
+testcase_ambient_caps() {
local PAMSERVICE TRANSIENTUNIT SCRIPT
# Verify that pam_systemd works and assigns ambient caps as it should
: >/failed
setup_test_user
-test_list_users_sessions
test_enable_debug
-test_properties
-test_started
-test_suspend_on_lid
-test_shutdown
-test_sanity_check
-test_session
-test_lock_idle_action
-test_session_properties
-test_stop_idle_session
-test_ambient_caps
+run_testcases
touch /testok
rm /failed
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
-
+# shellcheck disable=SC2317
set -eux
set -o pipefail
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
+
systemd-analyze log-level debug
unit=testsuite-38-sleep.service
grep -q "frozen $2" /sys/fs/cgroup/system.slice/"$1"/cgroup.events
}
-test_dbus_api() {
+testcase_dbus_api() {
echo "Test that DBus API works:"
echo -n " - Freeze(): "
dbus_freeze "${unit}"
echo
}
-test_jobs() {
+testcase_jobs() {
local pid_before=
local pid_after=
echo "Test that it is possible to apply jobs on frozen units:"
echo
}
-test_systemctl() {
+testcase_systemctl() {
echo "Test that systemctl freeze/thaw verbs:"
systemctl start "$unit"
echo
}
-test_systemctl_show() {
+testcase_systemctl_show() {
echo "Test systemctl show integration:"
systemctl start "$unit"
echo
}
-test_recursive() {
+testcase_recursive() {
local slice="bar.slice"
local unit="baz.service"
echo
}
-test_preserve_state() {
+testcase_preserve_state() {
local slice="bar.slice"
local unit="baz.service"
echo
}
-test -e /sys/fs/cgroup/system.slice/cgroup.freeze && {
+if [[ -e /sys/fs/cgroup/system.slice/cgroup.freeze ]]; then
start_test_service
- test_dbus_api
- test_systemctl
- test_systemctl_show
- test_jobs
- test_recursive
- test_preserve_state
-}
+ run_testcases
+fi
echo OK >/testok
exit 0
set -eux
set -o pipefail
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
-test_timedatectl() {
+testcase_timedatectl() {
timedatectl --no-pager --help
timedatectl --version
fi
}
-test_timezone() {
+testcase_timezone() {
local ORIG_TZ=
# Debian/Ubuntu specific file
fi
}
-test_adjtime() {
+testcase_adjtime() {
# test setting UTC vs. LOCAL in /etc/adjtime
if [[ -e /etc/adjtime ]]; then
mv /etc/adjtime /etc/adjtime.bak
wait "$MONPID" 2>/dev/null || true
}
-test_ntp() {
+testcase_ntp() {
# timesyncd has ConditionVirtualization=!container by default; drop/mock that for testing
if systemd-detect-virt --container --quiet; then
systemctl disable --quiet --now systemd-timesyncd
: >/failed
-test_timedatectl
-test_timezone
-test_adjtime
-test_ntp
+run_testcases
touch /testok
rm /failed
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2317
set -eux
set -o pipefail
exit 0
fi
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
exit 1
fi
-test_basic() {
+testcase_basic() {
local defs imgs output
local loop volume
umount "$imgs/mount"
}
-test_dropin() {
+testcase_dropin() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
EOF
}
-test_multiple_definitions() {
+testcase_multiple_definitions() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
EOF
}
-test_copy_blocks() {
+testcase_copy_blocks() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
cmp "$imgs/zzz" "$imgs/yyy"
}
-test_unaligned_partition() {
+testcase_unaligned_partition() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
assert_in "$imgs/unaligned3 : start= 3662944, size= 17308536, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
}
-test_issue_21817() {
+testcase_issue_21817() {
local defs imgs output
# testcase for #21817
assert_in "$imgs/21817.img2 : start= 104448, size= (100319| 98304)," "$output"
}
-test_issue_24553() {
+testcase_issue_24553() {
local defs imgs output
# testcase for #24553
assert_in "$imgs/zzz3 : start= 21495848, size= 3669936, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:59\"" "$output"
}
-test_zero_uuid() {
+testcase_zero_uuid() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
assert_in "$imgs/zero1 : start= 2048, size= 20480, type=${root_guid}, uuid=00000000-0000-0000-0000-000000000000" "$output"
}
-test_verity() {
+testcase_verity() {
local defs imgs output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
systemd-dissect -U "$imgs/mnt"
}
-test_exclude_files() {
+testcase_exclude_files() {
local defs imgs root output
defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
losetup -d "$loop"
}
-test_minimize() {
+testcase_minimize() {
local defs imgs output
if systemd-detect-virt --quiet --container; then
assert_in "${loop}p3 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DB081670-07AE-48CA-9F5E-813D5E40B976, name=\"linux-generic-2\"" "$output"
}
-test_basic
-test_dropin
-test_multiple_definitions
-test_copy_blocks
-test_unaligned_partition
-test_issue_21817
-test_issue_24553
-test_zero_uuid
-test_verity
-test_exclude_files
-test_minimize
+run_testcases
# Valid block sizes on the Linux block layer are >= 512 and <= PAGE_SIZE, and
# must be powers of 2. Which leaves exactly four different ones to test on
set -eux
set -o pipefail
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
fi
}
-test_hostname() {
+testcase_hostname() {
local orig=
if [[ -f /etc/hostname ]]; then
echo "$CHASSIS"
)
-test_chassis() {
+testcase_chassis() {
local i
if [[ -f /etc/machine-info ]]; then
systemctl stop systemd-hostnamed
}
-test_firmware_date() {
+testcase_firmware_date() {
# No DMI on s390x or ppc
if [[ ! -d /sys/class/dmi/id ]]; then
echo "/sys/class/dmi/id not found, skipping firmware date tests."
: >/failed
-test_hostname
-test_chassis
-test_firmware_date
+run_testcases
touch /testok
rm /failed