]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use subshells a bit more
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 17 Sep 2021 21:59:38 +0000 (23:59 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 18 Sep 2021 18:44:34 +0000 (20:44 +0200)
to tweak shell flags in specific functions without affecting the rest of
the script.

test/TEST-64-UDEV-STORAGE/test.sh
test/units/testsuite-64.sh

index cddd5229b097a88b34861fc40d4b803d03fe09cb..4c4b39dd3fdb0771396a2c6fd0f3c1fe5594b8fe 100755 (executable)
@@ -26,7 +26,9 @@ if ! get_bool "$QEMU_KVM"; then
     exit 0
 fi
 
-_host_has_feature() {
+_host_has_feature() {(
+    set -e
+
     case "${1:?}" in
         multipath)
             command -v multipath && command -v multipathd
@@ -43,36 +45,34 @@ _host_has_feature() {
             # a missing feature
             exit 1
     esac
-}
-
-test_append_files() {
-    (
-        local feature
-        # An associative array of requested (but optional) features and their
-        # respective "handlers" from test/test-functions
-        local -A features=(
-            [multipath]=install_multipath
-            [lvm]=install_lvm
-        )
+)}
+
+test_append_files() {(
+    local feature
+    # An associative array of requested (but optional) features and their
+    # respective "handlers" from test/test-functions
+    local -A features=(
+        [multipath]=install_multipath
+        [lvm]=install_lvm
+    )
 
-        instmods "=block" "=md" "=nvme" "=scsi"
-        install_dmevent
-        generate_module_dependencies
-        image_install lsblk wc
+    instmods "=block" "=md" "=nvme" "=scsi"
+    install_dmevent
+    generate_module_dependencies
+    image_install lsblk wc
 
-        # Install the optional features if the host has the respective tooling
-        for feature in "${!features[@]}"; do
-            if _host_has_feature "$feature"; then
-                "${features[$feature]}"
-            fi
-        done
+    # Install the optional features if the host has the respective tooling
+    for feature in "${!features[@]}"; do
+        if _host_has_feature "$feature"; then
+            "${features[$feature]}"
+        fi
+    done
 
-        for i in {0..127}; do
-            dd if=/dev/zero of="${TESTDIR:?}/disk$i.img" bs=1M count=1
-            echo "device$i" >"${TESTDIR:?}/disk$i.img"
-        done
-    )
-}
+    for i in {0..127}; do
+        dd if=/dev/zero of="${TESTDIR:?}/disk$i.img" bs=1M count=1
+        echo "device$i" >"${TESTDIR:?}/disk$i.img"
+    done
+)}
 
 test_run_one() {
     local test_id="${1:?}"
index ffac49089e98be754bb8ad10ac12364a5af45483..0dbfbc8e88b94b748042c998c83d3db5e0bcffb9 100755 (executable)
@@ -6,10 +6,8 @@ set -o pipefail
 
 # Check if all symlinks under /dev/disk/ are valid
 # shellcheck disable=SC2120
-helper_check_device_symlinks() {
-    # Disable verbose logging only for this function (and reset the signal handler
-    # when leaving the function)
-    set +x; trap "trap - RETURN; set -x" RETURN
+helper_check_device_symlinks() {(
+    set +x
 
     local dev link path paths target
 
@@ -40,7 +38,7 @@ helper_check_device_symlinks() {
             return 1
         fi
     done < <(find "${paths[@]}" -type l)
-}
+)}
 
 testcase_megasas2_basic() {
     lsblk -S