]>
Commit | Line | Data |
---|---|---|
6bb24f4d BB |
1 | #!/bin/bash |
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 | # | |
23 | basedir="$(dirname $0)" | |
24 | ||
25 | SCRIPT_COMMON=common.sh | |
26 | if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then | |
27 | . "${basedir}/${SCRIPT_COMMON}" | |
28 | else | |
29 | echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 | |
30 | fi | |
31 | ||
32 | . $STF_SUITE/include/default.cfg | |
33 | ||
34 | PROG=zfs-tests.sh | |
35 | SUDO=/usr/bin/sudo | |
36 | SETENFORCE=/usr/sbin/setenforce | |
37 | VERBOSE= | |
38 | QUIET= | |
39 | CLEANUP=1 | |
40 | CLEANUPALL=0 | |
41 | LOOPBACK=1 | |
42 | FILESIZE="2G" | |
43 | RUNFILE=${RUNFILE:-"linux.run"} | |
44 | FILEDIR=${FILEDIR:-/var/tmp} | |
45 | DISKS=${DISKS:-""} | |
46 | ||
47 | # | |
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. | |
51 | # | |
52 | cleanup() { | |
53 | if [ $CLEANUP -eq 0 ]; then | |
54 | return 0 | |
55 | fi | |
56 | ||
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) | |
62 | ||
63 | if [ -n "$DM_DEV" ]; then | |
64 | ${SUDO} ${DMSETUP} remove ${DM_DEV} || | |
65 | echo "Failed to remove: ${DM_DEV}" | |
66 | fi | |
67 | ||
68 | if [ -n "${TEST_LOOPBACK}" ]; then | |
69 | ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK} || | |
70 | echo "Failed to remove: ${TEST_LOOPBACK}" | |
71 | fi | |
72 | done | |
73 | fi | |
74 | ||
75 | for TEST_FILE in ${FILES}; do | |
76 | rm -f ${TEST_FILE} &>/dev/null | |
77 | done | |
78 | } | |
79 | trap cleanup EXIT | |
80 | ||
81 | # | |
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. | |
86 | # | |
87 | cleanup_all() { | |
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) | |
91 | ||
92 | msg | |
93 | msg "--- Cleanup ---" | |
94 | msg "Removing pool(s): $(echo ${TEST_POOLS} | tr '\n' ' ')" | |
95 | for TEST_POOL in $TEST_POOLS; do | |
96 | ${SUDO} ${ZPOOL} destroy ${TEST_POOL} | |
97 | done | |
98 | ||
99 | msg "Removing dm(s): $(${SUDO} ${DMSETUP} ls | | |
100 | grep loop | tr '\n' ' ')" | |
101 | ${SUDO} ${DMSETUP} remove_all | |
102 | ||
103 | msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS} | tr '\n' ' ')" | |
104 | for TEST_LOOPBACK in $TEST_LOOPBACKS; do | |
105 | ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK} | |
106 | done | |
107 | ||
108 | msg "Removing files(s): $(echo ${TEST_FILES} | tr '\n' ' ')" | |
109 | for TEST_FILE in $TEST_FILES; do | |
110 | ${SUDO} rm -f ${TEST_FILE} | |
111 | done | |
112 | } | |
113 | ||
114 | # | |
115 | # Log a failure message, cleanup, and return an error. | |
116 | # | |
117 | fail() { | |
118 | echo -e "${PROG}: $1" >&2 | |
119 | cleanup | |
120 | exit 1 | |
121 | } | |
122 | ||
123 | # | |
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. | |
126 | # | |
127 | # $RUNFILEDIR/<name> | |
128 | # $RUNFILEDIR/<name>.run | |
129 | # <name> | |
130 | # <name>.run | |
131 | # | |
132 | find_runfile() { | |
133 | local NAME=$1 | |
134 | local RESULT="" | |
135 | ||
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 | |
141 | RESULT="$NAME" | |
142 | elif [ -f "$NAME.run" ]; then | |
143 | RESULT="$NAME.run" | |
144 | fi | |
145 | ||
146 | echo "$RESULT" | |
147 | } | |
148 | ||
149 | # | |
150 | # Output a useful usage message. | |
151 | # | |
152 | usage() { | |
153 | cat << EOF | |
154 | USAGE: | |
155 | $0 [hvqxkf] [-s SIZE] [-r RUNFILE] | |
156 | ||
157 | DESCRIPTION: | |
158 | ZFS Test Suite launch script | |
159 | ||
160 | OPTIONS: | |
161 | -h Show this message | |
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: 4G) | |
169 | -r RUNFILE Run tests in RUNFILE (default: linux.run) | |
170 | ||
171 | EXAMPLES: | |
172 | # Run the default (linux) suite of tests and output the configuration used. | |
173 | $0 -v | |
174 | ||
175 | # Run a smaller suite of tests designed to run more quickly. | |
176 | $0 -r linux-fast | |
177 | ||
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. | |
180 | $0 -c | |
181 | ||
182 | EOF | |
183 | } | |
184 | ||
185 | while getopts 'hvqxkfd:s:r:?' OPTION; do | |
186 | case $OPTION in | |
187 | h) | |
188 | usage | |
189 | exit 1 | |
190 | ;; | |
191 | v) | |
192 | VERBOSE=1 | |
193 | ;; | |
194 | q) | |
195 | QUIET="-q" | |
196 | ;; | |
197 | x) | |
198 | CLEANUPALL=1 | |
199 | ;; | |
200 | k) | |
201 | CLEANUP=0 | |
202 | ;; | |
203 | f) | |
204 | LOOPBACK=0 | |
205 | ;; | |
206 | d) | |
207 | FILEDIR="$OPTARG" | |
208 | ;; | |
209 | s) | |
210 | FILESIZE="$OPTARG" | |
211 | ;; | |
212 | r) | |
213 | RUNFILE="$OPTARG" | |
214 | ;; | |
215 | ?) | |
216 | usage | |
217 | exit | |
218 | ;; | |
219 | esac | |
220 | done | |
221 | ||
222 | shift $((OPTIND-1)) | |
223 | ||
224 | FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"} | |
225 | LOOPBACKS=${LOOPBACKS:-""} | |
226 | ||
227 | # | |
228 | # Attempt to locate the runfile describing the test workload. | |
229 | # | |
230 | if [ -n "$RUNFILE" ]; then | |
231 | SAVED_RUNFILE="$RUNFILE" | |
232 | RUNFILE=$(find_runfile "$RUNFILE") | |
233 | [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE" | |
234 | fi | |
235 | ||
236 | if [ ! -r "$RUNFILE" ]; then | |
237 | fail "Cannot read runfile: $RUNFILE" | |
238 | fi | |
239 | ||
240 | # | |
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. | |
244 | # | |
245 | if [ $(id -u) = "0" ]; then | |
246 | fail "This script must not be run as root." | |
247 | fi | |
248 | ||
249 | if [ $(sudo whoami) != "root" ]; then | |
250 | fail "Passwordless sudo access required." | |
251 | fi | |
252 | ||
253 | # | |
254 | # Verify the ZFS module stack if loaded. | |
255 | # | |
256 | ${SUDO} ${ZFS_SH} &>/dev/null | |
257 | ||
258 | # | |
259 | # Attempt to cleanup all previous state for a new test run. | |
260 | # | |
261 | if [ $CLEANUPALL -ne 0 ]; then | |
262 | cleanup_all | |
263 | fi | |
264 | ||
265 | # | |
266 | # By default preserve any existing pools | |
267 | # | |
268 | if [ -z "${KEEP}" ]; then | |
269 | KEEP=$(${SUDO} ${ZPOOL} list -H -o name) | |
270 | if [ -z "${KEEP}" ]; then | |
271 | KEEP="rpool" | |
272 | fi | |
273 | fi | |
274 | ||
275 | msg | |
276 | msg "--- Configuration ---" | |
277 | msg "Runfile: $RUNFILE" | |
278 | msg "STF_TOOLS: $STF_TOOLS" | |
279 | msg "STF_SUITE: $STF_SUITE" | |
280 | ||
281 | # | |
282 | # No DISKS have been provided so a basic file or loopback based devices | |
283 | # must be created for the test suite to use. | |
284 | # | |
285 | if [ -z "${DISKS}" ]; then | |
286 | # | |
287 | # Create sparse files for the test suite. These may be used | |
288 | # directory or have loopback devices layered on them. | |
289 | # | |
290 | for TEST_FILE in ${FILES}; do | |
291 | [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" | |
292 | truncate -s ${FILESIZE} ${TEST_FILE} || | |
293 | fail "Failed creating: ${TEST_FILE} ($?)" | |
294 | DISKS="$DISKS$TEST_FILE " | |
295 | done | |
296 | ||
297 | # | |
298 | # If requested setup loopback devices backed by the sparse files. | |
299 | # | |
300 | if [ $LOOPBACK -eq 1 ]; then | |
301 | DISKS="" | |
302 | check_loop_utils | |
303 | ||
304 | for TEST_FILE in ${FILES}; do | |
305 | TEST_LOOPBACK=$(${SUDO} ${LOSETUP} -f) | |
306 | ${SUDO} ${LOSETUP} ${TEST_LOOPBACK} ${TEST_FILE} || | |
307 | fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" | |
308 | LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} " | |
309 | DISKS="$DISKS$(basename $TEST_LOOPBACK) " | |
310 | done | |
311 | fi | |
312 | fi | |
313 | ||
314 | NUM_DISKS=$(echo ${DISKS} | $AWK '{print NF}') | |
315 | [ $NUM_DISKS -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)" | |
316 | ||
317 | # | |
318 | # Disable SELinux until the ZFS Test Suite has been updated accordingly. | |
319 | # | |
320 | if [ -x ${SETENFORCE} ]; then | |
321 | ${SUDO} ${SETENFORCE} permissive &>/dev/null | |
322 | fi | |
323 | ||
324 | msg "FILEDIR: $FILEDIR" | |
325 | msg "FILES: $FILES" | |
326 | msg "LOOPBACKS: $LOOPBACKS" | |
327 | msg "DISKS: $DISKS" | |
328 | msg "NUM_DISKS: $NUM_DISKS" | |
329 | msg "FILESIZE: $FILESIZE" | |
330 | msg "Keep pool(s): $KEEP" | |
331 | msg "" | |
332 | ||
333 | export STF_TOOLS | |
334 | export STF_SUITE | |
335 | export DISKS | |
336 | export KEEP | |
337 | ||
338 | msg "${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}" | |
339 | ${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE} | |
340 | RESULT=$? | |
341 | echo | |
342 | ||
343 | exit ${RESULT} |