qemu-gdb: add $qemu_coroutine_sp and $qemu_coroutine_pc
[qemu/ar7.git] / tests / qemu-iotests / common
blob25c351bbd1fb4c417da11f811bbd49a58c22215e
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 rm -f "$OUTPUT_DIR/$iam.out"
29 _setenvironment
31 check=${check-true}
33 diff="diff -u"
34 verbose=false
35 debug=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
55 export QEMU_OPTIONS="-nodefaults"
57 for r
60 if $group
61 then
62 # arg after -g
63 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
64 s/ .*//p
65 }'`
66 if [ -z "$group_list" ]
67 then
68 echo "Group \"$r\" is empty or not defined?"
69 exit 1
71 [ ! -s $tmp.list ] && touch $tmp.list
72 for t in $group_list
74 if grep -s "^$t\$" $tmp.list >/dev/null
75 then
77 else
78 echo "$t" >>$tmp.list
80 done
81 group=false
82 continue
84 elif $xgroup
85 then
86 # arg after -x
87 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
88 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
89 s/ .*//p
90 }'`
91 if [ -z "$group_list" ]
92 then
93 echo "Group \"$r\" is empty or not defined?"
94 exit 1
96 numsed=0
97 rm -f $tmp.sed
98 for t in $group_list
100 if [ $numsed -gt 100 ]
101 then
102 sed -f $tmp.sed <$tmp.list >$tmp.tmp
103 mv $tmp.tmp $tmp.list
104 numsed=0
105 rm -f $tmp.sed
107 echo "/^$t\$/d" >>$tmp.sed
108 numsed=`expr $numsed + 1`
109 done
110 sed -f $tmp.sed <$tmp.list >$tmp.tmp
111 mv $tmp.tmp $tmp.list
112 xgroup=false
113 continue
115 elif $imgopts
116 then
117 IMGOPTS="$r"
118 imgopts=false
119 continue
120 elif $cachemode
121 then
122 CACHEMODE="$r"
123 CACHEMODE_IS_DEFAULT=false
124 cachemode=false
125 continue
128 xpand=true
129 case "$r"
132 -\? | -h | --help) # usage
133 echo "Usage: $0 [options] [testlist]"'
135 common options
136 -v verbose
137 -d debug
139 check options
140 -raw test raw (default)
141 -bochs test bochs
142 -cloop test cloop
143 -parallels test parallels
144 -qcow test qcow
145 -qcow2 test qcow2
146 -qed test qed
147 -vdi test vdi
148 -vpc test vpc
149 -vhdx test vhdx
150 -vmdk test vmdk
151 -file test file (default)
152 -rbd test rbd
153 -sheepdog test sheepdog
154 -nbd test nbd
155 -ssh test ssh
156 -nfs test nfs
157 -archipelago test archipelago
158 -xdiff graphical mode diff
159 -nocache use O_DIRECT on backing file
160 -misalign misalign memory allocations
161 -n show me, do not run tests
162 -o options -o options to pass to qemu-img create/convert
163 -T output timestamps
164 -r randomize test order
165 -c mode cache mode
167 testlist options
168 -g group[,group...] include tests from these groups
169 -x group[,group...] exclude tests from these groups
170 NNN include test NNN
171 NNN-NNN include test range (eg. 012-021)
173 exit 0
176 -raw)
177 IMGFMT=raw
178 xpand=false
181 -bochs)
182 IMGFMT=bochs
183 IMGFMT_GENERIC=false
184 xpand=false
187 -cloop)
188 IMGFMT=cloop
189 IMGFMT_GENERIC=false
190 xpand=false
193 -parallels)
194 IMGFMT=parallels
195 IMGFMT_GENERIC=false
196 xpand=false
199 -qcow)
200 IMGFMT=qcow
201 xpand=false
204 -qcow2)
205 IMGFMT=qcow2
206 xpand=false
209 -qed)
210 IMGFMT=qed
211 xpand=false
214 -vdi)
215 IMGFMT=vdi
216 xpand=false
219 -vmdk)
220 IMGFMT=vmdk
221 xpand=false
224 -vpc)
225 IMGFMT=vpc
226 xpand=false
229 -vhdx)
230 IMGFMT=vhdx
231 xpand=false
234 -file)
235 IMGPROTO=file
236 xpand=false
239 -rbd)
240 IMGPROTO=rbd
241 xpand=false
244 -sheepdog)
245 IMGPROTO=sheepdog
246 xpand=false
249 -nbd)
250 IMGPROTO=nbd
251 xpand=false
254 -ssh)
255 IMGPROTO=ssh
256 xpand=false
259 -nfs)
260 IMGPROTO=nfs
261 xpand=false
264 -archipelago)
265 IMGPROTO=archipelago
266 xpand=false
269 -nocache)
270 CACHEMODE="none"
271 CACHEMODE_IS_DEFAULT=false
272 xpand=false
275 -misalign)
276 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
277 xpand=false
280 -valgrind)
281 valgrind=true
282 xpand=false
285 -g) # -g group ... pick from group file
286 group=true
287 xpand=false
290 -xdiff) # graphical diff mode
291 xpand=false
293 if [ ! -z "$DISPLAY" ]
294 then
295 command -v xdiff >/dev/null 2>&1 && diff=xdiff
296 command -v gdiff >/dev/null 2>&1 && diff=gdiff
297 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
298 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
302 -n) # show me, don't do it
303 showme=true
304 xpand=false
307 imgopts=true
308 xpand=false
311 cachemode=true
312 xpand=false
314 -r) # randomize test order
315 randomize=true
316 xpand=false
319 -T) # turn on timestamp output
320 timestamp=true
321 xpand=false
325 verbose=true
326 xpand=false
329 debug=true
330 xpand=false
332 -x) # -x group ... exclude from group file
333 xgroup=true
334 xpand=false
336 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
337 echo "No tests?"
338 status=1
339 exit $status
342 [0-9]*-[0-9]*)
343 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
346 [0-9]*-)
347 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
348 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/.* //'`
349 if [ -z "$end" ]
350 then
351 echo "No tests in range \"$r\"?"
352 status=1
353 exit $status
358 start=$r
359 end=$r
362 esac
364 # get rid of leading 0s as can be interpreted as octal
365 start=`echo $start | sed 's/^0*//'`
366 end=`echo $end | sed 's/^0*//'`
368 if $xpand
369 then
370 have_test_arg=true
371 $AWK_PROG </dev/null '
372 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
373 | while read id
375 if grep -s "^$id " "$source_iotests/group" >/dev/null
376 then
377 # in group file ... OK
378 echo $id >>$tmp.list
379 else
380 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
381 then
382 # expunged ... will be reported, but not run, later
383 echo $id >>$tmp.list
384 else
385 # oops
386 if [ "$start" == "$end" -a "$id" == "$end" ]
387 then
388 echo "$id - unknown test"
389 exit 1
390 else
391 echo "$id - unknown test, ignored"
395 done || exit 1
398 done
400 # Set qemu-io cache mode with $CACHEMODE we have
401 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
403 # Set default options for qemu-img create -o if they were not specified
404 _set_default_imgopts
406 if [ -s $tmp.list ]
407 then
408 # found some valid test numbers ... this is good
410 else
411 if $have_test_arg
412 then
413 # had test numbers, but none in group file ... do nothing
414 touch $tmp.list
415 else
416 # no test numbers, do everything from group file
417 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
421 # should be sort -n, but this did not work for Linux when this
422 # was ported from IRIX
424 list=`sort $tmp.list`
425 rm -f $tmp.list $tmp.tmp $tmp.sed
427 if $randomize
428 then
429 list=`echo $list | awk -f randomize.awk`
432 [ "$QEMU" = "" ] && _fatal "qemu not found"
433 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
434 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
436 if [ "$IMGPROTO" = "nbd" ] ; then
437 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
440 if $valgrind; then
441 export REAL_QEMU_IO="$QEMU_IO_PROG"
442 export QEMU_IO_PROG=valgrind_qemu_io