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