net/cadence_gem: Improve can_receive debug printfery
[qemu.git] / tests / qemu-iotests / common
blob8b4e22c856e158d1de625efeadd39df03a5089f6
1 #!/bin/bash
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 imgopts=false
39 showme=false
40 sortme=false
41 expunge=true
42 have_test_arg=false
43 randomize=false
44 valgrind=false
45 cachemode=false
46 rm -f $tmp.list $tmp.tmp $tmp.sed
48 export IMGFMT=raw
49 export IMGFMT_GENERIC=true
50 export IMGPROTO=file
51 export IMGOPTS=""
52 export CACHEMODE="writeback"
53 export QEMU_IO_OPTIONS=""
54 export CACHEMODE_IS_DEFAULT=true
56 for r
59 if $group
60 then
61 # arg after -g
62 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
63 s/ .*//p
64 }'`
65 if [ -z "$group_list" ]
66 then
67 echo "Group \"$r\" is empty or not defined?"
68 exit 1
70 [ ! -s $tmp.list ] && touch $tmp.list
71 for t in $group_list
73 if grep -s "^$t\$" $tmp.list >/dev/null
74 then
76 else
77 echo "$t" >>$tmp.list
79 done
80 group=false
81 continue
83 elif $xgroup
84 then
85 # arg after -x
86 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
87 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
88 s/ .*//p
89 }'`
90 if [ -z "$group_list" ]
91 then
92 echo "Group \"$r\" is empty or not defined?"
93 exit 1
95 numsed=0
96 rm -f $tmp.sed
97 for t in $group_list
99 if [ $numsed -gt 100 ]
100 then
101 sed -f $tmp.sed <$tmp.list >$tmp.tmp
102 mv $tmp.tmp $tmp.list
103 numsed=0
104 rm -f $tmp.sed
106 echo "/^$t\$/d" >>$tmp.sed
107 numsed=`expr $numsed + 1`
108 done
109 sed -f $tmp.sed <$tmp.list >$tmp.tmp
110 mv $tmp.tmp $tmp.list
111 xgroup=false
112 continue
114 elif $imgopts
115 then
116 IMGOPTS="$r"
117 imgopts=false
118 continue
119 elif $cachemode
120 then
121 CACHEMODE="$r"
122 CACHEMODE_IS_DEFAULT=false
123 cachemode=false
124 continue
127 xpand=true
128 case "$r"
131 -\? | -h | --help) # usage
132 echo "Usage: $0 [options] [testlist]"'
134 common options
135 -v verbose
137 check options
138 -raw test raw (default)
139 -cow test cow
140 -qcow test qcow
141 -qcow2 test qcow2
142 -qed test qed
143 -vdi test vdi
144 -vpc test vpc
145 -vhdx test vhdx
146 -vmdk test vmdk
147 -rbd test rbd
148 -sheepdog test sheepdog
149 -nbd test nbd
150 -ssh test ssh
151 -xdiff graphical mode diff
152 -nocache use O_DIRECT on backing file
153 -misalign misalign memory allocations
154 -n show me, do not run tests
155 -o options -o options to pass to qemu-img create/convert
156 -T output timestamps
157 -r randomize test order
158 -c mode cache mode
160 testlist options
161 -g group[,group...] include tests from these groups
162 -x group[,group...] exclude tests from these groups
163 NNN include test NNN
164 NNN-NNN include test range (eg. 012-021)
166 exit 0
169 -raw)
170 IMGFMT=raw
171 xpand=false
174 -cow)
175 IMGFMT=cow
176 xpand=false
179 -qcow)
180 IMGFMT=qcow
181 xpand=false
184 -qcow2)
185 IMGFMT=qcow2
186 xpand=false
189 -qed)
190 IMGFMT=qed
191 xpand=false
194 -vdi)
195 IMGFMT=vdi
196 xpand=false
199 -vmdk)
200 IMGFMT=vmdk
201 xpand=false
204 -vpc)
205 IMGFMT=vpc
206 xpand=false
209 -vhdx)
210 IMGFMT=vhdx
211 xpand=false
214 -rbd)
215 IMGPROTO=rbd
216 xpand=false
218 -sheepdog)
219 IMGPROTO=sheepdog
220 xpand=false
222 -nbd)
223 IMGPROTO=nbd
224 xpand=false
226 -ssh)
227 IMGPROTO=ssh
228 xpand=false
230 -nocache)
231 CACHEMODE="none"
232 CACHEMODE_IS_DEFAULT=false
233 xpand=false
236 -misalign)
237 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
238 xpand=false
241 -valgrind)
242 valgrind=true
243 xpand=false
246 -g) # -g group ... pick from group file
247 group=true
248 xpand=false
251 -xdiff) # graphical diff mode
252 xpand=false
254 if [ ! -z "$DISPLAY" ]
255 then
256 which xdiff >/dev/null 2>&1 && diff=xdiff
257 which gdiff >/dev/null 2>&1 && diff=gdiff
258 which tkdiff >/dev/null 2>&1 && diff=tkdiff
259 which xxdiff >/dev/null 2>&1 && diff=xxdiff
263 -n) # show me, don't do it
264 showme=true
265 xpand=false
268 imgopts=true
269 xpand=false
272 cachemode=true
273 xpand=false
275 -r) # randomize test order
276 randomize=true
277 xpand=false
280 -T) # turn on timestamp output
281 timestamp=true
282 xpand=false
286 verbose=true
287 xpand=false
289 -x) # -x group ... exclude from group file
290 xgroup=true
291 xpand=false
293 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
294 echo "No tests?"
295 status=1
296 exit $status
299 [0-9]*-[0-9]*)
300 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
303 [0-9]*-)
304 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
305 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/.* //'`
306 if [ -z "$end" ]
307 then
308 echo "No tests in range \"$r\"?"
309 status=1
310 exit $status
315 start=$r
316 end=$r
319 esac
321 # get rid of leading 0s as can be interpreted as octal
322 start=`echo $start | sed 's/^0*//'`
323 end=`echo $end | sed 's/^0*//'`
325 if $xpand
326 then
327 have_test_arg=true
328 $AWK_PROG </dev/null '
329 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
330 | while read id
332 if grep -s "^$id " group >/dev/null
333 then
334 # in group file ... OK
335 echo $id >>$tmp.list
336 else
337 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
338 then
339 # expunged ... will be reported, but not run, later
340 echo $id >>$tmp.list
341 else
342 # oops
343 echo "$id - unknown test, ignored"
346 done
349 done
351 # Set qemu-io cache mode with $CACHEMODE we have
352 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
354 # Set default options for qemu-img create -o if they were not specified
355 _set_default_imgopts
357 if [ -s $tmp.list ]
358 then
359 # found some valid test numbers ... this is good
361 else
362 if $have_test_arg
363 then
364 # had test numbers, but none in group file ... do nothing
365 touch $tmp.list
366 else
367 # no test numbers, do everything from group file
368 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
372 # should be sort -n, but this did not work for Linux when this
373 # was ported from IRIX
375 list=`sort $tmp.list`
376 rm -f $tmp.list $tmp.tmp $tmp.sed
378 if $randomize
379 then
380 list=`echo $list | awk -f randomize.awk`
383 [ "$QEMU" = "" ] && _fatal "qemu not found"
384 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
385 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
387 if [ "$IMGPROTO" = "nbd" ] ; then
388 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
391 if $valgrind; then
392 export REAL_QEMU_IO="$QEMU_IO_PROG"
393 export QEMU_IO_PROG=valgrind_qemu_io