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/>.
22 if [ "$HOSTOS" == "Linux" ]
24 command dd --help |
grep noxfer
> /dev
/null
2>&1
28 command dd status
=noxfer $@
37 # poke_file 'test.img' 512 '\xff\xfe'
40 printf "$3" |
dd "of=$1" bs
=1 "seek=$2" conv
=notrunc
&>/dev
/null
43 # we need common.config
44 if [ "$iam" != "check" ]
46 if ! . .
/common.config
48 echo "$iam: failed to source common.config"
53 # make sure we have a standard umask
56 if [ "$IMGOPTSSYNTAX" = "true" ]; then
57 DRIVER
="driver=$IMGFMT"
58 if [ "$IMGFMT" = "luks" ]; then
59 DRIVER
="$DRIVER,key-secret=keysec0"
61 if [ "$IMGPROTO" = "file" ]; then
62 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
63 TEST_IMG
="$DRIVER,file.filename=$TEST_DIR/t.$IMGFMT"
64 elif [ "$IMGPROTO" = "nbd" ]; then
65 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
66 TEST_IMG
="$DRIVER,file.driver=nbd,file.host=127.0.0.1,file.port=10810"
67 elif [ "$IMGPROTO" = "ssh" ]; then
68 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
69 TEST_IMG
="$DRIVER,file.driver=ssh,file.host=127.0.0.1,file.path=$TEST_IMG_FILE"
70 elif [ "$IMGPROTO" = "nfs" ]; then
71 TEST_DIR
="$DRIVER,file.driver=nfs,file.filename=nfs://127.0.0.1/$TEST_DIR"
72 TEST_IMG
=$TEST_DIR/t.
$IMGFMT
74 TEST_IMG
="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
77 if [ "$IMGPROTO" = "file" ]; then
78 TEST_IMG
=$TEST_DIR/t.
$IMGFMT
79 elif [ "$IMGPROTO" = "nbd" ]; then
80 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
81 TEST_IMG
="nbd:127.0.0.1:10810"
82 elif [ "$IMGPROTO" = "ssh" ]; then
83 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
84 TEST_IMG
="ssh://127.0.0.1$TEST_IMG_FILE"
85 elif [ "$IMGPROTO" = "nfs" ]; then
86 TEST_DIR
="nfs://127.0.0.1/$TEST_DIR"
87 TEST_IMG
=$TEST_DIR/t.
$IMGFMT
88 elif [ "$IMGPROTO" = "vxhs" ]; then
89 TEST_IMG_FILE
=$TEST_DIR/t.
$IMGFMT
90 TEST_IMG
="vxhs://127.0.0.1:9999/t.$IMGFMT"
92 TEST_IMG
=$IMGPROTO:$TEST_DIR/t.
$IMGFMT
105 _set_default_imgopts
()
107 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" |
grep "compat=" > /dev
/null
); then
108 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "compat=1.1")
110 if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" |
grep "iter-time=" > /dev
/null
); then
111 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "iter-time=10")
117 SAMPLE_IMG_FILE
="${1%\.bz2}"
118 TEST_IMG
="$TEST_DIR/$SAMPLE_IMG_FILE"
119 bzcat
"$SAMPLE_IMG_DIR/$1" > "$TEST_IMG"
122 echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'"
129 # extra qemu-img options can be added by tests
130 # at least one argument (the image size) needs to be added
131 local extra_img_options
=""
136 local backing_file
=""
137 local object_options
=""
139 if [ -n "$TEST_IMG_FILE" ]; then
140 img_name
=$TEST_IMG_FILE
145 if [ -n "$IMGOPTS" ]; then
146 optstr
=$
(_optstr_add
"$optstr" "$IMGOPTS")
148 if [ -n "$IMGKEYSECRET" ]; then
149 object_options
="--object secret,id=keysec0,data=$IMGKEYSECRET"
150 optstr
=$
(_optstr_add
"$optstr" "key-secret=keysec0")
153 if [ "$1" = "-b" ]; then
158 if [ \
( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \
) -a -n "$CLUSTER_SIZE" ]; then
159 optstr
=$
(_optstr_add
"$optstr" "cluster_size=$CLUSTER_SIZE")
162 if [ -n "$optstr" ]; then
163 extra_img_options
="-o $optstr $extra_img_options"
166 # XXX(hch): have global image options?
168 if [ $use_backing = 1 ]; then
169 $QEMU_IMG create
$object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1
171 $QEMU_IMG create
$object_options -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1
173 ) | _filter_img_create
175 # Start an NBD server on the image file, which is what we'll be talking to
176 if [ $IMGPROTO = "nbd" ]; then
177 # Pass a sufficiently high number to -e that should be enough for all
179 eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT -e 42 $TEST_IMG_FILE >/dev/null &"
180 sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
183 # Start QNIO server on image directory for vxhs protocol
184 if [ $IMGPROTO = "vxhs" ]; then
185 eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &"
186 sleep 1 # Wait for server to come up.
193 if [ "$IMGFMT" = "vmdk" ]; then
194 # Remove all the extents for vmdk
195 "$QEMU_IMG" info
"$img" 2>/dev
/null |
grep 'filename:' | cut
-f 2 -d: \
196 |
xargs -I {} rm -f "{}"
206 if [ -f "${QEMU_TEST_DIR}/qemu-nbd.pid" ]; then
208 read QEMU_NBD_PID
< "${QEMU_TEST_DIR}/qemu-nbd.pid"
210 rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid"
212 rm -f "$TEST_IMG_FILE"
215 if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then
217 read QEMU_VXHS_PID
< "${TEST_DIR}/qemu-vxhs.pid"
218 kill ${QEMU_VXHS_PID} >/dev
/null
2>&1
219 rm -f "${TEST_DIR}/qemu-vxhs.pid"
221 rm -f "$TEST_IMG_FILE"
225 _rm_test_img
"$TEST_DIR/t.$IMGFMT"
226 _rm_test_img
"$TEST_DIR/t.$IMGFMT.orig"
227 _rm_test_img
"$TEST_DIR/t.$IMGFMT.base"
228 if [ -n "$SAMPLE_IMG_FILE" ]
230 rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
235 rbd
--no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev
/null
239 collie vdi delete
"$TEST_DIR/t.$IMGFMT"
248 if [ "$IMGOPTSSYNTAX" = "true" ]; then
249 $QEMU_IMG check
$QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1
251 $QEMU_IMG check
"$@" -f $IMGFMT "$TEST_IMG" 2>&1
253 ) | _filter_testdir | _filter_qemu_img_check
258 if [[ "$1" == "--format-specific" ]]; then
259 local format_specific
=1
262 local format_specific
=0
266 regex_json_spec_start
='^ *"format-specific": \{'
267 $QEMU_IMG info
"$@" "$TEST_IMG" 2>&1 | \
268 sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
269 -e "s#$TEST_DIR#TEST_DIR#g" \
270 -e "s#$IMGFMT#IMGFMT#g" \
271 -e "/^disk size:/ D" \
272 -e "/actual-size/ D" | \
273 while IFS
='' read line
; do
274 if [[ $format_specific == 1 ]]; then
276 elif [[ $line == "Format specific information:" ]]; then
278 elif [[ $line =~
$regex_json_spec_start ]]; then
280 regex_json_spec_end
="^${line%%[^ ]*}\\},? *$"
282 if [[ $discard == 0 ]]; then
284 elif [[ $discard == 1 && ! $line ]]; then
287 elif [[ $discard == 2 && $line =~
$regex_json_spec_end ]]; then
297 echo "Usage: _get_pids_by_name process-name" 1>&2
301 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
302 # HH:MM:SS before the psargs field, use this as the search anchor.
304 # Matches with $1 (process-name) occur if the first psarg is $1
305 # or ends in /$1 ... the matching uses sed's regular expressions,
306 # so passing a regex into $1 will work.
314 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
315 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
323 $NSLOOKUP_PROG $host |
$AWK_PROG '{ if ($1 == "Name:") print $2 }'
326 # check if run as root
330 id
=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
333 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
338 # bail out, setting up .notrun file
342 echo "$*" >"$OUTPUT_DIR/$seq.notrun"
343 echo "$seq not run: $*"
348 # just plain bail out
352 echo "$*" |
tee -a "$OUTPUT_DIR/$seq.full"
353 echo "(see $seq.full for details)"
358 # tests whether $IMGFMT is one of the supported image formats for a test
362 # "generic" is suitable for most image formats. For some formats it doesn't
363 # work, however (most notably read-only formats), so they can opt out by
364 # setting IMGFMT_GENERIC to false.
366 if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then
371 _notrun
"not suitable for this image format: $IMGFMT"
374 # tests whether $IMGFMT is one of the unsupported image format for a test
379 if [ "$f" = "$IMGFMT" ]; then
380 _notrun
"not suitable for this image format: $IMGFMT"
385 # tests whether $IMGPROTO is one of the supported image protocols for a test
390 if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
395 _notrun
"not suitable for this image protocol: $IMGPROTO"
398 # tests whether $IMGPROTO is specified as an unsupported image protocol for a test
403 if [ "$f" = "$IMGPROTO" ]; then
404 _notrun
"not suitable for this image protocol: $IMGPROTO"
410 # tests whether the host OS is one of the supported OSes for a test
416 if [ "$h" = "$HOSTOS" ]
422 _notrun
"not suitable for this OS: $HOSTOS"
425 _supported_cache_modes
()
428 if [ "$mode" = "$CACHEMODE" ]; then
432 _notrun
"not suitable for cache mode: $CACHEMODE"
435 _default_cache_mode
()
437 if $CACHEMODE_IS_DEFAULT; then
439 QEMU_IO
="$QEMU_IO --cache $1"
444 _unsupported_imgopts
()
448 if echo "$IMGOPTS" |
grep -q 2>/dev
/null
"$bad_opt"
450 _notrun
"not suitable for image option: $bad_opt"
455 # this test requires that a specified command (executable) exists
459 if [ "$1" = "QEMU" ]; then
461 elif [ "$1" = "QEMU_IMG" ]; then
463 elif [ "$1" = "QEMU_IO" ]; then
465 elif [ "$1" = "QEMU_NBD" ]; then
470 [ -x "$c" ] || _notrun
"$1 utility required, skipped this test"
473 _full_imgfmt_details
()
475 if [ -n "$IMGOPTS" ]; then
476 echo "$IMGFMT ($IMGOPTS)"
482 _full_imgproto_details
()
487 _full_platform_details
()
490 host=`hostname -s 2>/dev/null || hostname`
493 echo "$os/$platform $host $kernel"
499 echo Error must pass \
$seq.
503 if [ "`uname`" == "IRIX64" ] ||
[ "`uname`" == "IRIX" ]; then
505 elif [ "`uname`" == "Linux" ]; then
508 echo Error
test $seq does not run on the operating system
: `uname`
519 # make sure this script returns success