xref: /freebsd/sys/contrib/openzfs/scripts/zfs-tests.sh (revision 716fd348e01c5f2ba125f878a634a753436c2994)
1eda14cbcSMatt Macy#!/bin/sh
2e92ffd9bSMartin Matuska# shellcheck disable=SC2154
3eda14cbcSMatt Macy#
4eda14cbcSMatt Macy# CDDL HEADER START
5eda14cbcSMatt Macy#
6eda14cbcSMatt Macy# The contents of this file are subject to the terms of the
7eda14cbcSMatt Macy# Common Development and Distribution License, Version 1.0 only
8eda14cbcSMatt Macy# (the "License").  You may not use this file except in compliance
9eda14cbcSMatt Macy# with the License.
10eda14cbcSMatt Macy#
11eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12eda14cbcSMatt Macy# or http://www.opensolaris.org/os/licensing.
13eda14cbcSMatt Macy# See the License for the specific language governing permissions
14eda14cbcSMatt Macy# and limitations under the License.
15eda14cbcSMatt Macy#
16eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each
17eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the
19eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying
20eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner]
21eda14cbcSMatt Macy#
22eda14cbcSMatt Macy# CDDL HEADER END
23eda14cbcSMatt Macy#
24eda14cbcSMatt Macy
25681ce946SMartin Matuska#
26681ce946SMartin Matuska# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
27681ce946SMartin Matuska#
28681ce946SMartin Matuska
29*716fd348SMartin MatuskaSCRIPT_COMMON=${SCRIPT_COMMON:-${0%/*}/common.sh}
30*716fd348SMartin Matuska. "${SCRIPT_COMMON}" || exit
31eda14cbcSMatt Macy
32eda14cbcSMatt MacyPROG=zfs-tests.sh
33eda14cbcSMatt MacyVERBOSE="no"
34eda14cbcSMatt MacyQUIET=""
35eda14cbcSMatt MacyCLEANUP="yes"
36eda14cbcSMatt MacyCLEANUPALL="no"
37da5137abSMartin MatuskaKMSG=""
38eda14cbcSMatt MacyLOOPBACK="yes"
39eda14cbcSMatt MacySTACK_TRACER="no"
40eda14cbcSMatt MacyFILESIZE="4G"
41eda14cbcSMatt MacyDEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
42eda14cbcSMatt MacyRUNFILES=${RUNFILES:-$DEFAULT_RUNFILES}
43eda14cbcSMatt MacyFILEDIR=${FILEDIR:-/var/tmp}
44eda14cbcSMatt MacyDISKS=${DISKS:-""}
45eda14cbcSMatt MacySINGLETEST=""
46eda14cbcSMatt MacySINGLETESTUSER="root"
47eda14cbcSMatt MacyTAGS=""
48eda14cbcSMatt MacyITERATIONS=1
49eda14cbcSMatt MacyZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
50eda14cbcSMatt MacyZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
51*716fd348SMartin MatuskaUNAME=$(uname)
52681ce946SMartin MatuskaRERUN=""
53c03c5b1cSMartin MatuskaKMEMLEAK=""
54eda14cbcSMatt Macy
55eda14cbcSMatt Macy# Override some defaults if on FreeBSD
56eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then
57eda14cbcSMatt Macy	TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
58eda14cbcSMatt Macy	LOSETUP=/sbin/mdconfig
59eda14cbcSMatt Macy	DMSETUP=/sbin/gpart
60eda14cbcSMatt Macyelse
61eda14cbcSMatt Macy	ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
62eda14cbcSMatt Macy	TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
63eda14cbcSMatt Macy	LOSETUP=${LOSETUP:-/sbin/losetup}
64eda14cbcSMatt Macy	DMSETUP=${DMSETUP:-/sbin/dmsetup}
65eda14cbcSMatt Macyfi
66eda14cbcSMatt Macy
67eda14cbcSMatt Macy#
68eda14cbcSMatt Macy# Log an informational message when additional verbosity is enabled.
69eda14cbcSMatt Macy#
70eda14cbcSMatt Macymsg() {
71eda14cbcSMatt Macy	if [ "$VERBOSE" = "yes" ]; then
72eda14cbcSMatt Macy		echo "$@"
73eda14cbcSMatt Macy	fi
74eda14cbcSMatt Macy}
75eda14cbcSMatt Macy
76eda14cbcSMatt Macy#
77eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error.
78eda14cbcSMatt Macy#
79eda14cbcSMatt Macyfail() {
80eda14cbcSMatt Macy	echo "$PROG: $1" >&2
81eda14cbcSMatt Macy	cleanup
82eda14cbcSMatt Macy	exit 1
83eda14cbcSMatt Macy}
84eda14cbcSMatt Macy
85eda14cbcSMatt Macycleanup_freebsd_loopback() {
86eda14cbcSMatt Macy	for TEST_LOOPBACK in ${LOOPBACKS}; do
87eda14cbcSMatt Macy		if [ -c "/dev/${TEST_LOOPBACK}" ]; then
88eda14cbcSMatt Macy			sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" ||
89eda14cbcSMatt Macy			    echo "Failed to destroy: ${TEST_LOOPBACK}"
90eda14cbcSMatt Macy		fi
91eda14cbcSMatt Macy	done
92eda14cbcSMatt Macy}
93eda14cbcSMatt Macy
94eda14cbcSMatt Macycleanup_linux_loopback() {
95eda14cbcSMatt Macy	for TEST_LOOPBACK in ${LOOPBACKS}; do
96dae17134SMartin Matuska		LOOP_DEV="${TEST_LOOPBACK##*/}"
97eda14cbcSMatt Macy		DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \
98*716fd348SMartin Matuska		    awk -v l="${LOOP_DEV}" '$0 ~ l {print $1}')
99eda14cbcSMatt Macy
100eda14cbcSMatt Macy		if [ -n "$DM_DEV" ]; then
101eda14cbcSMatt Macy			sudo "${DMSETUP}" remove "${DM_DEV}" ||
102eda14cbcSMatt Macy			    echo "Failed to remove: ${DM_DEV}"
103eda14cbcSMatt Macy		fi
104eda14cbcSMatt Macy
105eda14cbcSMatt Macy		if [ -n "${TEST_LOOPBACK}" ]; then
106eda14cbcSMatt Macy			sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
107eda14cbcSMatt Macy			    echo "Failed to remove: ${TEST_LOOPBACK}"
108eda14cbcSMatt Macy		fi
109eda14cbcSMatt Macy	done
110eda14cbcSMatt Macy}
111eda14cbcSMatt Macy
112eda14cbcSMatt Macy#
113eda14cbcSMatt Macy# Attempt to remove loopback devices and files which where created earlier
114eda14cbcSMatt Macy# by this script to run the test framework.  The '-k' option may be passed
115eda14cbcSMatt Macy# to the script to suppress cleanup for debugging purposes.
116eda14cbcSMatt Macy#
117eda14cbcSMatt Macycleanup() {
118eda14cbcSMatt Macy	if [ "$CLEANUP" = "no" ]; then
119eda14cbcSMatt Macy		return 0
120eda14cbcSMatt Macy	fi
121eda14cbcSMatt Macy
122eda14cbcSMatt Macy
123eda14cbcSMatt Macy	if [ "$LOOPBACK" = "yes" ]; then
124eda14cbcSMatt Macy		if [ "$UNAME" = "FreeBSD" ] ; then
125eda14cbcSMatt Macy			cleanup_freebsd_loopback
126eda14cbcSMatt Macy		else
127eda14cbcSMatt Macy			cleanup_linux_loopback
128eda14cbcSMatt Macy		fi
129eda14cbcSMatt Macy	fi
130eda14cbcSMatt Macy
131*716fd348SMartin Matuska	# shellcheck disable=SC2086
132*716fd348SMartin Matuska	rm -f ${FILES} >/dev/null 2>&1
133eda14cbcSMatt Macy
134eda14cbcSMatt Macy	if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
135eda14cbcSMatt Macy		rm -Rf "$STF_PATH"
136eda14cbcSMatt Macy	fi
137eda14cbcSMatt Macy}
138eda14cbcSMatt Macytrap cleanup EXIT
139eda14cbcSMatt Macy
140eda14cbcSMatt Macy#
141eda14cbcSMatt Macy# Attempt to remove all testpools (testpool.XXX), unopened dm devices,
142eda14cbcSMatt Macy# loopback devices, and files.  This is a useful way to cleanup a previous
143eda14cbcSMatt Macy# test run failure which has left the system in an unknown state.  This can
144eda14cbcSMatt Macy# be dangerous and should only be used in a dedicated test environment.
145eda14cbcSMatt Macy#
146eda14cbcSMatt Macycleanup_all() {
147*716fd348SMartin Matuska	TEST_POOLS=$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | grep testpool)
148eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ] ; then
149eda14cbcSMatt Macy		TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l)
150eda14cbcSMatt Macy	else
151*716fd348SMartin Matuska		TEST_LOOPBACKS=$("${LOSETUP}" -a | awk -F: '/file-vdev/ {print $1}')
152eda14cbcSMatt Macy	fi
153*716fd348SMartin Matuska	TEST_FILES=$(ls "${FILEDIR}"/file-vdev* /var/tmp/file-vdev* 2>/dev/null)
154eda14cbcSMatt Macy
155eda14cbcSMatt Macy	msg
156eda14cbcSMatt Macy	msg "--- Cleanup ---"
157*716fd348SMartin Matuska	# shellcheck disable=2116,2086
158*716fd348SMartin Matuska	msg "Removing pool(s):     $(echo ${TEST_POOLS})"
159eda14cbcSMatt Macy	for TEST_POOL in $TEST_POOLS; do
160c03c5b1cSMartin Matuska		sudo env ASAN_OPTIONS=detect_leaks=false "$ZPOOL" destroy "${TEST_POOL}"
161eda14cbcSMatt Macy	done
162eda14cbcSMatt Macy
163eda14cbcSMatt Macy	if [ "$UNAME" != "FreeBSD" ] ; then
164*716fd348SMartin Matuska		msg "Removing all dm(s):   $(sudo "${DMSETUP}" ls |
165eda14cbcSMatt Macy		    grep loop | tr '\n' ' ')"
166eda14cbcSMatt Macy		sudo "${DMSETUP}" remove_all
167eda14cbcSMatt Macy	fi
168eda14cbcSMatt Macy
169*716fd348SMartin Matuska	# shellcheck disable=2116,2086
170*716fd348SMartin Matuska	msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS})"
171eda14cbcSMatt Macy	for TEST_LOOPBACK in $TEST_LOOPBACKS; do
172eda14cbcSMatt Macy		if [ "$UNAME" = "FreeBSD" ] ; then
173eda14cbcSMatt Macy			sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}"
174eda14cbcSMatt Macy		else
175eda14cbcSMatt Macy			sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
176eda14cbcSMatt Macy		fi
177eda14cbcSMatt Macy	done
178eda14cbcSMatt Macy
179*716fd348SMartin Matuska	# shellcheck disable=2116,2086
180*716fd348SMartin Matuska	msg "Removing files(s):    $(echo ${TEST_FILES})"
181*716fd348SMartin Matuska	# shellcheck disable=2086
182*716fd348SMartin Matuska	sudo rm -f ${TEST_FILES}
183eda14cbcSMatt Macy}
184eda14cbcSMatt Macy
185eda14cbcSMatt Macy#
186eda14cbcSMatt Macy# Takes a name as the only arguments and looks for the following variations
187eda14cbcSMatt Macy# on that name.  If one is found it is returned.
188eda14cbcSMatt Macy#
189eda14cbcSMatt Macy# $RUNFILE_DIR/<name>
190eda14cbcSMatt Macy# $RUNFILE_DIR/<name>.run
191eda14cbcSMatt Macy# <name>
192eda14cbcSMatt Macy# <name>.run
193eda14cbcSMatt Macy#
194eda14cbcSMatt Macyfind_runfile() {
195eda14cbcSMatt Macy	NAME=$1
196eda14cbcSMatt Macy
197eda14cbcSMatt Macy	if [ -f "$RUNFILE_DIR/$NAME" ]; then
198*716fd348SMartin Matuska		echo "$RUNFILE_DIR/$NAME"
199eda14cbcSMatt Macy	elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then
200*716fd348SMartin Matuska		echo "$RUNFILE_DIR/$NAME.run"
201eda14cbcSMatt Macy	elif [ -f "$NAME" ]; then
202*716fd348SMartin Matuska		echo "$NAME"
203eda14cbcSMatt Macy	elif [ -f "$NAME.run" ]; then
204*716fd348SMartin Matuska		echo "$NAME.run"
205*716fd348SMartin Matuska	else
206*716fd348SMartin Matuska		return 1
207eda14cbcSMatt Macy	fi
208eda14cbcSMatt Macy}
209eda14cbcSMatt Macy
210eda14cbcSMatt Macy#
211eda14cbcSMatt Macy# Symlink file if it appears under any of the given paths.
212eda14cbcSMatt Macy#
213eda14cbcSMatt Macycreate_links() {
214eda14cbcSMatt Macy	dir_list="$1"
215eda14cbcSMatt Macy	file_list="$2"
216eda14cbcSMatt Macy
217eda14cbcSMatt Macy	[ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set"
218eda14cbcSMatt Macy
219eda14cbcSMatt Macy	for i in $file_list; do
220eda14cbcSMatt Macy		for j in $dir_list; do
221eda14cbcSMatt Macy			[ ! -e "$STF_PATH/$i" ] || continue
222eda14cbcSMatt Macy
223eda14cbcSMatt Macy			if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then
224eda14cbcSMatt Macy				ln -sf "$j/$i" "$STF_PATH/$i" || \
225eda14cbcSMatt Macy				    fail "Couldn't link $i"
226eda14cbcSMatt Macy				break
227eda14cbcSMatt Macy			fi
228eda14cbcSMatt Macy		done
229eda14cbcSMatt Macy
230eda14cbcSMatt Macy		[ ! -e "$STF_PATH/$i" ] && \
231eda14cbcSMatt Macy		    STF_MISSING_BIN="$STF_MISSING_BIN $i"
232eda14cbcSMatt Macy	done
233eda14cbcSMatt Macy	STF_MISSING_BIN=${STF_MISSING_BIN# }
234eda14cbcSMatt Macy}
235eda14cbcSMatt Macy
236eda14cbcSMatt Macy#
237eda14cbcSMatt Macy# Constrain the path to limit the available binaries to a known set.
238eda14cbcSMatt Macy# When running in-tree a top level ./bin/ directory is created for
239eda14cbcSMatt Macy# convenience, otherwise a temporary directory is used.
240eda14cbcSMatt Macy#
241eda14cbcSMatt Macyconstrain_path() {
242eda14cbcSMatt Macy	. "$STF_SUITE/include/commands.cfg"
243eda14cbcSMatt Macy
244eda14cbcSMatt Macy	# On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils
245eda14cbcSMatt Macy	# install to /usr/local/sbin. To avoid testing the wrong utils we
246eda14cbcSMatt Macy	# need /usr/local to come before / in the path search order.
247eda14cbcSMatt Macy	SYSTEM_DIRS="/usr/local/bin /usr/local/sbin"
2487877fdebSMatt Macy	SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin $LIBEXEC_DIR"
249eda14cbcSMatt Macy
250eda14cbcSMatt Macy	if [ "$INTREE" = "yes" ]; then
251*716fd348SMartin Matuska		# Constrained path set to $(top_builddir)/tests/zfs-tests/bin
252eda14cbcSMatt Macy		STF_PATH="$BIN_DIR"
253eda14cbcSMatt Macy		STF_PATH_REMOVE="no"
254eda14cbcSMatt Macy		STF_MISSING_BIN=""
255eda14cbcSMatt Macy		if [ ! -d "$STF_PATH" ]; then
256eda14cbcSMatt Macy			mkdir "$STF_PATH"
257eda14cbcSMatt Macy			chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
258eda14cbcSMatt Macy		fi
259eda14cbcSMatt Macy
260eda14cbcSMatt Macy		# Special case links for standard zfs utilities
261*716fd348SMartin Matuska		create_links "$CMD_DIR" "$ZFS_FILES"
262eda14cbcSMatt Macy
263eda14cbcSMatt Macy		# Special case links for zfs test suite utilities
264*716fd348SMartin Matuska		create_links "$CMD_DIR/tests/zfs-tests/cmd" "$ZFSTEST_FILES"
265eda14cbcSMatt Macy	else
266eda14cbcSMatt Macy		# Constrained path set to /var/tmp/constrained_path.*
2677877fdebSMatt Macy		SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXXXX}
268eda14cbcSMatt Macy		STF_PATH=$(mktemp -d "$SYSTEMDIR")
269eda14cbcSMatt Macy		STF_PATH_REMOVE="yes"
270eda14cbcSMatt Macy		STF_MISSING_BIN=""
271eda14cbcSMatt Macy
272eda14cbcSMatt Macy		chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
273eda14cbcSMatt Macy
274eda14cbcSMatt Macy		# Special case links for standard zfs utilities
275eda14cbcSMatt Macy		create_links "$SYSTEM_DIRS" "$ZFS_FILES"
276eda14cbcSMatt Macy
277eda14cbcSMatt Macy		# Special case links for zfs test suite utilities
278eda14cbcSMatt Macy		create_links "$STF_SUITE/bin" "$ZFSTEST_FILES"
279eda14cbcSMatt Macy	fi
280eda14cbcSMatt Macy
281eda14cbcSMatt Macy	# Standard system utilities
282eda14cbcSMatt Macy	SYSTEM_FILES="$SYSTEM_FILES_COMMON"
283eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ] ; then
284eda14cbcSMatt Macy		SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD"
285eda14cbcSMatt Macy	else
286eda14cbcSMatt Macy		SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX"
287eda14cbcSMatt Macy	fi
288eda14cbcSMatt Macy	create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
289eda14cbcSMatt Macy
290eda14cbcSMatt Macy	# Exceptions
291eda14cbcSMatt Macy	if [ "$UNAME" = "Linux" ] ; then
292eda14cbcSMatt Macy		ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
293eda14cbcSMatt Macy		ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
294eda14cbcSMatt Macy		ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
295eda14cbcSMatt Macy		ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
296eda14cbcSMatt Macy	elif [ "$UNAME" = "FreeBSD" ] ; then
297eda14cbcSMatt Macy		ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
298eda14cbcSMatt Macy	fi
299eda14cbcSMatt Macy}
300eda14cbcSMatt Macy
301eda14cbcSMatt Macy#
302eda14cbcSMatt Macy# Output a useful usage message.
303eda14cbcSMatt Macy#
304eda14cbcSMatt Macyusage() {
305eda14cbcSMatt Macycat << EOF
306eda14cbcSMatt MacyUSAGE:
3072c48331dSMatt Macy$0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER]
308eda14cbcSMatt Macy
309eda14cbcSMatt MacyDESCRIPTION:
310eda14cbcSMatt Macy	ZFS Test Suite launch script
311eda14cbcSMatt Macy
312eda14cbcSMatt MacyOPTIONS:
313eda14cbcSMatt Macy	-h          Show this message
314eda14cbcSMatt Macy	-v          Verbose zfs-tests.sh output
315eda14cbcSMatt Macy	-q          Quiet test-runner output
316eda14cbcSMatt Macy	-x          Remove all testpools, dm, lo, and files (unsafe)
317eda14cbcSMatt Macy	-k          Disable cleanup after test failure
318da5137abSMartin Matuska	-K          Log test names to /dev/kmsg
319eda14cbcSMatt Macy	-f          Use files only, disables block device tests
320eda14cbcSMatt Macy	-S          Enable stack tracer (negative performance impact)
321eda14cbcSMatt Macy	-c          Only create and populate constrained path
322681ce946SMartin Matuska	-R          Automatically rerun failing tests
323c03c5b1cSMartin Matuska	-m          Enable kmemleak reporting (Linux only)
324eda14cbcSMatt Macy	-n NFSFILE  Use the nfsfile to determine the NFS configuration
325eda14cbcSMatt Macy	-I NUM      Number of iterations
326*716fd348SMartin Matuska	-d DIR      Use world-writable DIR for files and loopback devices
327eda14cbcSMatt Macy	-s SIZE     Use vdevs of SIZE (default: 4G)
328eda14cbcSMatt Macy	-r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES})
329eda14cbcSMatt Macy	-t PATH     Run single test at PATH relative to test suite
330eda14cbcSMatt Macy	-T TAGS     Comma separated list of tags (default: 'functional')
331eda14cbcSMatt Macy	-u USER     Run single test as USER (default: root)
332eda14cbcSMatt Macy
333eda14cbcSMatt MacyEXAMPLES:
334*716fd348SMartin Matuska# Run the default ($(echo "${DEFAULT_RUNFILES}" | sed 's/\.run//')) suite of tests and output the configuration used.
335eda14cbcSMatt Macy$0 -v
336eda14cbcSMatt Macy
337eda14cbcSMatt Macy# Run a smaller suite of tests designed to run more quickly.
338eda14cbcSMatt Macy$0 -r linux-fast
339eda14cbcSMatt Macy
340eda14cbcSMatt Macy# Run a single test
341eda14cbcSMatt Macy$0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh
342eda14cbcSMatt Macy
343eda14cbcSMatt Macy# Cleanup a previous run of the test suite prior to testing, run the
344*716fd348SMartin Matuska# default ($(echo "${DEFAULT_RUNFILES}" | sed 's/\.run//')) suite of tests and perform no cleanup on exit.
345eda14cbcSMatt Macy$0 -x
346eda14cbcSMatt Macy
347eda14cbcSMatt MacyEOF
348eda14cbcSMatt Macy}
349eda14cbcSMatt Macy
350da5137abSMartin Matuskawhile getopts 'hvqxkKfScRmn:d:s:r:?t:T:u:I:' OPTION; do
351eda14cbcSMatt Macy	case $OPTION in
352eda14cbcSMatt Macy	h)
353eda14cbcSMatt Macy		usage
354eda14cbcSMatt Macy		exit 1
355eda14cbcSMatt Macy		;;
356eda14cbcSMatt Macy	v)
357eda14cbcSMatt Macy		VERBOSE="yes"
358eda14cbcSMatt Macy		;;
359eda14cbcSMatt Macy	q)
360eda14cbcSMatt Macy		QUIET="yes"
361eda14cbcSMatt Macy		;;
362eda14cbcSMatt Macy	x)
363eda14cbcSMatt Macy		CLEANUPALL="yes"
364eda14cbcSMatt Macy		;;
365eda14cbcSMatt Macy	k)
366eda14cbcSMatt Macy		CLEANUP="no"
367eda14cbcSMatt Macy		;;
368da5137abSMartin Matuska	K)
369da5137abSMartin Matuska		KMSG="yes"
370da5137abSMartin Matuska		;;
371eda14cbcSMatt Macy	f)
372eda14cbcSMatt Macy		LOOPBACK="no"
373eda14cbcSMatt Macy		;;
374eda14cbcSMatt Macy	S)
375eda14cbcSMatt Macy		STACK_TRACER="yes"
376eda14cbcSMatt Macy		;;
377eda14cbcSMatt Macy	c)
378eda14cbcSMatt Macy		constrain_path
379eda14cbcSMatt Macy		exit
380eda14cbcSMatt Macy		;;
381681ce946SMartin Matuska	R)
382681ce946SMartin Matuska		RERUN="yes"
383681ce946SMartin Matuska		;;
384c03c5b1cSMartin Matuska	m)
385c03c5b1cSMartin Matuska		KMEMLEAK="yes"
386c03c5b1cSMartin Matuska		;;
387eda14cbcSMatt Macy	n)
388eda14cbcSMatt Macy		nfsfile=$OPTARG
389eda14cbcSMatt Macy		[ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile"
390eda14cbcSMatt Macy		export NFS=1
391eda14cbcSMatt Macy		. "$nfsfile"
392eda14cbcSMatt Macy		;;
393eda14cbcSMatt Macy	d)
394eda14cbcSMatt Macy		FILEDIR="$OPTARG"
395eda14cbcSMatt Macy		;;
396eda14cbcSMatt Macy	I)
397eda14cbcSMatt Macy		ITERATIONS="$OPTARG"
398eda14cbcSMatt Macy		if [ "$ITERATIONS" -le 0 ]; then
399eda14cbcSMatt Macy			fail "Iterations must be greater than 0."
400eda14cbcSMatt Macy		fi
401eda14cbcSMatt Macy		;;
402eda14cbcSMatt Macy	s)
403eda14cbcSMatt Macy		FILESIZE="$OPTARG"
404eda14cbcSMatt Macy		;;
405eda14cbcSMatt Macy	r)
406eda14cbcSMatt Macy		RUNFILES="$OPTARG"
407eda14cbcSMatt Macy		;;
408eda14cbcSMatt Macy	t)
409eda14cbcSMatt Macy		if [ -n "$SINGLETEST" ]; then
410eda14cbcSMatt Macy			fail "-t can only be provided once."
411eda14cbcSMatt Macy		fi
412eda14cbcSMatt Macy		SINGLETEST="$OPTARG"
413eda14cbcSMatt Macy		;;
414eda14cbcSMatt Macy	T)
415eda14cbcSMatt Macy		TAGS="$OPTARG"
416eda14cbcSMatt Macy		;;
417eda14cbcSMatt Macy	u)
418eda14cbcSMatt Macy		SINGLETESTUSER="$OPTARG"
419eda14cbcSMatt Macy		;;
420eda14cbcSMatt Macy	?)
421eda14cbcSMatt Macy		usage
422eda14cbcSMatt Macy		exit
423eda14cbcSMatt Macy		;;
424e92ffd9bSMartin Matuska	*)
425e92ffd9bSMartin Matuska		;;
426eda14cbcSMatt Macy	esac
427eda14cbcSMatt Macydone
428eda14cbcSMatt Macy
429eda14cbcSMatt Macyshift $((OPTIND-1))
430eda14cbcSMatt Macy
431eda14cbcSMatt MacyFILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
432eda14cbcSMatt MacyLOOPBACKS=${LOOPBACKS:-""}
433eda14cbcSMatt Macy
434eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then
435eda14cbcSMatt Macy	if [ -n "$TAGS" ]; then
436eda14cbcSMatt Macy		fail "-t and -T are mutually exclusive."
437eda14cbcSMatt Macy	fi
438eda14cbcSMatt Macy	RUNFILE_DIR="/var/tmp"
439eda14cbcSMatt Macy	RUNFILES="zfs-tests.$$.run"
440*716fd348SMartin Matuska	[ -n "$QUIET" ] && SINGLEQUIET="True" || SINGLEQUIET="False"
441eda14cbcSMatt Macy
442e92ffd9bSMartin Matuska	cat >"${RUNFILE_DIR}/${RUNFILES}" << EOF
443eda14cbcSMatt Macy[DEFAULT]
444eda14cbcSMatt Macypre =
445eda14cbcSMatt Macyquiet = $SINGLEQUIET
446eda14cbcSMatt Macypre_user = root
447eda14cbcSMatt Macyuser = $SINGLETESTUSER
448eda14cbcSMatt Macytimeout = 600
449eda14cbcSMatt Macypost_user = root
450eda14cbcSMatt Macypost =
451eda14cbcSMatt Macyoutputdir = /var/tmp/test_results
452eda14cbcSMatt MacyEOF
453*716fd348SMartin Matuska	SINGLETESTDIR="${SINGLETEST%/*}"
454eda14cbcSMatt Macy
455*716fd348SMartin Matuska	SETUPDIR="$SINGLETESTDIR"
456*716fd348SMartin Matuska	[ "${SETUPDIR#/}" = "$SETUPDIR" ] && SETUPDIR="$STF_SUITE/$SINGLETESTDIR"
457*716fd348SMartin Matuska	[ -x "$SETUPDIR/setup.ksh"   ] && SETUPSCRIPT="setup"     || SETUPSCRIPT=
458*716fd348SMartin Matuska	[ -x "$SETUPDIR/cleanup.ksh" ] && CLEANUPSCRIPT="cleanup" || CLEANUPSCRIPT=
459eda14cbcSMatt Macy
460*716fd348SMartin Matuska	SINGLETESTFILE="${SINGLETEST##*/}"
461e92ffd9bSMartin Matuska	cat >>"${RUNFILE_DIR}/${RUNFILES}" << EOF
462eda14cbcSMatt Macy
463eda14cbcSMatt Macy[$SINGLETESTDIR]
464eda14cbcSMatt Macytests = ['$SINGLETESTFILE']
465eda14cbcSMatt Macypre = $SETUPSCRIPT
466eda14cbcSMatt Macypost = $CLEANUPSCRIPT
467eda14cbcSMatt Macytags = ['functional']
468eda14cbcSMatt MacyEOF
469eda14cbcSMatt Macyfi
470eda14cbcSMatt Macy
471eda14cbcSMatt Macy#
472eda14cbcSMatt Macy# Use default tag if none was specified
473eda14cbcSMatt Macy#
474eda14cbcSMatt MacyTAGS=${TAGS:='functional'}
475eda14cbcSMatt Macy
476eda14cbcSMatt Macy#
477eda14cbcSMatt Macy# Attempt to locate the runfiles describing the test workload.
478eda14cbcSMatt Macy#
479eda14cbcSMatt MacyR=""
480eda14cbcSMatt MacyIFS=,
481eda14cbcSMatt Macyfor RUNFILE in $RUNFILES; do
482eda14cbcSMatt Macy	if [ -n "$RUNFILE" ]; then
483eda14cbcSMatt Macy		SAVED_RUNFILE="$RUNFILE"
484*716fd348SMartin Matuska		RUNFILE=$(find_runfile "$RUNFILE") ||
485*716fd348SMartin Matuska			fail "Cannot find runfile: $SAVED_RUNFILE"
486eda14cbcSMatt Macy		R="$R,$RUNFILE"
487eda14cbcSMatt Macy	fi
488eda14cbcSMatt Macy
489eda14cbcSMatt Macy	if [ ! -r "$RUNFILE" ]; then
490eda14cbcSMatt Macy		fail "Cannot read runfile: $RUNFILE"
491eda14cbcSMatt Macy	fi
492eda14cbcSMatt Macydone
493eda14cbcSMatt Macyunset IFS
494eda14cbcSMatt MacyRUNFILES=${R#,}
495eda14cbcSMatt Macy
496eda14cbcSMatt Macy#
497eda14cbcSMatt Macy# This script should not be run as root.  Instead the test user, which may
498eda14cbcSMatt Macy# be a normal user account, needs to be configured such that it can
499eda14cbcSMatt Macy# run commands via sudo passwordlessly.
500eda14cbcSMatt Macy#
501eda14cbcSMatt Macyif [ "$(id -u)" = "0" ]; then
502eda14cbcSMatt Macy	fail "This script must not be run as root."
503eda14cbcSMatt Macyfi
504eda14cbcSMatt Macy
505*716fd348SMartin Matuskaif [ "$(sudo id -un)" != "root" ]; then
506eda14cbcSMatt Macy	fail "Passwordless sudo access required."
507eda14cbcSMatt Macyfi
508eda14cbcSMatt Macy
509eda14cbcSMatt Macy#
510eda14cbcSMatt Macy# Constrain the available binaries to a known set.
511eda14cbcSMatt Macy#
512eda14cbcSMatt Macyconstrain_path
513eda14cbcSMatt Macy
514eda14cbcSMatt Macy#
515eda14cbcSMatt Macy# Check if ksh exists
516eda14cbcSMatt Macy#
517eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ]; then
518eda14cbcSMatt Macy	sudo ln -fs /usr/local/bin/ksh93 /bin/ksh
519eda14cbcSMatt Macyfi
520eda14cbcSMatt Macy[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
521eda14cbcSMatt Macy[ -e "$STF_SUITE/include/default.cfg" ] || fail \
522eda14cbcSMatt Macy    "Missing $STF_SUITE/include/default.cfg file."
523eda14cbcSMatt Macy
524eda14cbcSMatt Macy#
525eda14cbcSMatt Macy# Verify the ZFS module stack is loaded.
526eda14cbcSMatt Macy#
527eda14cbcSMatt Macyif [ "$STACK_TRACER" = "yes" ]; then
528eda14cbcSMatt Macy	sudo "${ZFS_SH}" -S >/dev/null 2>&1
529eda14cbcSMatt Macyelse
530eda14cbcSMatt Macy	sudo "${ZFS_SH}" >/dev/null 2>&1
531eda14cbcSMatt Macyfi
532eda14cbcSMatt Macy
533eda14cbcSMatt Macy#
534eda14cbcSMatt Macy# Attempt to cleanup all previous state for a new test run.
535eda14cbcSMatt Macy#
536eda14cbcSMatt Macyif [ "$CLEANUPALL" = "yes" ]; then
537eda14cbcSMatt Macy	cleanup_all
538eda14cbcSMatt Macyfi
539eda14cbcSMatt Macy
540eda14cbcSMatt Macy#
541eda14cbcSMatt Macy# By default preserve any existing pools
542eda14cbcSMatt Macy#
543eda14cbcSMatt Macyif [ -z "${KEEP}" ]; then
544*716fd348SMartin Matuska	KEEP="$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | tr -s '[:space:]' ' ')"
545eda14cbcSMatt Macy	if [ -z "${KEEP}" ]; then
546eda14cbcSMatt Macy		KEEP="rpool"
547eda14cbcSMatt Macy	fi
548eda14cbcSMatt Macyelse
549*716fd348SMartin Matuska	KEEP="$(echo "$KEEP" | tr -s '[:space:]' ' ')"
550eda14cbcSMatt Macyfi
551eda14cbcSMatt Macy
552eda14cbcSMatt Macy#
553eda14cbcSMatt Macy# NOTE: The following environment variables are undocumented
554eda14cbcSMatt Macy# and should be used for testing purposes only:
555eda14cbcSMatt Macy#
556eda14cbcSMatt Macy# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
557eda14cbcSMatt Macy# __ZFS_POOL_RESTRICT - iterate only over the pools it lists
558eda14cbcSMatt Macy#
559eda14cbcSMatt Macy# See libzfs/libzfs_config.c for more information.
560eda14cbcSMatt Macy#
561*716fd348SMartin Matuska__ZFS_POOL_EXCLUDE="$KEEP"
562eda14cbcSMatt Macy
563eda14cbcSMatt Macy. "$STF_SUITE/include/default.cfg"
564eda14cbcSMatt Macy
565eda14cbcSMatt Macy#
566eda14cbcSMatt Macy# No DISKS have been provided so a basic file or loopback based devices
567eda14cbcSMatt Macy# must be created for the test suite to use.
568eda14cbcSMatt Macy#
569eda14cbcSMatt Macyif [ -z "${DISKS}" ]; then
570eda14cbcSMatt Macy	#
5711f88aa09SMartin Matuska	# If this is a performance run, prevent accidental use of
5721f88aa09SMartin Matuska	# loopback devices.
5731f88aa09SMartin Matuska	#
5741f88aa09SMartin Matuska	[ "$TAGS" = "perf" ] && fail "Running perf tests without disks."
5751f88aa09SMartin Matuska
5761f88aa09SMartin Matuska	#
577eda14cbcSMatt Macy	# Create sparse files for the test suite.  These may be used
578eda14cbcSMatt Macy	# directory or have loopback devices layered on them.
579eda14cbcSMatt Macy	#
580eda14cbcSMatt Macy	for TEST_FILE in ${FILES}; do
581eda14cbcSMatt Macy		[ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
582eda14cbcSMatt Macy		truncate -s "${FILESIZE}" "${TEST_FILE}" ||
583eda14cbcSMatt Macy		    fail "Failed creating: ${TEST_FILE} ($?)"
584eda14cbcSMatt Macy	done
585eda14cbcSMatt Macy
586eda14cbcSMatt Macy	#
587eda14cbcSMatt Macy	# If requested setup loopback devices backed by the sparse files.
588eda14cbcSMatt Macy	#
589eda14cbcSMatt Macy	if [ "$LOOPBACK" = "yes" ]; then
590eda14cbcSMatt Macy		test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
591eda14cbcSMatt Macy
592eda14cbcSMatt Macy		for TEST_FILE in ${FILES}; do
593eda14cbcSMatt Macy			if [ "$UNAME" = "FreeBSD" ] ; then
594eda14cbcSMatt Macy				MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}")
595eda14cbcSMatt Macy				if [ -z "$MDDEVICE" ] ; then
596eda14cbcSMatt Macy					fail "Failed: ${TEST_FILE} -> loopback"
597eda14cbcSMatt Macy				fi
598eda14cbcSMatt Macy				DISKS="$DISKS $MDDEVICE"
599eda14cbcSMatt Macy				LOOPBACKS="$LOOPBACKS $MDDEVICE"
600eda14cbcSMatt Macy			else
601*716fd348SMartin Matuska				TEST_LOOPBACK=$(sudo "${LOSETUP}" --show -f "${TEST_FILE}") ||
602eda14cbcSMatt Macy				    fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
603dae17134SMartin Matuska				BASELOOPBACK="${TEST_LOOPBACK##*/}"
604eda14cbcSMatt Macy				DISKS="$DISKS $BASELOOPBACK"
605eda14cbcSMatt Macy				LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK"
606eda14cbcSMatt Macy			fi
607eda14cbcSMatt Macy		done
608eda14cbcSMatt Macy		DISKS=${DISKS# }
609eda14cbcSMatt Macy		LOOPBACKS=${LOOPBACKS# }
610eda14cbcSMatt Macy	else
611eda14cbcSMatt Macy		DISKS="$FILES"
612eda14cbcSMatt Macy	fi
613eda14cbcSMatt Macyfi
614eda14cbcSMatt Macy
6151f88aa09SMartin Matuska#
6161f88aa09SMartin Matuska# It may be desirable to test with fewer disks than the default when running
6171f88aa09SMartin Matuska# the performance tests, but the functional tests require at least three.
6181f88aa09SMartin Matuska#
619eda14cbcSMatt MacyNUM_DISKS=$(echo "${DISKS}" | awk '{print NF}')
6201f88aa09SMartin Matuskaif [ "$TAGS" != "perf" ]; then
621eda14cbcSMatt Macy	[ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
6221f88aa09SMartin Matuskafi
623eda14cbcSMatt Macy
624eda14cbcSMatt Macy#
625eda14cbcSMatt Macy# Disable SELinux until the ZFS Test Suite has been updated accordingly.
626eda14cbcSMatt Macy#
627*716fd348SMartin Matuskaif command -v setenforce >/dev/null; then
628eda14cbcSMatt Macy	sudo setenforce permissive >/dev/null 2>&1
629eda14cbcSMatt Macyfi
630eda14cbcSMatt Macy
631eda14cbcSMatt Macy#
632eda14cbcSMatt Macy# Enable internal ZFS debug log and clear it.
633eda14cbcSMatt Macy#
634eda14cbcSMatt Macyif [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then
635*716fd348SMartin Matuska	sudo sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable"
636*716fd348SMartin Matuska	sudo sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
637eda14cbcSMatt Macyfi
638eda14cbcSMatt Macy
6391f88aa09SMartin Matuskamsg
6401f88aa09SMartin Matuskamsg "--- Configuration ---"
6411f88aa09SMartin Matuskamsg "Runfiles:        $RUNFILES"
6421f88aa09SMartin Matuskamsg "STF_TOOLS:       $STF_TOOLS"
6431f88aa09SMartin Matuskamsg "STF_SUITE:       $STF_SUITE"
6441f88aa09SMartin Matuskamsg "STF_PATH:        $STF_PATH"
645eda14cbcSMatt Macymsg "FILEDIR:         $FILEDIR"
646eda14cbcSMatt Macymsg "FILES:           $FILES"
647eda14cbcSMatt Macymsg "LOOPBACKS:       $LOOPBACKS"
648eda14cbcSMatt Macymsg "DISKS:           $DISKS"
649eda14cbcSMatt Macymsg "NUM_DISKS:       $NUM_DISKS"
650eda14cbcSMatt Macymsg "FILESIZE:        $FILESIZE"
651eda14cbcSMatt Macymsg "ITERATIONS:      $ITERATIONS"
652eda14cbcSMatt Macymsg "TAGS:            $TAGS"
653eda14cbcSMatt Macymsg "STACK_TRACER:    $STACK_TRACER"
654eda14cbcSMatt Macymsg "Keep pool(s):    $KEEP"
655eda14cbcSMatt Macymsg "Missing util(s): $STF_MISSING_BIN"
656eda14cbcSMatt Macymsg ""
657eda14cbcSMatt Macy
658eda14cbcSMatt Macyexport STF_TOOLS
659eda14cbcSMatt Macyexport STF_SUITE
660eda14cbcSMatt Macyexport STF_PATH
661eda14cbcSMatt Macyexport DISKS
662eda14cbcSMatt Macyexport FILEDIR
663eda14cbcSMatt Macyexport KEEP
664eda14cbcSMatt Macyexport __ZFS_POOL_EXCLUDE
665eda14cbcSMatt Macyexport TESTFAIL_CALLBACKS
666eda14cbcSMatt Macy
667c03c5b1cSMartin Matuskamktemp_file() {
668eda14cbcSMatt Macy	if [ "$UNAME" = "FreeBSD" ]; then
669c03c5b1cSMartin Matuska		mktemp -u "${FILEDIR}/$1.XXXXXX"
670eda14cbcSMatt Macy	else
671c03c5b1cSMartin Matuska		mktemp -ut "$1.XXXXXX" -p "$FILEDIR"
672eda14cbcSMatt Macy	fi
673c03c5b1cSMartin Matuska}
674c03c5b1cSMartin Matuskamkdir -p "$FILEDIR" || :
675c03c5b1cSMartin MatuskaRESULTS_FILE=$(mktemp_file zts-results)
676c03c5b1cSMartin MatuskaREPORT_FILE=$(mktemp_file zts-report)
677eda14cbcSMatt Macy
678eda14cbcSMatt Macy#
679eda14cbcSMatt Macy# Run all the tests as specified.
680eda14cbcSMatt Macy#
681c03c5b1cSMartin Matuskamsg "${TEST_RUNNER}" \
682c03c5b1cSMartin Matuska    "${QUIET:+-q}" \
683c03c5b1cSMartin Matuska    "${KMEMLEAK:+-m}" \
684da5137abSMartin Matuska    "${KMSG:+-K}" \
685eda14cbcSMatt Macy    "-c \"${RUNFILES}\"" \
686eda14cbcSMatt Macy    "-T \"${TAGS}\"" \
687eda14cbcSMatt Macy    "-i \"${STF_SUITE}\"" \
688eda14cbcSMatt Macy    "-I \"${ITERATIONS}\""
689*716fd348SMartin Matuska{ PATH=$STF_PATH \
690*716fd348SMartin Matuska    ${TEST_RUNNER} \
691c03c5b1cSMartin Matuska    ${QUIET:+-q} \
692c03c5b1cSMartin Matuska    ${KMEMLEAK:+-m} \
693da5137abSMartin Matuska    ${KMSG:+-K} \
694eda14cbcSMatt Macy    -c "${RUNFILES}" \
695eda14cbcSMatt Macy    -T "${TAGS}" \
696eda14cbcSMatt Macy    -i "${STF_SUITE}" \
697eda14cbcSMatt Macy    -I "${ITERATIONS}" \
698c03c5b1cSMartin Matuska    2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE"
699c03c5b1cSMartin Matuskaread -r RUNRESULT <"$REPORT_FILE"
700c03c5b1cSMartin Matuska
701eda14cbcSMatt Macy#
702eda14cbcSMatt Macy# Analyze the results.
703eda14cbcSMatt Macy#
704681ce946SMartin Matuska${ZTS_REPORT} ${RERUN:+--no-maybes} "$RESULTS_FILE" >"$REPORT_FILE"
705eda14cbcSMatt MacyRESULT=$?
706681ce946SMartin Matuska
707681ce946SMartin Matuskaif [ "$RESULT" -eq "2" ] && [ -n "$RERUN" ]; then
708681ce946SMartin Matuska	MAYBES="$($ZTS_REPORT --list-maybes)"
709c03c5b1cSMartin Matuska	TEMP_RESULTS_FILE=$(mktemp_file zts-results-tmp)
710c03c5b1cSMartin Matuska	TEST_LIST=$(mktemp_file test-list)
711681ce946SMartin Matuska	grep "^Test:.*\[FAIL\]" "$RESULTS_FILE" >"$TEMP_RESULTS_FILE"
712681ce946SMartin Matuska	for test_name in $MAYBES; do
713681ce946SMartin Matuska		grep "$test_name " "$TEMP_RESULTS_FILE" >>"$TEST_LIST"
714681ce946SMartin Matuska	done
715*716fd348SMartin Matuska	{ PATH=$STF_PATH \
716*716fd348SMartin Matuska	    ${TEST_RUNNER} \
717c03c5b1cSMartin Matuska	        ${QUIET:+-q} \
718c03c5b1cSMartin Matuska	        ${KMEMLEAK:+-m} \
719681ce946SMartin Matuska	    -c "${RUNFILES}" \
720681ce946SMartin Matuska	    -T "${TAGS}" \
721681ce946SMartin Matuska	    -i "${STF_SUITE}" \
722681ce946SMartin Matuska	    -I "${ITERATIONS}" \
723681ce946SMartin Matuska	    -l "${TEST_LIST}" \
724c03c5b1cSMartin Matuska	    2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE"
725c03c5b1cSMartin Matuska	read -r RUNRESULT <"$REPORT_FILE"
726681ce946SMartin Matuska	#
727681ce946SMartin Matuska	# Analyze the results.
728681ce946SMartin Matuska	#
729681ce946SMartin Matuska	${ZTS_REPORT} --no-maybes "$RESULTS_FILE" >"$REPORT_FILE"
730681ce946SMartin Matuska	RESULT=$?
731681ce946SMartin Matuskafi
732681ce946SMartin Matuska
733681ce946SMartin Matuska
734eda14cbcSMatt Macycat "$REPORT_FILE"
735eda14cbcSMatt Macy
736eda14cbcSMatt MacyRESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE")
737eda14cbcSMatt Macyif [ -d "$RESULTS_DIR" ]; then
738eda14cbcSMatt Macy	cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results"
739eda14cbcSMatt Macyfi
740eda14cbcSMatt Macy
741*716fd348SMartin Matuskarm -f "$RESULTS_FILE" "$REPORT_FILE" "$TEST_LIST" "$TEMP_RESULTS_FILE"
742eda14cbcSMatt Macy
743eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then
744eda14cbcSMatt Macy	rm -f "$RUNFILES" >/dev/null 2>&1
745eda14cbcSMatt Macyfi
746eda14cbcSMatt Macy
747c03c5b1cSMartin Matuska[ "$RUNRESULT" -gt 3 ] && exit "$RUNRESULT" || exit "$RESULT"
748