]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
6bf19c94 CH |
2 | # |
3 | # Copyright (C) 2009 Red Hat, Inc. | |
4 | # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
e8c212d6 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6bf19c94 CH |
18 | # |
19 | ||
bde36af1 PMD |
20 | SED= |
21 | for sed in sed gsed; do | |
22 | ($sed --version | grep 'GNU sed') > /dev/null 2>&1 | |
23 | if [ "$?" -eq 0 ]; then | |
24 | SED=$sed | |
25 | break | |
26 | fi | |
27 | done | |
28 | if [ -z "$SED" ]; then | |
29 | echo "$0: GNU sed not found" | |
30 | exit 1 | |
31 | fi | |
32 | ||
6bf19c94 CH |
33 | dd() |
34 | { | |
35 | if [ "$HOSTOS" == "Linux" ] | |
79e40ab1 KW |
36 | then |
37 | command dd --help | grep noxfer > /dev/null 2>&1 | |
38 | ||
39 | if [ "$?" -eq 0 ] | |
40 | then | |
41 | command dd status=noxfer $@ | |
42 | else | |
43 | command dd $@ | |
44 | fi | |
6bf19c94 | 45 | else |
79e40ab1 | 46 | command dd $@ |
6bf19c94 CH |
47 | fi |
48 | } | |
49 | ||
23ea2ecc SH |
50 | # poke_file 'test.img' 512 '\xff\xfe' |
51 | poke_file() | |
52 | { | |
53 | printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null | |
54 | } | |
55 | ||
3817ce03 PB |
56 | |
57 | if ! . ./common.config | |
58 | then | |
4e670492 | 59 | echo "$0: failed to source common.config" |
3817ce03 | 60 | exit 1 |
6bf19c94 CH |
61 | fi |
62 | ||
036d8cbf AS |
63 | # Set the variables to the empty string to turn Valgrind off |
64 | # for specific processes, e.g. | |
65 | # $ VALGRIND_QEMU_IO= ./check -qcow2 -valgrind 015 | |
66 | ||
67 | : ${VALGRIND_QEMU_VM=$VALGRIND_QEMU} | |
68 | : ${VALGRIND_QEMU_IMG=$VALGRIND_QEMU} | |
69 | : ${VALGRIND_QEMU_IO=$VALGRIND_QEMU} | |
70 | : ${VALGRIND_QEMU_NBD=$VALGRIND_QEMU} | |
71 | : ${VALGRIND_QEMU_VXHS=$VALGRIND_QEMU} | |
72 | ||
73 | # The Valgrind own parameters may be set with | |
74 | # its environment variable VALGRIND_OPTS, e.g. | |
75 | # $ VALGRIND_OPTS="--leak-check=yes" ./check -qcow2 -valgrind 015 | |
76 | ||
77 | _qemu_proc_exec() | |
78 | { | |
79 | local VALGRIND_LOGFILE="$1" | |
80 | shift | |
8af224d6 | 81 | if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then |
036d8cbf AS |
82 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$@" |
83 | else | |
84 | exec "$@" | |
85 | fi | |
86 | } | |
87 | ||
88 | _qemu_proc_valgrind_log() | |
89 | { | |
90 | local VALGRIND_LOGFILE="$1" | |
91 | local RETVAL="$2" | |
8af224d6 | 92 | if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then |
036d8cbf AS |
93 | if [ $RETVAL == 99 ]; then |
94 | cat "${VALGRIND_LOGFILE}" | |
95 | fi | |
96 | rm -f "${VALGRIND_LOGFILE}" | |
97 | fi | |
98 | } | |
99 | ||
d1f2447a PB |
100 | _qemu_wrapper() |
101 | { | |
036d8cbf | 102 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind |
d1f2447a PB |
103 | ( |
104 | if [ -n "${QEMU_NEED_PID}" ]; then | |
105 | echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" | |
106 | fi | |
036d8cbf AS |
107 | VALGRIND_QEMU="${VALGRIND_QEMU_VM}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ |
108 | "$QEMU_PROG" $QEMU_OPTIONS "$@" | |
d1f2447a | 109 | ) |
036d8cbf AS |
110 | RETVAL=$? |
111 | _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL | |
112 | return $RETVAL | |
d1f2447a PB |
113 | } |
114 | ||
115 | _qemu_img_wrapper() | |
116 | { | |
036d8cbf AS |
117 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind |
118 | ( | |
119 | VALGRIND_QEMU="${VALGRIND_QEMU_IMG}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ | |
120 | "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@" | |
121 | ) | |
122 | RETVAL=$? | |
123 | _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL | |
124 | return $RETVAL | |
d1f2447a PB |
125 | } |
126 | ||
127 | _qemu_io_wrapper() | |
128 | { | |
129 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind | |
130 | local QEMU_IO_ARGS="$QEMU_IO_OPTIONS" | |
131 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | |
132 | QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS" | |
133 | if [ -n "$IMGKEYSECRET" ]; then | |
134 | QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS" | |
135 | fi | |
136 | fi | |
d1f2447a | 137 | ( |
036d8cbf AS |
138 | VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ |
139 | "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" | |
d1f2447a PB |
140 | ) |
141 | RETVAL=$? | |
036d8cbf AS |
142 | _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL |
143 | return $RETVAL | |
d1f2447a PB |
144 | } |
145 | ||
146 | _qemu_nbd_wrapper() | |
147 | { | |
036d8cbf AS |
148 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind |
149 | ( | |
150 | VALGRIND_QEMU="${VALGRIND_QEMU_NBD}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ | |
151 | "$QEMU_NBD_PROG" --pid-file="${QEMU_TEST_DIR}/qemu-nbd.pid" \ | |
152 | $QEMU_NBD_OPTIONS "$@" | |
153 | ) | |
154 | RETVAL=$? | |
155 | _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL | |
156 | return $RETVAL | |
d1f2447a PB |
157 | } |
158 | ||
159 | _qemu_vxhs_wrapper() | |
160 | { | |
036d8cbf | 161 | local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind |
d1f2447a PB |
162 | ( |
163 | echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" | |
036d8cbf AS |
164 | VALGRIND_QEMU="${VALGRIND_QEMU_VXHS}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ |
165 | "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" | |
d1f2447a | 166 | ) |
036d8cbf AS |
167 | RETVAL=$? |
168 | _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL | |
169 | return $RETVAL | |
d1f2447a PB |
170 | } |
171 | ||
8af224d6 AS |
172 | # Valgrind bug #409141 https://bugs.kde.org/show_bug.cgi?id=409141 |
173 | # Until valgrind 3.16+ is ubiquitous, we must work around a hang in | |
174 | # valgrind when issuing sigkill. Disable valgrind for this invocation. | |
175 | _NO_VALGRIND() | |
176 | { | |
177 | NO_VALGRIND="y" "$@" | |
178 | } | |
179 | ||
d1f2447a PB |
180 | export QEMU=_qemu_wrapper |
181 | export QEMU_IMG=_qemu_img_wrapper | |
182 | export QEMU_IO=_qemu_io_wrapper | |
183 | export QEMU_NBD=_qemu_nbd_wrapper | |
184 | export QEMU_VXHS=_qemu_vxhs_wrapper | |
185 | ||
076003f5 DB |
186 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
187 | DRIVER="driver=$IMGFMT" | |
cce293a2 PB |
188 | QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS" |
189 | if [ -n "$IMGKEYSECRET" ]; then | |
190 | QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS" | |
191 | fi | |
4e9b25fb DB |
192 | if [ "$IMGFMT" = "luks" ]; then |
193 | DRIVER="$DRIVER,key-secret=keysec0" | |
194 | fi | |
076003f5 DB |
195 | if [ "$IMGPROTO" = "file" ]; then |
196 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
197 | TEST_IMG="$DRIVER,file.filename=$TEST_DIR/t.$IMGFMT" | |
198 | elif [ "$IMGPROTO" = "nbd" ]; then | |
199 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
200 | TEST_IMG="$DRIVER,file.driver=nbd,file.host=127.0.0.1,file.port=10810" | |
201 | elif [ "$IMGPROTO" = "ssh" ]; then | |
202 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
203 | TEST_IMG="$DRIVER,file.driver=ssh,file.host=127.0.0.1,file.path=$TEST_IMG_FILE" | |
204 | elif [ "$IMGPROTO" = "nfs" ]; then | |
205 | TEST_DIR="$DRIVER,file.driver=nfs,file.filename=nfs://127.0.0.1/$TEST_DIR" | |
e5b77eec | 206 | TEST_IMG=$TEST_DIR/t.$IMGFMT |
076003f5 DB |
207 | else |
208 | TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT" | |
209 | fi | |
9cdfa1b3 | 210 | else |
cce293a2 | 211 | QEMU_IMG_EXTRA_ARGS= |
076003f5 DB |
212 | if [ "$IMGPROTO" = "file" ]; then |
213 | TEST_IMG=$TEST_DIR/t.$IMGFMT | |
214 | elif [ "$IMGPROTO" = "nbd" ]; then | |
215 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
216 | TEST_IMG="nbd:127.0.0.1:10810" | |
217 | elif [ "$IMGPROTO" = "ssh" ]; then | |
218 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
b8c1f901 | 219 | REMOTE_TEST_DIR="ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?$TEST_DIR" |
076003f5 DB |
220 | TEST_IMG="ssh://127.0.0.1$TEST_IMG_FILE" |
221 | elif [ "$IMGPROTO" = "nfs" ]; then | |
655ae6bb | 222 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT |
8908b253 | 223 | REMOTE_TEST_DIR="nfs://127.0.0.1$TEST_DIR" |
655ae6bb | 224 | TEST_IMG="nfs://127.0.0.1$TEST_IMG_FILE" |
ae0c0a3d AM |
225 | elif [ "$IMGPROTO" = "vxhs" ]; then |
226 | TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | |
227 | TEST_IMG="vxhs://127.0.0.1:9999/t.$IMGFMT" | |
076003f5 DB |
228 | else |
229 | TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT | |
230 | fi | |
9cdfa1b3 | 231 | fi |
59fa68f3 | 232 | ORIG_TEST_IMG="$TEST_IMG" |
6bf19c94 | 233 | |
cce293a2 | 234 | if [ -z "$TEST_DIR" ]; then |
e8d81a61 | 235 | TEST_DIR=$PWD/scratch |
cce293a2 PB |
236 | fi |
237 | ||
238 | QEMU_TEST_DIR="${TEST_DIR}" | |
239 | ||
240 | if [ ! -e "$TEST_DIR" ]; then | |
241 | mkdir "$TEST_DIR" | |
242 | fi | |
243 | ||
244 | if [ ! -d "$TEST_DIR" ]; then | |
49cedf17 | 245 | echo "common.rc: Error: \$TEST_DIR ($TEST_DIR) is not a directory" |
cce293a2 PB |
246 | exit 1 |
247 | fi | |
248 | ||
8908b253 KW |
249 | if [ -z "$REMOTE_TEST_DIR" ]; then |
250 | REMOTE_TEST_DIR="$TEST_DIR" | |
251 | fi | |
252 | ||
cce293a2 | 253 | if [ ! -d "$SAMPLE_IMG_DIR" ]; then |
49cedf17 | 254 | echo "common.rc: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory" |
cce293a2 PB |
255 | exit 1 |
256 | fi | |
257 | ||
85edbd37 JC |
258 | _use_sample_img() |
259 | { | |
260 | SAMPLE_IMG_FILE="${1%\.bz2}" | |
261 | TEST_IMG="$TEST_DIR/$SAMPLE_IMG_FILE" | |
262 | bzcat "$SAMPLE_IMG_DIR/$1" > "$TEST_IMG" | |
263 | if [ $? -ne 0 ] | |
264 | then | |
265 | echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'" | |
266 | exit 1 | |
267 | fi | |
268 | } | |
269 | ||
2f9d4083 FZ |
270 | _stop_nbd_server() |
271 | { | |
272 | if [ -f "${QEMU_TEST_DIR}/qemu-nbd.pid" ]; then | |
273 | local QEMU_NBD_PID | |
274 | read QEMU_NBD_PID < "${QEMU_TEST_DIR}/qemu-nbd.pid" | |
275 | kill ${QEMU_NBD_PID} | |
276 | rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid" | |
277 | fi | |
278 | } | |
279 | ||
6bf19c94 CH |
280 | _make_test_img() |
281 | { | |
282 | # extra qemu-img options can be added by tests | |
283 | # at least one argument (the image size) needs to be added | |
21af8148 | 284 | local extra_img_options="" |
21af8148 | 285 | local image_size=$* |
89004368 | 286 | local optstr="" |
a9660664 | 287 | local img_name="" |
0018c03f JC |
288 | local use_backing=0 |
289 | local backing_file="" | |
b7e875b2 | 290 | local object_options="" |
a9660664 NT |
291 | |
292 | if [ -n "$TEST_IMG_FILE" ]; then | |
293 | img_name=$TEST_IMG_FILE | |
294 | else | |
295 | img_name=$TEST_IMG | |
296 | fi | |
89004368 KW |
297 | |
298 | if [ -n "$IMGOPTS" ]; then | |
299 | optstr=$(_optstr_add "$optstr" "$IMGOPTS") | |
300 | fi | |
b7e875b2 DB |
301 | if [ -n "$IMGKEYSECRET" ]; then |
302 | object_options="--object secret,id=keysec0,data=$IMGKEYSECRET" | |
303 | optstr=$(_optstr_add "$optstr" "key-secret=keysec0") | |
304 | fi | |
6bf19c94 | 305 | |
21af8148 | 306 | if [ "$1" = "-b" ]; then |
0018c03f JC |
307 | use_backing=1 |
308 | backing_file=$2 | |
21af8148 SW |
309 | image_size=$3 |
310 | fi | |
f5a4bbd9 | 311 | if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then |
89004368 KW |
312 | optstr=$(_optstr_add "$optstr" "cluster_size=$CLUSTER_SIZE") |
313 | fi | |
314 | ||
315 | if [ -n "$optstr" ]; then | |
316 | extra_img_options="-o $optstr $extra_img_options" | |
8fc1024c KW |
317 | fi |
318 | ||
2f9d4083 FZ |
319 | if [ $IMGPROTO = "nbd" ]; then |
320 | _stop_nbd_server | |
321 | fi | |
322 | ||
6bf19c94 | 323 | # XXX(hch): have global image options? |
0018c03f JC |
324 | ( |
325 | if [ $use_backing = 1 ]; then | |
b7e875b2 | 326 | $QEMU_IMG create $object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1 |
0018c03f | 327 | else |
b7e875b2 | 328 | $QEMU_IMG create $object_options -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1 |
0018c03f | 329 | fi |
6ffb4cb6 | 330 | ) | _filter_img_create |
a9660664 NT |
331 | |
332 | # Start an NBD server on the image file, which is what we'll be talking to | |
333 | if [ $IMGPROTO = "nbd" ]; then | |
03a0aa37 HR |
334 | # Pass a sufficiently high number to -e that should be enough for all |
335 | # tests | |
147b44be | 336 | eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT -e 42 -x '' $TEST_IMG_FILE >/dev/null &" |
a9660664 NT |
337 | sleep 1 # FIXME: qemu-nbd needs to be listening before we continue |
338 | fi | |
ae0c0a3d AM |
339 | |
340 | # Start QNIO server on image directory for vxhs protocol | |
341 | if [ $IMGPROTO = "vxhs" ]; then | |
342 | eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &" | |
343 | sleep 1 # Wait for server to come up. | |
344 | fi | |
6bf19c94 CH |
345 | } |
346 | ||
487c1910 FZ |
347 | _rm_test_img() |
348 | { | |
349 | local img=$1 | |
350 | if [ "$IMGFMT" = "vmdk" ]; then | |
351 | # Remove all the extents for vmdk | |
c5575274 | 352 | "$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 -d: \ |
487c1910 FZ |
353 | | xargs -I {} rm -f "{}" |
354 | fi | |
c5575274 | 355 | rm -f "$img" |
487c1910 FZ |
356 | } |
357 | ||
6bf19c94 CH |
358 | _cleanup_test_img() |
359 | { | |
9cdfa1b3 MK |
360 | case "$IMGPROTO" in |
361 | ||
a9660664 | 362 | nbd) |
2f9d4083 | 363 | _stop_nbd_server |
fef9c191 | 364 | rm -f "$TEST_IMG_FILE" |
a9660664 | 365 | ;; |
ae0c0a3d AM |
366 | vxhs) |
367 | if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then | |
368 | local QEMU_VXHS_PID | |
369 | read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid" | |
370 | kill ${QEMU_VXHS_PID} >/dev/null 2>&1 | |
371 | rm -f "${TEST_DIR}/qemu-vxhs.pid" | |
372 | fi | |
373 | rm -f "$TEST_IMG_FILE" | |
374 | ;; | |
375 | ||
9cdfa1b3 | 376 | file) |
487c1910 FZ |
377 | _rm_test_img "$TEST_DIR/t.$IMGFMT" |
378 | _rm_test_img "$TEST_DIR/t.$IMGFMT.orig" | |
379 | _rm_test_img "$TEST_DIR/t.$IMGFMT.base" | |
85edbd37 JC |
380 | if [ -n "$SAMPLE_IMG_FILE" ] |
381 | then | |
382 | rm -f "$TEST_DIR/$SAMPLE_IMG_FILE" | |
59fa68f3 KW |
383 | SAMPLE_IMG_FILE= |
384 | TEST_IMG="$ORIG_TEST_IMG" | |
85edbd37 | 385 | fi |
9cdfa1b3 MK |
386 | ;; |
387 | ||
388 | rbd) | |
9147d019 | 389 | rbd --no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev/null |
9cdfa1b3 MK |
390 | ;; |
391 | ||
392 | sheepdog) | |
fef9c191 | 393 | collie vdi delete "$TEST_DIR/t.$IMGFMT" |
9cdfa1b3 MK |
394 | ;; |
395 | ||
396 | esac | |
6bf19c94 CH |
397 | } |
398 | ||
399 | _check_test_img() | |
400 | { | |
076003f5 DB |
401 | ( |
402 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | |
403 | $QEMU_IMG check $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | |
404 | else | |
405 | $QEMU_IMG check "$@" -f $IMGFMT "$TEST_IMG" 2>&1 | |
406 | fi | |
86ce1f6e | 407 | ) | _filter_testdir | _filter_qemu_img_check |
6bf19c94 CH |
408 | } |
409 | ||
514d9da5 SH |
410 | _img_info() |
411 | { | |
e800e5d4 KW |
412 | if [[ "$1" == "--format-specific" ]]; then |
413 | local format_specific=1 | |
414 | shift | |
415 | else | |
416 | local format_specific=0 | |
417 | fi | |
418 | ||
4c2e9465 HR |
419 | discard=0 |
420 | regex_json_spec_start='^ *"format-specific": \{' | |
d06195e6 | 421 | $QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \ |
8908b253 KW |
422 | sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \ |
423 | -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ | |
514d9da5 SH |
424 | -e "s#$TEST_DIR#TEST_DIR#g" \ |
425 | -e "s#$IMGFMT#IMGFMT#g" \ | |
426 | -e "/^disk size:/ D" \ | |
4c2e9465 | 427 | -e "/actual-size/ D" | \ |
6dd6d7ab | 428 | while IFS='' read -r line; do |
e800e5d4 KW |
429 | if [[ $format_specific == 1 ]]; then |
430 | discard=0 | |
431 | elif [[ $line == "Format specific information:" ]]; then | |
4c2e9465 HR |
432 | discard=1 |
433 | elif [[ $line =~ $regex_json_spec_start ]]; then | |
434 | discard=2 | |
435 | regex_json_spec_end="^${line%%[^ ]*}\\},? *$" | |
436 | fi | |
437 | if [[ $discard == 0 ]]; then | |
438 | echo "$line" | |
439 | elif [[ $discard == 1 && ! $line ]]; then | |
440 | echo | |
441 | discard=0 | |
442 | elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then | |
443 | discard=0 | |
444 | fi | |
445 | done | |
514d9da5 SH |
446 | } |
447 | ||
6bf19c94 CH |
448 | # bail out, setting up .notrun file |
449 | # | |
450 | _notrun() | |
451 | { | |
e8f8624d | 452 | echo "$*" >"$OUTPUT_DIR/$seq.notrun" |
6bf19c94 CH |
453 | echo "$seq not run: $*" |
454 | status=0 | |
455 | exit | |
456 | } | |
457 | ||
458 | # just plain bail out | |
459 | # | |
460 | _fail() | |
461 | { | |
e8f8624d | 462 | echo "$*" | tee -a "$OUTPUT_DIR/$seq.full" |
6bf19c94 CH |
463 | echo "(see $seq.full for details)" |
464 | status=1 | |
465 | exit 1 | |
466 | } | |
467 | ||
468 | # tests whether $IMGFMT is one of the supported image formats for a test | |
469 | # | |
470 | _supported_fmt() | |
471 | { | |
47f73da0 SH |
472 | # "generic" is suitable for most image formats. For some formats it doesn't |
473 | # work, however (most notably read-only formats), so they can opt out by | |
474 | # setting IMGFMT_GENERIC to false. | |
6bf19c94 | 475 | for f; do |
89e91181 | 476 | if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then |
79e40ab1 KW |
477 | return |
478 | fi | |
6bf19c94 CH |
479 | done |
480 | ||
481 | _notrun "not suitable for this image format: $IMGFMT" | |
482 | } | |
483 | ||
b4a2caa4 NS |
484 | # tests whether $IMGFMT is one of the unsupported image format for a test |
485 | # | |
486 | _unsupported_fmt() | |
487 | { | |
488 | for f; do | |
489 | if [ "$f" = "$IMGFMT" ]; then | |
490 | _notrun "not suitable for this image format: $IMGFMT" | |
491 | fi | |
492 | done | |
493 | } | |
494 | ||
9cdfa1b3 MK |
495 | # tests whether $IMGPROTO is one of the supported image protocols for a test |
496 | # | |
497 | _supported_proto() | |
498 | { | |
499 | for f; do | |
79e40ab1 KW |
500 | if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then |
501 | return | |
502 | fi | |
9cdfa1b3 MK |
503 | done |
504 | ||
505 | _notrun "not suitable for this image protocol: $IMGPROTO" | |
506 | } | |
507 | ||
dfac03dc JC |
508 | # tests whether $IMGPROTO is specified as an unsupported image protocol for a test |
509 | # | |
510 | _unsupported_proto() | |
511 | { | |
512 | for f; do | |
513 | if [ "$f" = "$IMGPROTO" ]; then | |
514 | _notrun "not suitable for this image protocol: $IMGPROTO" | |
515 | return | |
516 | fi | |
517 | done | |
518 | } | |
519 | ||
6bf19c94 CH |
520 | # tests whether the host OS is one of the supported OSes for a test |
521 | # | |
522 | _supported_os() | |
523 | { | |
524 | for h | |
525 | do | |
79e40ab1 KW |
526 | if [ "$h" = "$HOSTOS" ] |
527 | then | |
528 | return | |
529 | fi | |
6bf19c94 CH |
530 | done |
531 | ||
532 | _notrun "not suitable for this OS: $HOSTOS" | |
533 | } | |
534 | ||
f210a83c | 535 | _supported_cache_modes() |
166f3c7b | 536 | { |
f210a83c FZ |
537 | for mode; do |
538 | if [ "$mode" = "$CACHEMODE" ]; then | |
539 | return | |
540 | fi | |
166f3c7b | 541 | done |
f210a83c FZ |
542 | _notrun "not suitable for cache mode: $CACHEMODE" |
543 | } | |
544 | ||
545 | _default_cache_mode() | |
546 | { | |
547 | if $CACHEMODE_IS_DEFAULT; then | |
548 | CACHEMODE="$1" | |
549 | QEMU_IO="$QEMU_IO --cache $1" | |
550 | return | |
551 | fi | |
166f3c7b SH |
552 | } |
553 | ||
2c77f52e FZ |
554 | _unsupported_imgopts() |
555 | { | |
556 | for bad_opt | |
557 | do | |
558 | if echo "$IMGOPTS" | grep -q 2>/dev/null "$bad_opt" | |
559 | then | |
560 | _notrun "not suitable for image option: $bad_opt" | |
561 | fi | |
562 | done | |
563 | } | |
564 | ||
6bf19c94 CH |
565 | # this test requires that a specified command (executable) exists |
566 | # | |
567 | _require_command() | |
568 | { | |
934659c4 HR |
569 | if [ "$1" = "QEMU" ]; then |
570 | c=$QEMU_PROG | |
571 | elif [ "$1" = "QEMU_IMG" ]; then | |
572 | c=$QEMU_IMG_PROG | |
573 | elif [ "$1" = "QEMU_IO" ]; then | |
574 | c=$QEMU_IO_PROG | |
575 | elif [ "$1" = "QEMU_NBD" ]; then | |
576 | c=$QEMU_NBD_PROG | |
577 | else | |
578 | eval c=\$$1 | |
579 | fi | |
9c468a01 | 580 | [ -x "$c" ] || _notrun "$1 utility required, skipped this test" |
6bf19c94 CH |
581 | } |
582 | ||
21b43d00 TH |
583 | # Check that a set of drivers has been whitelisted in the QEMU binary |
584 | # | |
585 | _require_drivers() | |
586 | { | |
587 | available=$($QEMU -drive format=help | \ | |
588 | sed -e '/Supported formats:/!d' -e 's/Supported formats://') | |
589 | for driver | |
590 | do | |
591 | if ! echo "$available" | grep -q " $driver\( \|$\)"; then | |
592 | _notrun "$driver not available" | |
593 | fi | |
594 | done | |
595 | } | |
596 | ||
6bf19c94 | 597 | # make sure this script returns success |
a2d9c0c4 | 598 | true |