From: Frantisek Sumsal Date: Mon, 22 May 2023 14:02:43 +0000 (+0200) Subject: test: use run_testcases() in a few more places X-Git-Tag: v254-rc1~419^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F27733%2Fhead;p=thirdparty%2Fsystemd.git test: use run_testcases() in a few more places --- diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index 2f80cf25648..1b5a1775ee7 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -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 diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh index cd24fee9e53..78228ab0b22 100755 --- a/test/units/testsuite-35.sh +++ b/test/units/testsuite-35.sh @@ -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 </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 diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index c5f9bcc22c8..735cadb59ee 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -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 diff --git a/test/units/testsuite-45.sh b/test/units/testsuite-45.sh index b21b1105d70..d5a0448ad57 100755 --- a/test/units/testsuite-45.sh +++ b/test/units/testsuite-45.sh @@ -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 diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index ecb376476ab..b1b40851dba 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.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 @@ -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 diff --git a/test/units/testsuite-71.sh b/test/units/testsuite-71.sh index fca1819b744..1c884324cbf 100755 --- a/test/units/testsuite-71.sh +++ b/test/units/testsuite-71.sh @@ -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