From de11005c1ac9b0ea2a5bd70aabae8c4012a4f87a Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Sep 2021 23:59:38 +0200 Subject: [PATCH] test: use subshells a bit more to tweak shell flags in specific functions without affecting the rest of the script. --- test/TEST-64-UDEV-STORAGE/test.sh | 58 +++++++++++++++---------------- test/units/testsuite-64.sh | 8 ++--- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/test/TEST-64-UDEV-STORAGE/test.sh b/test/TEST-64-UDEV-STORAGE/test.sh index cddd5229b09..4c4b39dd3fd 100755 --- a/test/TEST-64-UDEV-STORAGE/test.sh +++ b/test/TEST-64-UDEV-STORAGE/test.sh @@ -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 - ) - - 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 - - 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_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 + + # 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 +)} test_run_one() { local test_id="${1:?}" diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh index ffac49089e9..0dbfbc8e88b 100755 --- a/test/units/testsuite-64.sh +++ b/test/units/testsuite-64.sh @@ -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