xref: /freebsd/sys/contrib/openzfs/scripts/zfs-tests.sh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
17a7741afSMartin Matuska#!/usr/bin/env bash
2*61145dc2SMartin Matuska# SPDX-License-Identifier: CDDL-1.0
3e92ffd9bSMartin Matuska# shellcheck disable=SC2154
47a7741afSMartin Matuska# shellcheck disable=SC2292
5eda14cbcSMatt Macy#
6eda14cbcSMatt Macy# CDDL HEADER START
7eda14cbcSMatt Macy#
8eda14cbcSMatt Macy# The contents of this file are subject to the terms of the
9eda14cbcSMatt Macy# Common Development and Distribution License, Version 1.0 only
10eda14cbcSMatt Macy# (the "License").  You may not use this file except in compliance
11eda14cbcSMatt Macy# with the License.
12eda14cbcSMatt Macy#
13eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0.
15eda14cbcSMatt Macy# See the License for the specific language governing permissions
16eda14cbcSMatt Macy# and limitations under the License.
17eda14cbcSMatt Macy#
18eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each
19eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the
21eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying
22eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner]
23eda14cbcSMatt Macy#
24eda14cbcSMatt Macy# CDDL HEADER END
25eda14cbcSMatt Macy#
26eda14cbcSMatt Macy
27681ce946SMartin Matuska#
28681ce946SMartin Matuska# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
29681ce946SMartin Matuska#
30681ce946SMartin Matuska
31716fd348SMartin MatuskaSCRIPT_COMMON=${SCRIPT_COMMON:-${0%/*}/common.sh}
32716fd348SMartin Matuska. "${SCRIPT_COMMON}" || exit
33eda14cbcSMatt Macy
34eda14cbcSMatt MacyPROG=zfs-tests.sh
35eda14cbcSMatt MacyVERBOSE="no"
36eda14cbcSMatt MacyQUIET=""
370d4ad640SMartin MatuskaDEBUG=""
38eda14cbcSMatt MacyCLEANUP="yes"
39eda14cbcSMatt MacyCLEANUPALL="no"
40da5137abSMartin MatuskaKMSG=""
41eda14cbcSMatt MacyLOOPBACK="yes"
42eda14cbcSMatt MacySTACK_TRACER="no"
43eda14cbcSMatt MacyFILESIZE="4G"
44eda14cbcSMatt MacyDEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
45eda14cbcSMatt MacyRUNFILES=${RUNFILES:-$DEFAULT_RUNFILES}
46eda14cbcSMatt MacyFILEDIR=${FILEDIR:-/var/tmp}
47eda14cbcSMatt MacyDISKS=${DISKS:-""}
48eda14cbcSMatt MacySINGLETEST=""
49eda14cbcSMatt MacySINGLETESTUSER="root"
50eda14cbcSMatt MacyTAGS=""
51eda14cbcSMatt MacyITERATIONS=1
52eda14cbcSMatt MacyZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
53eda14cbcSMatt MacyZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
54716fd348SMartin MatuskaUNAME=$(uname)
55681ce946SMartin MatuskaRERUN=""
56c03c5b1cSMartin MatuskaKMEMLEAK=""
57eda14cbcSMatt Macy
58eda14cbcSMatt Macy# Override some defaults if on FreeBSD
59eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then
60eda14cbcSMatt Macy	TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
61eda14cbcSMatt Macy	LOSETUP=/sbin/mdconfig
62eda14cbcSMatt Macy	DMSETUP=/sbin/gpart
63eda14cbcSMatt Macyelse
64eda14cbcSMatt Macy	ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
65eda14cbcSMatt Macy	TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
66eda14cbcSMatt Macy	LOSETUP=${LOSETUP:-/sbin/losetup}
67eda14cbcSMatt Macy	DMSETUP=${DMSETUP:-/sbin/dmsetup}
68eda14cbcSMatt Macyfi
69eda14cbcSMatt Macy
70eda14cbcSMatt Macy#
71eda14cbcSMatt Macy# Log an informational message when additional verbosity is enabled.
72eda14cbcSMatt Macy#
73eda14cbcSMatt Macymsg() {
74eda14cbcSMatt Macy	if [ "$VERBOSE" = "yes" ]; then
75eda14cbcSMatt Macy		echo "$@"
76eda14cbcSMatt Macy	fi
77eda14cbcSMatt Macy}
78eda14cbcSMatt Macy
79eda14cbcSMatt Macy#
80eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error.
81eda14cbcSMatt Macy#
82eda14cbcSMatt Macyfail() {
83eda14cbcSMatt Macy	echo "$PROG: $1" >&2
84eda14cbcSMatt Macy	cleanup
85eda14cbcSMatt Macy	exit 1
86eda14cbcSMatt Macy}
87eda14cbcSMatt Macy
88eda14cbcSMatt Macycleanup_freebsd_loopback() {
89eda14cbcSMatt Macy	for TEST_LOOPBACK in ${LOOPBACKS}; do
90eda14cbcSMatt Macy		if [ -c "/dev/${TEST_LOOPBACK}" ]; then
91eda14cbcSMatt Macy			sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" ||
92eda14cbcSMatt Macy			    echo "Failed to destroy: ${TEST_LOOPBACK}"
93eda14cbcSMatt Macy		fi
94eda14cbcSMatt Macy	done
95eda14cbcSMatt Macy}
96eda14cbcSMatt Macy
97eda14cbcSMatt Macycleanup_linux_loopback() {
98eda14cbcSMatt Macy	for TEST_LOOPBACK in ${LOOPBACKS}; do
99dae17134SMartin Matuska		LOOP_DEV="${TEST_LOOPBACK##*/}"
100eda14cbcSMatt Macy		DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \
101716fd348SMartin Matuska		    awk -v l="${LOOP_DEV}" '$0 ~ l {print $1}')
102eda14cbcSMatt Macy
103eda14cbcSMatt Macy		if [ -n "$DM_DEV" ]; then
104eda14cbcSMatt Macy			sudo "${DMSETUP}" remove "${DM_DEV}" ||
105eda14cbcSMatt Macy			    echo "Failed to remove: ${DM_DEV}"
106eda14cbcSMatt Macy		fi
107eda14cbcSMatt Macy
108eda14cbcSMatt Macy		if [ -n "${TEST_LOOPBACK}" ]; then
109eda14cbcSMatt Macy			sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
110eda14cbcSMatt Macy			    echo "Failed to remove: ${TEST_LOOPBACK}"
111eda14cbcSMatt Macy		fi
112eda14cbcSMatt Macy	done
113eda14cbcSMatt Macy}
114eda14cbcSMatt Macy
115eda14cbcSMatt Macy#
116eda14cbcSMatt Macy# Attempt to remove loopback devices and files which where created earlier
117eda14cbcSMatt Macy# by this script to run the test framework.  The '-k' option may be passed
118eda14cbcSMatt Macy# to the script to suppress cleanup for debugging purposes.
119eda14cbcSMatt Macy#
120eda14cbcSMatt Macycleanup() {
121eda14cbcSMatt Macy	if [ "$CLEANUP" = "no" ]; then
122eda14cbcSMatt Macy		return 0
123eda14cbcSMatt Macy	fi
124eda14cbcSMatt Macy
125eda14cbcSMatt Macy
126eda14cbcSMatt Macy	if [ "$LOOPBACK" = "yes" ]; then
127eda14cbcSMatt Macy		if [ "$UNAME" = "FreeBSD" ] ; then
128eda14cbcSMatt Macy			cleanup_freebsd_loopback
129eda14cbcSMatt Macy		else
130eda14cbcSMatt Macy			cleanup_linux_loopback
131eda14cbcSMatt Macy		fi
132eda14cbcSMatt Macy	fi
133eda14cbcSMatt Macy
134716fd348SMartin Matuska	# shellcheck disable=SC2086
135716fd348SMartin Matuska	rm -f ${FILES} >/dev/null 2>&1
136eda14cbcSMatt Macy
137eda14cbcSMatt Macy	if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
138eda14cbcSMatt Macy		rm -Rf "$STF_PATH"
139eda14cbcSMatt Macy	fi
140eda14cbcSMatt Macy}
141eda14cbcSMatt Macytrap cleanup EXIT
142eda14cbcSMatt Macy
143eda14cbcSMatt Macy#
144eda14cbcSMatt Macy# Attempt to remove all testpools (testpool.XXX), unopened dm devices,
145eda14cbcSMatt Macy# loopback devices, and files.  This is a useful way to cleanup a previous
146eda14cbcSMatt Macy# test run failure which has left the system in an unknown state.  This can
147eda14cbcSMatt Macy# be dangerous and should only be used in a dedicated test environment.
148eda14cbcSMatt Macy#
149eda14cbcSMatt Macycleanup_all() {
150716fd348SMartin Matuska	TEST_POOLS=$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | grep testpool)
151eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ] ; then
152eda14cbcSMatt Macy		TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l)
153eda14cbcSMatt Macy	else
154716fd348SMartin Matuska		TEST_LOOPBACKS=$("${LOSETUP}" -a | awk -F: '/file-vdev/ {print $1}')
155eda14cbcSMatt Macy	fi
156d2a8fad3SMartin Matuska	TEST_FILES=$(ls "${FILEDIR}"/file-vdev* 2>/dev/null)
157eda14cbcSMatt Macy
158eda14cbcSMatt Macy	msg
159eda14cbcSMatt Macy	msg "--- Cleanup ---"
160716fd348SMartin Matuska	# shellcheck disable=2116,2086
161716fd348SMartin Matuska	msg "Removing pool(s):     $(echo ${TEST_POOLS})"
162eda14cbcSMatt Macy	for TEST_POOL in $TEST_POOLS; do
163c03c5b1cSMartin Matuska		sudo env ASAN_OPTIONS=detect_leaks=false "$ZPOOL" destroy "${TEST_POOL}"
164eda14cbcSMatt Macy	done
165eda14cbcSMatt Macy
166eda14cbcSMatt Macy	if [ "$UNAME" != "FreeBSD" ] ; then
167716fd348SMartin Matuska		msg "Removing all dm(s):   $(sudo "${DMSETUP}" ls |
168eda14cbcSMatt Macy		    grep loop | tr '\n' ' ')"
169eda14cbcSMatt Macy		sudo "${DMSETUP}" remove_all
170eda14cbcSMatt Macy	fi
171eda14cbcSMatt Macy
172716fd348SMartin Matuska	# shellcheck disable=2116,2086
173716fd348SMartin Matuska	msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS})"
174eda14cbcSMatt Macy	for TEST_LOOPBACK in $TEST_LOOPBACKS; do
175eda14cbcSMatt Macy		if [ "$UNAME" = "FreeBSD" ] ; then
176eda14cbcSMatt Macy			sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}"
177eda14cbcSMatt Macy		else
178eda14cbcSMatt Macy			sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
179eda14cbcSMatt Macy		fi
180eda14cbcSMatt Macy	done
181eda14cbcSMatt Macy
182716fd348SMartin Matuska	# shellcheck disable=2116,2086
183716fd348SMartin Matuska	msg "Removing files(s):    $(echo ${TEST_FILES})"
184716fd348SMartin Matuska	# shellcheck disable=2086
185716fd348SMartin Matuska	sudo rm -f ${TEST_FILES}
186eda14cbcSMatt Macy}
187eda14cbcSMatt Macy
188eda14cbcSMatt Macy#
189eda14cbcSMatt Macy# Takes a name as the only arguments and looks for the following variations
190eda14cbcSMatt Macy# on that name.  If one is found it is returned.
191eda14cbcSMatt Macy#
192eda14cbcSMatt Macy# $RUNFILE_DIR/<name>
193eda14cbcSMatt Macy# $RUNFILE_DIR/<name>.run
194eda14cbcSMatt Macy# <name>
195eda14cbcSMatt Macy# <name>.run
196eda14cbcSMatt Macy#
197eda14cbcSMatt Macyfind_runfile() {
198eda14cbcSMatt Macy	NAME=$1
199eda14cbcSMatt Macy
200eda14cbcSMatt Macy	if [ -f "$RUNFILE_DIR/$NAME" ]; then
201716fd348SMartin Matuska		echo "$RUNFILE_DIR/$NAME"
202eda14cbcSMatt Macy	elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then
203716fd348SMartin Matuska		echo "$RUNFILE_DIR/$NAME.run"
204eda14cbcSMatt Macy	elif [ -f "$NAME" ]; then
205716fd348SMartin Matuska		echo "$NAME"
206eda14cbcSMatt Macy	elif [ -f "$NAME.run" ]; then
207716fd348SMartin Matuska		echo "$NAME.run"
208716fd348SMartin Matuska	else
209716fd348SMartin Matuska		return 1
210eda14cbcSMatt Macy	fi
211eda14cbcSMatt Macy}
212eda14cbcSMatt Macy
2137a7741afSMartin Matuska# Given a TAGS with a format like "1/3" or "2/3" then divide up the test list
2147a7741afSMartin Matuska# into portions and print that portion.  So "1/3" for "the first third of the
2157a7741afSMartin Matuska# test tags".
2167a7741afSMartin Matuska#
2177a7741afSMartin Matuska#
2187a7741afSMartin Matuskasplit_tags() {
2197a7741afSMartin Matuska	# Get numerator and denominator
2207a7741afSMartin Matuska	NUM=$(echo "$TAGS" | cut -d/ -f1)
2217a7741afSMartin Matuska	DEN=$(echo "$TAGS" | cut -d/ -f2)
2227a7741afSMartin Matuska	# At the point this is called, RUNFILES will contain a comma separated
2237a7741afSMartin Matuska	# list of full paths to the runfiles, like:
2247a7741afSMartin Matuska	#
2257a7741afSMartin Matuska	# "/home/hutter/qemu/tests/runfiles/common.run,/home/hutter/qemu/tests/runfiles/linux.run"
2267a7741afSMartin Matuska	#
2277a7741afSMartin Matuska	# So to get tags for our selected tests we do:
2287a7741afSMartin Matuska	#
2297a7741afSMartin Matuska	# 1. Remove unneeded chars: [],\
2307a7741afSMartin Matuska	# 2. Print out the last field of each tag line.  This will be the tag
2317a7741afSMartin Matuska	#    for the test (like 'zpool_add').
2327a7741afSMartin Matuska	# 3. Remove duplicates between the runfiles.  If the same tag is defined
2337a7741afSMartin Matuska	#    in multiple runfiles, then when you do '-T <tag>' ZTS is smart
2347a7741afSMartin Matuska	#    enough to know to run the tag in each runfile.  So '-T zpool_add'
2357a7741afSMartin Matuska	#    will run the zpool_add from common.run and linux.run.
2367a7741afSMartin Matuska	# 4. Ignore the 'functional' tag since we only want individual tests
2377a7741afSMartin Matuska	# 5. Print out the tests in our faction of all tests.  This uses modulus
2387a7741afSMartin Matuska	#    so "1/3" will run tests 1,3,6,9 etc.  That way the tests are
2397a7741afSMartin Matuska	#    interleaved so, say, "3/4" isn't running all the zpool_* tests that
2407a7741afSMartin Matuska	#    appear alphabetically at the end.
2417a7741afSMartin Matuska	# 6. Remove trailing comma from list
2427a7741afSMartin Matuska	#
2437a7741afSMartin Matuska	# TAGS will then look like:
2447a7741afSMartin Matuska	#
2457a7741afSMartin Matuska	# "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..."
2467a7741afSMartin Matuska
2477a7741afSMartin Matuska	# Change the comma to a space for easy processing
2487a7741afSMartin Matuska	_RUNFILES=${RUNFILES//","/" "}
2497a7741afSMartin Matuska	# shellcheck disable=SC2002,SC2086
2507a7741afSMartin Matuska	cat $_RUNFILES | tr -d "[],\'" | awk '/tags = /{print $NF}' | sort | \
2517a7741afSMartin Matuska		uniq | grep -v functional | \
2527a7741afSMartin Matuska		awk -v num="$NUM" -v den="$DEN" '{ if(NR % den == (num - 1)) {printf "%s,",$0}}' | \
2537a7741afSMartin Matuska		sed -E 's/,$//'
2547a7741afSMartin Matuska}
2557a7741afSMartin Matuska
256eda14cbcSMatt Macy#
257eda14cbcSMatt Macy# Symlink file if it appears under any of the given paths.
258eda14cbcSMatt Macy#
259eda14cbcSMatt Macycreate_links() {
260eda14cbcSMatt Macy	dir_list="$1"
261eda14cbcSMatt Macy	file_list="$2"
262eda14cbcSMatt Macy
263eda14cbcSMatt Macy	[ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set"
264eda14cbcSMatt Macy
265eda14cbcSMatt Macy	for i in $file_list; do
266eda14cbcSMatt Macy		for j in $dir_list; do
267eda14cbcSMatt Macy			[ ! -e "$STF_PATH/$i" ] || continue
268eda14cbcSMatt Macy
269eda14cbcSMatt Macy			if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then
270eda14cbcSMatt Macy				ln -sf "$j/$i" "$STF_PATH/$i" || \
271eda14cbcSMatt Macy				    fail "Couldn't link $i"
272eda14cbcSMatt Macy				break
273eda14cbcSMatt Macy			fi
274eda14cbcSMatt Macy		done
275eda14cbcSMatt Macy
276eda14cbcSMatt Macy		[ ! -e "$STF_PATH/$i" ] && \
277eda14cbcSMatt Macy		    STF_MISSING_BIN="$STF_MISSING_BIN $i"
278eda14cbcSMatt Macy	done
279eda14cbcSMatt Macy	STF_MISSING_BIN=${STF_MISSING_BIN# }
280eda14cbcSMatt Macy}
281eda14cbcSMatt Macy
282eda14cbcSMatt Macy#
283eda14cbcSMatt Macy# Constrain the path to limit the available binaries to a known set.
284eda14cbcSMatt Macy# When running in-tree a top level ./bin/ directory is created for
285eda14cbcSMatt Macy# convenience, otherwise a temporary directory is used.
286eda14cbcSMatt Macy#
287eda14cbcSMatt Macyconstrain_path() {
288eda14cbcSMatt Macy	. "$STF_SUITE/include/commands.cfg"
289eda14cbcSMatt Macy
290eda14cbcSMatt Macy	# On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils
291eda14cbcSMatt Macy	# install to /usr/local/sbin. To avoid testing the wrong utils we
292eda14cbcSMatt Macy	# need /usr/local to come before / in the path search order.
293eda14cbcSMatt Macy	SYSTEM_DIRS="/usr/local/bin /usr/local/sbin"
2947877fdebSMatt Macy	SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin $LIBEXEC_DIR"
295eda14cbcSMatt Macy
296eda14cbcSMatt Macy	if [ "$INTREE" = "yes" ]; then
297716fd348SMartin Matuska		# Constrained path set to $(top_builddir)/tests/zfs-tests/bin
298eda14cbcSMatt Macy		STF_PATH="$BIN_DIR"
299eda14cbcSMatt Macy		STF_PATH_REMOVE="no"
300eda14cbcSMatt Macy		STF_MISSING_BIN=""
301eda14cbcSMatt Macy		if [ ! -d "$STF_PATH" ]; then
302eda14cbcSMatt Macy			mkdir "$STF_PATH"
303eda14cbcSMatt Macy			chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
304eda14cbcSMatt Macy		fi
305eda14cbcSMatt Macy
306eda14cbcSMatt Macy		# Special case links for standard zfs utilities
307716fd348SMartin Matuska		create_links "$CMD_DIR" "$ZFS_FILES"
308eda14cbcSMatt Macy
309eda14cbcSMatt Macy		# Special case links for zfs test suite utilities
310716fd348SMartin Matuska		create_links "$CMD_DIR/tests/zfs-tests/cmd" "$ZFSTEST_FILES"
311eda14cbcSMatt Macy	else
312d2a8fad3SMartin Matuska		# Constrained path set to $FILEDIR/constrained_path.*
313d2a8fad3SMartin Matuska		SYSTEMDIR=${SYSTEMDIR:-$FILEDIR/constrained_path.XXXXXX}
314eda14cbcSMatt Macy		STF_PATH=$(mktemp -d "$SYSTEMDIR")
315eda14cbcSMatt Macy		STF_PATH_REMOVE="yes"
316eda14cbcSMatt Macy		STF_MISSING_BIN=""
317eda14cbcSMatt Macy
318eda14cbcSMatt Macy		chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
319eda14cbcSMatt Macy
320eda14cbcSMatt Macy		# Special case links for standard zfs utilities
321eda14cbcSMatt Macy		create_links "$SYSTEM_DIRS" "$ZFS_FILES"
322eda14cbcSMatt Macy
323eda14cbcSMatt Macy		# Special case links for zfs test suite utilities
324eda14cbcSMatt Macy		create_links "$STF_SUITE/bin" "$ZFSTEST_FILES"
325eda14cbcSMatt Macy	fi
326eda14cbcSMatt Macy
327eda14cbcSMatt Macy	# Standard system utilities
328eda14cbcSMatt Macy	SYSTEM_FILES="$SYSTEM_FILES_COMMON"
329eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ] ; then
330eda14cbcSMatt Macy		SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD"
331eda14cbcSMatt Macy	else
332eda14cbcSMatt Macy		SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX"
333eda14cbcSMatt Macy	fi
334eda14cbcSMatt Macy	create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
335eda14cbcSMatt Macy
336eda14cbcSMatt Macy	# Exceptions
337eda14cbcSMatt Macy	if [ "$UNAME" = "Linux" ] ; then
338eda14cbcSMatt Macy		ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
339eda14cbcSMatt Macy		ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
340eda14cbcSMatt Macy		ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
341eda14cbcSMatt Macy		ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
342eda14cbcSMatt Macy	elif [ "$UNAME" = "FreeBSD" ] ; then
343eda14cbcSMatt Macy		ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
344eda14cbcSMatt Macy	fi
345eda14cbcSMatt Macy}
346eda14cbcSMatt Macy
347eda14cbcSMatt Macy#
348eda14cbcSMatt Macy# Output a useful usage message.
349eda14cbcSMatt Macy#
350eda14cbcSMatt Macyusage() {
351eda14cbcSMatt Macycat << EOF
352eda14cbcSMatt MacyUSAGE:
3532c48331dSMatt Macy$0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER]
354eda14cbcSMatt Macy
355eda14cbcSMatt MacyDESCRIPTION:
356eda14cbcSMatt Macy	ZFS Test Suite launch script
357eda14cbcSMatt Macy
358eda14cbcSMatt MacyOPTIONS:
359eda14cbcSMatt Macy	-h          Show this message
360eda14cbcSMatt Macy	-v          Verbose zfs-tests.sh output
361eda14cbcSMatt Macy	-q          Quiet test-runner output
3620d4ad640SMartin Matuska	-D          Debug; show all test output immediately (noisy)
363eda14cbcSMatt Macy	-x          Remove all testpools, dm, lo, and files (unsafe)
364eda14cbcSMatt Macy	-k          Disable cleanup after test failure
365da5137abSMartin Matuska	-K          Log test names to /dev/kmsg
366eda14cbcSMatt Macy	-f          Use files only, disables block device tests
367eda14cbcSMatt Macy	-S          Enable stack tracer (negative performance impact)
368eda14cbcSMatt Macy	-c          Only create and populate constrained path
369681ce946SMartin Matuska	-R          Automatically rerun failing tests
370c03c5b1cSMartin Matuska	-m          Enable kmemleak reporting (Linux only)
371eda14cbcSMatt Macy	-n NFSFILE  Use the nfsfile to determine the NFS configuration
372eda14cbcSMatt Macy	-I NUM      Number of iterations
373716fd348SMartin Matuska	-d DIR      Use world-writable DIR for files and loopback devices
374eda14cbcSMatt Macy	-s SIZE     Use vdevs of SIZE (default: 4G)
375eda14cbcSMatt Macy	-r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES})
3761719886fSMartin Matuska	-t PATH|NAME  Run single test at PATH relative to test suite,
3771719886fSMartin Matuska	                or search for test by NAME
378eda14cbcSMatt Macy	-T TAGS     Comma separated list of tags (default: 'functional')
3797a7741afSMartin Matuska	            Alternately, specify a fraction like "1/3" or "2/3" to
3807a7741afSMartin Matuska		     run the first third of tests or 2nd third of the tests.  This
3817a7741afSMartin Matuska		     is useful for splitting up the test amongst different
3827a7741afSMartin Matuska		     runners.
383eda14cbcSMatt Macy	-u USER     Run single test as USER (default: root)
384eda14cbcSMatt Macy
385eda14cbcSMatt MacyEXAMPLES:
3867a7741afSMartin Matuska# Run the default ${DEFAULT_RUNFILES//\.run/} suite of tests and output the configuration used.
387eda14cbcSMatt Macy$0 -v
388eda14cbcSMatt Macy
389eda14cbcSMatt Macy# Run a smaller suite of tests designed to run more quickly.
390eda14cbcSMatt Macy$0 -r linux-fast
391eda14cbcSMatt Macy
392eda14cbcSMatt Macy# Run a single test
393eda14cbcSMatt Macy$0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh
394eda14cbcSMatt Macy
3951719886fSMartin Matuska# Run a single test by name
3961719886fSMartin Matuska$0 -t zfs_bookmark_cliargs
3971719886fSMartin Matuska
398eda14cbcSMatt Macy# Cleanup a previous run of the test suite prior to testing, run the
3997a7741afSMartin Matuska# default ${DEFAULT_RUNFILES//\.run//} suite of tests and perform no cleanup on exit.
400eda14cbcSMatt Macy$0 -x
401eda14cbcSMatt Macy
402eda14cbcSMatt MacyEOF
403eda14cbcSMatt Macy}
404eda14cbcSMatt Macy
4050d4ad640SMartin Matuskawhile getopts 'hvqxkKfScRmn:d:Ds:r:?t:T:u:I:' OPTION; do
406eda14cbcSMatt Macy	case $OPTION in
407eda14cbcSMatt Macy	h)
408eda14cbcSMatt Macy		usage
409eda14cbcSMatt Macy		exit 1
410eda14cbcSMatt Macy		;;
411eda14cbcSMatt Macy	v)
412eda14cbcSMatt Macy		VERBOSE="yes"
413eda14cbcSMatt Macy		;;
414eda14cbcSMatt Macy	q)
415eda14cbcSMatt Macy		QUIET="yes"
416eda14cbcSMatt Macy		;;
417eda14cbcSMatt Macy	x)
418eda14cbcSMatt Macy		CLEANUPALL="yes"
419eda14cbcSMatt Macy		;;
420eda14cbcSMatt Macy	k)
421eda14cbcSMatt Macy		CLEANUP="no"
422eda14cbcSMatt Macy		;;
423da5137abSMartin Matuska	K)
424da5137abSMartin Matuska		KMSG="yes"
425da5137abSMartin Matuska		;;
426eda14cbcSMatt Macy	f)
427eda14cbcSMatt Macy		LOOPBACK="no"
428eda14cbcSMatt Macy		;;
429eda14cbcSMatt Macy	S)
430eda14cbcSMatt Macy		STACK_TRACER="yes"
431eda14cbcSMatt Macy		;;
432eda14cbcSMatt Macy	c)
433eda14cbcSMatt Macy		constrain_path
434eda14cbcSMatt Macy		exit
435eda14cbcSMatt Macy		;;
436681ce946SMartin Matuska	R)
437681ce946SMartin Matuska		RERUN="yes"
438681ce946SMartin Matuska		;;
439c03c5b1cSMartin Matuska	m)
440c03c5b1cSMartin Matuska		KMEMLEAK="yes"
441c03c5b1cSMartin Matuska		;;
442eda14cbcSMatt Macy	n)
443eda14cbcSMatt Macy		nfsfile=$OPTARG
444eda14cbcSMatt Macy		[ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile"
445eda14cbcSMatt Macy		export NFS=1
446eda14cbcSMatt Macy		. "$nfsfile"
447eda14cbcSMatt Macy		;;
448eda14cbcSMatt Macy	d)
449eda14cbcSMatt Macy		FILEDIR="$OPTARG"
450eda14cbcSMatt Macy		;;
4510d4ad640SMartin Matuska	D)
4520d4ad640SMartin Matuska		DEBUG="yes"
4530d4ad640SMartin Matuska		;;
454eda14cbcSMatt Macy	I)
455eda14cbcSMatt Macy		ITERATIONS="$OPTARG"
456eda14cbcSMatt Macy		if [ "$ITERATIONS" -le 0 ]; then
457eda14cbcSMatt Macy			fail "Iterations must be greater than 0."
458eda14cbcSMatt Macy		fi
459eda14cbcSMatt Macy		;;
460eda14cbcSMatt Macy	s)
461eda14cbcSMatt Macy		FILESIZE="$OPTARG"
462eda14cbcSMatt Macy		;;
463eda14cbcSMatt Macy	r)
464eda14cbcSMatt Macy		RUNFILES="$OPTARG"
465eda14cbcSMatt Macy		;;
466eda14cbcSMatt Macy	t)
467eda14cbcSMatt Macy		if [ -n "$SINGLETEST" ]; then
468eda14cbcSMatt Macy			fail "-t can only be provided once."
469eda14cbcSMatt Macy		fi
470eda14cbcSMatt Macy		SINGLETEST="$OPTARG"
471eda14cbcSMatt Macy		;;
472eda14cbcSMatt Macy	T)
473eda14cbcSMatt Macy		TAGS="$OPTARG"
474eda14cbcSMatt Macy		;;
475eda14cbcSMatt Macy	u)
476eda14cbcSMatt Macy		SINGLETESTUSER="$OPTARG"
477eda14cbcSMatt Macy		;;
478eda14cbcSMatt Macy	?)
479eda14cbcSMatt Macy		usage
480eda14cbcSMatt Macy		exit
481eda14cbcSMatt Macy		;;
482e92ffd9bSMartin Matuska	*)
483e92ffd9bSMartin Matuska		;;
484eda14cbcSMatt Macy	esac
485eda14cbcSMatt Macydone
486eda14cbcSMatt Macy
487eda14cbcSMatt Macyshift $((OPTIND-1))
488eda14cbcSMatt Macy
489eda14cbcSMatt MacyFILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
490eda14cbcSMatt MacyLOOPBACKS=${LOOPBACKS:-""}
491eda14cbcSMatt Macy
492eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then
493eda14cbcSMatt Macy	if [ -n "$TAGS" ]; then
494eda14cbcSMatt Macy		fail "-t and -T are mutually exclusive."
495eda14cbcSMatt Macy	fi
496d2a8fad3SMartin Matuska	RUNFILE_DIR="$FILEDIR"
497eda14cbcSMatt Macy	RUNFILES="zfs-tests.$$.run"
498716fd348SMartin Matuska	[ -n "$QUIET" ] && SINGLEQUIET="True" || SINGLEQUIET="False"
499eda14cbcSMatt Macy
500e92ffd9bSMartin Matuska	cat >"${RUNFILE_DIR}/${RUNFILES}" << EOF
501eda14cbcSMatt Macy[DEFAULT]
502eda14cbcSMatt Macypre =
503eda14cbcSMatt Macyquiet = $SINGLEQUIET
504eda14cbcSMatt Macypre_user = root
505eda14cbcSMatt Macyuser = $SINGLETESTUSER
506eda14cbcSMatt Macytimeout = 600
507eda14cbcSMatt Macypost_user = root
508eda14cbcSMatt Macypost =
509eda14cbcSMatt MacyEOF
5101719886fSMartin Matuska	if [ "$SINGLETEST" = "${SINGLETEST%/*}" ] ; then
5111719886fSMartin Matuska		NEWSINGLETEST=$(find "$STF_SUITE" -name "$SINGLETEST*" -print -quit)
5121719886fSMartin Matuska		if [ -z "$NEWSINGLETEST" ] ; then
5131719886fSMartin Matuska			fail "couldn't find test matching '$SINGLETEST'"
5141719886fSMartin Matuska		fi
5151719886fSMartin Matuska		SINGLETEST=$NEWSINGLETEST
5161719886fSMartin Matuska	fi
517eda14cbcSMatt Macy
5181719886fSMartin Matuska	SINGLETESTDIR="${SINGLETEST%/*}"
519716fd348SMartin Matuska	SETUPDIR="$SINGLETESTDIR"
520716fd348SMartin Matuska	[ "${SETUPDIR#/}" = "$SETUPDIR" ] && SETUPDIR="$STF_SUITE/$SINGLETESTDIR"
521716fd348SMartin Matuska	[ -x "$SETUPDIR/setup.ksh"   ] && SETUPSCRIPT="setup"     || SETUPSCRIPT=
522716fd348SMartin Matuska	[ -x "$SETUPDIR/cleanup.ksh" ] && CLEANUPSCRIPT="cleanup" || CLEANUPSCRIPT=
523eda14cbcSMatt Macy
524716fd348SMartin Matuska	SINGLETESTFILE="${SINGLETEST##*/}"
525e92ffd9bSMartin Matuska	cat >>"${RUNFILE_DIR}/${RUNFILES}" << EOF
526eda14cbcSMatt Macy
527eda14cbcSMatt Macy[$SINGLETESTDIR]
528eda14cbcSMatt Macytests = ['$SINGLETESTFILE']
529eda14cbcSMatt Macypre = $SETUPSCRIPT
530eda14cbcSMatt Macypost = $CLEANUPSCRIPT
531eda14cbcSMatt Macytags = ['functional']
532eda14cbcSMatt MacyEOF
533eda14cbcSMatt Macyfi
534eda14cbcSMatt Macy
535eda14cbcSMatt Macy#
536eda14cbcSMatt Macy# Use default tag if none was specified
537eda14cbcSMatt Macy#
538eda14cbcSMatt MacyTAGS=${TAGS:='functional'}
539eda14cbcSMatt Macy
5407a7741afSMartin Matuska
5417a7741afSMartin Matuska
542eda14cbcSMatt Macy#
543eda14cbcSMatt Macy# Attempt to locate the runfiles describing the test workload.
544eda14cbcSMatt Macy#
545eda14cbcSMatt MacyR=""
546eda14cbcSMatt MacyIFS=,
547eda14cbcSMatt Macyfor RUNFILE in $RUNFILES; do
548eda14cbcSMatt Macy	if [ -n "$RUNFILE" ]; then
549eda14cbcSMatt Macy		SAVED_RUNFILE="$RUNFILE"
550716fd348SMartin Matuska		RUNFILE=$(find_runfile "$RUNFILE") ||
551716fd348SMartin Matuska			fail "Cannot find runfile: $SAVED_RUNFILE"
552eda14cbcSMatt Macy		R="$R,$RUNFILE"
553eda14cbcSMatt Macy	fi
554eda14cbcSMatt Macy
555eda14cbcSMatt Macy	if [ ! -r "$RUNFILE" ]; then
556eda14cbcSMatt Macy		fail "Cannot read runfile: $RUNFILE"
557eda14cbcSMatt Macy	fi
558eda14cbcSMatt Macydone
559eda14cbcSMatt Macyunset IFS
560eda14cbcSMatt MacyRUNFILES=${R#,}
561eda14cbcSMatt Macy
5627a7741afSMartin Matuska# The tag can be a fraction to indicate which portion of ZTS to run, Like
5637a7741afSMartin Matuska#
5647a7741afSMartin Matuska# 	"1/3": Run first one third of all tests in runfiles
5657a7741afSMartin Matuska#	"2/3": Run second one third of all test in runfiles
5667a7741afSMartin Matuska#	"6/10": Run 6th tenth of all tests in runfiles
5677a7741afSMartin Matuska#
5687a7741afSMartin Matuska# This is useful for splitting up the test across multiple runners.
5697a7741afSMartin Matuska#
5707a7741afSMartin Matuska# After this code block, TAGS will be transformed from something like
5717a7741afSMartin Matuska# "1/3" to a comma separate taglist, like:
5727a7741afSMartin Matuska#
5737a7741afSMartin Matuska# "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..."
5747a7741afSMartin Matuska#
5757a7741afSMartin Matuskaif echo "$TAGS" | grep -Eq '^[0-9]+/[0-9]+$' ; then
5767a7741afSMartin Matuska	TAGS=$(split_tags)
5777a7741afSMartin Matuskafi
5787a7741afSMartin Matuska
579eda14cbcSMatt Macy#
580eda14cbcSMatt Macy# This script should not be run as root.  Instead the test user, which may
581eda14cbcSMatt Macy# be a normal user account, needs to be configured such that it can
582eda14cbcSMatt Macy# run commands via sudo passwordlessly.
583eda14cbcSMatt Macy#
584eda14cbcSMatt Macyif [ "$(id -u)" = "0" ]; then
585eda14cbcSMatt Macy	fail "This script must not be run as root."
586eda14cbcSMatt Macyfi
587eda14cbcSMatt Macy
588716fd348SMartin Matuskaif [ "$(sudo id -un)" != "root" ]; then
589eda14cbcSMatt Macy	fail "Passwordless sudo access required."
590eda14cbcSMatt Macyfi
591eda14cbcSMatt Macy
592eda14cbcSMatt Macy#
593eda14cbcSMatt Macy# Constrain the available binaries to a known set.
594eda14cbcSMatt Macy#
595eda14cbcSMatt Macyconstrain_path
596eda14cbcSMatt Macy
597eda14cbcSMatt Macy#
598eda14cbcSMatt Macy# Check if ksh exists
599eda14cbcSMatt Macy#
600eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ]; then
601eda14cbcSMatt Macy	sudo ln -fs /usr/local/bin/ksh93 /bin/ksh
602eda14cbcSMatt Macyfi
603eda14cbcSMatt Macy[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
604eda14cbcSMatt Macy[ -e "$STF_SUITE/include/default.cfg" ] || fail \
605eda14cbcSMatt Macy    "Missing $STF_SUITE/include/default.cfg file."
606eda14cbcSMatt Macy
607eda14cbcSMatt Macy#
608eda14cbcSMatt Macy# Verify the ZFS module stack is loaded.
609eda14cbcSMatt Macy#
610eda14cbcSMatt Macyif [ "$STACK_TRACER" = "yes" ]; then
611eda14cbcSMatt Macy	sudo "${ZFS_SH}" -S >/dev/null 2>&1
612eda14cbcSMatt Macyelse
613eda14cbcSMatt Macy	sudo "${ZFS_SH}" >/dev/null 2>&1
614eda14cbcSMatt Macyfi
615eda14cbcSMatt Macy
616eda14cbcSMatt Macy#
617eda14cbcSMatt Macy# Attempt to cleanup all previous state for a new test run.
618eda14cbcSMatt Macy#
619eda14cbcSMatt Macyif [ "$CLEANUPALL" = "yes" ]; then
620eda14cbcSMatt Macy	cleanup_all
621eda14cbcSMatt Macyfi
622eda14cbcSMatt Macy
623eda14cbcSMatt Macy#
624eda14cbcSMatt Macy# By default preserve any existing pools
625eda14cbcSMatt Macy#
626eda14cbcSMatt Macyif [ -z "${KEEP}" ]; then
627716fd348SMartin Matuska	KEEP="$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | tr -s '[:space:]' ' ')"
628eda14cbcSMatt Macy	if [ -z "${KEEP}" ]; then
629eda14cbcSMatt Macy		KEEP="rpool"
630eda14cbcSMatt Macy	fi
631eda14cbcSMatt Macyelse
632716fd348SMartin Matuska	KEEP="$(echo "$KEEP" | tr -s '[:space:]' ' ')"
633eda14cbcSMatt Macyfi
634eda14cbcSMatt Macy
635eda14cbcSMatt Macy#
636eda14cbcSMatt Macy# NOTE: The following environment variables are undocumented
637eda14cbcSMatt Macy# and should be used for testing purposes only:
638eda14cbcSMatt Macy#
639eda14cbcSMatt Macy# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
640eda14cbcSMatt Macy# __ZFS_POOL_RESTRICT - iterate only over the pools it lists
641eda14cbcSMatt Macy#
642eda14cbcSMatt Macy# See libzfs/libzfs_config.c for more information.
643eda14cbcSMatt Macy#
644716fd348SMartin Matuska__ZFS_POOL_EXCLUDE="$KEEP"
645eda14cbcSMatt Macy
646eda14cbcSMatt Macy. "$STF_SUITE/include/default.cfg"
647eda14cbcSMatt Macy
648eda14cbcSMatt Macy#
649eda14cbcSMatt Macy# No DISKS have been provided so a basic file or loopback based devices
650eda14cbcSMatt Macy# must be created for the test suite to use.
651eda14cbcSMatt Macy#
652eda14cbcSMatt Macyif [ -z "${DISKS}" ]; then
653eda14cbcSMatt Macy	#
6541f88aa09SMartin Matuska	# If this is a performance run, prevent accidental use of
6551f88aa09SMartin Matuska	# loopback devices.
6561f88aa09SMartin Matuska	#
6571f88aa09SMartin Matuska	[ "$TAGS" = "perf" ] && fail "Running perf tests without disks."
6581f88aa09SMartin Matuska
6591f88aa09SMartin Matuska	#
660eda14cbcSMatt Macy	# Create sparse files for the test suite.  These may be used
661eda14cbcSMatt Macy	# directory or have loopback devices layered on them.
662eda14cbcSMatt Macy	#
663eda14cbcSMatt Macy	for TEST_FILE in ${FILES}; do
664eda14cbcSMatt Macy		[ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
665eda14cbcSMatt Macy		truncate -s "${FILESIZE}" "${TEST_FILE}" ||
666eda14cbcSMatt Macy		    fail "Failed creating: ${TEST_FILE} ($?)"
667eda14cbcSMatt Macy	done
668eda14cbcSMatt Macy
669eda14cbcSMatt Macy	#
670eda14cbcSMatt Macy	# If requested setup loopback devices backed by the sparse files.
671eda14cbcSMatt Macy	#
672eda14cbcSMatt Macy	if [ "$LOOPBACK" = "yes" ]; then
673eda14cbcSMatt Macy		test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
674eda14cbcSMatt Macy
675eda14cbcSMatt Macy		for TEST_FILE in ${FILES}; do
676eda14cbcSMatt Macy			if [ "$UNAME" = "FreeBSD" ] ; then
677eda14cbcSMatt Macy				MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}")
678eda14cbcSMatt Macy				if [ -z "$MDDEVICE" ] ; then
679eda14cbcSMatt Macy					fail "Failed: ${TEST_FILE} -> loopback"
680eda14cbcSMatt Macy				fi
681eda14cbcSMatt Macy				DISKS="$DISKS $MDDEVICE"
682eda14cbcSMatt Macy				LOOPBACKS="$LOOPBACKS $MDDEVICE"
683eda14cbcSMatt Macy			else
684716fd348SMartin Matuska				TEST_LOOPBACK=$(sudo "${LOSETUP}" --show -f "${TEST_FILE}") ||
685eda14cbcSMatt Macy				    fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
686dae17134SMartin Matuska				BASELOOPBACK="${TEST_LOOPBACK##*/}"
687eda14cbcSMatt Macy				DISKS="$DISKS $BASELOOPBACK"
688eda14cbcSMatt Macy				LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK"
689eda14cbcSMatt Macy			fi
690eda14cbcSMatt Macy		done
691eda14cbcSMatt Macy		DISKS=${DISKS# }
692eda14cbcSMatt Macy		LOOPBACKS=${LOOPBACKS# }
693eda14cbcSMatt Macy	else
694eda14cbcSMatt Macy		DISKS="$FILES"
695eda14cbcSMatt Macy	fi
696eda14cbcSMatt Macyfi
697eda14cbcSMatt Macy
6981f88aa09SMartin Matuska#
6991f88aa09SMartin Matuska# It may be desirable to test with fewer disks than the default when running
7001f88aa09SMartin Matuska# the performance tests, but the functional tests require at least three.
7011f88aa09SMartin Matuska#
702eda14cbcSMatt MacyNUM_DISKS=$(echo "${DISKS}" | awk '{print NF}')
7031f88aa09SMartin Matuskaif [ "$TAGS" != "perf" ]; then
704eda14cbcSMatt Macy	[ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
7051f88aa09SMartin Matuskafi
706eda14cbcSMatt Macy
707eda14cbcSMatt Macy#
708eda14cbcSMatt Macy# Disable SELinux until the ZFS Test Suite has been updated accordingly.
709eda14cbcSMatt Macy#
710716fd348SMartin Matuskaif command -v setenforce >/dev/null; then
711eda14cbcSMatt Macy	sudo setenforce permissive >/dev/null 2>&1
712eda14cbcSMatt Macyfi
713eda14cbcSMatt Macy
714eda14cbcSMatt Macy#
715eda14cbcSMatt Macy# Enable internal ZFS debug log and clear it.
716eda14cbcSMatt Macy#
717eda14cbcSMatt Macyif [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then
718716fd348SMartin Matuska	sudo sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable"
719716fd348SMartin Matuska	sudo sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
720eda14cbcSMatt Macyfi
721eda14cbcSMatt Macy
722d2a8fad3SMartin Matuska#
723d2a8fad3SMartin Matuska# Set TMPDIR. Some tests run mktemp, and we want those files contained to
724d2a8fad3SMartin Matuska# the work dir the same as any other.
725d2a8fad3SMartin Matuska#
726d2a8fad3SMartin Matuskaexport TMPDIR="$FILEDIR"
727d2a8fad3SMartin Matuska
7281f88aa09SMartin Matuskamsg
7291f88aa09SMartin Matuskamsg "--- Configuration ---"
7301f88aa09SMartin Matuskamsg "Runfiles:        $RUNFILES"
7311f88aa09SMartin Matuskamsg "STF_TOOLS:       $STF_TOOLS"
7321f88aa09SMartin Matuskamsg "STF_SUITE:       $STF_SUITE"
7331f88aa09SMartin Matuskamsg "STF_PATH:        $STF_PATH"
734eda14cbcSMatt Macymsg "FILEDIR:         $FILEDIR"
735d2a8fad3SMartin Matuskamsg "TMPDIR:          $TMPDIR"
736eda14cbcSMatt Macymsg "FILES:           $FILES"
737eda14cbcSMatt Macymsg "LOOPBACKS:       $LOOPBACKS"
738eda14cbcSMatt Macymsg "DISKS:           $DISKS"
739eda14cbcSMatt Macymsg "NUM_DISKS:       $NUM_DISKS"
740eda14cbcSMatt Macymsg "FILESIZE:        $FILESIZE"
741eda14cbcSMatt Macymsg "ITERATIONS:      $ITERATIONS"
742eda14cbcSMatt Macymsg "TAGS:            $TAGS"
743eda14cbcSMatt Macymsg "STACK_TRACER:    $STACK_TRACER"
744eda14cbcSMatt Macymsg "Keep pool(s):    $KEEP"
745eda14cbcSMatt Macymsg "Missing util(s): $STF_MISSING_BIN"
746eda14cbcSMatt Macymsg ""
747eda14cbcSMatt Macy
748eda14cbcSMatt Macyexport STF_TOOLS
749eda14cbcSMatt Macyexport STF_SUITE
750eda14cbcSMatt Macyexport STF_PATH
751eda14cbcSMatt Macyexport DISKS
752eda14cbcSMatt Macyexport FILEDIR
753eda14cbcSMatt Macyexport KEEP
754eda14cbcSMatt Macyexport __ZFS_POOL_EXCLUDE
755eda14cbcSMatt Macyexport TESTFAIL_CALLBACKS
756eda14cbcSMatt Macy
757c03c5b1cSMartin Matuskamktemp_file() {
758eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ]; then
759c03c5b1cSMartin Matuska		mktemp -u "${FILEDIR}/$1.XXXXXX"
760eda14cbcSMatt Macy	else
761c03c5b1cSMartin Matuska		mktemp -ut "$1.XXXXXX" -p "$FILEDIR"
762eda14cbcSMatt Macy	fi
763c03c5b1cSMartin Matuska}
764c03c5b1cSMartin Matuskamkdir -p "$FILEDIR" || :
765c03c5b1cSMartin MatuskaRESULTS_FILE=$(mktemp_file zts-results)
766c03c5b1cSMartin MatuskaREPORT_FILE=$(mktemp_file zts-report)
767eda14cbcSMatt Macy
768eda14cbcSMatt Macy#
769eda14cbcSMatt Macy# Run all the tests as specified.
770eda14cbcSMatt Macy#
771c03c5b1cSMartin Matuskamsg "${TEST_RUNNER}" \
772c03c5b1cSMartin Matuska    "${QUIET:+-q}" \
7730d4ad640SMartin Matuska    "${DEBUG:+-D}" \
774c03c5b1cSMartin Matuska    "${KMEMLEAK:+-m}" \
775da5137abSMartin Matuska    "${KMSG:+-K}" \
776eda14cbcSMatt Macy    "-c \"${RUNFILES}\"" \
777eda14cbcSMatt Macy    "-T \"${TAGS}\"" \
778eda14cbcSMatt Macy    "-i \"${STF_SUITE}\"" \
779eda14cbcSMatt Macy    "-I \"${ITERATIONS}\""
780716fd348SMartin Matuska{ PATH=$STF_PATH \
781716fd348SMartin Matuska    ${TEST_RUNNER} \
782c03c5b1cSMartin Matuska    ${QUIET:+-q} \
7830d4ad640SMartin Matuska    ${DEBUG:+-D} \
784c03c5b1cSMartin Matuska    ${KMEMLEAK:+-m} \
785da5137abSMartin Matuska    ${KMSG:+-K} \
786eda14cbcSMatt Macy    -c "${RUNFILES}" \
787eda14cbcSMatt Macy    -T "${TAGS}" \
788eda14cbcSMatt Macy    -i "${STF_SUITE}" \
789eda14cbcSMatt Macy    -I "${ITERATIONS}" \
790c03c5b1cSMartin Matuska    2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE"
791c03c5b1cSMartin Matuskaread -r RUNRESULT <"$REPORT_FILE"
792c03c5b1cSMartin Matuska
793eda14cbcSMatt Macy#
794eda14cbcSMatt Macy# Analyze the results.
795eda14cbcSMatt Macy#
796681ce946SMartin Matuska${ZTS_REPORT} ${RERUN:+--no-maybes} "$RESULTS_FILE" >"$REPORT_FILE"
797eda14cbcSMatt MacyRESULT=$?
798681ce946SMartin Matuska
799681ce946SMartin Matuskaif [ "$RESULT" -eq "2" ] && [ -n "$RERUN" ]; then
800681ce946SMartin Matuska	MAYBES="$($ZTS_REPORT --list-maybes)"
801c03c5b1cSMartin Matuska	TEMP_RESULTS_FILE=$(mktemp_file zts-results-tmp)
802c03c5b1cSMartin Matuska	TEST_LIST=$(mktemp_file test-list)
803681ce946SMartin Matuska	grep "^Test:.*\[FAIL\]" "$RESULTS_FILE" >"$TEMP_RESULTS_FILE"
804681ce946SMartin Matuska	for test_name in $MAYBES; do
805681ce946SMartin Matuska		grep "$test_name " "$TEMP_RESULTS_FILE" >>"$TEST_LIST"
806681ce946SMartin Matuska	done
807716fd348SMartin Matuska	{ PATH=$STF_PATH \
808716fd348SMartin Matuska	    ${TEST_RUNNER} \
809c03c5b1cSMartin Matuska	        ${QUIET:+-q} \
8100d4ad640SMartin Matuska	        ${DEBUG:+-D} \
811c03c5b1cSMartin Matuska	        ${KMEMLEAK:+-m} \
812681ce946SMartin Matuska	    -c "${RUNFILES}" \
813681ce946SMartin Matuska	    -T "${TAGS}" \
814681ce946SMartin Matuska	    -i "${STF_SUITE}" \
815681ce946SMartin Matuska	    -I "${ITERATIONS}" \
816681ce946SMartin Matuska	    -l "${TEST_LIST}" \
817c03c5b1cSMartin Matuska	    2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE"
818c03c5b1cSMartin Matuska	read -r RUNRESULT <"$REPORT_FILE"
819681ce946SMartin Matuska	#
820681ce946SMartin Matuska	# Analyze the results.
821681ce946SMartin Matuska	#
822681ce946SMartin Matuska	${ZTS_REPORT} --no-maybes "$RESULTS_FILE" >"$REPORT_FILE"
823681ce946SMartin Matuska	RESULT=$?
824681ce946SMartin Matuskafi
825681ce946SMartin Matuska
826681ce946SMartin Matuska
827eda14cbcSMatt Macycat "$REPORT_FILE"
828eda14cbcSMatt Macy
829eda14cbcSMatt MacyRESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE")
830eda14cbcSMatt Macyif [ -d "$RESULTS_DIR" ]; then
831eda14cbcSMatt Macy	cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results"
832eda14cbcSMatt Macyfi
833eda14cbcSMatt Macy
834716fd348SMartin Matuskarm -f "$RESULTS_FILE" "$REPORT_FILE" "$TEST_LIST" "$TEMP_RESULTS_FILE"
835eda14cbcSMatt Macy
836eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then
837eda14cbcSMatt Macy	rm -f "$RUNFILES" >/dev/null 2>&1
838eda14cbcSMatt Macyfi
839eda14cbcSMatt Macy
840c03c5b1cSMartin Matuska[ "$RUNRESULT" -gt 3 ] && exit "$RUNRESULT" || exit "$RESULT"
841