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