target-i386: do not pass MSR_TSC_AUX to KVM ioctls if CPUID bit is not set
[qemu/ar7.git] / tests / qemu-iotests / common
blob49e19311292f0ea13cff6404fbd0d144b3b64516
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"
55 export VALGRIND_QEMU=
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 -luks test luks
159 -xdiff graphical mode diff
160 -nocache use O_DIRECT on backing file
161 -misalign misalign memory allocations
162 -n show me, do not run tests
163 -o options -o options to pass to qemu-img create/convert
164 -T output timestamps
165 -r randomize test order
166 -c mode cache mode
168 testlist options
169 -g group[,group...] include tests from these groups
170 -x group[,group...] exclude tests from these groups
171 NNN include test NNN
172 NNN-NNN include test range (eg. 012-021)
174 exit 0
177 -raw)
178 IMGFMT=raw
179 xpand=false
182 -bochs)
183 IMGFMT=bochs
184 IMGFMT_GENERIC=false
185 xpand=false
188 -cloop)
189 IMGFMT=cloop
190 IMGFMT_GENERIC=false
191 xpand=false
194 -parallels)
195 IMGFMT=parallels
196 IMGFMT_GENERIC=false
197 xpand=false
200 -qcow)
201 IMGFMT=qcow
202 xpand=false
205 -qcow2)
206 IMGFMT=qcow2
207 xpand=false
210 -qed)
211 IMGFMT=qed
212 xpand=false
215 -vdi)
216 IMGFMT=vdi
217 xpand=false
220 -vmdk)
221 IMGFMT=vmdk
222 xpand=false
225 -vpc)
226 IMGFMT=vpc
227 xpand=false
230 -vhdx)
231 IMGFMT=vhdx
232 xpand=false
235 -file)
236 IMGPROTO=file
237 xpand=false
240 -rbd)
241 IMGPROTO=rbd
242 xpand=false
245 -sheepdog)
246 IMGPROTO=sheepdog
247 xpand=false
250 -nbd)
251 IMGPROTO=nbd
252 xpand=false
255 -ssh)
256 IMGPROTO=ssh
257 xpand=false
260 -nfs)
261 IMGPROTO=nfs
262 xpand=false
265 -archipelago)
266 IMGPROTO=archipelago
267 xpand=false
270 -nocache)
271 CACHEMODE="none"
272 CACHEMODE_IS_DEFAULT=false
273 xpand=false
276 -misalign)
277 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
278 xpand=false
281 -valgrind)
282 VALGRIND_QEMU='y'
283 xpand=false
286 -g) # -g group ... pick from group file
287 group=true
288 xpand=false
291 -xdiff) # graphical diff mode
292 xpand=false
294 if [ ! -z "$DISPLAY" ]
295 then
296 command -v xdiff >/dev/null 2>&1 && diff=xdiff
297 command -v gdiff >/dev/null 2>&1 && diff=gdiff
298 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
299 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
303 -n) # show me, don't do it
304 showme=true
305 xpand=false
308 imgopts=true
309 xpand=false
312 cachemode=true
313 xpand=false
315 -r) # randomize test order
316 randomize=true
317 xpand=false
320 -T) # turn on timestamp output
321 timestamp=true
322 xpand=false
326 verbose=true
327 xpand=false
330 debug=true
331 xpand=false
333 -x) # -x group ... exclude from group file
334 xgroup=true
335 xpand=false
337 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
338 echo "No tests?"
339 status=1
340 exit $status
343 [0-9]*-[0-9]*)
344 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
347 [0-9]*-)
348 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
349 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/.* //'`
350 if [ -z "$end" ]
351 then
352 echo "No tests in range \"$r\"?"
353 status=1
354 exit $status
359 start=$r
360 end=$r
363 esac
365 # get rid of leading 0s as can be interpreted as octal
366 start=`echo $start | sed 's/^0*//'`
367 end=`echo $end | sed 's/^0*//'`
369 if $xpand
370 then
371 have_test_arg=true
372 $AWK_PROG </dev/null '
373 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
374 | while read id
376 if grep -s "^$id " "$source_iotests/group" >/dev/null
377 then
378 # in group file ... OK
379 echo $id >>$tmp.list
380 else
381 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
382 then
383 # expunged ... will be reported, but not run, later
384 echo $id >>$tmp.list
385 else
386 # oops
387 if [ "$start" == "$end" -a "$id" == "$end" ]
388 then
389 echo "$id - unknown test"
390 exit 1
391 else
392 echo "$id - unknown test, ignored"
396 done || exit 1
399 done
401 # Set qemu-io cache mode with $CACHEMODE we have
402 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
404 # Set default options for qemu-img create -o if they were not specified
405 _set_default_imgopts
407 if [ -s $tmp.list ]
408 then
409 # found some valid test numbers ... this is good
411 else
412 if $have_test_arg
413 then
414 # had test numbers, but none in group file ... do nothing
415 touch $tmp.list
416 else
417 # no test numbers, do everything from group file
418 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
422 # should be sort -n, but this did not work for Linux when this
423 # was ported from IRIX
425 list=`sort $tmp.list`
426 rm -f $tmp.list $tmp.tmp $tmp.sed
428 if $randomize
429 then
430 list=`echo $list | awk -f randomize.awk`
433 [ "$QEMU" = "" ] && _fatal "qemu not found"
434 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
435 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
437 if [ "$IMGPROTO" = "nbd" ] ; then
438 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"