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