test: use subshells a bit more

to tweak shell flags in specific functions without affecting the rest of
the script.
This commit is contained in:
Frantisek Sumsal 2021-09-17 23:59:38 +02:00
parent b216501a8e
commit de11005c1a
2 changed files with 32 additions and 34 deletions

View file

@ -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:?}"

View file

@ -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