3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 for sed in sed gsed
; do
22 ($sed --version |
grep 'GNU sed') > /dev
/null
2>&1
23 if [ "$?" -eq 0 ]; then
28 if [ -z "$SED" ]; then
29 echo "$0: GNU sed not found"
35 if [ "$HOSTOS" == "Linux" ]
37 command dd --help |
grep noxfer
> /dev
/null
2>&1
41 command dd status
=noxfer $@
50 # poke_file 'test.img' 512 '\xff\xfe'
53 printf "$3" |
dd "of=$1" bs
=1 "seek=$2" conv
=notrunc
&>/dev
/null
57 if ! . .
/common.config
59 echo "$0: failed to source common.config"
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
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}
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
79 local VALGRIND_LOGFILE
="$1"
81 if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
82 exec valgrind
--log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$@"
88 _qemu_proc_valgrind_log
()
90 local VALGRIND_LOGFILE
="$1"
92 if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
93 if [ $RETVAL == 99 ]; then
94 cat "${VALGRIND_LOGFILE}"
96 rm -f "${VALGRIND_LOGFILE}"
102 local VALGRIND_LOGFILE
="${TEST_DIR}"/$$.valgrind
104 if [ -n "${QEMU_NEED_PID}" ]; then
105 echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"
107 VALGRIND_QEMU
="${VALGRIND_QEMU_VM}" _qemu_proc_exec
"${VALGRIND_LOGFILE}" \
108 "$QEMU_PROG" $QEMU_OPTIONS "$@"
111 _qemu_proc_valgrind_log
"${VALGRIND_LOGFILE}" $RETVAL
117 local VALGRIND_LOGFILE
="${TEST_DIR}"/$$.valgrind
119 VALGRIND_QEMU
="${VALGRIND_QEMU_IMG}" _qemu_proc_exec
"${VALGRIND_LOGFILE}" \
120 "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@"
123 _qemu_proc_valgrind_log
"${VALGRIND_LOGFILE}" $RETVAL
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"
138 VALGRIND_QEMU
="${VALGRIND_QEMU_IO}" _qemu_proc_exec
"${VALGRIND_LOGFILE}" \
139 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
142 _qemu_proc_valgrind_log
"${VALGRIND_LOGFILE}" $RETVAL
148 local VALGRIND_LOGFILE
="${TEST_DIR}"/$$.valgrind
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 "$@"
155 _qemu_proc_valgrind_log
"${VALGRIND_LOGFILE}" $RETVAL
161 local VALGRIND_LOGFILE
="${TEST_DIR}"/$$.valgrind
163 echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid"
164 VALGRIND_QEMU
="${VALGRIND_QEMU_VXHS}" _qemu_proc_exec
"${VALGRIND_LOGFILE}" \
165 "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@"
168 _qemu_proc_valgrind_log
"${VALGRIND_LOGFILE}" $RETVAL
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.
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
186 if [ "$IMGOPTSSYNTAX" = "true" ]; then
187 DRIVER
="driver=$IMGFMT"
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"
192 if [ "$IMGFMT" = "luks" ]; then
193 DRIVER
="$DRIVER,key-secret=keysec0"
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"
206 TEST_IMG
=$TEST_DIR/t.
$IMGFMT
208 TEST_IMG
="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
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
219 REMOTE_TEST_DIR
="ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?$TEST_DIR"
220 TEST_IMG
="ssh://127.0.0.1$TEST_IMG_FILE"
221 elif [ "$IMGPROTO" = "nfs" ]; then
222 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
223 REMOTE_TEST_DIR
="nfs://127.0.0.1$TEST_DIR"
224 TEST_IMG
="nfs://127.0.0.1$TEST_IMG_FILE"
225 elif [ "$IMGPROTO" = "vxhs" ]; then
226 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
227 TEST_IMG
="vxhs://127.0.0.1:9999/t.$IMGFMT"
229 TEST_IMG
=$IMGPROTO:$TEST_DIR/t.
$IMGFMT
232 ORIG_TEST_IMG
="$TEST_IMG"
234 if [ -z "$TEST_DIR" ]; then
235 TEST_DIR
=$PWD/scratch
238 QEMU_TEST_DIR
="${TEST_DIR}"
240 if [ ! -e "$TEST_DIR" ]; then
244 if [ ! -d "$TEST_DIR" ]; then
245 echo "common.rc: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
249 if [ -z "$REMOTE_TEST_DIR" ]; then
250 REMOTE_TEST_DIR
="$TEST_DIR"
253 if [ ! -d "$SAMPLE_IMG_DIR" ]; then
254 echo "common.rc: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
260 SAMPLE_IMG_FILE
="${1%\.bz2}"
261 TEST_IMG
="$TEST_DIR/$SAMPLE_IMG_FILE"
262 bzcat
"$SAMPLE_IMG_DIR/$1" > "$TEST_IMG"
265 echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'"
272 if [ -f "${QEMU_TEST_DIR}/qemu-nbd.pid" ]; then
274 read QEMU_NBD_PID
< "${QEMU_TEST_DIR}/qemu-nbd.pid"
276 rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid"
282 # extra qemu-img options can be added by tests
283 # at least one argument (the image size) needs to be added
284 local extra_img_options
=""
289 local backing_file
=""
290 local object_options
=""
292 if [ -n "$TEST_IMG_FILE" ]; then
293 img_name
=$TEST_IMG_FILE
298 if [ -n "$IMGOPTS" ]; then
299 optstr
=$
(_optstr_add
"$optstr" "$IMGOPTS")
301 if [ -n "$IMGKEYSECRET" ]; then
302 object_options
="--object secret,id=keysec0,data=$IMGKEYSECRET"
303 optstr
=$
(_optstr_add
"$optstr" "key-secret=keysec0")
306 if [ "$1" = "-b" ]; then
311 if [ \
( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \
) -a -n "$CLUSTER_SIZE" ]; then
312 optstr
=$
(_optstr_add
"$optstr" "cluster_size=$CLUSTER_SIZE")
315 if [ -n "$optstr" ]; then
316 extra_img_options
="-o $optstr $extra_img_options"
319 if [ $IMGPROTO = "nbd" ]; then
323 # XXX(hch): have global image options?
325 if [ $use_backing = 1 ]; then
326 $QEMU_IMG create
$object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1
328 $QEMU_IMG create
$object_options -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1
330 ) | _filter_img_create
332 # Start an NBD server on the image file, which is what we'll be talking to
333 if [ $IMGPROTO = "nbd" ]; then
334 # Pass a sufficiently high number to -e that should be enough for all
336 eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT -e 42 -x '' $TEST_IMG_FILE >/dev/null &"
337 sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
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.
350 if [ "$IMGFMT" = "vmdk" ]; then
351 # Remove all the extents for vmdk
352 "$QEMU_IMG" info
"$img" 2>/dev
/null |
grep 'filename:' | cut
-f 2 -d: \
353 |
xargs -I {} rm -f "{}"
364 rm -f "$TEST_IMG_FILE"
367 if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then
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"
373 rm -f "$TEST_IMG_FILE"
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"
380 if [ -n "$SAMPLE_IMG_FILE" ]
382 rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
384 TEST_IMG
="$ORIG_TEST_IMG"
389 rbd
--no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev
/null
393 collie vdi delete
"$TEST_DIR/t.$IMGFMT"
402 if [ "$IMGOPTSSYNTAX" = "true" ]; then
403 $QEMU_IMG check
$QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1
405 $QEMU_IMG check
"$@" -f $IMGFMT "$TEST_IMG" 2>&1
407 ) | _filter_testdir | _filter_qemu_img_check
409 # return real qemu_img check status, to analyze in
410 # _check_test_img_ignore_leaks
411 return ${PIPESTATUS[0]}
414 _check_test_img_ignore_leaks
()
416 out
=$
(_check_test_img
"$@")
418 if [ $status = 3 ]; then
419 # This must correspond to success output in dump_human_image_check()
420 echo "No errors were found on the image."
429 if [[ "$1" == "--format-specific" ]]; then
430 local format_specific
=1
433 local format_specific
=0
437 regex_json_spec_start
='^ *"format-specific": \{'
438 $QEMU_IMG info
$QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \
439 sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
440 -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
441 -e "s#$TEST_DIR#TEST_DIR#g" \
442 -e "s#$IMGFMT#IMGFMT#g" \
443 -e "/^disk size:/ D" \
444 -e "/actual-size/ D" | \
445 while IFS
='' read -r line
; do
446 if [[ $format_specific == 1 ]]; then
448 elif [[ $line == "Format specific information:" ]]; then
450 elif [[ $line =~
$regex_json_spec_start ]]; then
452 regex_json_spec_end
="^${line%%[^ ]*}\\},? *$"
454 if [[ $discard == 0 ]]; then
456 elif [[ $discard == 1 && ! $line ]]; then
459 elif [[ $discard == 2 && $line =~
$regex_json_spec_end ]]; then
465 # bail out, setting up .notrun file
469 echo "$*" >"$OUTPUT_DIR/$seq.notrun"
470 echo "$seq not run: $*"
475 # bail out, setting up .casenotrun file
476 # The function _casenotrun() is used as a notifier. It is the
477 # caller's responsibility to make skipped a particular test.
481 echo " [case not run] $*" >>"$OUTPUT_DIR/$seq.casenotrun"
484 # just plain bail out
488 echo "$*" |
tee -a "$OUTPUT_DIR/$seq.full"
489 echo "(see $seq.full for details)"
494 # tests whether $IMGFMT is one of the supported image formats for a test
498 # "generic" is suitable for most image formats. For some formats it doesn't
499 # work, however (most notably read-only formats), so they can opt out by
500 # setting IMGFMT_GENERIC to false.
502 if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then
507 _notrun
"not suitable for this image format: $IMGFMT"
510 # tests whether $IMGFMT is one of the unsupported image format for a test
515 if [ "$f" = "$IMGFMT" ]; then
516 _notrun
"not suitable for this image format: $IMGFMT"
521 # tests whether $IMGPROTO is one of the supported image protocols for a test
526 if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
531 _notrun
"not suitable for this image protocol: $IMGPROTO"
534 # tests whether $IMGPROTO is specified as an unsupported image protocol for a test
539 if [ "$f" = "$IMGPROTO" ]; then
540 _notrun
"not suitable for this image protocol: $IMGPROTO"
546 # tests whether the host OS is one of the supported OSes for a test
552 if [ "$h" = "$HOSTOS" ]
558 _notrun
"not suitable for this OS: $HOSTOS"
561 _supported_cache_modes
()
564 if [ "$mode" = "$CACHEMODE" ]; then
568 _notrun
"not suitable for cache mode: $CACHEMODE"
571 _default_cache_mode
()
573 if $CACHEMODE_IS_DEFAULT; then
575 QEMU_IO
="$QEMU_IO --cache $1"
580 _unsupported_imgopts
()
584 if echo "$IMGOPTS" |
grep -q 2>/dev
/null
"$bad_opt"
586 _notrun
"not suitable for image option: $bad_opt"
591 # this test requires that a specified command (executable) exists
595 if [ "$1" = "QEMU" ]; then
597 elif [ "$1" = "QEMU_IMG" ]; then
599 elif [ "$1" = "QEMU_IO" ]; then
601 elif [ "$1" = "QEMU_NBD" ]; then
606 [ -x "$c" ] || _notrun
"$1 utility required, skipped this test"
609 # Check that a set of drivers has been whitelisted in the QEMU binary
613 available
=$
($QEMU -drive format
=help | \
614 sed -e '/Supported formats:/!d' -e 's/Supported formats://')
617 if ! echo "$available" |
grep -q " $driver\( \|$\)"; then
618 _notrun
"$driver not available"
623 # make sure this script returns success