]>
git.proxmox.com Git - mirror_zfs.git/blob - scripts/zfs-tests.sh
01fb2b28990782d6b3cb84e23c7d7f276f52184a
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]
23 basedir
="$(dirname $0)"
25 SCRIPT_COMMON
=common.sh
26 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
27 .
"${basedir}/${SCRIPT_COMMON}"
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
32 .
$STF_SUITE/include
/default.cfg
36 SETENFORCE
=/usr
/sbin
/setenforce
43 RUNFILE
=${RUNFILE:-"linux.run"}
44 FILEDIR
=${FILEDIR:-/var/tmp}
48 # Attempt to remove loopback devices and files which where created earlier
49 # by this script to run the test framework. The '-k' option may be passed
50 # to the script to suppress cleanup for debugging purposes.
53 if [ $CLEANUP -eq 0 ]; then
57 if [ $LOOPBACK -eq 1 ]; then
58 for TEST_LOOPBACK
in ${LOOPBACKS}; do
59 LOOP_DEV
=$
(basename $TEST_LOOPBACK)
60 DM_DEV
=$
(${SUDO} ${DMSETUP} ls 2>/dev
/null | \
61 grep ${LOOP_DEV} | cut
-f1)
63 if [ -n "$DM_DEV" ]; then
64 ${SUDO} ${DMSETUP} remove ${DM_DEV} ||
65 echo "Failed to remove: ${DM_DEV}"
68 if [ -n "${TEST_LOOPBACK}" ]; then
69 ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK} ||
70 echo "Failed to remove: ${TEST_LOOPBACK}"
75 for TEST_FILE
in ${FILES}; do
76 rm -f ${TEST_FILE} &>/dev
/null
82 # Attempt to remove all testpools (testpool.XXX), unopened dm devices,
83 # loopback devices, and files. This is a useful way to cleanup a previous
84 # test run failure which has left the system in an unknown state. This can
85 # be dangerous and should only be used in a dedicated test environment.
88 local TEST_POOLS
=$
(${SUDO} ${ZPOOL} list
-H -o name |
grep testpool
)
89 local TEST_LOOPBACKS
=$
(${SUDO} ${LOSETUP} -a|
grep file-vdev|cut
-f1 -d:)
90 local TEST_FILES
=$
(ls /var
/tmp
/file-vdev
* 2>/dev
/null
)
94 msg
"Removing pool(s): $(echo ${TEST_POOLS} | tr '\n' ' ')"
95 for TEST_POOL
in $TEST_POOLS; do
96 ${SUDO} ${ZPOOL} destroy ${TEST_POOL}
99 msg
"Removing dm(s): $(${SUDO} ${DMSETUP} ls |
100 grep loop | tr '\n' ' ')"
101 ${SUDO} ${DMSETUP} remove_all
103 msg
"Removing loopback(s): $(echo ${TEST_LOOPBACKS} | tr '\n' ' ')"
104 for TEST_LOOPBACK
in $TEST_LOOPBACKS; do
105 ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK}
108 msg
"Removing files(s): $(echo ${TEST_FILES} | tr '\n' ' ')"
109 for TEST_FILE
in $TEST_FILES; do
110 ${SUDO} rm -f ${TEST_FILE}
115 # Log a failure message, cleanup, and return an error.
118 echo -e "${PROG}: $1" >&2
124 # Takes a name as the only arguments and looks for the following variations
125 # on that name. If one is found it is returned.
128 # $RUNFILEDIR/<name>.run
136 if [ -f "$RUNFILEDIR/$NAME" ]; then
137 RESULT
="$RUNFILEDIR/$NAME"
138 elif [ -f "$RUNFILEDIR/$NAME.run" ]; then
139 RESULT
="$RUNFILEDIR/$NAME.run"
140 elif [ -f "$NAME" ]; then
142 elif [ -f "$NAME.run" ]; then
150 # Output a useful usage message.
155 $0 [hvqxkf] [-s SIZE] [-r RUNFILE]
158 ZFS Test Suite launch script
162 -v Verbose zfs-tests.sh output
163 -q Quiet test-runner output
164 -x Remove all testpools, dm, lo, and files (unsafe)
165 -k Disable cleanup after test failure
166 -f Use files only, disables block device tests
167 -d DIR Use DIR for files and loopback devices
168 -s SIZE Use vdevs of SIZE (default: 2G)
169 -r RUNFILE Run tests in RUNFILE (default: linux.run)
172 # Run the default (linux) suite of tests and output the configuration used.
175 # Run a smaller suite of tests designed to run more quickly.
178 # Cleanup a previous run of the test suite prior to testing, run the
179 # default (linux) suite of tests and perform no cleanup on exit.
185 while getopts 'hvqxkfd:s:r:?' OPTION
; do
224 FILES
=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
225 LOOPBACKS
=${LOOPBACKS:-""}
228 # Attempt to locate the runfile describing the test workload.
230 if [ -n "$RUNFILE" ]; then
231 SAVED_RUNFILE
="$RUNFILE"
232 RUNFILE
=$
(find_runfile
"$RUNFILE")
233 [ -z "$RUNFILE" ] && fail
"Cannot find runfile: $SAVED_RUNFILE"
236 if [ ! -r "$RUNFILE" ]; then
237 fail
"Cannot read runfile: $RUNFILE"
241 # This script should not be run as root. Instead the test user, which may
242 # be a normal user account, needs to be configured such that it can
243 # run commands via sudo passwordlessly.
245 if [ $
(id
-u) = "0" ]; then
246 fail
"This script must not be run as root."
249 if [ $
(sudo whoami
) != "root" ]; then
250 fail
"Passwordless sudo access required."
254 # Check if ksh exists
256 if [ -z "$(which ksh 2>/dev/null)" ]; then
257 fail
"This test suite requires ksh."
261 # Verify the ZFS module stack if loaded.
263 ${SUDO} ${ZFS_SH} &>/dev
/null
266 # Attempt to cleanup all previous state for a new test run.
268 if [ $CLEANUPALL -ne 0 ]; then
273 # By default preserve any existing pools
275 if [ -z "${KEEP}" ]; then
276 KEEP
=$
(${SUDO} ${ZPOOL} list
-H -o name
)
277 if [ -z "${KEEP}" ]; then
283 msg
"--- Configuration ---"
284 msg
"Runfile: $RUNFILE"
285 msg
"STF_TOOLS: $STF_TOOLS"
286 msg
"STF_SUITE: $STF_SUITE"
289 # No DISKS have been provided so a basic file or loopback based devices
290 # must be created for the test suite to use.
292 if [ -z "${DISKS}" ]; then
294 # Create sparse files for the test suite. These may be used
295 # directory or have loopback devices layered on them.
297 for TEST_FILE
in ${FILES}; do
298 [ -f "$TEST_FILE" ] && fail
"Failed file exists: ${TEST_FILE}"
299 truncate
-s ${FILESIZE} ${TEST_FILE} ||
300 fail
"Failed creating: ${TEST_FILE} ($?)"
301 DISKS
="$DISKS$TEST_FILE "
305 # If requested setup loopback devices backed by the sparse files.
307 if [ $LOOPBACK -eq 1 ]; then
311 for TEST_FILE
in ${FILES}; do
312 TEST_LOOPBACK
=$
(${SUDO} ${LOSETUP} -f)
313 ${SUDO} ${LOSETUP} ${TEST_LOOPBACK} ${TEST_FILE} ||
314 fail
"Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
315 LOOPBACKS
="${LOOPBACKS}${TEST_LOOPBACK} "
316 DISKS
="$DISKS$(basename $TEST_LOOPBACK) "
321 NUM_DISKS
=$
(echo ${DISKS} |
$AWK '{print NF}')
322 [ $NUM_DISKS -lt 3 ] && fail
"Not enough disks ($NUM_DISKS/3 minimum)"
325 # Disable SELinux until the ZFS Test Suite has been updated accordingly.
327 if [ -x ${SETENFORCE} ]; then
328 ${SUDO} ${SETENFORCE} permissive
&>/dev
/null
331 msg
"FILEDIR: $FILEDIR"
333 msg
"LOOPBACKS: $LOOPBACKS"
335 msg
"NUM_DISKS: $NUM_DISKS"
336 msg
"FILESIZE: $FILESIZE"
337 msg
"Keep pool(s): $KEEP"
345 msg
"${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}"
346 ${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}