Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging
[qemu/kevin.git] / tests / qemu-iotests / common
blob4d5650d7c8157a10153a0b4d236c154235e2f235
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 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
90 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
91 s/ .*//p
92 }'`
93 if [ -z "$group_list" ]
94 then
95 echo "Group \"$r\" is empty or not defined?"
96 exit 1
98 numsed=0
99 rm -f $tmp.sed
100 for t in $group_list
102 if [ $numsed -gt 100 ]
103 then
104 sed -f $tmp.sed <$tmp.list >$tmp.tmp
105 mv $tmp.tmp $tmp.list
106 numsed=0
107 rm -f $tmp.sed
109 echo "/^$t\$/d" >>$tmp.sed
110 numsed=`expr $numsed + 1`
111 done
112 sed -f $tmp.sed <$tmp.list >$tmp.tmp
113 mv $tmp.tmp $tmp.list
114 xgroup=false
115 continue
117 elif $imgopts
118 then
119 IMGOPTS="$r"
120 imgopts=false
121 continue
122 elif $cachemode
123 then
124 CACHEMODE="$r"
125 CACHEMODE_IS_DEFAULT=false
126 cachemode=false
127 continue
130 xpand=true
131 case "$r"
134 -\? | -h | --help) # usage
135 echo "Usage: $0 [options] [testlist]"'
137 common options
138 -v verbose
139 -d debug
141 check options
142 -raw test raw (default)
143 -bochs test bochs
144 -cloop test cloop
145 -parallels test parallels
146 -qcow test qcow
147 -qcow2 test qcow2
148 -qed test qed
149 -vdi test vdi
150 -vpc test vpc
151 -vhdx test vhdx
152 -vmdk test vmdk
153 -file test file (default)
154 -rbd test rbd
155 -sheepdog test sheepdog
156 -nbd test nbd
157 -ssh test ssh
158 -nfs test nfs
159 -luks test luks
160 -xdiff graphical mode diff
161 -nocache use O_DIRECT on backing file
162 -misalign misalign memory allocations
163 -n show me, do not run tests
164 -o options -o options to pass to qemu-img create/convert
165 -T output timestamps
166 -r randomize test order
167 -c mode cache mode
169 testlist options
170 -g group[,group...] include tests from these groups
171 -x group[,group...] exclude tests from these groups
172 NNN include test NNN
173 NNN-NNN include test range (eg. 012-021)
175 exit 0
178 -raw)
179 IMGFMT=raw
180 xpand=false
183 -bochs)
184 IMGFMT=bochs
185 IMGFMT_GENERIC=false
186 xpand=false
189 -cloop)
190 IMGFMT=cloop
191 IMGFMT_GENERIC=false
192 xpand=false
195 -parallels)
196 IMGFMT=parallels
197 IMGFMT_GENERIC=false
198 xpand=false
201 -qcow)
202 IMGFMT=qcow
203 xpand=false
206 -qcow2)
207 IMGFMT=qcow2
208 xpand=false
211 -luks)
212 IMGOPTSSYNTAX=true
213 IMGFMT=luks
214 IMGKEYSECRET=123456
215 xpand=false
218 -qed)
219 IMGFMT=qed
220 xpand=false
223 -vdi)
224 IMGFMT=vdi
225 xpand=false
228 -vmdk)
229 IMGFMT=vmdk
230 xpand=false
233 -vpc)
234 IMGFMT=vpc
235 xpand=false
238 -vhdx)
239 IMGFMT=vhdx
240 xpand=false
243 -file)
244 IMGPROTO=file
245 xpand=false
248 -rbd)
249 IMGPROTO=rbd
250 xpand=false
253 -sheepdog)
254 IMGPROTO=sheepdog
255 xpand=false
258 -nbd)
259 IMGPROTO=nbd
260 xpand=false
263 -ssh)
264 IMGPROTO=ssh
265 xpand=false
268 -nfs)
269 IMGPROTO=nfs
270 xpand=false
273 -nocache)
274 CACHEMODE="none"
275 CACHEMODE_IS_DEFAULT=false
276 xpand=false
279 -misalign)
280 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
281 xpand=false
284 -valgrind)
285 VALGRIND_QEMU='y'
286 xpand=false
289 -g) # -g group ... pick from group file
290 group=true
291 xpand=false
294 -xdiff) # graphical diff mode
295 xpand=false
297 if [ ! -z "$DISPLAY" ]
298 then
299 command -v xdiff >/dev/null 2>&1 && diff=xdiff
300 command -v gdiff >/dev/null 2>&1 && diff=gdiff
301 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
302 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
306 -n) # show me, don't do it
307 showme=true
308 xpand=false
311 imgopts=true
312 xpand=false
315 cachemode=true
316 xpand=false
318 -r) # randomize test order
319 randomize=true
320 xpand=false
323 -T) # turn on timestamp output
324 timestamp=true
325 xpand=false
329 verbose=true
330 xpand=false
333 debug=true
334 xpand=false
336 -x) # -x group ... exclude from group file
337 xgroup=true
338 xpand=false
340 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
341 echo "No tests?"
342 status=1
343 exit $status
346 [0-9]*-[0-9]*)
347 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
350 [0-9]*-)
351 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
352 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/.* //'`
353 if [ -z "$end" ]
354 then
355 echo "No tests in range \"$r\"?"
356 status=1
357 exit $status
362 start=$r
363 end=$r
366 esac
368 # get rid of leading 0s as can be interpreted as octal
369 start=`echo $start | sed 's/^0*//'`
370 end=`echo $end | sed 's/^0*//'`
372 if $xpand
373 then
374 have_test_arg=true
375 $AWK_PROG </dev/null '
376 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
377 | while read id
379 if grep -s "^$id " "$source_iotests/group" >/dev/null
380 then
381 # in group file ... OK
382 echo $id >>$tmp.list
383 else
384 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
385 then
386 # expunged ... will be reported, but not run, later
387 echo $id >>$tmp.list
388 else
389 # oops
390 if [ "$start" == "$end" -a "$id" == "$end" ]
391 then
392 echo "$id - unknown test"
393 exit 1
394 else
395 echo "$id - unknown test, ignored"
399 done || exit 1
402 done
404 # Set qemu-io cache mode with $CACHEMODE we have
405 if [ "$IMGOPTSSYNTAX" = "true" ]; then
406 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
407 else
408 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
411 # Set default options for qemu-img create -o if they were not specified
412 _set_default_imgopts
414 if [ -s $tmp.list ]
415 then
416 # found some valid test numbers ... this is good
418 else
419 if $have_test_arg
420 then
421 # had test numbers, but none in group file ... do nothing
422 touch $tmp.list
423 else
424 # no test numbers, do everything from group file
425 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
429 # should be sort -n, but this did not work for Linux when this
430 # was ported from IRIX
432 list=`sort $tmp.list`
433 rm -f $tmp.list $tmp.tmp $tmp.sed
435 if $randomize
436 then
437 list=`echo $list | awk -f randomize.awk`
440 [ "$QEMU" = "" ] && _fatal "qemu not found"
441 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
442 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
444 if [ "$IMGPROTO" = "nbd" ] ; then
445 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"