add support for the vdi image format
[qemu-iotests/stefanha.git] / common
blob360b058e35baafef89b2f48e6a6e51993722a755
1 #!/bin/sh
3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # common procedures for QA scripts
23 _setenvironment()
25 MSGVERB="text:action"
26 export MSGVERB
29 here=`pwd`
30 rm -f $here/$iam.out
31 _setenvironment
33 check=${check-true}
35 diff="diff -u"
36 verbose=false
37 group=false
38 xgroup=false
39 showme=false
40 sortme=false
41 expunge=true
42 have_test_arg=false
43 randomize=false
44 rm -f $tmp.list $tmp.tmp $tmp.sed
46 export IMGFMT=raw
47 export QEMU_IO_OPTIONS=""
49 for r
52 if $group
53 then
54 # arg after -g
55 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
56 s/ .*//p
57 }'`
58 if [ -z "$group_list" ]
59 then
60 echo "Group \"$r\" is empty or not defined?"
61 exit 1
63 [ ! -s $tmp.list ] && touch $tmp.list
64 for t in $group_list
66 if grep -s "^$t\$" $tmp.list >/dev/null
67 then
69 else
70 echo "$t" >>$tmp.list
72 done
73 group=false
74 continue
76 elif $xgroup
77 then
78 # arg after -x
79 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
80 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
81 s/ .*//p
82 }'`
83 if [ -z "$group_list" ]
84 then
85 echo "Group \"$r\" is empty or not defined?"
86 exit 1
88 numsed=0
89 rm -f $tmp.sed
90 for t in $group_list
92 if [ $numsed -gt 100 ]
93 then
94 sed -f $tmp.sed <$tmp.list >$tmp.tmp
95 mv $tmp.tmp $tmp.list
96 numsed=0
97 rm -f $tmp.sed
99 echo "/^$t\$/d" >>$tmp.sed
100 numsed=`expr $numsed + 1`
101 done
102 sed -f $tmp.sed <$tmp.list >$tmp.tmp
103 mv $tmp.tmp $tmp.list
104 xgroup=false
105 continue
108 xpand=true
109 case "$r"
112 -\? | -h | --help) # usage
113 echo "Usage: $0 [options] [testlist]"'
115 common options
116 -v verbose
118 check options
119 -raw test raw (default)
120 -cow test cow
121 -qcow test qcow
122 -qcow2 test qcow2
123 -vdi test vdi
124 -vpc test vpc
125 -vmdk test vmdk
126 -xdiff graphical mode diff
127 -nocache use O_DIRECT on backing file
128 -misalign misalign memory allocations
129 -n show me, do not run tests
130 -T output timestamps
131 -r randomize test order
133 testlist options
134 -g group[,group...] include tests from these groups
135 -x group[,group...] exclude tests from these groups
136 NNN include test NNN
137 NNN-NNN include test range (eg. 012-021)
139 exit 0
142 -raw)
143 IMGFMT=raw
144 xpand=false
147 -cow)
148 IMGFMT=cow
149 xpand=false
152 -qcow)
153 IMGFMT=qcow
154 xpand=false
157 -qcow2)
158 IMGFMT=qcow2
159 xpand=false
162 -vdi)
163 IMGFMT=vdi
164 xpand=false
167 -vmdk)
168 IMGFMT=vmdk
169 xpand=false
172 -vpc)
173 IMGFMT=vpc
174 xpand=false
177 -nocache)
178 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
179 xpand=false
182 -misalign)
183 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
184 xpand=false
187 -g) # -g group ... pick from group file
188 group=true
189 xpand=false
192 -xdiff) # graphical diff mode
193 xpand=false
195 if [ ! -z "$DISPLAY" ]
196 then
197 which xdiff >/dev/null 2>&1 && diff=xdiff
198 which gdiff >/dev/null 2>&1 && diff=gdiff
199 which tkdiff >/dev/null 2>&1 && diff=tkdiff
200 which xxdiff >/dev/null 2>&1 && diff=xxdiff
204 -n) # show me, don't do it
205 showme=true
206 xpand=false
208 -r) # randomize test order
209 randomize=true
210 xpand=false
213 -T) # turn on timestamp output
214 timestamp=true
215 xpand=false
219 verbose=true
220 xpand=false
222 -x) # -x group ... exclude from group file
223 xgroup=true
224 xpand=false
226 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
227 echo "No tests?"
228 status=1
229 exit $status
232 [0-9]*-[0-9]*)
233 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
236 [0-9]*-)
237 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
238 end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/ *$//' -e 's/.* //'`
239 if [ -z "$end" ]
240 then
241 echo "No tests in range \"$r\"?"
242 status=1
243 exit $status
248 start=$r
249 end=$r
252 esac
254 # get rid of leading 0s as can be interpreted as octal
255 start=`echo $start | sed 's/^0*//'`
256 end=`echo $end | sed 's/^0*//'`
258 if $xpand
259 then
260 have_test_arg=true
261 $AWK_PROG </dev/null '
262 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
263 | while read id
265 if grep -s "^$id " group >/dev/null
266 then
267 # in group file ... OK
268 echo $id >>$tmp.list
269 else
270 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
271 then
272 # expunged ... will be reported, but not run, later
273 echo $id >>$tmp.list
274 else
275 # oops
276 echo "$id - unknown test, ignored"
279 done
282 done
284 if [ -s $tmp.list ]
285 then
286 # found some valid test numbers ... this is good
288 else
289 if $have_test_arg
290 then
291 # had test numbers, but none in group file ... do nothing
292 touch $tmp.list
293 else
294 # no test numbers, do everything from group file
295 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
299 # should be sort -n, but this did not work for Linux when this
300 # was ported from IRIX
302 list=`sort $tmp.list`
303 rm -f $tmp.list $tmp.tmp $tmp.sed
305 if $randomize
306 then
307 list=`echo $list | awk -f randomize.awk`
310 [ "$QEMU" = "" ] && _fatal "qemu not found"
311 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
312 [ "$QEMU_IO" = "" ] && _fatal "qemu-img not found"