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
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.
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]
24 BASE_DIR
=$
(dirname "$0")
25 SCRIPT_COMMON
=common.sh
26 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
27 .
"${BASE_DIR}/${SCRIPT_COMMON}"
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
40 DEFAULT_RUNFILES
="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
41 RUNFILES
=${RUNFILES:-$DEFAULT_RUNFILES}
42 FILEDIR
=${FILEDIR:-/var/tmp}
48 ZFS_DBGMSG
="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
49 ZFS_DMESG
="$STF_SUITE/callbacks/zfs_dmesg.ksh"
52 # Override some defaults if on FreeBSD
53 if [ "$UNAME" = "FreeBSD" ] ; then
54 TESTFAIL_CALLBACKS
=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
55 LOSETUP
=/sbin
/mdconfig
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}
65 # Log an informational message when additional verbosity is enabled.
68 if [ "$VERBOSE" = "yes" ]; then
74 # Log a failure message, cleanup, and return an error.
82 cleanup_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}"
91 cleanup_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)
97 if [ -n "$DM_DEV" ]; then
98 sudo
"${DMSETUP}" remove
"${DM_DEV}" ||
99 echo "Failed to remove: ${DM_DEV}"
102 if [ -n "${TEST_LOOPBACK}" ]; then
103 sudo
"${LOSETUP}" -d "${TEST_LOOPBACK}" ||
104 echo "Failed to remove: ${TEST_LOOPBACK}"
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.
115 if [ "$CLEANUP" = "no" ]; then
120 if [ "$LOOPBACK" = "yes" ]; then
121 if [ "$UNAME" = "FreeBSD" ] ; then
122 cleanup_freebsd_loopback
124 cleanup_linux_loopback
128 for TEST_FILE
in ${FILES}; do
129 rm -f "${TEST_FILE}" >/dev
/null
2>&1
132 if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
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.
145 TEST_POOLS
=$
(sudo
"$ZPOOL" list
-H -o name |
grep testpool
)
146 if [ "$UNAME" = "FreeBSD" ] ; then
147 TEST_LOOPBACKS
=$
(sudo
"${LOSETUP}" -l)
149 TEST_LOOPBACKS
=$
(sudo
"${LOSETUP}" -a|
grep file-vdev|cut
-f1 -d:)
151 TEST_FILES
=$
(ls /var
/tmp
/file-vdev
* 2>/dev
/null
)
154 msg
"--- Cleanup ---"
155 msg
"Removing pool(s): $(echo "${TEST_POOLS}" | tr '\n' ' ')"
156 for TEST_POOL
in $TEST_POOLS; do
157 sudo
"$ZPOOL" destroy
"${TEST_POOL}"
160 if [ "$UNAME" != "FreeBSD" ] ; then
161 msg
"Removing dm(s): $(sudo "${DMSETUP}" ls |
162 grep loop | tr '\n' ' ')"
163 sudo
"${DMSETUP}" remove_all
166 msg
"Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
167 for TEST_LOOPBACK
in $TEST_LOOPBACKS; do
168 if [ "$UNAME" = "FreeBSD" ] ; then
169 sudo
"${LOSETUP}" -d -u "${TEST_LOOPBACK}"
171 sudo
"${LOSETUP}" -d "${TEST_LOOPBACK}"
175 msg
"Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
176 for TEST_FILE
in $TEST_FILES; do
177 sudo
rm -f "${TEST_FILE}"
182 # Takes a name as the only arguments and looks for the following variations
183 # on that name. If one is found it is returned.
185 # $RUNFILE_DIR/<name>
186 # $RUNFILE_DIR/<name>.run
194 if [ -f "$RUNFILE_DIR/$NAME" ]; then
195 RESULT
="$RUNFILE_DIR/$NAME"
196 elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then
197 RESULT
="$RUNFILE_DIR/$NAME.run"
198 elif [ -f "$NAME" ]; then
200 elif [ -f "$NAME.run" ]; then
208 # Symlink file if it appears under any of the given paths.
214 [ -n "$STF_PATH" ] || fail
"STF_PATH wasn't correctly set"
216 for i
in $file_list; do
217 for j
in $dir_list; do
218 [ ! -e "$STF_PATH/$i" ] ||
continue
220 if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then
221 ln -sf "$j/$i" "$STF_PATH/$i" || \
222 fail
"Couldn't link $i"
227 [ ! -e "$STF_PATH/$i" ] && \
228 STF_MISSING_BIN
="$STF_MISSING_BIN $i"
230 STF_MISSING_BIN
=${STF_MISSING_BIN# }
234 # Constrain the path to limit the available binaries to a known set.
235 # When running in-tree a top level ./bin/ directory is created for
236 # convenience, otherwise a temporary directory is used.
239 .
"$STF_SUITE/include/commands.cfg"
241 # On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils
242 # install to /usr/local/sbin. To avoid testing the wrong utils we
243 # need /usr/local to come before / in the path search order.
244 SYSTEM_DIRS
="/usr/local/bin /usr/local/sbin"
245 SYSTEM_DIRS
="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin"
247 if [ "$INTREE" = "yes" ]; then
248 # Constrained path set to ./zfs/bin/
252 if [ ! -d "$STF_PATH" ]; then
254 chmod 755 "$STF_PATH" || fail
"Couldn't chmod $STF_PATH"
257 # Special case links for standard zfs utilities
258 DIRS
="$(find "$CMD_DIR" -type d \( ! -name .deps -a \
259 ! -name .libs \) -print | tr '\n' ' ')"
260 create_links
"$DIRS" "$ZFS_FILES"
262 # Special case links for zfs test suite utilities
263 DIRS
="$(find "$STF_SUITE" -type d \( ! -name .deps -a \
264 ! -name .libs \) -print | tr '\n' ' ')"
265 create_links
"$DIRS" "$ZFSTEST_FILES"
267 # Constrained path set to /var/tmp/constrained_path.*
268 SYSTEMDIR
=${SYSTEMDIR:-/var/tmp/constrained_path.XXXX}
269 STF_PATH
=$
(mktemp
-d "$SYSTEMDIR")
270 STF_PATH_REMOVE
="yes"
273 chmod 755 "$STF_PATH" || fail
"Couldn't chmod $STF_PATH"
275 # Special case links for standard zfs utilities
276 create_links
"$SYSTEM_DIRS" "$ZFS_FILES"
278 # Special case links for zfs test suite utilities
279 create_links
"$STF_SUITE/bin" "$ZFSTEST_FILES"
282 # Standard system utilities
283 SYSTEM_FILES
="$SYSTEM_FILES_COMMON"
284 if [ "$UNAME" = "FreeBSD" ] ; then
285 SYSTEM_FILES
="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD"
287 SYSTEM_FILES
="$SYSTEM_FILES $SYSTEM_FILES_LINUX"
289 create_links
"$SYSTEM_DIRS" "$SYSTEM_FILES"
292 ln -fs "$STF_PATH/awk" "$STF_PATH/nawk"
293 if [ "$UNAME" = "Linux" ] ; then
294 ln -fs /sbin
/fsck.ext4
"$STF_PATH/fsck"
295 ln -fs /sbin
/mkfs.ext4
"$STF_PATH/newfs"
296 ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
297 ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
298 ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
299 ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
300 elif [ "$UNAME" = "FreeBSD" ] ; then
301 ln -fs /usr
/local
/bin
/ksh93
"$STF_PATH/ksh"
306 # Output a useful usage message.
311 $0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER]
314 ZFS Test Suite launch script
318 -v Verbose zfs-tests.sh output
319 -q Quiet test-runner output
320 -x Remove all testpools, dm, lo, and files (unsafe)
321 -k Disable cleanup after test failure
322 -f Use files only, disables block device tests
323 -S Enable stack tracer (negative performance impact)
324 -c Only create and populate constrained path
325 -n NFSFILE Use the nfsfile to determine the NFS configuration
326 -I NUM Number of iterations
327 -d DIR Use DIR for files and loopback devices
328 -s SIZE Use vdevs of SIZE (default: 4G)
329 -r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES})
330 -t PATH Run single test at PATH relative to test suite
331 -T TAGS Comma separated list of tags (default: 'functional')
332 -u USER Run single test as USER (default: root)
335 # Run the default (linux) suite of tests and output the configuration used.
338 # Run a smaller suite of tests designed to run more quickly.
342 $0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh
344 # Cleanup a previous run of the test suite prior to testing, run the
345 # default (linux) suite of tests and perform no cleanup on exit.
351 while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION
; do
358 # shellcheck disable=SC2034
382 [ -f "$nfsfile" ] || fail
"Cannot read file: $nfsfile"
391 if [ "$ITERATIONS" -le 0 ]; then
392 fail
"Iterations must be greater than 0."
402 if [ -n "$SINGLETEST" ]; then
403 fail
"-t can only be provided once."
411 SINGLETESTUSER
="$OPTARG"
422 FILES
=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
423 LOOPBACKS
=${LOOPBACKS:-""}
425 if [ -n "$SINGLETEST" ]; then
426 if [ -n "$TAGS" ]; then
427 fail
"-t and -T are mutually exclusive."
429 RUNFILE_DIR
="/var/tmp"
430 RUNFILES
="zfs-tests.$$.run"
433 if [ -n "$QUIET" ]; then
437 cat >$RUNFILE_DIR/$RUNFILES << EOF
442 user = $SINGLETESTUSER
446 outputdir = /var/tmp/test_results
448 SINGLETESTDIR
=$
(dirname "$SINGLETEST")
449 SINGLETESTFILE
=$
(basename "$SINGLETEST")
453 if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then
457 if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then
458 CLEANUPSCRIPT
="cleanup"
461 cat >>$RUNFILE_DIR/$RUNFILES << EOF
464 tests = ['$SINGLETESTFILE']
466 post = $CLEANUPSCRIPT
467 tags = ['functional']
472 # Use default tag if none was specified
474 TAGS
=${TAGS:='functional'}
477 # Attempt to locate the runfiles describing the test workload.
481 for RUNFILE
in $RUNFILES; do
482 if [ -n "$RUNFILE" ]; then
483 SAVED_RUNFILE
="$RUNFILE"
484 RUNFILE
=$
(find_runfile
"$RUNFILE")
485 [ -z "$RUNFILE" ] && fail
"Cannot find runfile: $SAVED_RUNFILE"
489 if [ ! -r "$RUNFILE" ]; then
490 fail
"Cannot read runfile: $RUNFILE"
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.
501 if [ "$(id -u)" = "0" ]; then
502 fail
"This script must not be run as root."
505 if [ "$(sudo whoami)" != "root" ]; then
506 fail
"Passwordless sudo access required."
510 # Constrain the available binaries to a known set.
515 # Check if ksh exists
517 if [ "$UNAME" = "FreeBSD" ]; then
518 sudo
ln -fs /usr
/local
/bin
/ksh93
/bin
/ksh
520 [ -e "$STF_PATH/ksh" ] || fail
"This test suite requires ksh."
521 [ -e "$STF_SUITE/include/default.cfg" ] || fail \
522 "Missing $STF_SUITE/include/default.cfg file."
525 # Verify the ZFS module stack is loaded.
527 if [ "$STACK_TRACER" = "yes" ]; then
528 sudo
"${ZFS_SH}" -S >/dev
/null
2>&1
530 sudo
"${ZFS_SH}" >/dev
/null
2>&1
534 # Attempt to cleanup all previous state for a new test run.
536 if [ "$CLEANUPALL" = "yes" ]; then
541 # By default preserve any existing pools
542 # NOTE: Since 'zpool list' outputs a newline-delimited list convert $KEEP from
543 # space-delimited to newline-delimited.
545 if [ -z "${KEEP}" ]; then
546 KEEP
="$(sudo "$ZPOOL" list -H -o name)"
547 if [ -z "${KEEP}" ]; then
551 KEEP
="$(echo "$KEEP" | tr '[:blank:]' '\n')"
555 # NOTE: The following environment variables are undocumented
556 # and should be used for testing purposes only:
558 # __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
559 # __ZFS_POOL_RESTRICT - iterate only over the pools it lists
561 # See libzfs/libzfs_config.c for more information.
563 if [ "$UNAME" = "FreeBSD" ] ; then
564 __ZFS_POOL_EXCLUDE
="$(echo "$KEEP" | tr -s '\n' ' ')"
566 __ZFS_POOL_EXCLUDE
="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
569 .
"$STF_SUITE/include/default.cfg"
572 msg
"--- Configuration ---"
573 msg
"Runfiles: $RUNFILES"
574 msg
"STF_TOOLS: $STF_TOOLS"
575 msg
"STF_SUITE: $STF_SUITE"
576 msg
"STF_PATH: $STF_PATH"
579 # No DISKS have been provided so a basic file or loopback based devices
580 # must be created for the test suite to use.
582 if [ -z "${DISKS}" ]; then
584 # Create sparse files for the test suite. These may be used
585 # directory or have loopback devices layered on them.
587 for TEST_FILE
in ${FILES}; do
588 [ -f "$TEST_FILE" ] && fail
"Failed file exists: ${TEST_FILE}"
589 truncate
-s "${FILESIZE}" "${TEST_FILE}" ||
590 fail
"Failed creating: ${TEST_FILE} ($?)"
594 # If requested setup loopback devices backed by the sparse files.
596 if [ "$LOOPBACK" = "yes" ]; then
597 test -x "$LOSETUP" || fail
"$LOSETUP utility must be installed"
599 for TEST_FILE
in ${FILES}; do
600 if [ "$UNAME" = "FreeBSD" ] ; then
601 MDDEVICE
=$
(sudo
"${LOSETUP}" -a -t vnode
-f "${TEST_FILE}")
602 if [ -z "$MDDEVICE" ] ; then
603 fail
"Failed: ${TEST_FILE} -> loopback"
605 DISKS
="$DISKS $MDDEVICE"
606 LOOPBACKS
="$LOOPBACKS $MDDEVICE"
608 TEST_LOOPBACK
=$
(sudo
"${LOSETUP}" -f)
609 sudo
"${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
610 fail
"Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
611 BASELOOPBACK
=$
(basename "$TEST_LOOPBACK")
612 DISKS
="$DISKS $BASELOOPBACK"
613 LOOPBACKS
="$LOOPBACKS $TEST_LOOPBACK"
617 LOOPBACKS
=${LOOPBACKS# }
623 NUM_DISKS
=$
(echo "${DISKS}" |
awk '{print NF}')
624 [ "$NUM_DISKS" -lt 3 ] && fail
"Not enough disks ($NUM_DISKS/3 minimum)"
627 # Disable SELinux until the ZFS Test Suite has been updated accordingly.
629 if [ -x "$STF_PATH/setenforce" ]; then
630 sudo setenforce permissive
>/dev
/null
2>&1
634 # Enable internal ZFS debug log and clear it.
636 if [ -e /sys
/module
/zfs
/parameters
/zfs_dbgmsg_enable
]; then
637 sudo
/bin
/sh
-c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable"
638 sudo
/bin
/sh
-c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
641 msg
"FILEDIR: $FILEDIR"
643 msg
"LOOPBACKS: $LOOPBACKS"
645 msg
"NUM_DISKS: $NUM_DISKS"
646 msg
"FILESIZE: $FILESIZE"
647 msg
"ITERATIONS: $ITERATIONS"
649 msg
"STACK_TRACER: $STACK_TRACER"
650 msg
"Keep pool(s): $KEEP"
651 msg
"Missing util(s): $STF_MISSING_BIN"
660 export __ZFS_POOL_EXCLUDE
661 export TESTFAIL_CALLBACKS
662 export PATH
=$STF_PATH
664 if [ "$UNAME" = "FreeBSD" ] ; then
665 mkdir
-p "$FILEDIR" || true
666 RESULTS_FILE
=$
(mktemp
-u "${FILEDIR}/zts-results.XXXX")
667 REPORT_FILE
=$
(mktemp
-u "${FILEDIR}/zts-report.XXXX")
669 RESULTS_FILE
=$
(mktemp
-u -t zts-results.XXXX
-p "$FILEDIR")
670 REPORT_FILE
=$
(mktemp
-u -t zts-report.XXXX
-p "$FILEDIR")
674 # Run all the tests as specified.
676 msg
"${TEST_RUNNER} ${QUIET:+-q}" \
677 "-c \"${RUNFILES}\"" \
679 "-i \"${STF_SUITE}\"" \
680 "-I \"${ITERATIONS}\""
681 ${TEST_RUNNER} ${QUIET:+-q} \
686 2>&1 |
tee "$RESULTS_FILE"
689 # Analyze the results.
691 ${ZTS_REPORT} "$RESULTS_FILE" >"$REPORT_FILE"
695 RESULTS_DIR
=$
(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE")
696 if [ -d "$RESULTS_DIR" ]; then
697 cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results"
700 rm -f "$RESULTS_FILE" "$REPORT_FILE"
702 if [ -n "$SINGLETEST" ]; then
703 rm -f "$RUNFILES" >/dev
/null
2>&1