tests: Fix gcov paths for relocated device sources
[qemu/qmp-unstable.git] / tests / qemu-iotests / common
blob5795358924872ef54f29ad3b941930e9b8cb0818
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 here=`pwd`
29 rm -f $here/$iam.out
30 _setenvironment
32 check=${check-true}
34 diff="diff -u"
35 verbose=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 <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 <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
137 check options
138 -raw test raw (default)
139 -cow test cow
140 -qcow test qcow
141 -qcow2 test qcow2
142 -qed test qed
143 -vdi test vdi
144 -vpc test vpc
145 -vhdx test vhdx
146 -vmdk test vmdk
147 -file test file (default)
148 -rbd test rbd
149 -sheepdog test sheepdog
150 -nbd test nbd
151 -ssh test ssh
152 -nfs test nfs
153 -xdiff graphical mode diff
154 -nocache use O_DIRECT on backing file
155 -misalign misalign memory allocations
156 -n show me, do not run tests
157 -o options -o options to pass to qemu-img create/convert
158 -T output timestamps
159 -r randomize test order
160 -c mode cache mode
162 testlist options
163 -g group[,group...] include tests from these groups
164 -x group[,group...] exclude tests from these groups
165 NNN include test NNN
166 NNN-NNN include test range (eg. 012-021)
168 exit 0
171 -raw)
172 IMGFMT=raw
173 xpand=false
176 -cow)
177 IMGFMT=cow
178 xpand=false
181 -qcow)
182 IMGFMT=qcow
183 xpand=false
186 -qcow2)
187 IMGFMT=qcow2
188 xpand=false
191 -qed)
192 IMGFMT=qed
193 xpand=false
196 -vdi)
197 IMGFMT=vdi
198 xpand=false
201 -vmdk)
202 IMGFMT=vmdk
203 xpand=false
206 -vpc)
207 IMGFMT=vpc
208 xpand=false
211 -vhdx)
212 IMGFMT=vhdx
213 xpand=false
216 -file)
217 IMGPROTO=file
218 xpand=false
221 -rbd)
222 IMGPROTO=rbd
223 xpand=false
226 -sheepdog)
227 IMGPROTO=sheepdog
228 xpand=false
231 -nbd)
232 IMGPROTO=nbd
233 xpand=false
236 -ssh)
237 IMGPROTO=ssh
238 xpand=false
241 -nfs)
242 IMGPROTO=nfs
243 xpand=false
246 -nocache)
247 CACHEMODE="none"
248 CACHEMODE_IS_DEFAULT=false
249 xpand=false
252 -misalign)
253 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
254 xpand=false
257 -valgrind)
258 valgrind=true
259 xpand=false
262 -g) # -g group ... pick from group file
263 group=true
264 xpand=false
267 -xdiff) # graphical diff mode
268 xpand=false
270 if [ ! -z "$DISPLAY" ]
271 then
272 which xdiff >/dev/null 2>&1 && diff=xdiff
273 which gdiff >/dev/null 2>&1 && diff=gdiff
274 which tkdiff >/dev/null 2>&1 && diff=tkdiff
275 which xxdiff >/dev/null 2>&1 && diff=xxdiff
279 -n) # show me, don't do it
280 showme=true
281 xpand=false
284 imgopts=true
285 xpand=false
288 cachemode=true
289 xpand=false
291 -r) # randomize test order
292 randomize=true
293 xpand=false
296 -T) # turn on timestamp output
297 timestamp=true
298 xpand=false
302 verbose=true
303 xpand=false
305 -x) # -x group ... exclude from group file
306 xgroup=true
307 xpand=false
309 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
310 echo "No tests?"
311 status=1
312 exit $status
315 [0-9]*-[0-9]*)
316 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
319 [0-9]*-)
320 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
321 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/.* //'`
322 if [ -z "$end" ]
323 then
324 echo "No tests in range \"$r\"?"
325 status=1
326 exit $status
331 start=$r
332 end=$r
335 esac
337 # get rid of leading 0s as can be interpreted as octal
338 start=`echo $start | sed 's/^0*//'`
339 end=`echo $end | sed 's/^0*//'`
341 if $xpand
342 then
343 have_test_arg=true
344 $AWK_PROG </dev/null '
345 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
346 | while read id
348 if grep -s "^$id " group >/dev/null
349 then
350 # in group file ... OK
351 echo $id >>$tmp.list
352 else
353 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
354 then
355 # expunged ... will be reported, but not run, later
356 echo $id >>$tmp.list
357 else
358 # oops
359 echo "$id - unknown test, ignored"
362 done
365 done
367 # Set qemu-io cache mode with $CACHEMODE we have
368 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
370 # Set default options for qemu-img create -o if they were not specified
371 _set_default_imgopts
373 if [ -s $tmp.list ]
374 then
375 # found some valid test numbers ... this is good
377 else
378 if $have_test_arg
379 then
380 # had test numbers, but none in group file ... do nothing
381 touch $tmp.list
382 else
383 # no test numbers, do everything from group file
384 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
388 # should be sort -n, but this did not work for Linux when this
389 # was ported from IRIX
391 list=`sort $tmp.list`
392 rm -f $tmp.list $tmp.tmp $tmp.sed
394 if $randomize
395 then
396 list=`echo $list | awk -f randomize.awk`
399 [ "$QEMU" = "" ] && _fatal "qemu not found"
400 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
401 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
403 if [ "$IMGPROTO" = "nbd" ] ; then
404 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
407 if $valgrind; then
408 export REAL_QEMU_IO="$QEMU_IO_PROG"
409 export QEMU_IO_PROG=valgrind_qemu_io