summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMatthew Macy <[email protected]>2019-12-18 12:29:43 -0800
committerBrian Behlendorf <[email protected]>2019-12-18 12:29:43 -0800
commit7839c4b5e1e79e29f0df4ec9fe5e1e7182473e47 (patch)
treeef0214b6e757aeb181e54944abffe4e116bbf018 /scripts
parent118fc3ef07c53a88ea1d4c21142a2b01c4648434 (diff)
Update ZTS to work on FreeBSD
Update the common ZTS scripts and individual test cases as needed in order to allow them to be run on FreeBSD. The high level goal is to provide compatibility wrappers whenever possible to minimize changes to individual test cases. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: John Kennedy <[email protected]> Signed-off-by: Matt Macy <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #9692
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/zfs-tests.sh166
1 files changed, 121 insertions, 45 deletions
diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh
index 1610d4a57..bcd115100 100755
--- a/scripts/zfs-tests.sh
+++ b/scripts/zfs-tests.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
#
# CDDL HEADER START
#
@@ -47,10 +47,19 @@ TAGS=""
ITERATIONS=1
ZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
ZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
-ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
-TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
-LOSETUP=${LOSETUP:-/sbin/losetup}
-DMSETUP=${DMSETUP:-/sbin/dmsetup}
+UNAME=$(uname -s)
+
+# Override some defaults if on FreeBSD
+if [ "$UNAME" = "FreeBSD" ] ; then
+ TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
+ LOSETUP=/sbin/mdconfig
+ DMSETUP=/sbin/gpart
+else
+ ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
+ TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
+ LOSETUP=${LOSETUP:-/sbin/losetup}
+ DMSETUP=${DMSETUP:-/sbin/dmsetup}
+fi
#
# Log an informational message when additional verbosity is enabled.
@@ -70,6 +79,33 @@ fail() {
exit 1
}
+cleanup_freebsd_loopback() {
+ for TEST_LOOPBACK in ${LOOPBACKS}; do
+ if [ -c "/dev/${TEST_LOOPBACK}" ]; then
+ sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" ||
+ echo "Failed to destroy: ${TEST_LOOPBACK}"
+ fi
+ done
+}
+
+cleanup_linux_loopback() {
+ for TEST_LOOPBACK in ${LOOPBACKS}; do
+ 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}" ||
+ echo "Failed to remove: ${DM_DEV}"
+ fi
+
+ if [ -n "${TEST_LOOPBACK}" ]; then
+ sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
+ echo "Failed to remove: ${TEST_LOOPBACK}"
+ fi
+ done
+}
+
#
# Attempt to remove loopback devices and files which where created earlier
# by this script to run the test framework. The '-k' option may be passed
@@ -80,22 +116,13 @@ cleanup() {
return 0
fi
- if [ "$LOOPBACK" = "yes" ]; 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)
-
- if [ -n "$DM_DEV" ]; then
- sudo "${DMSETUP}" remove "${DM_DEV}" ||
- echo "Failed to remove: ${DM_DEV}"
- fi
- if [ -n "${TEST_LOOPBACK}" ]; then
- sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
- echo "Failed to remove: ${TEST_LOOPBACK}"
- fi
- done
+ if [ "$LOOPBACK" = "yes" ]; then
+ if [ "$UNAME" = "FreeBSD" ] ; then
+ cleanup_freebsd_loopback
+ else
+ cleanup_linux_loopback
+ fi
fi
for TEST_FILE in ${FILES}; do
@@ -118,7 +145,11 @@ cleanup_all() {
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:)
+ 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=$(ls /var/tmp/file-vdev* 2>/dev/null)
@@ -129,13 +160,19 @@ cleanup_all() {
sudo "$ZPOOL" destroy "${TEST_POOL}"
done
- msg "Removing dm(s): $(sudo "${DMSETUP}" ls |
- grep loop | tr '\n' ' ')"
- sudo "${DMSETUP}" remove_all
+ if [ "$UNAME" != "FreeBSD" ] ; then
+ msg "Removing dm(s): $(sudo "${DMSETUP}" ls |
+ grep loop | tr '\n' ' ')"
+ sudo "${DMSETUP}" remove_all
+ fi
msg "Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
for TEST_LOOPBACK in $TEST_LOOPBACKS; do
- sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
+ if [ "$UNAME" = "FreeBSD" ] ; then
+ sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}"
+ else
+ sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
+ fi
done
msg "Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
@@ -202,6 +239,9 @@ create_links() {
constrain_path() {
. "$STF_SUITE/include/commands.cfg"
+ SYSTEM_DIRS="/bin /sbin /usr/bin /usr/sbin"
+ SYSTEM_DIRS+=" /usr/local/bin /usr/local/sbin"
+
if [ "$INTREE" = "yes" ]; then
# Constrained path set to ./zfs/bin/
STF_PATH="$BIN_DIR"
@@ -224,30 +264,40 @@ constrain_path() {
else
# Constrained path set to /var/tmp/constrained_path.*
SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXX}
- STF_PATH=$(/bin/mktemp -d "$SYSTEMDIR")
+ STF_PATH=$(mktemp -d "$SYSTEMDIR")
STF_PATH_REMOVE="yes"
STF_MISSING_BIN=""
chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
# Special case links for standard zfs utilities
- create_links "/bin /usr/bin /sbin /usr/sbin" "$ZFS_FILES"
+ create_links "$SYSTEM_DIRS" "$ZFS_FILES"
# Special case links for zfs test suite utilities
create_links "$STF_SUITE/bin" "$ZFSTEST_FILES"
fi
# Standard system utilities
- create_links "/bin /usr/bin /sbin /usr/sbin" "$SYSTEM_FILES"
+ SYSTEM_FILES="$SYSTEM_FILES_COMMON"
+ if [ "$UNAME" = "FreeBSD" ] ; then
+ SYSTEM_FILES+=" $SYSTEM_FILES_FREEBSD"
+ else
+ SYSTEM_FILES+=" $SYSTEM_FILES_LINUX"
+ fi
+ create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
# Exceptions
ln -fs "$STF_PATH/awk" "$STF_PATH/nawk"
- ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
- ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
- ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
- ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
- ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
- ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
+ if [ "$UNAME" = "Linux" ] ; then
+ ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
+ ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
+ ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
+ ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
+ ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
+ ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
+ elif [ "$UNAME" = "FreeBSD" ] ; then
+ ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
+ fi
if [ -L "$STF_PATH/arc_summary3" ]; then
ln -fs "$STF_PATH/arc_summary3" "$STF_PATH/arc_summary"
@@ -466,6 +516,9 @@ constrain_path
#
# Check if ksh exists
#
+if [ "$UNAME" = "FreeBSD" ]; then
+ sudo ln -fs /usr/local/bin/ksh93 /bin/ksh
+fi
[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
[ -e "$STF_SUITE/include/default.cfg" ] || fail \
"Missing $STF_SUITE/include/default.cfg file."
@@ -509,7 +562,11 @@ fi
#
# See libzfs/libzfs_config.c for more information.
#
-__ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
+if [ "$UNAME" = "FreeBSD" ] ; then
+ __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | tr -s '\n' ' ')"
+else
+ __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
+fi
. "$STF_SUITE/include/default.cfg"
@@ -549,15 +606,28 @@ if [ -z "${DISKS}" ]; then
test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
for TEST_FILE in ${FILES}; do
- 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"
+ if [ "$UNAME" = "FreeBSD" ] ; then
+ MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}")
+ if [ -z "$MDDEVICE" ] ; then
+ fail "Failed: ${TEST_FILE} -> loopback"
+ fi
+ LOOPBACKS="${LOOPBACKS}${MDDEVICE} "
+ if [[ "$DISKS" ]]; then
+ DISKS="$DISKS $MDDEVICE"
+ else
+ DISKS="$MDDEVICE"
+ fi
else
- DISKS="$BASELOOPBACKS"
+ 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
fi
done
fi
@@ -604,8 +674,14 @@ export __ZFS_POOL_EXCLUDE
export TESTFAIL_CALLBACKS
export PATH=$STF_PATH
-RESULTS_FILE=$(mktemp -u -t zts-results.XXXX -p "$FILEDIR")
-REPORT_FILE=$(mktemp -u -t zts-report.XXXX -p "$FILEDIR")
+if [ "$UNAME" = "FreeBSD" ] ; then
+ mkdir -p "$FILEDIR" || true
+ RESULTS_FILE=$(mktemp -u "${FILEDIR}/zts-results.XXXX")
+ REPORT_FILE=$(mktemp -u "${FILEDIR}/zts-report.XXXX")
+else
+ RESULTS_FILE=$(mktemp -u -t zts-results.XXXX -p "$FILEDIR")
+ REPORT_FILE=$(mktemp -u -t zts-report.XXXX -p "$FILEDIR")
+fi
#
# Run all the tests as specified.