Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20150715-1' into...
[qemu/ar7.git] / tests / qemu-iotests / common
blob1030aaf25b2ff2c02aa0662ac91601bb92fdfa75
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
56 for r
59 if $group
60 then
61 # arg after -g
62 group_list=`sed -n <"$source_iotests/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 <"$source_iotests/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
136 -d debug
138 check options
139 -raw test raw (default)
140 -bochs test bochs
141 -cloop test cloop
142 -parallels test parallels
143 -qcow test qcow
144 -qcow2 test qcow2
145 -qed test qed
146 -vdi test vdi
147 -vpc test vpc
148 -vhdx test vhdx
149 -vmdk test vmdk
150 -file test file (default)
151 -rbd test rbd
152 -sheepdog test sheepdog
153 -nbd test nbd
154 -ssh test ssh
155 -nfs test nfs
156 -archipelago test archipelago
157 -xdiff graphical mode diff
158 -nocache use O_DIRECT on backing file
159 -misalign misalign memory allocations
160 -n show me, do not run tests
161 -o options -o options to pass to qemu-img create/convert
162 -T output timestamps
163 -r randomize test order
164 -c mode cache mode
166 testlist options
167 -g group[,group...] include tests from these groups
168 -x group[,group...] exclude tests from these groups
169 NNN include test NNN
170 NNN-NNN include test range (eg. 012-021)
172 exit 0
175 -raw)
176 IMGFMT=raw
177 xpand=false
180 -bochs)
181 IMGFMT=bochs
182 IMGFMT_GENERIC=false
183 xpand=false
186 -cloop)
187 IMGFMT=cloop
188 IMGFMT_GENERIC=false
189 xpand=false
192 -parallels)
193 IMGFMT=parallels
194 IMGFMT_GENERIC=false
195 xpand=false
198 -qcow)
199 IMGFMT=qcow
200 xpand=false
203 -qcow2)
204 IMGFMT=qcow2
205 xpand=false
208 -qed)
209 IMGFMT=qed
210 xpand=false
213 -vdi)
214 IMGFMT=vdi
215 xpand=false
218 -vmdk)
219 IMGFMT=vmdk
220 xpand=false
223 -vpc)
224 IMGFMT=vpc
225 xpand=false
228 -vhdx)
229 IMGFMT=vhdx
230 xpand=false
233 -file)
234 IMGPROTO=file
235 xpand=false
238 -rbd)
239 IMGPROTO=rbd
240 xpand=false
243 -sheepdog)
244 IMGPROTO=sheepdog
245 xpand=false
248 -nbd)
249 IMGPROTO=nbd
250 xpand=false
253 -ssh)
254 IMGPROTO=ssh
255 xpand=false
258 -nfs)
259 IMGPROTO=nfs
260 xpand=false
263 -archipelago)
264 IMGPROTO=archipelago
265 xpand=false
268 -nocache)
269 CACHEMODE="none"
270 CACHEMODE_IS_DEFAULT=false
271 xpand=false
274 -misalign)
275 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
276 xpand=false
279 -valgrind)
280 valgrind=true
281 xpand=false
284 -g) # -g group ... pick from group file
285 group=true
286 xpand=false
289 -xdiff) # graphical diff mode
290 xpand=false
292 if [ ! -z "$DISPLAY" ]
293 then
294 command -v xdiff >/dev/null 2>&1 && diff=xdiff
295 command -v gdiff >/dev/null 2>&1 && diff=gdiff
296 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
297 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
301 -n) # show me, don't do it
302 showme=true
303 xpand=false
306 imgopts=true
307 xpand=false
310 cachemode=true
311 xpand=false
313 -r) # randomize test order
314 randomize=true
315 xpand=false
318 -T) # turn on timestamp output
319 timestamp=true
320 xpand=false
324 verbose=true
325 xpand=false
328 debug=true
329 xpand=false
331 -x) # -x group ... exclude from group file
332 xgroup=true
333 xpand=false
335 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
336 echo "No tests?"
337 status=1
338 exit $status
341 [0-9]*-[0-9]*)
342 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
345 [0-9]*-)
346 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
347 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/.* //'`
348 if [ -z "$end" ]
349 then
350 echo "No tests in range \"$r\"?"
351 status=1
352 exit $status
357 start=$r
358 end=$r
361 esac
363 # get rid of leading 0s as can be interpreted as octal
364 start=`echo $start | sed 's/^0*//'`
365 end=`echo $end | sed 's/^0*//'`
367 if $xpand
368 then
369 have_test_arg=true
370 $AWK_PROG </dev/null '
371 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
372 | while read id
374 if grep -s "^$id " "$source_iotests/group" >/dev/null
375 then
376 # in group file ... OK
377 echo $id >>$tmp.list
378 else
379 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
380 then
381 # expunged ... will be reported, but not run, later
382 echo $id >>$tmp.list
383 else
384 # oops
385 if [ "$start" == "$end" -a "$id" == "$end" ]
386 then
387 echo "$id - unknown test"
388 exit 1
389 else
390 echo "$id - unknown test, ignored"
394 done || exit 1
397 done
399 # Set qemu-io cache mode with $CACHEMODE we have
400 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
402 # Set default options for qemu-img create -o if they were not specified
403 _set_default_imgopts
405 if [ -s $tmp.list ]
406 then
407 # found some valid test numbers ... this is good
409 else
410 if $have_test_arg
411 then
412 # had test numbers, but none in group file ... do nothing
413 touch $tmp.list
414 else
415 # no test numbers, do everything from group file
416 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
420 # should be sort -n, but this did not work for Linux when this
421 # was ported from IRIX
423 list=`sort $tmp.list`
424 rm -f $tmp.list $tmp.tmp $tmp.sed
426 if $randomize
427 then
428 list=`echo $list | awk -f randomize.awk`
431 [ "$QEMU" = "" ] && _fatal "qemu not found"
432 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
433 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
435 if [ "$IMGPROTO" = "nbd" ] ; then
436 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
439 if $valgrind; then
440 export REAL_QEMU_IO="$QEMU_IO_PROG"
441 export QEMU_IO_PROG=valgrind_qemu_io