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