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