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 # we need common.config
38 if [ "$iam" != "check" ]
40 if ! . ./common.config
42 echo "$iam: failed to source common.config"
47 # make sure we have a standard umask
50 if [ "$IMGPROTO" = "file" ]; then
51 TEST_IMG=$TEST_DIR/t.$IMGFMT
53 TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
65 _set_default_imgopts()
67 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
68 IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
74 # extra qemu-img options can be added by tests
75 # at least one argument (the image size) needs to be added
76 local extra_img_options=""
80 if [ -n "$IMGOPTS" ]; then
81 optstr=$(_optstr_add "$optstr" "$IMGOPTS")
84 if [ "$1" = "-b" ]; then
85 extra_img_options="$1 $2"
88 if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then
89 optstr=$(_optstr_add "$optstr" "cluster_size=$CLUSTER_SIZE")
92 if [ -n "$optstr" ]; then
93 extra_img_options="-o $optstr $extra_img_options"
96 # XXX(hch): have global image options?
97 $QEMU_IMG create -f $IMGFMT $extra_img_options $TEST_IMG $image_size | \
98 sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" | \
99 sed -e "s#$TEST_DIR#TEST_DIR#g" | \
100 sed -e "s#$IMGFMT#IMGFMT#g" | \
101 sed -e "s# encryption=off##g" | \
102 sed -e "s# cluster_size=[0-9]\\+##g" | \
103 sed -e "s# table_size=0##g" | \
104 sed -e "s# compat='[^']*'##g" | \
105 sed -e "s# compat6=off##g" | \
106 sed -e "s# static=off##g"
114 rm -f $TEST_DIR/t.$IMGFMT
115 rm -f $TEST_DIR/t.$IMGFMT.orig
116 rm -f $TEST_DIR/t.$IMGFMT.base
120 rbd rm $TEST_DIR/t.$IMGFMT > /dev/null
124 collie vdi delete $TEST_DIR/t.$IMGFMT
132 $QEMU_IMG check -f $IMGFMT $TEST_IMG 2>&1 | \
133 sed -e 's/qemu-img\: This image format does not support checks/No errors were found on the image./'
140 echo "Usage: _get_pids_by_name process-name" 1>&2
144 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
145 # HH:MM:SS before the psargs field, use this as the search anchor.
147 # Matches with $1 (process-name) occur if the first psarg is $1
148 # or ends in /$1 ... the matching uses sed's regular expressions,
149 # so passing a regex into $1 will work.
157 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
158 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
166 $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
169 # check if run as root
173 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
176 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
182 # Do a command, log it to $seq.full, optionally test return status
183 # and die if command fails. If called with one argument _do executes the
184 # command, logs it, and returns its exit status. With two arguments _do
185 # first prints the message passed in the first argument, and then "done"
186 # or "fail" depending on the return status of the command passed in the
187 # second argument. If the command fails and the variable _do_die_on_error
188 # is set to "always" or the two argument form is used and _do_die_on_error
189 # is set to "message_only" _do will print an error message to
194 if [ $# -eq 1 ]; then
196 elif [ $# -eq 2 ]; then
201 echo "Usage: _do [note] cmd" 1>&2
205 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
206 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
207 cat $tmp._out >>$here/$seq.full
208 if [ $# -eq 2 ]; then
209 if [ $ret -eq 0 ]; then
216 && [ "$_do_die_on_error" = "always" \
217 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
220 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
227 # bail out, setting up .notrun file
231 echo "$*" >$seq.notrun
232 echo "$seq not run: $*"
237 # just plain bail out
241 echo "$*" | tee -a $here/$seq.full
242 echo "(see $seq.full for details)"
247 # tests whether $IMGFMT is one of the supported image formats for a test
252 if [ "$f" = "$IMGFMT" -o "$f" = "generic" ]; then
257 _notrun "not suitable for this image format: $IMGFMT"
260 # tests whether $IMGPROTO is one of the supported image protocols for a test
265 if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
270 _notrun "not suitable for this image protocol: $IMGPROTO"
273 # tests whether the host OS is one of the supported OSes for a test
279 if [ "$h" = "$HOSTOS" ]
285 _notrun "not suitable for this OS: $HOSTOS"
288 # this test requires that a specified command (executable) exists
292 [ -x "$1" ] || _notrun "$1 utility required, skipped this test"
295 _full_imgfmt_details()
297 if [ -n "$IMGOPTS" ]; then
298 echo "$IMGFMT ($IMGOPTS)"
304 _full_imgproto_details()
309 _full_platform_details()
315 echo "$os/$platform $host $kernel"
321 echo Error must pass \$seq.
325 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
327 elif [ "`uname`" == "Linux" ]; then
330 echo Error test $seq does not run on the operating system: `uname`
341 # make sure this script returns success