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
39 RUNFILE
=${RUNFILE:-"linux.run"}
40 FILEDIR
=${FILEDIR:-/var/tmp}
46 ZFS_DBGMSG
="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
47 ZFS_DMESG
="$STF_SUITE/callbacks/zfs_dmesg.ksh"
48 ZFS_MMP
="$STF_SUITE/callbacks/zfs_mmp.ksh"
49 TESTFAIL_CALLBACKS
=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
50 LOSETUP
=${LOSETUP:-/sbin/losetup}
51 DMSETUP
=${DMSETUP:-/sbin/dmsetup}
54 # Log an informational message when additional verbosity is enabled.
57 if [ "$VERBOSE" = "yes" ]; then
63 # Log a failure message, cleanup, and return an error.
66 echo -e "$PROG: $1" >&2
72 # Attempt to remove loopback devices and files which where created earlier
73 # by this script to run the test framework. The '-k' option may be passed
74 # to the script to suppress cleanup for debugging purposes.
77 if [ "$CLEANUP" = "no" ]; then
81 if [ "$LOOPBACK" = "yes" ]; then
82 for TEST_LOOPBACK
in ${LOOPBACKS}; do
83 LOOP_DEV
=$
(basename "$TEST_LOOPBACK")
84 DM_DEV
=$
(sudo
"${DMSETUP}" ls 2>/dev
/null | \
85 grep "${LOOP_DEV}" | cut
-f1)
87 if [ -n "$DM_DEV" ]; then
88 sudo
"${DMSETUP}" remove
"${DM_DEV}" ||
89 echo "Failed to remove: ${DM_DEV}"
92 if [ -n "${TEST_LOOPBACK}" ]; then
93 sudo
"${LOSETUP}" -d "${TEST_LOOPBACK}" ||
94 echo "Failed to remove: ${TEST_LOOPBACK}"
99 for TEST_FILE
in ${FILES}; do
100 rm -f "${TEST_FILE}" &>/dev
/null
103 if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then
110 # Attempt to remove all testpools (testpool.XXX), unopened dm devices,
111 # loopback devices, and files. This is a useful way to cleanup a previous
112 # test run failure which has left the system in an unknown state. This can
113 # be dangerous and should only be used in a dedicated test environment.
117 TEST_POOLS
=$
(sudo
"$ZPOOL" list
-H -o name |
grep testpool
)
119 TEST_LOOPBACKS
=$
(sudo
"${LOSETUP}" -a|
grep file-vdev|cut
-f1 -d:)
121 TEST_FILES
=$
(ls /var
/tmp
/file-vdev
* 2>/dev
/null
)
124 msg
"--- Cleanup ---"
125 msg
"Removing pool(s): $(echo "${TEST_POOLS}" | tr '\n' ' ')"
126 for TEST_POOL
in $TEST_POOLS; do
127 sudo
"$ZPOOL" destroy
"${TEST_POOL}"
130 msg
"Removing dm(s): $(sudo "${DMSETUP}" ls |
131 grep loop | tr '\n' ' ')"
132 sudo
"${DMSETUP}" remove_all
134 msg
"Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
135 for TEST_LOOPBACK
in $TEST_LOOPBACKS; do
136 sudo
"${LOSETUP}" -d "${TEST_LOOPBACK}"
139 msg
"Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
140 for TEST_FILE
in $TEST_FILES; do
141 sudo
rm -f "${TEST_FILE}"
146 # Takes a name as the only arguments and looks for the following variations
147 # on that name. If one is found it is returned.
149 # $RUNFILE_DIR/<name>
150 # $RUNFILE_DIR/<name>.run
158 if [ -f "$RUNFILE_DIR/$NAME" ]; then
159 RESULT
="$RUNFILE_DIR/$NAME"
160 elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then
161 RESULT
="$RUNFILE_DIR/$NAME.run"
162 elif [ -f "$NAME" ]; then
164 elif [ -f "$NAME.run" ]; then
172 # Symlink file if it appears under any of the given paths.
178 [ -n "$STF_PATH" ] || fail
"STF_PATH wasn't correctly set"
180 for i
in $file_list; do
181 for j
in $dir_list; do
182 [ ! -e "$STF_PATH/$i" ] ||
continue
184 if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then
185 ln -s "$j/$i" "$STF_PATH/$i" || \
186 fail
"Couldn't link $i"
191 [ ! -e "$STF_PATH/$i" ] && STF_MISSING_BIN
="$STF_MISSING_BIN$i "
196 # Constrain the path to limit the available binaries to a known set.
197 # When running in-tree a top level ./bin/ directory is created for
198 # convenience, otherwise a temporary directory is used.
201 .
"$STF_SUITE/include/commands.cfg"
203 if [ "$INTREE" = "yes" ]; then
204 # Constrained path set to ./zfs/bin/
208 if [ ! -d "$STF_PATH" ]; then
210 chmod 755 "$STF_PATH" || fail
"Couldn't chmod $STF_PATH"
213 # Special case links for standard zfs utilities
214 DIRS
="$(find "$CMD_DIR" -type d \( ! -name .deps -a \
215 ! -name .libs \) -print | tr '\n' ' ')"
216 create_links
"$DIRS" "$ZFS_FILES"
218 # Special case links for zfs test suite utilities
219 DIRS
="$(find "$STF_SUITE" -type d \( ! -name .deps -a \
220 ! -name .libs \) -print | tr '\n' ' ')"
221 create_links
"$DIRS" "$ZFSTEST_FILES"
223 # Constrained path set to /var/tmp/constrained_path.*
224 SYSTEMDIR
=${SYSTEMDIR:-/var/tmp/constrained_path.XXXX}
225 STF_PATH
=$
(/bin
/mktemp
-d "$SYSTEMDIR")
226 STF_PATH_REMOVE
="yes"
229 chmod 755 "$STF_PATH" || fail
"Couldn't chmod $STF_PATH"
231 # Special case links for standard zfs utilities
232 create_links
"/bin /usr/bin /sbin /usr/sbin" "$ZFS_FILES"
234 # Special case links for zfs test suite utilities
235 create_links
"$STF_SUITE/bin" "$ZFSTEST_FILES"
238 # Standard system utilities
239 create_links
"/bin /usr/bin /sbin /usr/sbin" "$SYSTEM_FILES"
242 ln -fs "$STF_PATH/awk" "$STF_PATH/nawk"
243 ln -fs /sbin
/fsck.ext4
"$STF_PATH/fsck"
244 ln -fs /sbin
/mkfs.ext4
"$STF_PATH/newfs"
245 ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
246 ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
247 ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
248 ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
252 # Output a useful usage message.
257 $0 [hvqxkf] [-s SIZE] [-r RUNFILE] [-t PATH] [-u USER]
260 ZFS Test Suite launch script
264 -v Verbose zfs-tests.sh output
265 -q Quiet test-runner output
266 -x Remove all testpools, dm, lo, and files (unsafe)
267 -k Disable cleanup after test failure
268 -f Use files only, disables block device tests
269 -c Only create and populate constrained path
270 -I NUM Number of iterations
271 -d DIR Use DIR for files and loopback devices
272 -s SIZE Use vdevs of SIZE (default: 4G)
273 -r RUNFILE Run tests in RUNFILE (default: linux.run)
274 -t PATH Run single test at PATH relative to test suite
275 -T TAGS Comma separated list of tags (default: 'functional')
276 -u USER Run single test as USER (default: root)
279 # Run the default (linux) suite of tests and output the configuration used.
282 # Run a smaller suite of tests designed to run more quickly.
285 # Cleanup a previous run of the test suite prior to testing, run the
286 # default (linux) suite of tests and perform no cleanup on exit.
292 while getopts 'hvqxkfcd:s:r:?t:T:u:I:' OPTION
; do
299 # shellcheck disable=SC2034
323 if [ "$ITERATIONS" -le 0 ]; then
324 fail
"Iterations must be greater than 0."
334 if [ ${#SINGLETEST[@]} -ne 0 ]; then
335 fail
"-t can only be provided once."
337 SINGLETEST
+=("$OPTARG")
343 SINGLETESTUSER
="$OPTARG"
354 FILES
=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
355 LOOPBACKS
=${LOOPBACKS:-""}
357 if [ ${#SINGLETEST[@]} -ne 0 ]; then
358 if [ -n "$TAGS" ]; then
359 fail
"-t and -T are mutually exclusive."
361 RUNFILE_DIR
="/var/tmp"
362 RUNFILE
="zfs-tests.$$.run"
365 if [ -n "$QUIET" ]; then
369 cat >$RUNFILE_DIR/$RUNFILE << EOF
374 user = $SINGLETESTUSER
378 outputdir = /var/tmp/test_results
380 for t
in "${SINGLETEST[@]}"
382 SINGLETESTDIR
=$
(dirname "$t")
383 SINGLETESTFILE
=$
(basename "$t")
387 if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then
391 if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then
392 CLEANUPSCRIPT
="cleanup"
395 cat >>$RUNFILE_DIR/$RUNFILE << EOF
398 tests = ['$SINGLETESTFILE']
400 post = $CLEANUPSCRIPT
401 tags = ['functional']
407 # Use default tag if none was specified
409 TAGS
=${TAGS:='functional'}
412 # Attempt to locate the runfile describing the test workload.
414 if [ -n "$RUNFILE" ]; then
415 SAVED_RUNFILE
="$RUNFILE"
416 RUNFILE
=$
(find_runfile
"$RUNFILE")
417 [ -z "$RUNFILE" ] && fail
"Cannot find runfile: $SAVED_RUNFILE"
420 if [ ! -r "$RUNFILE" ]; then
421 fail
"Cannot read runfile: $RUNFILE"
425 # This script should not be run as root. Instead the test user, which may
426 # be a normal user account, needs to be configured such that it can
427 # run commands via sudo passwordlessly.
429 if [ "$(id -u)" = "0" ]; then
430 fail
"This script must not be run as root."
433 if [ "$(sudo whoami)" != "root" ]; then
434 fail
"Passwordless sudo access required."
438 # Constrain the available binaries to a known set.
443 # Check if ksh exists
445 [ -e "$STF_PATH/ksh" ] || fail
"This test suite requires ksh."
446 [ -e "$STF_SUITE/include/default.cfg" ] || fail \
447 "Missing $STF_SUITE/include/default.cfg file."
450 # Verify the ZFS module stack is loaded.
452 sudo
"${ZFS_SH}" &>/dev
/null
455 # Attempt to cleanup all previous state for a new test run.
457 if [ "$CLEANUPALL" = "yes" ]; then
462 # By default preserve any existing pools
463 # NOTE: Since 'zpool list' outputs a newline-delimited list convert $KEEP from
464 # space-delimited to newline-delimited.
466 if [ -z "${KEEP}" ]; then
467 KEEP
="$(sudo "$ZPOOL" list -H -o name)"
468 if [ -z "${KEEP}" ]; then
472 KEEP
="$(echo -e "${KEEP//[[:blank:]]/\n}")"
476 # NOTE: The following environment variables are undocumented
477 # and should be used for testing purposes only:
479 # __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
480 # __ZFS_POOL_RESTRICT - iterate only over the pools it lists
482 # See libzfs/libzfs_config.c for more information.
484 __ZFS_POOL_EXCLUDE
="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
486 .
"$STF_SUITE/include/default.cfg"
489 msg
"--- Configuration ---"
490 msg
"Runfile: $RUNFILE"
491 msg
"STF_TOOLS: $STF_TOOLS"
492 msg
"STF_SUITE: $STF_SUITE"
493 msg
"STF_PATH: $STF_PATH"
496 # No DISKS have been provided so a basic file or loopback based devices
497 # must be created for the test suite to use.
499 if [ -z "${DISKS}" ]; then
501 # Create sparse files for the test suite. These may be used
502 # directory or have loopback devices layered on them.
504 for TEST_FILE
in ${FILES}; do
505 [ -f "$TEST_FILE" ] && fail
"Failed file exists: ${TEST_FILE}"
506 truncate
-s "${FILESIZE}" "${TEST_FILE}" ||
507 fail
"Failed creating: ${TEST_FILE} ($?)"
508 DISKS
="$DISKS$TEST_FILE "
512 # If requested setup loopback devices backed by the sparse files.
514 if [ "$LOOPBACK" = "yes" ]; then
517 test -x "$LOSETUP" || fail
"$LOSETUP utility must be installed"
519 for TEST_FILE
in ${FILES}; do
520 TEST_LOOPBACK
=$
(sudo
"${LOSETUP}" -f)
521 sudo
"${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
522 fail
"Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
523 LOOPBACKS
="${LOOPBACKS}${TEST_LOOPBACK} "
524 BASELOOPBACKS
=$
(basename "$TEST_LOOPBACK")
525 DISKS
="$DISKS$BASELOOPBACKS "
530 NUM_DISKS
=$
(echo "${DISKS}" |
awk '{print NF}')
531 [ "$NUM_DISKS" -lt 3 ] && fail
"Not enough disks ($NUM_DISKS/3 minimum)"
534 # Disable SELinux until the ZFS Test Suite has been updated accordingly.
536 if [ -x "$STF_PATH/setenforce" ]; then
537 sudo setenforce permissive
&>/dev
/null
541 # Enable internal ZFS debug log and clear it.
543 if [ -e /sys
/module
/zfs
/parameters
/zfs_dbgmsg_enable
]; then
544 sudo
/bin
/sh
-c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable"
545 sudo
/bin
/sh
-c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
548 msg
"FILEDIR: $FILEDIR"
550 msg
"LOOPBACKS: $LOOPBACKS"
552 msg
"NUM_DISKS: $NUM_DISKS"
553 msg
"FILESIZE: $FILESIZE"
554 msg
"ITERATIONS: $ITERATIONS"
556 msg
"Keep pool(s): $KEEP"
557 msg
"Missing util(s): $STF_MISSING_BIN"
566 export __ZFS_POOL_EXCLUDE
567 export TESTFAIL_CALLBACKS
568 export PATH
=$STF_PATH
570 msg
"${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -T ${TAGS} -i ${STF_SUITE}" \
572 ${TEST_RUNNER} ${QUIET} -c "${RUNFILE}" -T "${TAGS}" -i "${STF_SUITE}" \
577 if [ ${#SINGLETEST[@]} -ne 0 ]; then
578 rm -f "$RUNFILE" &>/dev/null