Remove reduntant qemu: from error functions
[qemu/ar7.git] / tests / qemu-iotests / common
blobf2a7199c4b8fe0a85878101b6a61e15f0f04c089
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 cachemode=false
45 rm -f $tmp.list $tmp.tmp $tmp.sed
47 export IMGFMT=raw
48 export IMGFMT_GENERIC=true
49 export IMGPROTO=file
50 export IMGOPTS=""
51 export CACHEMODE="writeback"
52 export QEMU_IO_OPTIONS=""
53 export CACHEMODE_IS_DEFAULT=true
54 export QEMU_OPTIONS="-nodefaults -machine accel=qtest"
55 export VALGRIND_QEMU=
56 export IMGKEYSECRET=
57 export IMGOPTSSYNTAX=false
59 for r
62 if $group
63 then
64 # arg after -g
65 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
66 s/ .*//p
67 }'`
68 if [ -z "$group_list" ]
69 then
70 echo "Group \"$r\" is empty or not defined?"
71 exit 1
73 [ ! -s $tmp.list ] && touch $tmp.list
74 for t in $group_list
76 if grep -s "^$t\$" $tmp.list >/dev/null
77 then
79 else
80 echo "$t" >>$tmp.list
82 done
83 group=false
84 continue
86 elif $xgroup
87 then
88 # arg after -x
89 # Populate $tmp.list with all tests
90 awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null
91 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
92 s/ .*//p
93 }'`
94 if [ -z "$group_list" ]
95 then
96 echo "Group \"$r\" is empty or not defined?"
97 exit 1
99 numsed=0
100 rm -f $tmp.sed
101 for t in $group_list
103 if [ $numsed -gt 100 ]
104 then
105 sed -f $tmp.sed <$tmp.list >$tmp.tmp
106 mv $tmp.tmp $tmp.list
107 numsed=0
108 rm -f $tmp.sed
110 echo "/^$t\$/d" >>$tmp.sed
111 numsed=`expr $numsed + 1`
112 done
113 sed -f $tmp.sed <$tmp.list >$tmp.tmp
114 mv $tmp.tmp $tmp.list
115 xgroup=false
116 continue
118 elif $imgopts
119 then
120 IMGOPTS="$r"
121 imgopts=false
122 continue
123 elif $cachemode
124 then
125 CACHEMODE="$r"
126 CACHEMODE_IS_DEFAULT=false
127 cachemode=false
128 continue
131 xpand=true
132 case "$r"
135 -\? | -h | --help) # usage
136 echo "Usage: $0 [options] [testlist]"'
138 common options
139 -v verbose
140 -d debug
142 image format options
143 -raw test raw (default)
144 -bochs test bochs
145 -cloop test cloop
146 -parallels test parallels
147 -qcow test qcow
148 -qcow2 test qcow2
149 -qed test qed
150 -vdi test vdi
151 -vpc test vpc
152 -vhdx test vhdx
153 -vmdk test vmdk
154 -luks test luks
156 image protocol options
157 -file test file (default)
158 -rbd test rbd
159 -sheepdog test sheepdog
160 -nbd test nbd
161 -ssh test ssh
162 -nfs test nfs
163 -vxhs test vxhs
165 other options
166 -xdiff graphical mode diff
167 -nocache use O_DIRECT on backing file
168 -misalign misalign memory allocations
169 -n show me, do not run tests
170 -o options -o options to pass to qemu-img create/convert
171 -T output timestamps
172 -r randomize test order
173 -c mode cache mode
175 testlist options
176 -g group[,group...] include tests from these groups
177 -x group[,group...] exclude tests from these groups
178 NNN include test NNN
179 NNN-NNN include test range (eg. 012-021)
181 exit 0
184 -raw)
185 IMGFMT=raw
186 xpand=false
189 -bochs)
190 IMGFMT=bochs
191 IMGFMT_GENERIC=false
192 xpand=false
195 -cloop)
196 IMGFMT=cloop
197 IMGFMT_GENERIC=false
198 xpand=false
201 -parallels)
202 IMGFMT=parallels
203 IMGFMT_GENERIC=false
204 xpand=false
207 -qcow)
208 IMGFMT=qcow
209 xpand=false
212 -qcow2)
213 IMGFMT=qcow2
214 xpand=false
217 -luks)
218 IMGOPTSSYNTAX=true
219 IMGFMT=luks
220 IMGKEYSECRET=123456
221 xpand=false
224 -qed)
225 IMGFMT=qed
226 xpand=false
229 -vdi)
230 IMGFMT=vdi
231 xpand=false
234 -vmdk)
235 IMGFMT=vmdk
236 xpand=false
239 -vpc)
240 IMGFMT=vpc
241 xpand=false
244 -vhdx)
245 IMGFMT=vhdx
246 xpand=false
249 -file)
250 IMGPROTO=file
251 xpand=false
254 -rbd)
255 IMGPROTO=rbd
256 xpand=false
259 -sheepdog)
260 IMGPROTO=sheepdog
261 xpand=false
264 -nbd)
265 IMGPROTO=nbd
266 xpand=false
269 -vxhs)
270 IMGPROTO=vxhs
271 xpand=false
274 -ssh)
275 IMGPROTO=ssh
276 xpand=false
279 -nfs)
280 IMGPROTO=nfs
281 xpand=false
284 -nocache)
285 CACHEMODE="none"
286 CACHEMODE_IS_DEFAULT=false
287 xpand=false
290 -misalign)
291 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
292 xpand=false
295 -valgrind)
296 VALGRIND_QEMU='y'
297 xpand=false
300 -g) # -g group ... pick from group file
301 group=true
302 xpand=false
305 -xdiff) # graphical diff mode
306 xpand=false
308 if [ ! -z "$DISPLAY" ]
309 then
310 command -v xdiff >/dev/null 2>&1 && diff=xdiff
311 command -v gdiff >/dev/null 2>&1 && diff=gdiff
312 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
313 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
317 -n) # show me, don't do it
318 showme=true
319 xpand=false
322 imgopts=true
323 xpand=false
326 cachemode=true
327 xpand=false
329 -r) # randomize test order
330 randomize=true
331 xpand=false
334 -T) # turn on timestamp output
335 timestamp=true
336 xpand=false
340 verbose=true
341 xpand=false
344 debug=true
345 xpand=false
347 -x) # -x group ... exclude from group file
348 xgroup=true
349 xpand=false
351 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
352 echo "No tests?"
353 status=1
354 exit $status
357 [0-9]*-[0-9]*)
358 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
361 [0-9]*-)
362 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
363 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/.* //'`
364 if [ -z "$end" ]
365 then
366 echo "No tests in range \"$r\"?"
367 status=1
368 exit $status
373 start=$r
374 end=$r
377 esac
379 # get rid of leading 0s as can be interpreted as octal
380 start=`echo $start | sed 's/^0*//'`
381 end=`echo $end | sed 's/^0*//'`
383 if $xpand
384 then
385 have_test_arg=true
386 $AWK_PROG </dev/null '
387 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
388 | while read id
390 if grep -s "^$id " "$source_iotests/group" >/dev/null
391 then
392 # in group file ... OK
393 echo $id >>$tmp.list
394 else
395 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
396 then
397 # expunged ... will be reported, but not run, later
398 echo $id >>$tmp.list
399 else
400 # oops
401 if [ "$start" == "$end" -a "$id" == "$end" ]
402 then
403 echo "$id - unknown test"
404 exit 1
405 else
406 echo "$id - unknown test, ignored"
410 done || exit 1
413 done
415 # Set qemu-io cache mode with $CACHEMODE we have
416 if [ "$IMGOPTSSYNTAX" = "true" ]; then
417 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
418 else
419 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
422 # Set default options for qemu-img create -o if they were not specified
423 _set_default_imgopts
425 if [ -s $tmp.list ]
426 then
427 # found some valid test numbers ... this is good
429 else
430 if $have_test_arg
431 then
432 # had test numbers, but none in group file ... do nothing
433 touch $tmp.list
434 else
435 # no test numbers, do everything from group file
436 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
440 # should be sort -n, but this did not work for Linux when this
441 # was ported from IRIX
443 list=`sort $tmp.list`
444 rm -f $tmp.list $tmp.tmp $tmp.sed
446 if $randomize
447 then
448 list=`echo $list | awk -f randomize.awk`
451 [ "$QEMU" = "" ] && _fatal "qemu not found"
452 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
453 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
455 if [ "$IMGPROTO" = "nbd" ] ; then
456 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"