summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-11-20 12:17:05 +0100
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-11-20 21:26:08 +0100
commitb54bc139ae91b417996ddc85585710ebf3324237 (patch)
tree3f31de18068359103ad0ad3636c725648adf6942 /test
parenttest-condition: skip group test during Debian package build (diff)
downloadsystemd-b54bc139ae91b417996ddc85585710ebf3324237.tar.xz
systemd-b54bc139ae91b417996ddc85585710ebf3324237.zip
test: make the LOOKS_LIKE_* variables proper booleans
Diffstat (limited to 'test')
-rw-r--r--test/test-functions51
1 files changed, 26 insertions, 25 deletions
diff --git a/test/test-functions b/test/test-functions
index 7375d3465c..f6323245ae 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -14,20 +14,39 @@
# * koalaman/shellcheck#280
set -o pipefail
+# Simple wrapper to unify boolean checks.
+# Note: this function needs to stay near the top of the file, so we can use it
+# in code in the outermost scope.
+get_bool() {
+ # Make the value lowercase to make the regex matching simpler
+ local _bool="${1,,}"
+
+ # Consider empty value as "false"
+ if [[ -z "$_bool" || "$_bool" =~ ^(0|no|false)$ ]]; then
+ return 1
+ elif [[ "$_bool" =~ ^(1|yes|true)$ ]]; then
+ return 0
+ else
+ echo >&2 "Value '$_bool' is not a valid boolean value"
+ exit 1
+ fi
+}
+
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
os_release=$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release)
# shellcheck source=/dev/null
source "$os_release"
-[[ "$ID" = "debian" || " $ID_LIKE " = *" debian "* ]] && LOOKS_LIKE_DEBIAN=yes || LOOKS_LIKE_DEBIAN=""
-[[ "$ID" = "arch" || " $ID_LIKE " = *" arch "* ]] && LOOKS_LIKE_ARCH=yes || LOOKS_LIKE_ARCH=""
-[[ " $ID_LIKE " = *" suse "* ]] && LOOKS_LIKE_SUSE=yes || LOOKS_LIKE_SUSE=""
+[[ "$ID" == "debian" || " $ID_LIKE " == *" debian "* ]] && LOOKS_LIKE_DEBIAN=yes || LOOKS_LIKE_DEBIAN=no
+[[ "$ID" == "arch" || " $ID_LIKE " == *" arch "* ]] && LOOKS_LIKE_ARCH=yes || LOOKS_LIKE_ARCH=no
+[[ " $ID_LIKE " == *" suse "* ]] && LOOKS_LIKE_SUSE=yes || LOOKS_LIKE_SUSE=no
+
KERNEL_VER="${KERNEL_VER-$(uname -r)}"
QEMU_TIMEOUT="${QEMU_TIMEOUT:-1800}"
NSPAWN_TIMEOUT="${NSPAWN_TIMEOUT:-1800}"
TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out
-[[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext4}"
+get_bool "$LOOKS_LIKE_SUSE" && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext4}"
UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}"
# Note that defining a different IMAGE_NAME in a test setup script will only result
@@ -41,24 +60,6 @@ TEST_PARALLELIZE="${TEST_PARALLELIZE:-0}"
TEST_SUPPORTING_SERVICES_SHOULD_BE_MASKED="${TEST_SUPPORTING_SERVICES_SHOULD_BE_MASKED:-1}"
LOOPDEV=
-# Simple wrapper to unify boolean checks.
-# Note: this function needs to stay near the top of the file, so we can use it
-# in code in the outermost scope.
-get_bool() {
- # Make the value lowercase to make the regex matching simpler
- local _bool="${1,,}"
-
- # Consider empty value as "false"
- if [[ -z "$_bool" || "$_bool" =~ ^(0|no|false)$ ]]; then
- return 1
- elif [[ "$_bool" =~ ^(1|yes|true)$ ]]; then
- return 0
- else
- echo >&2 "Value '$_bool' is not a valid boolean value"
- exit 1
- fi
-}
-
# Since in Bash we can have only one handler per signal, let's overcome this
# limitation by having one global handler for the EXIT signal which executes
# all registered handlers
@@ -501,11 +502,11 @@ run_qemu() {
if [[ ! "$INITRD" ]]; then
if [[ -e "$default_fedora_initrd" ]]; then
INITRD="$default_fedora_initrd"
- elif [[ "$LOOKS_LIKE_DEBIAN" && -e "$default_debian_initrd" ]]; then
+ elif get_bool "$LOOKS_LIKE_DEBIAN" && [[ -e "$default_debian_initrd" ]]; then
INITRD="$default_debian_initrd"
- elif [[ "$LOOKS_LIKE_ARCH" && -e "$default_arch_initrd" ]]; then
+ elif get_bool "$LOOKS_LIKE_ARCH" && [[ -e "$default_arch_initrd" ]]; then
INITRD="$default_arch_initrd"
- elif [[ "$LOOKS_LIKE_SUSE" && -e "$default_suse_initrd" ]]; then
+ elif get_bool "$LOOKS_LIKE_SUSE" && [[ -e "$default_suse_initrd" ]]; then
INITRD="$default_suse_initrd"
fi
fi