]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use run_testcases() in a few more places 27733/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 22 May 2023 14:02:43 +0000 (16:02 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 22 May 2023 14:02:49 +0000 (16:02 +0200)
test/units/testsuite-15.sh
test/units/testsuite-35.sh
test/units/testsuite-38.sh
test/units/testsuite-45.sh
test/units/testsuite-58.sh
test/units/testsuite-71.sh

index 2f80cf256480bad0aa7a95b8925c06fc605467f3..1b5a1775ee72f8f11ba33da1c04db8ac0d5419eb 100755 (executable)
@@ -3,6 +3,9 @@
 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 || :
@@ -58,7 +61,7 @@ check_ko () {
     ! check_ok "$@"
 }
 
-test_basic_dropins () {
+testcase_basic_dropins () {
     echo "Testing basic dropins..."
 
     echo "*** test a wants b wants c"
@@ -124,7 +127,7 @@ EOF
     clear_units test15-{a,b,c,c1}.service
 }
 
-test_linked_units () {
+testcase_linked_units () {
     echo "Testing linked units..."
     echo "*** test linked unit (same basename)"
 
@@ -151,7 +154,7 @@ test_linked_units () {
     clear_units test15-{a,b}.service
 }
 
-test_template_alias() {
+testcase_template_alias() {
     echo "Testing instance alias..."
     echo "*** forward"
 
@@ -177,7 +180,7 @@ test_template_alias() {
     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
@@ -223,7 +226,7 @@ ExecCondition=echo $dropin
     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
@@ -282,7 +285,7 @@ MemoryMax=1000000001
     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"
 
@@ -317,7 +320,7 @@ test_transient_service_dropins () {
        /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"
 
@@ -367,7 +370,7 @@ test_transient_slice_dropins () {
        /etc/systemd/system/a-b-.slice.d/drop3.conf
 }
 
-test_template_dropins () {
+testcase_template_dropins () {
     echo "Testing template dropins..."
 
     create_services foo bar@ yup@
@@ -516,7 +519,7 @@ EOF
     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"
@@ -548,7 +551,7 @@ test_alias_dropins () {
     clear_units test15-{a,x,y}.service
 }
 
-test_masked_dropins () {
+testcase_masked_dropins () {
     echo "Testing masked dropins..."
 
     create_services test15-a test15-b
@@ -669,7 +672,7 @@ EOF
     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
@@ -682,7 +685,7 @@ test_invalid_dropins () {
     return 0
 }
 
-test_symlink_dropin_directory () {
+testcase_symlink_dropin_directory () {
     # For issue #21920.
     echo "Testing symlink drop-in directory..."
     create_services test15-a
@@ -701,17 +704,6 @@ EOF
     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
index cd24fee9e534dc4543a16892806477072b603b0c..78228ab0b22373483b4789c1b07332f793596276 100755 (executable)
@@ -3,6 +3,8 @@
 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
 
@@ -33,7 +35,7 @@ EOF
     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
@@ -55,7 +57,7 @@ EOF
     rm -rf /run/systemd/logind.conf.d
 }
 
-test_started() {
+testcase_started() {
     local pid
 
     systemctl restart systemd-logind.service
@@ -89,7 +91,7 @@ teardown_suspend() (
     return 0
 )
 
-test_suspend_on_lid() {
+testcase_suspend_on_lid() {
     local pid input_name lid_dev
 
     if systemd-detect-virt --quiet --container; then
@@ -198,7 +200,7 @@ EOF
     assert_eq "$(systemctl show systemd-logind.service -p ExecMainPID --value)" "$pid"
 }
 
-test_shutdown() {
+testcase_shutdown() {
     local pid
 
     # save pid
@@ -338,7 +340,7 @@ EOF
     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
@@ -382,7 +384,7 @@ EOF
     loginctl flush-devices
 }
 
-test_session() {
+testcase_session() {
     local dev
 
     if systemd-detect-virt --quiet --container; then
@@ -459,7 +461,7 @@ teardown_lock_idle_action() (
     return 0
 )
 
-test_lock_idle_action() {
+testcase_lock_idle_action() {
     local ts
 
     if [[ ! -c /dev/tty2 ]]; then
@@ -505,7 +507,7 @@ EOF
     fi
 }
 
-test_session_properties() {
+testcase_session_properties() {
     local s
 
     if [[ ! -c /dev/tty2 ]]; then
@@ -520,7 +522,7 @@ test_session_properties() {
     /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
@@ -560,7 +562,7 @@ teardown_stop_idle_session() (
     cleanup_session
 )
 
-test_stop_idle_session() {
+testcase_stop_idle_session() {
     local id ts
 
     if [[ ! -c /dev/tty2 ]]; then
@@ -586,7 +588,7 @@ EOF
     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
@@ -641,18 +643,8 @@ EOF
 : >/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
index c5f9bcc22c8a68b95083a1e91a4a4876c727e048..735cadb59ee8076572a0349edd6ce35c57e5727f 100755 (executable)
@@ -1,9 +1,12 @@
 #!/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
@@ -105,7 +108,7 @@ check_cgroup_state() {
     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}"
@@ -139,7 +142,7 @@ test_dbus_api() {
     echo
 }
 
-test_jobs() {
+testcase_jobs() {
     local pid_before=
     local pid_after=
     echo "Test that it is possible to apply jobs on frozen units:"
@@ -164,7 +167,7 @@ test_jobs() {
     echo
 }
 
-test_systemctl() {
+testcase_systemctl() {
     echo "Test that systemctl freeze/thaw verbs:"
 
     systemctl start "$unit"
@@ -190,7 +193,7 @@ test_systemctl() {
     echo
 }
 
-test_systemctl_show() {
+testcase_systemctl_show() {
     echo "Test systemctl show integration:"
 
     systemctl start "$unit"
@@ -213,7 +216,7 @@ test_systemctl_show() {
     echo
 }
 
-test_recursive() {
+testcase_recursive() {
     local slice="bar.slice"
     local unit="baz.service"
 
@@ -243,7 +246,7 @@ test_recursive() {
     echo
 }
 
-test_preserve_state() {
+testcase_preserve_state() {
     local slice="bar.slice"
     local unit="baz.service"
 
@@ -290,15 +293,10 @@ test_preserve_state() {
     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
index b21b1105d7010fdd3652ef2179e4cf701e55670f..d5a0448ad57ab70c6637f7998582706bf4004ef8 100755 (executable)
@@ -4,10 +4,12 @@
 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
 
@@ -36,7 +38,7 @@ restore_timezone() {
     fi
 }
 
-test_timezone() {
+testcase_timezone() {
     local ORIG_TZ=
 
     # Debian/Ubuntu specific file
@@ -87,7 +89,7 @@ check_adjtime_not_exist() {
     fi
 }
 
-test_adjtime() {
+testcase_adjtime() {
     # test setting UTC vs. LOCAL in /etc/adjtime
     if [[ -e /etc/adjtime ]]; then
         mv /etc/adjtime /etc/adjtime.bak
@@ -221,7 +223,7 @@ wait_mon() {
     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
@@ -277,10 +279,7 @@ EOF
 
 : >/failed
 
-test_timedatectl
-test_timezone
-test_adjtime
-test_ntp
+run_testcases
 
 touch /testok
 rm /failed
index ecb376476ab5eb43b682a063958195bddc2d0175..b1b40851dba7b7cd29c62c62301090c6f3dd0a6f 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
 # SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2317
 set -eux
 set -o pipefail
 
@@ -11,6 +12,8 @@ if ! command -v systemd-repart &>/dev/null; then
     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
 
@@ -88,7 +91,7 @@ else
     exit 1
 fi
 
-test_basic() {
+testcase_basic() {
     local defs imgs output
     local loop volume
 
@@ -338,7 +341,7 @@ $imgs/zzz7 : start=     6291416, size=       98304, type=0FC63DAF-8483-4772-8E79
     umount "$imgs/mount"
 }
 
-test_dropin() {
+testcase_dropin() {
     local defs imgs output
 
     defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
@@ -396,7 +399,7 @@ EOF
 EOF
 }
 
-test_multiple_definitions() {
+testcase_multiple_definitions() {
     local defs imgs output
 
     defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
@@ -467,7 +470,7 @@ EOF
 EOF
 }
 
-test_copy_blocks() {
+testcase_copy_blocks() {
     local defs imgs output
 
     defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
@@ -549,7 +552,7 @@ EOF
     cmp "$imgs/zzz" "$imgs/yyy"
 }
 
-test_unaligned_partition() {
+testcase_unaligned_partition() {
     local defs imgs output
 
     defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
@@ -584,7 +587,7 @@ EOF
     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
@@ -620,7 +623,7 @@ EOF
     assert_in "$imgs/21817.img2 : start=      104448, size=      (100319| 98304)," "$output"
 }
 
-test_issue_24553() {
+testcase_issue_24553() {
     local defs imgs output
 
     # testcase for #24553
@@ -720,7 +723,7 @@ EOF
     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")"
@@ -748,7 +751,7 @@ EOF
     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")"
@@ -837,7 +840,7 @@ EOF
     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")"
@@ -922,7 +925,7 @@ EOF
     losetup -d "$loop"
 }
 
-test_minimize() {
+testcase_minimize() {
     local defs imgs output
 
     if systemd-detect-virt --quiet --container; then
@@ -1035,17 +1038,7 @@ EOF
     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
index fca1819b7446d7cd1f2440d73eac46fd35030a69..1c884324cbfaba5ce5df2be58aa2ad087c779549 100755 (executable)
@@ -4,6 +4,8 @@
 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
 
@@ -15,7 +17,7 @@ restore_hostname() {
     fi
 }
 
-test_hostname() {
+testcase_hostname() {
     local orig=
 
     if [[ -f /etc/hostname ]]; then
@@ -59,7 +61,7 @@ get_chassis() (
     echo "$CHASSIS"
 )
 
-test_chassis() {
+testcase_chassis() {
     local i
 
     if [[ -f /etc/machine-info ]]; then
@@ -96,7 +98,7 @@ restore_sysfs_dmi() {
     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."
@@ -131,9 +133,7 @@ EOF
 
 : >/failed
 
-test_hostname
-test_chassis
-test_firmware_date
+run_testcases
 
 touch /testok
 rm /failed