diff options
author | Ryan Moeller <[email protected]> | 2020-08-07 17:10:48 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-07 14:10:48 -0700 |
commit | d4e6e9597d322df47a5d177ba40c86e35bfb1e05 (patch) | |
tree | 036093548b9050b1aed2480e5f1d3dd85f523924 | |
parent | 0cab7970f9c10284d2dae47de52c974101e68274 (diff) |
ZTS: Remove bashisms from zfs-tests.sh
Bring zfs-tests.sh in to compliance with the other scripts
by converting it /bin/sh for to avoid a dependency on bash.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #10640
-rwxr-xr-x | scripts/zfs-tests.sh | 117 | ||||
-rw-r--r-- | tests/zfs-tests/include/default.cfg.in | 34 |
2 files changed, 70 insertions, 81 deletions
diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh index 241346784..004d0cbf3 100755 --- a/scripts/zfs-tests.sh +++ b/scripts/zfs-tests.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # # CDDL HEADER START # @@ -41,7 +41,7 @@ DEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run" RUNFILES=${RUNFILES:-$DEFAULT_RUNFILES} FILEDIR=${FILEDIR:-/var/tmp} DISKS=${DISKS:-""} -SINGLETEST=() +SINGLETEST="" SINGLETESTUSER="root" TAGS="" ITERATIONS=1 @@ -74,7 +74,7 @@ msg() { # Log a failure message, cleanup, and return an error. # fail() { - echo -e "$PROG: $1" >&2 + echo "$PROG: $1" >&2 cleanup exit 1 } @@ -126,7 +126,7 @@ cleanup() { fi for TEST_FILE in ${FILES}; do - rm -f "${TEST_FILE}" &>/dev/null + rm -f "${TEST_FILE}" >/dev/null 2>&1 done if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then @@ -142,15 +142,15 @@ trap cleanup EXIT # be dangerous and should only be used in a dedicated test environment. # cleanup_all() { - local TEST_POOLS + TEST_POOLS TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool) - local TEST_LOOPBACKS + TEST_LOOPBACKS if [ "$UNAME" = "FreeBSD" ] ; then TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l) else TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:) fi - local TEST_FILES + TEST_FILES TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null) msg @@ -191,8 +191,8 @@ cleanup_all() { # <name>.run # find_runfile() { - local NAME=$1 - local RESULT="" + NAME=$1 + RESULT="" if [ -f "$RUNFILE_DIR/$NAME" ]; then RESULT="$RUNFILE_DIR/$NAME" @@ -211,8 +211,8 @@ find_runfile() { # Symlink file if it appears under any of the given paths. # create_links() { - local dir_list="$1" - local file_list="$2" + dir_list="$1" + file_list="$2" [ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set" @@ -227,8 +227,10 @@ create_links() { fi done - [ ! -e "$STF_PATH/$i" ] && STF_MISSING_BIN="$STF_MISSING_BIN$i " + [ ! -e "$STF_PATH/$i" ] && \ + STF_MISSING_BIN="$STF_MISSING_BIN $i" done + STF_MISSING_BIN=${STF_MISSING_BIN# } } # @@ -243,7 +245,7 @@ constrain_path() { # install to /usr/local/sbin. To avoid testing the wrong utils we # need /usr/local to come before / in the path search order. SYSTEM_DIRS="/usr/local/bin /usr/local/sbin" - SYSTEM_DIRS+=" /usr/bin /usr/sbin /bin /sbin" + SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin" if [ "$INTREE" = "yes" ]; then # Constrained path set to ./zfs/bin/ @@ -283,9 +285,9 @@ constrain_path() { # Standard system utilities SYSTEM_FILES="$SYSTEM_FILES_COMMON" if [ "$UNAME" = "FreeBSD" ] ; then - SYSTEM_FILES+=" $SYSTEM_FILES_FREEBSD" + SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD" else - SYSTEM_FILES+=" $SYSTEM_FILES_LINUX" + SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX" fi create_links "$SYSTEM_DIRS" "$SYSTEM_FILES" @@ -380,7 +382,7 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do ;; n) nfsfile=$OPTARG - [[ -f $nfsfile ]] || fail "Cannot read file: $nfsfile" + [ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile" export NFS=1 . "$nfsfile" ;; @@ -400,10 +402,10 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do RUNFILES="$OPTARG" ;; t) - if [ ${#SINGLETEST[@]} -ne 0 ]; then + if [ -n "$SINGLETEST" ]; then fail "-t can only be provided once." fi - SINGLETEST+=("$OPTARG") + SINGLETEST="$OPTARG" ;; T) TAGS="$OPTARG" @@ -423,7 +425,7 @@ shift $((OPTIND-1)) FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"} LOOPBACKS=${LOOPBACKS:-""} -if [ ${#SINGLETEST[@]} -ne 0 ]; then +if [ -n "$SINGLETEST" ]; then if [ -n "$TAGS" ]; then fail "-t and -T are mutually exclusive." fi @@ -446,22 +448,20 @@ post_user = root post = outputdir = /var/tmp/test_results EOF - for t in "${SINGLETEST[@]}" - do - SINGLETESTDIR=$(dirname "$t") - SINGLETESTFILE=$(basename "$t") - SETUPSCRIPT= - CLEANUPSCRIPT= - - if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then - SETUPSCRIPT="setup" - fi + SINGLETESTDIR=$(dirname "$SINGLETEST") + SINGLETESTFILE=$(basename "$SINGLETEST") + SETUPSCRIPT= + CLEANUPSCRIPT= - if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then - CLEANUPSCRIPT="cleanup" - fi + if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then + SETUPSCRIPT="setup" + fi - cat >>$RUNFILE_DIR/$RUNFILES << EOF + if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then + CLEANUPSCRIPT="cleanup" + fi + + cat >>$RUNFILE_DIR/$RUNFILES << EOF [$SINGLETESTDIR] tests = ['$SINGLETESTFILE'] @@ -469,7 +469,6 @@ pre = $SETUPSCRIPT post = $CLEANUPSCRIPT tags = ['functional'] EOF - done fi # @@ -487,7 +486,7 @@ for RUNFILE in $RUNFILES; do SAVED_RUNFILE="$RUNFILE" RUNFILE=$(find_runfile "$RUNFILE") [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE" - R+="${R:+,}${RUNFILE}" + R="$R,$RUNFILE" fi if [ ! -r "$RUNFILE" ]; then @@ -495,7 +494,7 @@ for RUNFILE in $RUNFILES; do fi done unset IFS -RUNFILES=$R +RUNFILES=${R#,} # # This script should not be run as root. Instead the test user, which may @@ -529,9 +528,9 @@ fi # Verify the ZFS module stack is loaded. # if [ "$STACK_TRACER" = "yes" ]; then - sudo "${ZFS_SH}" -S &>/dev/null + sudo "${ZFS_SH}" -S >/dev/null 2>&1 else - sudo "${ZFS_SH}" &>/dev/null + sudo "${ZFS_SH}" >/dev/null 2>&1 fi # @@ -552,7 +551,7 @@ if [ -z "${KEEP}" ]; then KEEP="rpool" fi else - KEEP="$(echo -e "${KEEP//[[:blank:]]/\n}")" + KEEP="$(echo "$KEEP" | tr '[:blank:]' '\n')" fi # @@ -592,19 +591,12 @@ if [ -z "${DISKS}" ]; then [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" truncate -s "${FILESIZE}" "${TEST_FILE}" || fail "Failed creating: ${TEST_FILE} ($?)" - if [[ "$DISKS" ]]; then - DISKS="$DISKS $TEST_FILE" - else - DISKS="$TEST_FILE" - fi done # # If requested setup loopback devices backed by the sparse files. # if [ "$LOOPBACK" = "yes" ]; then - DISKS="" - test -x "$LOSETUP" || fail "$LOSETUP utility must be installed" for TEST_FILE in ${FILES}; do @@ -613,25 +605,21 @@ if [ -z "${DISKS}" ]; then if [ -z "$MDDEVICE" ] ; then fail "Failed: ${TEST_FILE} -> loopback" fi - LOOPBACKS="${LOOPBACKS}${MDDEVICE} " - if [[ "$DISKS" ]]; then - DISKS="$DISKS $MDDEVICE" - else - DISKS="$MDDEVICE" - fi + DISKS="$DISKS $MDDEVICE" + LOOPBACKS="$LOOPBACKS $MDDEVICE" else TEST_LOOPBACK=$(sudo "${LOSETUP}" -f) sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" || fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" - LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} " - BASELOOPBACKS=$(basename "$TEST_LOOPBACK") - if [[ "$DISKS" ]]; then - DISKS="$DISKS $BASELOOPBACKS" - else - DISKS="$BASELOOPBACKS" - fi + BASELOOPBACK=$(basename "$TEST_LOOPBACK") + DISKS="$DISKS $BASELOOPBACK" + LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK" fi done + DISKS=${DISKS# } + LOOPBACKS=${LOOPBACKS# } + else + DISKS="$FILES" fi fi @@ -642,7 +630,7 @@ NUM_DISKS=$(echo "${DISKS}" | awk '{print NF}') # Disable SELinux until the ZFS Test Suite has been updated accordingly. # if [ -x "$STF_PATH/setenforce" ]; then - sudo setenforce permissive &>/dev/null + sudo setenforce permissive >/dev/null 2>&1 fi # @@ -703,10 +691,9 @@ ${TEST_RUNNER} ${QUIET:+-q} \ # # Analyze the results. # -set -o pipefail -${ZTS_REPORT} "$RESULTS_FILE" | tee "$REPORT_FILE" +${ZTS_REPORT} "$RESULTS_FILE" >"$REPORT_FILE" RESULT=$? -set +o pipefail +cat "$REPORT_FILE" RESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE") if [ -d "$RESULTS_DIR" ]; then @@ -715,8 +702,8 @@ fi rm -f "$RESULTS_FILE" "$REPORT_FILE" -if [ ${#SINGLETEST[@]} -ne 0 ]; then - rm -f "$RUNFILES" &>/dev/null +if [ -n "$SINGLETEST" ]; then + rm -f "$RUNFILES" >/dev/null 2>&1 fi exit ${RESULT} diff --git a/tests/zfs-tests/include/default.cfg.in b/tests/zfs-tests/include/default.cfg.in index 741c0d3b2..8ec0b96e2 100644 --- a/tests/zfs-tests/include/default.cfg.in +++ b/tests/zfs-tests/include/default.cfg.in @@ -1,3 +1,5 @@ +#!/bin/sh + # # CDDL HEADER START # @@ -30,7 +32,6 @@ # . $STF_SUITE/include/commands.cfg -. $STF_SUITE/include/libtest.shlib # ZFS Directories export ZEDLET_ETC_DIR=${ZEDLET_ETC_DIR:-@sysconfdir@/zfs/zed.d} @@ -143,17 +144,6 @@ export SPA_MINDEVSIZE=$((64 * 1024 * 1024)) # For iscsi target support export ISCSITGTFILE=/tmp/iscsitgt_file export ISCSITGT_FMRI=svc:/system/iscsitgt:default -if is_illumos; then -export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \ - '{print $3}') -fi - -# -# finally, if we're running in a local zone -# we take some additional actions -if ! is_global_zone; then - reexport_pool -fi export ZFS_VERSION=5 export ZFS_ALL_VERSIONS="1 2 3 4 5" @@ -164,7 +154,8 @@ done export MAX_PARTITIONS=8 -if is_linux; then +case $(uname -o) in +GNU/Linux) unpack_opts="--sparse -xf" pack_opts="--sparse -cf" verbose=" -v" @@ -185,7 +176,8 @@ if is_linux; then NEWFS_DEFAULT_FS="ext2" SLICE_PREFIX="" -elif is_freebsd; then + ;; +FreeBSD) unpack_opts="xv" pack_opts="cf" verbose="v" @@ -200,7 +192,16 @@ elif is_freebsd; then NEWFS_DEFAULT_FS="ufs" SLICE_PREFIX="p" -else + ;; +illumos) + export AUTO_SNAP=$(svcs -a | \ + awk '/auto-snapshot/ && /online/ { print $3 }') + # finally, if we're running in a local zone + # we take some additional actions + if [ "$(zonename 2>/dev/null)" != "global" ]; then + reexport_pool + fi + unpack_opts="xv" pack_opts="cf" verbose="v" @@ -214,7 +215,8 @@ else NEWFS_DEFAULT_FS="ufs" SLICE_PREFIX="s" -fi + ;; +esac export unpack_opts pack_opts verbose unpack_preserve pack_preserve \ ZVOL_DEVDIR ZVOL_RDEVDIR DEV_DSKDIR DEV_RDSKDIR DEV_MPATHDIR \ ZEDLET_DIR ZED_LOG ZED_DEBUG_LOG VDEVID_CONF VDEVID_CONF_ETC \ |