aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/zfs-tests.sh
diff options
context:
space:
mode:
authorGiuseppe Di Natale <[email protected]>2017-03-09 10:20:15 -0800
committerBrian Behlendorf <[email protected]>2017-03-09 10:20:15 -0800
commitc552fbc5f025f3c1e74b85c1c0d536ee272defd0 (patch)
tree4ae7a1c1b195703d748d030b1f94ecb701ed5199 /scripts/zfs-tests.sh
parent9b77d1c9585572b7ce3af204d40278752d5f5842 (diff)
Enable shellcheck to run for select scripts
Enable shellcheck to run on zed scripts, paxcheck.sh, zfs-tests.sh, zfs.sh, and zloop.sh. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Giuseppe Di Natale <[email protected]> Closes #5812
Diffstat (limited to 'scripts/zfs-tests.sh')
-rwxr-xr-xscripts/zfs-tests.sh65
1 files changed, 35 insertions, 30 deletions
diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh
index f06d6a1ab..72876a65b 100755
--- a/scripts/zfs-tests.sh
+++ b/scripts/zfs-tests.sh
@@ -20,7 +20,7 @@
#
# CDDL HEADER END
#
-basedir="$(dirname $0)"
+basedir=$(dirname "$0")
SCRIPT_COMMON=common.sh
if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
@@ -29,7 +29,7 @@ else
echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
fi
-. $STF_SUITE/include/default.cfg
+. "$STF_SUITE/include/default.cfg"
PROG=zfs-tests.sh
SUDO=/usr/bin/sudo
@@ -58,24 +58,24 @@ cleanup() {
if [ $LOOPBACK -eq 1 ]; then
for TEST_LOOPBACK in ${LOOPBACKS}; do
- LOOP_DEV=$(basename $TEST_LOOPBACK)
- DM_DEV=$(${SUDO} ${DMSETUP} ls 2>/dev/null | \
- grep ${LOOP_DEV} | cut -f1)
+ LOOP_DEV=$(basename "$TEST_LOOPBACK")
+ DM_DEV=$(${SUDO} "${DMSETUP}" ls 2>/dev/null | \
+ grep "${LOOP_DEV}" | cut -f1)
if [ -n "$DM_DEV" ]; then
- ${SUDO} ${DMSETUP} remove ${DM_DEV} ||
+ ${SUDO} "${DMSETUP}" remove "${DM_DEV}" ||
echo "Failed to remove: ${DM_DEV}"
fi
if [ -n "${TEST_LOOPBACK}" ]; then
- ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK} ||
+ ${SUDO} "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
echo "Failed to remove: ${TEST_LOOPBACK}"
fi
done
fi
for TEST_FILE in ${FILES}; do
- rm -f ${TEST_FILE} &>/dev/null
+ rm -f "${TEST_FILE}" &>/dev/null
done
}
trap cleanup EXIT
@@ -87,29 +87,32 @@ trap cleanup EXIT
# be dangerous and should only be used in a dedicated test environment.
#
cleanup_all() {
- local TEST_POOLS=$(${SUDO} ${ZPOOL} list -H -o name | grep testpool)
- local TEST_LOOPBACKS=$(${SUDO} ${LOSETUP} -a|grep file-vdev|cut -f1 -d:)
- local TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
+ local TEST_POOLS
+ TEST_POOLS=$(${SUDO} "${ZPOOL}" list -H -o name | grep testpool)
+ local TEST_LOOPBACKS
+ TEST_LOOPBACKS=$(${SUDO} "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:)
+ local TEST_FILES
+ TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
msg
msg "--- Cleanup ---"
- msg "Removing pool(s): $(echo ${TEST_POOLS} | tr '\n' ' ')"
+ msg "Removing pool(s): $(echo "${TEST_POOLS}" | tr '\n' ' ')"
for TEST_POOL in $TEST_POOLS; do
- ${SUDO} ${ZPOOL} destroy ${TEST_POOL}
+ ${SUDO} "${ZPOOL}" destroy "${TEST_POOL}"
done
- msg "Removing dm(s): $(${SUDO} ${DMSETUP} ls |
+ msg "Removing dm(s): $(${SUDO} "${DMSETUP}" ls |
grep loop | tr '\n' ' ')"
- ${SUDO} ${DMSETUP} remove_all
+ ${SUDO} "${DMSETUP}" remove_all
- msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS} | tr '\n' ' ')"
+ msg "Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
for TEST_LOOPBACK in $TEST_LOOPBACKS; do
- ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK}
+ ${SUDO} "${LOSETUP}" -d "${TEST_LOOPBACK}"
done
- msg "Removing files(s): $(echo ${TEST_FILES} | tr '\n' ' ')"
+ msg "Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
for TEST_FILE in $TEST_FILES; do
- ${SUDO} rm -f ${TEST_FILE}
+ ${SUDO} rm -f "${TEST_FILE}"
done
}
@@ -193,6 +196,7 @@ while getopts 'hvqxkfd:s:r:?t:u:' OPTION; do
exit 1
;;
v)
+ # shellcheck disable=SC2034
VERBOSE=1
;;
q)
@@ -300,11 +304,11 @@ fi
# be a normal user account, needs to be configured such that it can
# run commands via sudo passwordlessly.
#
-if [ $(id -u) = "0" ]; then
+if [ "$(id -u)" = "0" ]; then
fail "This script must not be run as root."
fi
-if [ $(sudo whoami) != "root" ]; then
+if [ "$(sudo whoami)" != "root" ]; then
fail "Passwordless sudo access required."
fi
@@ -318,7 +322,7 @@ fi
#
# Verify the ZFS module stack if loaded.
#
-${SUDO} ${ZFS_SH} &>/dev/null
+${SUDO} "${ZFS_SH}" &>/dev/null
#
# Attempt to cleanup all previous state for a new test run.
@@ -331,7 +335,7 @@ fi
# By default preserve any existing pools
#
if [ -z "${KEEP}" ]; then
- KEEP=$(${SUDO} ${ZPOOL} list -H -o name)
+ KEEP=$(${SUDO} "${ZPOOL}" list -H -o name)
if [ -z "${KEEP}" ]; then
KEEP="rpool"
fi
@@ -356,7 +360,7 @@ if [ -z "${DISKS}" ]; then
#
for TEST_FILE in ${FILES}; do
[ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
- truncate -s ${FILESIZE} ${TEST_FILE} ||
+ truncate -s "${FILESIZE}" "${TEST_FILE}" ||
fail "Failed creating: ${TEST_FILE} ($?)"
DISKS="$DISKS$TEST_FILE "
done
@@ -369,17 +373,18 @@ if [ -z "${DISKS}" ]; then
check_loop_utils
for TEST_FILE in ${FILES}; do
- TEST_LOOPBACK=$(${SUDO} ${LOSETUP} -f)
- ${SUDO} ${LOSETUP} ${TEST_LOOPBACK} ${TEST_FILE} ||
+ TEST_LOOPBACK=$(${SUDO} "${LOSETUP}" -f)
+ ${SUDO} "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} "
- DISKS="$DISKS$(basename $TEST_LOOPBACK) "
+ BASELOOPBACKS=$(basename "$TEST_LOOPBACK")
+ DISKS="$DISKS$BASELOOPBACKS "
done
fi
fi
-NUM_DISKS=$(echo ${DISKS} | $AWK '{print NF}')
-[ $NUM_DISKS -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
+NUM_DISKS=$(echo "${DISKS}" | $AWK '{print NF}')
+[ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
#
# Disable SELinux until the ZFS Test Suite has been updated accordingly.
@@ -404,7 +409,7 @@ export KEEP
export __ZFS_POOL_EXCLUDE
msg "${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}"
-${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}
+${TEST_RUNNER} ${QUIET} -c "${RUNFILE}" -i "${STF_SUITE}"
RESULT=$?
echo