test qemu-img rebase
[qemu-iotests/stefanha.git] / common
blobc2467664108058da27e2af0f66b741526c673531
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, see <http://www.gnu.org/licenses/>.
19 # common procedures for QA scripts
22 _setenvironment()
24 MSGVERB="text:action"
25 export MSGVERB
28 here=`pwd`
29 rm -f $here/$iam.out
30 _setenvironment
32 check=${check-true}
34 diff="diff -u"
35 verbose=false
36 group=false
37 xgroup=false
38 showme=false
39 sortme=false
40 expunge=true
41 have_test_arg=false
42 randomize=false
43 rm -f $tmp.list $tmp.tmp $tmp.sed
45 export IMGFMT=raw
46 export QEMU_IO_OPTIONS=""
48 for r
51 if $group
52 then
53 # arg after -g
54 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
55 s/ .*//p
56 }'`
57 if [ -z "$group_list" ]
58 then
59 echo "Group \"$r\" is empty or not defined?"
60 exit 1
62 [ ! -s $tmp.list ] && touch $tmp.list
63 for t in $group_list
65 if grep -s "^$t\$" $tmp.list >/dev/null
66 then
68 else
69 echo "$t" >>$tmp.list
71 done
72 group=false
73 continue
75 elif $xgroup
76 then
77 # arg after -x
78 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
79 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
80 s/ .*//p
81 }'`
82 if [ -z "$group_list" ]
83 then
84 echo "Group \"$r\" is empty or not defined?"
85 exit 1
87 numsed=0
88 rm -f $tmp.sed
89 for t in $group_list
91 if [ $numsed -gt 100 ]
92 then
93 sed -f $tmp.sed <$tmp.list >$tmp.tmp
94 mv $tmp.tmp $tmp.list
95 numsed=0
96 rm -f $tmp.sed
98 echo "/^$t\$/d" >>$tmp.sed
99 numsed=`expr $numsed + 1`
100 done
101 sed -f $tmp.sed <$tmp.list >$tmp.tmp
102 mv $tmp.tmp $tmp.list
103 xgroup=false
104 continue
107 xpand=true
108 case "$r"
111 -\? | -h | --help) # usage
112 echo "Usage: $0 [options] [testlist]"'
114 common options
115 -v verbose
117 check options
118 -raw test raw (default)
119 -cow test cow
120 -qcow test qcow
121 -qcow2 test qcow2
122 -vdi test vdi
123 -vpc test vpc
124 -vmdk test vmdk
125 -xdiff graphical mode diff
126 -nocache use O_DIRECT on backing file
127 -misalign misalign memory allocations
128 -n show me, do not run tests
129 -T output timestamps
130 -r randomize test order
132 testlist options
133 -g group[,group...] include tests from these groups
134 -x group[,group...] exclude tests from these groups
135 NNN include test NNN
136 NNN-NNN include test range (eg. 012-021)
138 exit 0
141 -raw)
142 IMGFMT=raw
143 xpand=false
146 -cow)
147 IMGFMT=cow
148 xpand=false
151 -qcow)
152 IMGFMT=qcow
153 xpand=false
156 -qcow2)
157 IMGFMT=qcow2
158 xpand=false
161 -vdi)
162 IMGFMT=vdi
163 xpand=false
166 -vmdk)
167 IMGFMT=vmdk
168 xpand=false
171 -vpc)
172 IMGFMT=vpc
173 xpand=false
176 -nocache)
177 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
178 xpand=false
181 -misalign)
182 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
183 xpand=false
186 -g) # -g group ... pick from group file
187 group=true
188 xpand=false
191 -xdiff) # graphical diff mode
192 xpand=false
194 if [ ! -z "$DISPLAY" ]
195 then
196 which xdiff >/dev/null 2>&1 && diff=xdiff
197 which gdiff >/dev/null 2>&1 && diff=gdiff
198 which tkdiff >/dev/null 2>&1 && diff=tkdiff
199 which xxdiff >/dev/null 2>&1 && diff=xxdiff
203 -n) # show me, don't do it
204 showme=true
205 xpand=false
207 -r) # randomize test order
208 randomize=true
209 xpand=false
212 -T) # turn on timestamp output
213 timestamp=true
214 xpand=false
218 verbose=true
219 xpand=false
221 -x) # -x group ... exclude from group file
222 xgroup=true
223 xpand=false
225 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
226 echo "No tests?"
227 status=1
228 exit $status
231 [0-9]*-[0-9]*)
232 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
235 [0-9]*-)
236 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
237 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/.* //'`
238 if [ -z "$end" ]
239 then
240 echo "No tests in range \"$r\"?"
241 status=1
242 exit $status
247 start=$r
248 end=$r
251 esac
253 # get rid of leading 0s as can be interpreted as octal
254 start=`echo $start | sed 's/^0*//'`
255 end=`echo $end | sed 's/^0*//'`
257 if $xpand
258 then
259 have_test_arg=true
260 $AWK_PROG </dev/null '
261 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
262 | while read id
264 if grep -s "^$id " group >/dev/null
265 then
266 # in group file ... OK
267 echo $id >>$tmp.list
268 else
269 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
270 then
271 # expunged ... will be reported, but not run, later
272 echo $id >>$tmp.list
273 else
274 # oops
275 echo "$id - unknown test, ignored"
278 done
281 done
283 if [ -s $tmp.list ]
284 then
285 # found some valid test numbers ... this is good
287 else
288 if $have_test_arg
289 then
290 # had test numbers, but none in group file ... do nothing
291 touch $tmp.list
292 else
293 # no test numbers, do everything from group file
294 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
298 # should be sort -n, but this did not work for Linux when this
299 # was ported from IRIX
301 list=`sort $tmp.list`
302 rm -f $tmp.list $tmp.tmp $tmp.sed
304 if $randomize
305 then
306 list=`echo $list | awk -f randomize.awk`
309 [ "$QEMU" = "" ] && _fatal "qemu not found"
310 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
311 [ "$QEMU_IO" = "" ] && _fatal "qemu-img not found"