]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/zfs-tests.sh
Add Linux kmemleak support to ZTS
[mirror_zfs.git] / scripts / zfs-tests.sh
CommitLineData
d4e6e959 1#!/bin/sh
6bb24f4d
BB
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License"). You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
6bb24f4d 23
d3463615
PD
24#
25# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
26#
27
c8f9061f 28BASE_DIR=$(dirname "$0")
6bb24f4d 29SCRIPT_COMMON=common.sh
c8f9061f
BB
30if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
31. "${BASE_DIR}/${SCRIPT_COMMON}"
6bb24f4d
BB
32else
33echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
34fi
35
6bb24f4d 36PROG=zfs-tests.sh
c8f9061f 37VERBOSE="no"
a18f8bce 38QUIET=""
c8f9061f
BB
39CLEANUP="yes"
40CLEANUPALL="no"
41LOOPBACK="yes"
ef57371a 42STACK_TRACER="no"
d7958b4c 43FILESIZE="4G"
5e74ac51
RM
44DEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
45RUNFILES=${RUNFILES:-$DEFAULT_RUNFILES}
6bb24f4d
BB
46FILEDIR=${FILEDIR:-/var/tmp}
47DISKS=${DISKS:-""}
d4e6e959 48SINGLETEST=""
d8fa599f 49SINGLETESTUSER="root"
271955da 50TAGS=""
9a810efb 51ITERATIONS=1
00481e7d
BB
52ZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
53ZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
7839c4b5 54UNAME=$(uname -s)
d3463615 55RERUN=""
a69765ea 56KMEMLEAK=""
7839c4b5
MM
57
58# Override some defaults if on FreeBSD
59if [ "$UNAME" = "FreeBSD" ] ; then
60 TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
61 LOSETUP=/sbin/mdconfig
62 DMSETUP=/sbin/gpart
63else
64 ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
65 TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
66 LOSETUP=${LOSETUP:-/sbin/losetup}
67 DMSETUP=${DMSETUP:-/sbin/dmsetup}
68fi
c8f9061f
BB
69
70#
71# Log an informational message when additional verbosity is enabled.
72#
73msg() {
74 if [ "$VERBOSE" = "yes" ]; then
75 echo "$@"
76 fi
77}
78
79#
80# Log a failure message, cleanup, and return an error.
81#
82fail() {
d4e6e959 83 echo "$PROG: $1" >&2
c8f9061f
BB
84 cleanup
85 exit 1
86}
6bb24f4d 87
7839c4b5
MM
88cleanup_freebsd_loopback() {
89 for TEST_LOOPBACK in ${LOOPBACKS}; do
90 if [ -c "/dev/${TEST_LOOPBACK}" ]; then
91 sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" ||
92 echo "Failed to destroy: ${TEST_LOOPBACK}"
93 fi
94 done
95}
96
97cleanup_linux_loopback() {
98 for TEST_LOOPBACK in ${LOOPBACKS}; do
745a7f78 99 LOOP_DEV="${TEST_LOOPBACK##*/}"
7839c4b5
MM
100 DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \
101 grep "${LOOP_DEV}" | cut -f1)
102
103 if [ -n "$DM_DEV" ]; then
104 sudo "${DMSETUP}" remove "${DM_DEV}" ||
105 echo "Failed to remove: ${DM_DEV}"
106 fi
107
108 if [ -n "${TEST_LOOPBACK}" ]; then
109 sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
110 echo "Failed to remove: ${TEST_LOOPBACK}"
111 fi
112 done
113}
114
6bb24f4d
BB
115#
116# Attempt to remove loopback devices and files which where created earlier
117# by this script to run the test framework. The '-k' option may be passed
118# to the script to suppress cleanup for debugging purposes.
119#
120cleanup() {
c8f9061f 121 if [ "$CLEANUP" = "no" ]; then
6bb24f4d
BB
122 return 0
123 fi
124
6bb24f4d 125
7839c4b5
MM
126 if [ "$LOOPBACK" = "yes" ]; then
127 if [ "$UNAME" = "FreeBSD" ] ; then
128 cleanup_freebsd_loopback
129 else
130 cleanup_linux_loopback
131 fi
6bb24f4d
BB
132 fi
133
134 for TEST_FILE in ${FILES}; do
d4e6e959 135 rm -f "${TEST_FILE}" >/dev/null 2>&1
6bb24f4d 136 done
c1d9abf9 137
c8f9061f 138 if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
c1d9abf9
JWK
139 rm -Rf "$STF_PATH"
140 fi
6bb24f4d
BB
141}
142trap cleanup EXIT
143
144#
145# Attempt to remove all testpools (testpool.XXX), unopened dm devices,
146# loopback devices, and files. This is a useful way to cleanup a previous
147# test run failure which has left the system in an unknown state. This can
148# be dangerous and should only be used in a dedicated test environment.
149#
150cleanup_all() {
74698631 151 TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool)
7839c4b5
MM
152 if [ "$UNAME" = "FreeBSD" ] ; then
153 TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l)
154 else
155 TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:)
156 fi
c552fbc5 157 TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
6bb24f4d
BB
158
159 msg
160 msg "--- Cleanup ---"
c552fbc5 161 msg "Removing pool(s): $(echo "${TEST_POOLS}" | tr '\n' ' ')"
6bb24f4d 162 for TEST_POOL in $TEST_POOLS; do
74698631 163 sudo "$ZPOOL" destroy "${TEST_POOL}"
6bb24f4d
BB
164 done
165
7839c4b5
MM
166 if [ "$UNAME" != "FreeBSD" ] ; then
167 msg "Removing dm(s): $(sudo "${DMSETUP}" ls |
168 grep loop | tr '\n' ' ')"
169 sudo "${DMSETUP}" remove_all
170 fi
6bb24f4d 171
c552fbc5 172 msg "Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
6bb24f4d 173 for TEST_LOOPBACK in $TEST_LOOPBACKS; do
7839c4b5
MM
174 if [ "$UNAME" = "FreeBSD" ] ; then
175 sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}"
176 else
177 sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
178 fi
6bb24f4d
BB
179 done
180
c552fbc5 181 msg "Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
6bb24f4d 182 for TEST_FILE in $TEST_FILES; do
c1d9abf9 183 sudo rm -f "${TEST_FILE}"
6bb24f4d
BB
184 done
185}
186
6bb24f4d
BB
187#
188# Takes a name as the only arguments and looks for the following variations
189# on that name. If one is found it is returned.
190#
c8f9061f
BB
191# $RUNFILE_DIR/<name>
192# $RUNFILE_DIR/<name>.run
6bb24f4d
BB
193# <name>
194# <name>.run
195#
196find_runfile() {
d4e6e959
RM
197 NAME=$1
198 RESULT=""
6bb24f4d 199
c8f9061f
BB
200 if [ -f "$RUNFILE_DIR/$NAME" ]; then
201 RESULT="$RUNFILE_DIR/$NAME"
202 elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then
203 RESULT="$RUNFILE_DIR/$NAME.run"
6bb24f4d
BB
204 elif [ -f "$NAME" ]; then
205 RESULT="$NAME"
206 elif [ -f "$NAME.run" ]; then
207 RESULT="$NAME.run"
208 fi
209
210 echo "$RESULT"
211}
212
c1d9abf9
JWK
213#
214# Symlink file if it appears under any of the given paths.
215#
216create_links() {
d4e6e959
RM
217 dir_list="$1"
218 file_list="$2"
c1d9abf9 219
74698631 220 [ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set"
c1d9abf9
JWK
221
222 for i in $file_list; do
223 for j in $dir_list; do
224 [ ! -e "$STF_PATH/$i" ] || continue
225
74698631 226 if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then
9f0a21e6 227 ln -sf "$j/$i" "$STF_PATH/$i" || \
c1d9abf9
JWK
228 fail "Couldn't link $i"
229 break
230 fi
231 done
232
d4e6e959
RM
233 [ ! -e "$STF_PATH/$i" ] && \
234 STF_MISSING_BIN="$STF_MISSING_BIN $i"
c1d9abf9 235 done
d4e6e959 236 STF_MISSING_BIN=${STF_MISSING_BIN# }
c1d9abf9
JWK
237}
238
239#
240# Constrain the path to limit the available binaries to a known set.
241# When running in-tree a top level ./bin/ directory is created for
242# convenience, otherwise a temporary directory is used.
243#
244constrain_path() {
74698631 245 . "$STF_SUITE/include/commands.cfg"
c1d9abf9 246
74b4d349
RM
247 # On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils
248 # install to /usr/local/sbin. To avoid testing the wrong utils we
249 # need /usr/local to come before / in the path search order.
250 SYSTEM_DIRS="/usr/local/bin /usr/local/sbin"
52c85375 251 SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin $LIBEXEC_DIR"
7839c4b5 252
c8f9061f
BB
253 if [ "$INTREE" = "yes" ]; then
254 # Constrained path set to ./zfs/bin/
255 STF_PATH="$BIN_DIR"
256 STF_PATH_REMOVE="no"
257 STF_MISSING_BIN=""
c1d9abf9
JWK
258 if [ ! -d "$STF_PATH" ]; then
259 mkdir "$STF_PATH"
c8f9061f 260 chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
c1d9abf9 261 fi
c8f9061f
BB
262
263 # Special case links for standard zfs utilities
264 DIRS="$(find "$CMD_DIR" -type d \( ! -name .deps -a \
265 ! -name .libs \) -print | tr '\n' ' ')"
266 create_links "$DIRS" "$ZFS_FILES"
267
268 # Special case links for zfs test suite utilities
269 DIRS="$(find "$STF_SUITE" -type d \( ! -name .deps -a \
270 ! -name .libs \) -print | tr '\n' ' ')"
271 create_links "$DIRS" "$ZFSTEST_FILES"
c1d9abf9 272 else
c8f9061f 273 # Constrained path set to /var/tmp/constrained_path.*
9109b89c 274 SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXXXX}
7839c4b5 275 STF_PATH=$(mktemp -d "$SYSTEMDIR")
c8f9061f
BB
276 STF_PATH_REMOVE="yes"
277 STF_MISSING_BIN=""
c1d9abf9 278
c8f9061f 279 chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
c1d9abf9 280
c1d9abf9 281 # Special case links for standard zfs utilities
7839c4b5 282 create_links "$SYSTEM_DIRS" "$ZFS_FILES"
c1d9abf9 283
c8f9061f
BB
284 # Special case links for zfs test suite utilities
285 create_links "$STF_SUITE/bin" "$ZFSTEST_FILES"
c1d9abf9
JWK
286 fi
287
c8f9061f 288 # Standard system utilities
7839c4b5
MM
289 SYSTEM_FILES="$SYSTEM_FILES_COMMON"
290 if [ "$UNAME" = "FreeBSD" ] ; then
d4e6e959 291 SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD"
7839c4b5 292 else
d4e6e959 293 SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX"
7839c4b5
MM
294 fi
295 create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
c8f9061f 296
c1d9abf9 297 # Exceptions
74698631 298 ln -fs "$STF_PATH/awk" "$STF_PATH/nawk"
7839c4b5
MM
299 if [ "$UNAME" = "Linux" ] ; then
300 ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
301 ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
302 ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
303 ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
304 ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
305 ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
306 elif [ "$UNAME" = "FreeBSD" ] ; then
307 ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
308 fi
c1d9abf9
JWK
309}
310
6bb24f4d
BB
311#
312# Output a useful usage message.
313#
314usage() {
315cat << EOF
316USAGE:
5a877a89 317$0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER]
6bb24f4d
BB
318
319DESCRIPTION:
320 ZFS Test Suite launch script
321
322OPTIONS:
323 -h Show this message
324 -v Verbose zfs-tests.sh output
325 -q Quiet test-runner output
326 -x Remove all testpools, dm, lo, and files (unsafe)
327 -k Disable cleanup after test failure
328 -f Use files only, disables block device tests
ef57371a 329 -S Enable stack tracer (negative performance impact)
c8f9061f 330 -c Only create and populate constrained path
d3463615 331 -R Automatically rerun failing tests
a69765ea 332 -m Enable kmemleak reporting (Linux only)
96342996 333 -n NFSFILE Use the nfsfile to determine the NFS configuration
9a810efb 334 -I NUM Number of iterations
6bb24f4d 335 -d DIR Use DIR for files and loopback devices
d7958b4c 336 -s SIZE Use vdevs of SIZE (default: 4G)
5e74ac51 337 -r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES})
d25534f8 338 -t PATH Run single test at PATH relative to test suite
271955da 339 -T TAGS Comma separated list of tags (default: 'functional')
d8fa599f 340 -u USER Run single test as USER (default: root)
6bb24f4d
BB
341
342EXAMPLES:
343# Run the default (linux) suite of tests and output the configuration used.
344$0 -v
345
346# Run a smaller suite of tests designed to run more quickly.
347$0 -r linux-fast
348
603059e4
CS
349# Run a single test
350$0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh
351
6bb24f4d
BB
352# Cleanup a previous run of the test suite prior to testing, run the
353# default (linux) suite of tests and perform no cleanup on exit.
e6123796 354$0 -x
6bb24f4d
BB
355
356EOF
357}
358
a69765ea 359while getopts 'hvqxkfScRmn:d:s:r:?t:T:u:I:' OPTION; do
6bb24f4d
BB
360 case $OPTION in
361 h)
362 usage
363 exit 1
364 ;;
365 v)
c8f9061f 366 VERBOSE="yes"
6bb24f4d
BB
367 ;;
368 q)
a18f8bce 369 QUIET="yes"
6bb24f4d
BB
370 ;;
371 x)
c8f9061f 372 CLEANUPALL="yes"
6bb24f4d
BB
373 ;;
374 k)
c8f9061f 375 CLEANUP="no"
6bb24f4d
BB
376 ;;
377 f)
c8f9061f
BB
378 LOOPBACK="no"
379 ;;
ef57371a
TN
380 S)
381 STACK_TRACER="yes"
382 ;;
c8f9061f
BB
383 c)
384 constrain_path
385 exit
6bb24f4d 386 ;;
d3463615
PD
387 R)
388 RERUN="yes"
389 ;;
a69765ea
DS
390 m)
391 KMEMLEAK="yes"
392 ;;
96342996
AG
393 n)
394 nfsfile=$OPTARG
d4e6e959 395 [ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile"
96342996
AG
396 export NFS=1
397 . "$nfsfile"
398 ;;
6bb24f4d
BB
399 d)
400 FILEDIR="$OPTARG"
401 ;;
9a810efb
GDN
402 I)
403 ITERATIONS="$OPTARG"
404 if [ "$ITERATIONS" -le 0 ]; then
405 fail "Iterations must be greater than 0."
406 fi
407 ;;
6bb24f4d
BB
408 s)
409 FILESIZE="$OPTARG"
410 ;;
411 r)
5e74ac51 412 RUNFILES="$OPTARG"
6bb24f4d 413 ;;
d8fa599f 414 t)
d4e6e959 415 if [ -n "$SINGLETEST" ]; then
d8fa599f
GDN
416 fail "-t can only be provided once."
417 fi
d4e6e959 418 SINGLETEST="$OPTARG"
d8fa599f 419 ;;
9a810efb
GDN
420 T)
421 TAGS="$OPTARG"
422 ;;
d8fa599f
GDN
423 u)
424 SINGLETESTUSER="$OPTARG"
425 ;;
6bb24f4d
BB
426 ?)
427 usage
428 exit
429 ;;
430 esac
431done
432
433shift $((OPTIND-1))
434
435FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
436LOOPBACKS=${LOOPBACKS:-""}
437
d4e6e959 438if [ -n "$SINGLETEST" ]; then
271955da 439 if [ -n "$TAGS" ]; then
440 fail "-t and -T are mutually exclusive."
441 fi
c8f9061f 442 RUNFILE_DIR="/var/tmp"
5e74ac51 443 RUNFILES="zfs-tests.$$.run"
d8fa599f
GDN
444 SINGLEQUIET="False"
445
446 if [ -n "$QUIET" ]; then
447 SINGLEQUIET="True"
448 fi
449
5e74ac51 450 cat >$RUNFILE_DIR/$RUNFILES << EOF
d8fa599f
GDN
451[DEFAULT]
452pre =
453quiet = $SINGLEQUIET
454pre_user = root
455user = $SINGLETESTUSER
456timeout = 600
457post_user = root
458post =
459outputdir = /var/tmp/test_results
460EOF
d4e6e959
RM
461 SINGLETESTDIR=$(dirname "$SINGLETEST")
462 SINGLETESTFILE=$(basename "$SINGLETEST")
463 SETUPSCRIPT=
464 CLEANUPSCRIPT=
d8fa599f 465
d4e6e959
RM
466 if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then
467 SETUPSCRIPT="setup"
468 fi
d8fa599f 469
d4e6e959
RM
470 if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then
471 CLEANUPSCRIPT="cleanup"
472 fi
473
474 cat >>$RUNFILE_DIR/$RUNFILES << EOF
d8fa599f
GDN
475
476[$SINGLETESTDIR]
477tests = ['$SINGLETESTFILE']
478pre = $SETUPSCRIPT
479post = $CLEANUPSCRIPT
271955da 480tags = ['functional']
d8fa599f 481EOF
d8fa599f
GDN
482fi
483
271955da 484#
485# Use default tag if none was specified
486#
487TAGS=${TAGS:='functional'}
488
6bb24f4d 489#
5e74ac51 490# Attempt to locate the runfiles describing the test workload.
6bb24f4d 491#
5e74ac51
RM
492R=""
493IFS=,
494for RUNFILE in $RUNFILES; do
495 if [ -n "$RUNFILE" ]; then
496 SAVED_RUNFILE="$RUNFILE"
497 RUNFILE=$(find_runfile "$RUNFILE")
498 [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE"
d4e6e959 499 R="$R,$RUNFILE"
5e74ac51 500 fi
6bb24f4d 501
5e74ac51
RM
502 if [ ! -r "$RUNFILE" ]; then
503 fail "Cannot read runfile: $RUNFILE"
504 fi
505done
506unset IFS
d4e6e959 507RUNFILES=${R#,}
6bb24f4d
BB
508
509#
510# This script should not be run as root. Instead the test user, which may
511# be a normal user account, needs to be configured such that it can
512# run commands via sudo passwordlessly.
513#
c552fbc5 514if [ "$(id -u)" = "0" ]; then
6bb24f4d
BB
515 fail "This script must not be run as root."
516fi
517
c552fbc5 518if [ "$(sudo whoami)" != "root" ]; then
6bb24f4d
BB
519 fail "Passwordless sudo access required."
520fi
521
c1d9abf9 522#
c8f9061f 523# Constrain the available binaries to a known set.
c1d9abf9
JWK
524#
525constrain_path
526
e6123796
JX
527#
528# Check if ksh exists
529#
7839c4b5
MM
530if [ "$UNAME" = "FreeBSD" ]; then
531 sudo ln -fs /usr/local/bin/ksh93 /bin/ksh
532fi
74698631 533[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
3f03fc8d
BB
534[ -e "$STF_SUITE/include/default.cfg" ] || fail \
535 "Missing $STF_SUITE/include/default.cfg file."
e6123796 536
6bb24f4d 537#
c8f9061f 538# Verify the ZFS module stack is loaded.
6bb24f4d 539#
ef57371a 540if [ "$STACK_TRACER" = "yes" ]; then
d4e6e959 541 sudo "${ZFS_SH}" -S >/dev/null 2>&1
ef57371a 542else
d4e6e959 543 sudo "${ZFS_SH}" >/dev/null 2>&1
ef57371a 544fi
6bb24f4d
BB
545
546#
547# Attempt to cleanup all previous state for a new test run.
548#
c8f9061f 549if [ "$CLEANUPALL" = "yes" ]; then
6bb24f4d
BB
550 cleanup_all
551fi
552
553#
554# By default preserve any existing pools
3fd3e56c 555# NOTE: Since 'zpool list' outputs a newline-delimited list convert $KEEP from
556# space-delimited to newline-delimited.
6bb24f4d
BB
557#
558if [ -z "${KEEP}" ]; then
3fd3e56c 559 KEEP="$(sudo "$ZPOOL" list -H -o name)"
6bb24f4d
BB
560 if [ -z "${KEEP}" ]; then
561 KEEP="rpool"
562 fi
3fd3e56c 563else
d4e6e959 564 KEEP="$(echo "$KEEP" | tr '[:blank:]' '\n')"
6bb24f4d
BB
565fi
566
3fd3e56c 567#
568# NOTE: The following environment variables are undocumented
569# and should be used for testing purposes only:
570#
571# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
572# __ZFS_POOL_RESTRICT - iterate only over the pools it lists
573#
574# See libzfs/libzfs_config.c for more information.
575#
7839c4b5
MM
576if [ "$UNAME" = "FreeBSD" ] ; then
577 __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | tr -s '\n' ' ')"
578else
579 __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
580fi
d21d5b82 581
74698631 582. "$STF_SUITE/include/default.cfg"
c1d9abf9 583
6bb24f4d
BB
584#
585# No DISKS have been provided so a basic file or loopback based devices
586# must be created for the test suite to use.
587#
588if [ -z "${DISKS}" ]; then
94299107
JWK
589 #
590 # If this is a performance run, prevent accidental use of
591 # loopback devices.
592 #
593 [ "$TAGS" = "perf" ] && fail "Running perf tests without disks."
594
6bb24f4d
BB
595 #
596 # Create sparse files for the test suite. These may be used
597 # directory or have loopback devices layered on them.
598 #
599 for TEST_FILE in ${FILES}; do
600 [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
c552fbc5 601 truncate -s "${FILESIZE}" "${TEST_FILE}" ||
6bb24f4d 602 fail "Failed creating: ${TEST_FILE} ($?)"
6bb24f4d
BB
603 done
604
605 #
606 # If requested setup loopback devices backed by the sparse files.
607 #
c8f9061f 608 if [ "$LOOPBACK" = "yes" ]; then
c8f9061f 609 test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
6bb24f4d
BB
610
611 for TEST_FILE in ${FILES}; do
7839c4b5
MM
612 if [ "$UNAME" = "FreeBSD" ] ; then
613 MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}")
614 if [ -z "$MDDEVICE" ] ; then
615 fail "Failed: ${TEST_FILE} -> loopback"
616 fi
d4e6e959
RM
617 DISKS="$DISKS $MDDEVICE"
618 LOOPBACKS="$LOOPBACKS $MDDEVICE"
5c596ba7 619 else
7839c4b5
MM
620 TEST_LOOPBACK=$(sudo "${LOSETUP}" -f)
621 sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
622 fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
745a7f78 623 BASELOOPBACK="${TEST_LOOPBACK##*/}"
d4e6e959
RM
624 DISKS="$DISKS $BASELOOPBACK"
625 LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK"
5c596ba7 626 fi
6bb24f4d 627 done
d4e6e959
RM
628 DISKS=${DISKS# }
629 LOOPBACKS=${LOOPBACKS# }
630 else
631 DISKS="$FILES"
6bb24f4d
BB
632 fi
633fi
634
94299107
JWK
635#
636# It may be desirable to test with fewer disks than the default when running
637# the performance tests, but the functional tests require at least three.
638#
c8f9061f 639NUM_DISKS=$(echo "${DISKS}" | awk '{print NF}')
94299107
JWK
640if [ "$TAGS" != "perf" ]; then
641 [ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
642fi
6bb24f4d
BB
643
644#
645# Disable SELinux until the ZFS Test Suite has been updated accordingly.
646#
c1d9abf9 647if [ -x "$STF_PATH/setenforce" ]; then
d4e6e959 648 sudo setenforce permissive >/dev/null 2>&1
6bb24f4d
BB
649fi
650
00481e7d 651#
27ef66ef 652# Enable internal ZFS debug log and clear it.
00481e7d
BB
653#
654if [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then
655 sudo /bin/sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable"
656 sudo /bin/sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
657fi
658
94299107
JWK
659msg
660msg "--- Configuration ---"
661msg "Runfiles: $RUNFILES"
662msg "STF_TOOLS: $STF_TOOLS"
663msg "STF_SUITE: $STF_SUITE"
664msg "STF_PATH: $STF_PATH"
6bb24f4d
BB
665msg "FILEDIR: $FILEDIR"
666msg "FILES: $FILES"
667msg "LOOPBACKS: $LOOPBACKS"
668msg "DISKS: $DISKS"
669msg "NUM_DISKS: $NUM_DISKS"
670msg "FILESIZE: $FILESIZE"
9a810efb
GDN
671msg "ITERATIONS: $ITERATIONS"
672msg "TAGS: $TAGS"
ef57371a 673msg "STACK_TRACER: $STACK_TRACER"
6bb24f4d 674msg "Keep pool(s): $KEEP"
c1d9abf9 675msg "Missing util(s): $STF_MISSING_BIN"
6bb24f4d
BB
676msg ""
677
678export STF_TOOLS
679export STF_SUITE
c1d9abf9 680export STF_PATH
6bb24f4d 681export DISKS
3fd3e56c 682export FILEDIR
6bb24f4d 683export KEEP
d21d5b82 684export __ZFS_POOL_EXCLUDE
00481e7d 685export TESTFAIL_CALLBACKS
c1d9abf9 686export PATH=$STF_PATH
6bb24f4d 687
f2eaa978
AZ
688mktemp_file() {
689 if [ "$UNAME" = "FreeBSD" ]; then
690 mktemp -u "${FILEDIR}/$1.XXXXXX"
691 else
692 mktemp -ut "$1.XXXXXX" -p "$FILEDIR"
693 fi
694}
695mkdir -p "$FILEDIR" || :
696RESULTS_FILE=$(mktemp_file zts-results)
697REPORT_FILE=$(mktemp_file zts-report)
e4a3297a
BB
698
699#
700# Run all the tests as specified.
701#
a69765ea
DS
702msg "${TEST_RUNNER}" \
703 "${QUIET:+-q}" \
704 "${KMEMLEAK:+-m}" \
5e74ac51 705 "-c \"${RUNFILES}\"" \
a18f8bce
RM
706 "-T \"${TAGS}\"" \
707 "-i \"${STF_SUITE}\"" \
708 "-I \"${ITERATIONS}\""
a69765ea 709${TEST_RUNNER} ${QUIET:+-q} ${KMEMLEAK:+-m} \
5e74ac51 710 -c "${RUNFILES}" \
a18f8bce
RM
711 -T "${TAGS}" \
712 -i "${STF_SUITE}" \
713 -I "${ITERATIONS}" \
714 2>&1 | tee "$RESULTS_FILE"
e4a3297a
BB
715#
716# Analyze the results.
717#
d3463615 718${ZTS_REPORT} ${RERUN:+--no-maybes} "$RESULTS_FILE" >"$REPORT_FILE"
6bb24f4d 719RESULT=$?
d3463615
PD
720
721if [ "$RESULT" -eq "2" ] && [ -n "$RERUN" ]; then
722 MAYBES="$($ZTS_REPORT --list-maybes)"
f2eaa978
AZ
723 TEMP_RESULTS_FILE=$(mktemp_file zts-results-tmp)
724 TEST_LIST=$(mktemp_file test-list)
d3463615
PD
725 grep "^Test:.*\[FAIL\]" "$RESULTS_FILE" >"$TEMP_RESULTS_FILE"
726 for test_name in $MAYBES; do
727 grep "$test_name " "$TEMP_RESULTS_FILE" >>"$TEST_LIST"
728 done
a69765ea 729 ${TEST_RUNNER} ${QUIET:+-q} ${KMEMLEAK:+-m} \
d3463615
PD
730 -c "${RUNFILES}" \
731 -T "${TAGS}" \
732 -i "${STF_SUITE}" \
733 -I "${ITERATIONS}" \
734 -l "${TEST_LIST}" \
735 2>&1 | tee "$RESULTS_FILE"
736 #
737 # Analyze the results.
738 #
739 ${ZTS_REPORT} --no-maybes "$RESULTS_FILE" >"$REPORT_FILE"
740 RESULT=$?
741fi
742
743
d4e6e959 744cat "$REPORT_FILE"
e4a3297a
BB
745
746RESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE")
747if [ -d "$RESULTS_DIR" ]; then
748 cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results"
749fi
750
751rm -f "$RESULTS_FILE" "$REPORT_FILE"
6bb24f4d 752
d4e6e959
RM
753if [ -n "$SINGLETEST" ]; then
754 rm -f "$RUNFILES" >/dev/null 2>&1
d8fa599f
GDN
755fi
756
6bb24f4d 757exit ${RESULT}