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/>.
20 # bail out, setting up .notrun file
23 echo "$*" >"$TEST_DIR/$seq.notrun"
24 echo "$seq not run: $*"
29 if ! command -v gsed
>/dev
/null
2>&1; then
30 if sed --version 2>&1 |
grep -v 'not GNU sed' |
grep 'GNU sed' > /dev
/null
;
39 _notrun
"GNU sed not available"
46 if [ "$HOSTOS" == "Linux" ]
48 command dd --help |
grep noxfer
> /dev
/null
2>&1
52 command dd status
=noxfer $@
61 # poke_file 'test.img' 512 '\xff\xfe'
64 printf "$3" |
dd "of=$1" bs
=1 "seek=$2" conv
=notrunc
&>/dev
/null
67 # poke_file_le $img_filename $offset $byte_width $value
68 # Example: poke_file_le "$TEST_IMG" 512 2 65534
71 local img
=$1 ofs
=$2 len
=$3 val
=$4 str
=''
74 str
+=$
(printf '\\x%02x' $
((val
& 0xff)))
78 poke_file
"$img" "$ofs" "$str"
81 # poke_file_be $img_filename $offset $byte_width $value
82 # Example: poke_file_be "$TEST_IMG" 512 2 65279
85 local img
=$1 ofs
=$2 len
=$3 val
=$4
86 local str
=$
(printf "%0$((len * 2))x\n" $val |
sed 's/\(..\)/\\x\1/g')
88 poke_file
"$img" "$ofs" "$str"
91 # peek_file_le 'test.img' 512 2 => 65534
94 local val
=0 shift=0 byte
96 # coreutils' od --endian is not portable, so manually assemble bytes.
97 for byte
in $
(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
98 val
=$
(( val |
(byte
<< shift) ))
104 # peek_file_be 'test.img' 512 2 => 65279
109 # coreutils' od --endian is not portable, so manually assemble bytes.
110 for byte
in $
(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
111 val
=$
(( (val
<< 8) | byte ))
116 # peek_file_raw 'test.img' 512 2 => '\xff\xfe'. Do not use if the raw data
117 # is likely to contain \0 or trailing \n.
120 dd if="$1" bs=1 skip="$2" count="$3" status=none
124 test -f $config || config=../common.config
127 echo "$0: failed to find common.config"
132 echo "$0: failed to source common.config"
136 # Set the variables to the empty string to turn Valgrind off
137 # for specific processes, e.g.
138 # $ VALGRIND_QEMU_IO= ./check -qcow2 -valgrind 015
140 : ${VALGRIND_QEMU_VM=$VALGRIND_QEMU}
141 : ${VALGRIND_QEMU_IMG=$VALGRIND_QEMU}
142 : ${VALGRIND_QEMU_IO=$VALGRIND_QEMU}
143 : ${VALGRIND_QEMU_NBD=$VALGRIND_QEMU}
144 : ${VALGRIND_QSD=$VALGRIND_QEMU}
146 # The Valgrind own parameters may be set with
147 # its environment variable VALGRIND_OPTS, e.g.
148 # $ VALGRIND_OPTS="--leak-check=yes" ./check -qcow2 -valgrind 015
152 local VALGRIND_LOGFILE="$1"
154 if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
155 exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$@"
161 _qemu_proc_valgrind_log()
163 local VALGRIND_LOGFILE="$1"
165 if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
166 if [ $RETVAL == 99 ]; then
167 cat "${VALGRIND_LOGFILE}"
169 rm -f "${VALGRIND_LOGFILE}"
175 local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
177 if [ -n "${QEMU_NEED_PID}" ]; then
178 echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"
182 if [ -n "${GDB_OPTIONS}" ]; then
183 GDB="gdbserver ${GDB_OPTIONS}"
186 VALGRIND_QEMU="${VALGRIND_QEMU_VM}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
187 $GDB "$QEMU_PROG" $QEMU_OPTIONS "$@"
190 _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
196 local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
198 VALGRIND_QEMU="${VALGRIND_QEMU_IMG}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
199 "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@"
202 _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
208 local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
209 local QEMU_IO_ARGS="$QEMU_IO_OPTIONS"
210 if [ "$IMGOPTSSYNTAX" = "true" ]; then
211 QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS"
212 if [ -n "$IMGKEYSECRET" ]; then
213 QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS"
217 VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
218 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
221 _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
227 local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
229 VALGRIND_QEMU="${VALGRIND_QEMU_NBD}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
230 "$QEMU_NBD_PROG" --pid-file="${QEMU_TEST_DIR}/qemu-nbd.pid" \
231 $QEMU_NBD_OPTIONS "$@"
234 _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
238 _qemu_storage_daemon_wrapper()
240 local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
242 if [ -n "${QSD_NEED_PID}" ]; then
243 echo $BASHPID > "${QEMU_TEST_DIR}/qemu-storage-daemon.pid"
245 VALGRIND_QEMU="${VALGRIND_QSD}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
246 "$QSD_PROG" $QSD_OPTIONS "$@"
249 _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
253 # Valgrind bug #409141 https://bugs.kde.org/show_bug.cgi?id=409141
254 # Until valgrind 3.16+ is ubiquitous, we must work around a hang in
255 # valgrind when issuing sigkill. Disable valgrind for this invocation.
261 export QEMU=_qemu_wrapper
262 export QEMU_IMG=_qemu_img_wrapper
263 export QEMU_IO=_qemu_io_wrapper
264 export QEMU_NBD=_qemu_nbd_wrapper
265 export QSD=_qemu_storage_daemon_wrapper
267 if [ "$IMGOPTSSYNTAX" = "true" ]; then
268 DRIVER="driver=$IMGFMT"
269 QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS"
270 if [ -n "$IMGKEYSECRET" ]; then
271 QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS"
273 if [ "$IMGFMT" = "luks" ]; then
274 DRIVER="$DRIVER,key-secret=keysec0"
276 if [ "$IMGPROTO" = "file" ]; then
277 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
278 TEST_IMG="$DRIVER,file.filename=$TEST_DIR/t.$IMGFMT"
279 elif [ "$IMGPROTO" = "nbd" ]; then
280 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
281 TEST_IMG="$DRIVER,file.driver=nbd,file.type=unix"
282 TEST_IMG="$TEST_IMG,file.path=$SOCK_DIR/nbd"
283 elif [ "$IMGPROTO" = "fuse" ]; then
284 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
285 TEST_IMG="$DRIVER,file.filename=$SOCK_DIR/fuse-t.$IMGFMT"
286 elif [ "$IMGPROTO" = "ssh" ]; then
287 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
288 TEST_IMG="$DRIVER,file.driver=ssh,file.host=127.0.0.1,file.path=$TEST_IMG_FILE"
289 elif [ "$IMGPROTO" = "nfs" ]; then
290 TEST_DIR="$DRIVER,file.driver=nfs,file.filename=nfs://127.0.0.1/$TEST_DIR"
291 TEST_IMG=$TEST_DIR/t.$IMGFMT
293 TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
297 if [ "$IMGPROTO" = "file" ]; then
298 TEST_IMG=$TEST_DIR/t.$IMGFMT
299 elif [ "$IMGPROTO" = "nbd" ]; then
300 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
301 TEST_IMG="nbd+unix:///?socket=$SOCK_DIR/nbd"
302 elif [ "$IMGPROTO" = "fuse" ]; then
303 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
304 TEST_IMG="$SOCK_DIR/fuse-t.$IMGFMT"
305 elif [ "$IMGPROTO" = "ssh" ]; then
306 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
307 REMOTE_TEST_DIR="ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?$TEST_DIR"
308 TEST_IMG="ssh://127.0.0.1$TEST_IMG_FILE"
309 elif [ "$IMGPROTO" = "nfs" ]; then
310 TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
311 REMOTE_TEST_DIR="nfs://127.0.0.1$TEST_DIR"
312 TEST_IMG="nfs://127.0.0.1$TEST_IMG_FILE"
314 TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
317 ORIG_TEST_IMG_FILE=$TEST_IMG_FILE
318 ORIG_TEST_IMG="$TEST_IMG"
323 if [ -z "$TEST_DIR" ]; then
324 TEST_DIR=$PWD/scratch
327 QEMU_TEST_DIR="${TEST_DIR}"
329 if [ ! -e "$TEST_DIR" ]; then
333 if [ ! -d "$TEST_DIR" ]; then
334 echo "common.rc: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
338 if [ -z "$REMOTE_TEST_DIR" ]; then
339 REMOTE_TEST_DIR="$TEST_DIR"
342 if [ ! -d "$SAMPLE_IMG_DIR" ]; then
343 echo "common.rc: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
349 SAMPLE_IMG_FILE="${1%\.bz2}"
350 TEST_IMG="$TEST_DIR/$SAMPLE_IMG_FILE"
351 bzcat "$SAMPLE_IMG_DIR/$1" > "$TEST_IMG"
354 echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'"
361 if [ -f "${QEMU_TEST_DIR}/qemu-nbd.pid" ]; then
363 read QEMU_NBD_PID < "${QEMU_TEST_DIR}/qemu-nbd.pid"
365 rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid" "$SOCK_DIR/nbd"
369 # Gets the data_file value from IMGOPTS and replaces the '$TEST_IMG'
371 # Caution: The replacement is done with sed, so $1 must be escaped
372 # properly. (The delimiter is '#'.)
375 if ! echo "$IMGOPTS" | grep -q 'data_file='; then
379 echo "$IMGOPTS" | sed -e 's/.*data_file=\([^,]*\).*/\1/' \
380 | sed -e "s#\\\$TEST_IMG#$1#"
383 # Translate a $TEST_IMG to its corresponding $TEST_IMG_FILE for
384 # different protocols
385 _test_img_to_test_img_file()
393 echo "$1" | sed -e "s#$SOCK_DIR/fuse-#$TEST_DIR/#"
397 echo "$1" | sed -e "s#nfs://127.0.0.1##"
402 sed -e "s#ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?##"
413 # extra qemu-img options can be added by tests
414 # at least one argument (the image size) needs to be added
415 local extra_img_options=""
419 local backing_file=""
420 local object_options=""
421 local opts_param=false
424 if [[ $IMGPROTO == fuse && $TEST_IMG == $SOCK_DIR/fuse-* ]]; then
425 # The caller may be trying to overwrite an existing image
426 _rm_test_img "$TEST_IMG"
429 if [ -z "$TEST_IMG_FILE" ]; then
431 elif [ "$IMGOPTSSYNTAX" != "true" -a \
432 "$TEST_IMG_FILE" = "$ORIG_TEST_IMG_FILE" ]; then
433 # Handle cases of tests only updating TEST_IMG, but not TEST_IMG_FILE
434 img_name=$(_test_img_to_test_img_file "$TEST_IMG")
435 if [ "$?" != 0 ]; then
436 img_name=$TEST_IMG_FILE
439 # $TEST_IMG_FILE is not the default value, so it definitely has been
440 # modified by the test
441 img_name=$TEST_IMG_FILE
444 if [ -n "$IMGOPTS" ]; then
445 imgopts_expanded=$(echo "$IMGOPTS" | sed -e "s#\\\$TEST_IMG#$img_name#")
446 optstr=$(_optstr_add "$optstr" "$imgopts_expanded")
448 if [ -n "$IMGKEYSECRET" ]; then
449 object_options="--object secret,id=keysec0,data=$IMGKEYSECRET"
450 optstr=$(_optstr_add "$optstr" "key-secret=keysec0")
454 if [ "$use_backing" = "1" -a -z "$backing_file" ]; then
457 elif $opts_param; then
458 optstr=$(_optstr_add "$optstr" "$param")
477 misc_params=("${misc_params[@]}" "$param")
482 if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then
483 optstr=$(_optstr_add "$optstr" "cluster_size=$CLUSTER_SIZE")
486 if [ -n "$optstr" ]; then
487 extra_img_options="-o $optstr $extra_img_options"
490 if [ $IMGPROTO = "nbd" ]; then
494 # XXX(hch): have global image options?
496 if [ $use_backing = 1 ]; then
497 $QEMU_IMG create $object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" "${misc_params[@]}" 2>&1
499 $QEMU_IMG create $object_options -f $IMGFMT $extra_img_options "$img_name" "${misc_params[@]}" 2>&1
501 ) | _filter_img_create
503 # Start an NBD server on the image file, which is what we'll be talking to.
504 # Once NBD gains resize support, we may also want to use -f raw at the
505 # server and interpret format over NBD, but for now, the format is
506 # interpreted at the server and raw data sent over NBD.
507 if [ $IMGPROTO = "nbd" ]; then
508 # Pass a sufficiently high number to -e that should be enough for all
510 eval "$QEMU_NBD -v -t -k '$SOCK_DIR/nbd' -f $IMGFMT -e 42 -x '' $TEST_IMG_FILE >/dev/null &"
511 sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
514 if [ $IMGPROTO = "fuse" -a -f "$img_name" ]; then
520 export_mp=$(echo "$img_name" | sed -e "s#$TEST_DIR/#$SOCK_DIR/fuse-#")
521 if ! echo "$export_mp" | grep -q "^$SOCK_DIR"; then
522 echo 'Cannot use FUSE exports with images outside of TEST_DIR' >&2
527 rm -f "$SOCK_DIR/fuse-output"
529 # Usually, users would export formatted nodes. But we present fuse as a
530 # protocol-level driver here, so we have to leave the format to the
532 # Switch off allow-other, because in general we do not need it for
533 # iotests. The default allow-other=auto has the downside of printing a
534 # fusermount error on its first attempt if allow_other is not
535 # permissible, which we would need to filter.
536 QSD_NEED_PID=y $QSD \
537 --blockdev file,node-name=export-node,filename=$img_name,discard=unmap \
538 --export fuse,id=fuse-export,node-name=export-node,mountpoint="$export_mp",writable=on,growable=on,allow-other=off \
541 pidfile="$QEMU_TEST_DIR/qemu-storage-daemon.pid"
543 # Wait for the PID file
544 while [ ! -f "$pidfile" ]; do
548 pid=$(cat "$pidfile")
552 FUSE_EXPORTS+=("$export_mp")
560 if [[ $IMGPROTO == fuse && $img == $SOCK_DIR/fuse-* ]]; then
568 for i in "${!FUSE_EXPORTS[@]}"; do
569 if [ "${FUSE_EXPORTS[i]}" = "$img" ]; then
575 if [ -z "$index" ]; then
576 # Probably gone already
580 kill "${FUSE_PIDS[index]}"
582 # Wait until the mount is gone
585 # Will show the mount point; if the mount is still there,
587 df_output=$(df "$img" 2>/dev/null)
589 # But df may also show an error ("Transpoint endpoint not
590 # connected"), so retry in such cases
591 if [ -n "$df_output" ]; then
592 if ! echo "$df_output" | grep -q "$img"; then
599 timeout=$((timeout - 1))
600 if [ "$timeout" = 0 ]; then
601 echo 'Failed to take down FUSE export' >&2
608 unset "FUSE_PIDS[$index]"
609 unset "FUSE_EXPORTS[$index]"
611 image_file=$(echo "$img" | sed -e "s#$SOCK_DIR/fuse-#$TEST_DIR/#")
612 _rm_test_img "$image_file"
616 if [ "$IMGFMT" = "vmdk" ]; then
617 # Remove all the extents for vmdk
618 "$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 -d: \
619 | xargs -I {} rm -f "{}"
620 elif [ "$IMGFMT" = "qcow2" ]; then
621 # Remove external data file
622 if data_file=$(_get_data_file "$img"); then
635 rm -f "$TEST_IMG_FILE"
641 for mp in "${FUSE_EXPORTS[@]}"; do
650 _rm_test_img "$TEST_DIR/t.$IMGFMT"
651 _rm_test_img "$TEST_DIR/t.$IMGFMT.orig"
652 _rm_test_img "$TEST_DIR/t.$IMGFMT.base"
653 if [ -n "$SAMPLE_IMG_FILE" ]
655 rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
657 TEST_IMG="$ORIG_TEST_IMG"
662 rbd --no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev/null
671 if [ "$IMGOPTSSYNTAX" = "true" ]; then
672 $QEMU_IMG check $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1
674 $QEMU_IMG check "$@" -f $IMGFMT "$TEST_IMG" 2>&1
676 ) | _filter_testdir | _filter_qemu_img_check
678 # return real qemu_img check status, to analyze in
679 # _check_test_img_ignore_leaks
680 return ${PIPESTATUS[0]}
683 _check_test_img_ignore_leaks()
685 out=$(_check_test_img "$@")
687 if [ $status = 3 ]; then
688 # This must correspond to success output in dump_human_image_check()
689 echo "No errors were found on the image."
698 if [[ "$1" == "--format-specific" ]]; then
699 local format_specific=1
702 local format_specific=0
706 regex_json_spec_start='^ *"format-specific": \{'
707 $QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \
708 sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
709 -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
710 -e "s#$TEST_DIR#TEST_DIR#g" \
711 -e "s#$SOCK_DIR/fuse-#TEST_DIR/#g" \
712 -e "s#$IMGFMT#IMGFMT#g" \
713 -e 's/\(compression type: \)\(zlib\|zstd\)/\1COMPRESSION_TYPE/' \
714 -e "/^disk size:/ D" \
715 -e "/actual-size/ D" | \
716 while IFS='' read -r line; do
717 if [[ $format_specific == 1 ]]; then
719 elif [[ $line == "Format specific information:" ]]; then
721 elif [[ $line =~ $regex_json_spec_start ]]; then
723 regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
725 if [[ $discard == 0 ]]; then
727 elif [[ $discard == 1 && ! $line ]]; then
730 elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
736 # bail out, setting up .casenotrun file
737 # The function _casenotrun() is used as a notifier. It is the
738 # caller's responsibility to make skipped a particular test.
742 echo " [case not run] $*" >>"$TEST_DIR/$seq.casenotrun"
745 # just plain bail out
749 echo "$*" | tee -a "$TEST_DIR/$seq.full"
750 echo "(see $seq.full for details)"
755 # tests whether $IMGFMT is one of the supported image formats for a test
759 # "generic" is suitable for most image formats. For some formats it doesn't
760 # work, however (most notably read-only formats), so they can opt out by
761 # setting IMGFMT_GENERIC to false.
763 if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then
764 if [ "$IMGFMT" = "luks" ]; then
765 _require_working_luks
771 _notrun "not suitable for this image format: $IMGFMT"
774 # tests whether $IMGFMT is one of the unsupported image format for a test
779 if [ "$f" = "$IMGFMT" ]; then
780 _notrun "not suitable for this image format: $IMGFMT"
785 # tests whether $IMGPROTO is one of the supported image protocols for a test
790 if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
795 _notrun "not suitable for this image protocol: $IMGPROTO"
798 # tests whether $IMGPROTO is specified as an unsupported image protocol for a test
803 if [ "$f" = "$IMGPROTO" ]; then
804 _notrun "not suitable for this image protocol: $IMGPROTO"
810 # tests whether the host OS is one of the supported OSes for a test
816 if [ "$h" = "$HOSTOS" ]
822 _notrun "not suitable for this OS: $HOSTOS"
825 _supported_cache_modes()
828 if [ "$mode" = "$CACHEMODE" ]; then
832 _notrun "not suitable for cache mode: $CACHEMODE"
835 # Check whether the filesystem supports O_DIRECT
838 testfile="$TEST_DIR"/_check_o_direct
839 $QEMU_IMG create -f raw "$testfile" 1M > /dev/null
840 out=$($QEMU_IO -f raw -t none -c quit "$testfile" 2>&1)
843 [[ "$out" != *"O_DIRECT"* ]]
848 if ! _check_o_direct; then
849 _notrun "file system on $TEST_DIR does not support O_DIRECT"
855 if [ $CACHEMODE == "none" ] || [ $CACHEMODE == "directsync" ]; then
862 # $1 - cache mode to use by default
863 # $2 - (optional) cache mode to use by default if O_DIRECT is not supported
864 _default_cache_mode()
866 if $CACHEMODE_IS_DEFAULT; then
867 if [ -z "$2" ] || _check_o_direct; then
872 QEMU_IO="$QEMU_IO --cache $CACHEMODE"
877 _supported_aio_modes()
880 if [ "$mode" = "$AIOMODE" ]; then
884 _notrun "not suitable for aio mode: $AIOMODE"
889 QEMU_IO="$QEMU_IO --aio $1"
892 _unsupported_imgopts()
896 # Add a space so tests can match for whitespace that marks the
897 # end of an option (\b or \> are not portable)
898 if echo "$IMGOPTS " | grep -q 2>/dev/null "$bad_opt"
900 _notrun "not suitable for image option: $bad_opt"
905 # Caution: Overwrites $TEST_DIR/t.luks
906 _require_working_luks()
908 file="$TEST_DIR/t.luks"
911 $QEMU_IMG create -f luks \
912 --object secret,id=sec0,data=hunter0 \
921 IMGFMT='luks' _rm_test_img "$file"
923 if [ $status != 0 ]; then
924 reason=$(echo "$output" | grep "$file:" | sed -e "s#.*$file: *##")
925 if [ -z "$reason" ]; then
926 reason="Failed to create a LUKS image"
932 # this test requires that a specified command (executable) exists
936 if [ "$1" = "QEMU" ]; then
938 elif [ "$1" = "QEMU_IMG" ]; then
940 elif [ "$1" = "QEMU_IO" ]; then
942 elif [ "$1" = "QEMU_NBD" ]; then
947 [ -x "$c" ] || _notrun "$1 utility required, skipped this test"
950 # Check that a set of drivers has been whitelisted in the QEMU binary
954 available=$($QEMU -drive format=help | \
955 sed -e '/Supported formats:/!d' -e 's/Supported formats://')
958 if ! echo "$available" | grep -q " $driver\( \|$\)"; then
959 _notrun "$driver not available"
964 # Check that we have a file system that allows huge (but very sparse) files
966 _require_large_file()
968 if ! truncate --size="$1" "$TEST_IMG"; then
969 _notrun "file system on $TEST_DIR does not support large enough files"
974 # Check that a set of devices is available in the QEMU binary
978 available=$($QEMU -M none -device help | \
979 grep ^name | sed -e 's/^name "//' -e 's/".*$//')
982 if ! echo "$available" | grep -q "$device" ; then
983 _notrun "$device not available"
988 _require_one_device_of()
990 available=$($QEMU -M none -device help | \
991 grep ^name | sed -e 's/^name "//' -e 's/".*$//')
994 if echo "$available" | grep -q "$device" ; then
998 _notrun "$* not available"
1001 _qcow2_dump_header()
1003 if [[ "$1" == "--no-filter-compression" ]]; then
1004 local filter_compression=0
1007 local filter_compression=1
1011 if [ -z "$img" ]; then
1015 if [[ $filter_compression == 0 ]]; then
1016 $PYTHON qcow2.py "$img" dump-header
1018 $PYTHON qcow2.py "$img" dump-header | _filter_qcow2_compression_type_bit
1022 # make sure this script returns success