]> git.proxmox.com Git - qemu.git/blame - tests/qemu-iotests/common
Merge branch 'x86cpu_qom_tcg_v2' of git://github.com/imammedo/qemu
[qemu.git] / tests / qemu-iotests / common
CommitLineData
908eaf68 1#!/bin/bash
6bf19c94
CH
2#
3# Copyright (C) 2009 Red Hat, Inc.
4# Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
5#
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.
9#
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.
14#
15# You should have received a copy of the GNU General Public License
e8c212d6 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
6bf19c94
CH
17#
18#
19# common procedures for QA scripts
20#
21
22_setenvironment()
23{
24 MSGVERB="text:action"
25 export MSGVERB
26}
27
28here=`pwd`
29rm -f $here/$iam.out
30_setenvironment
31
32check=${check-true}
33
34diff="diff -u"
35verbose=false
36group=false
37xgroup=false
89004368 38imgopts=false
6bf19c94
CH
39showme=false
40sortme=false
41expunge=true
42have_test_arg=false
43randomize=false
2f24e8fb 44valgrind=false
6bf19c94
CH
45rm -f $tmp.list $tmp.tmp $tmp.sed
46
47export IMGFMT=raw
9cdfa1b3 48export IMGPROTO=file
89004368 49export IMGOPTS=""
6bf19c94
CH
50export QEMU_IO_OPTIONS=""
51
52for r
53do
54
55 if $group
56 then
57 # arg after -g
58 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
59s/ .*//p
60}'`
61 if [ -z "$group_list" ]
62 then
63 echo "Group \"$r\" is empty or not defined?"
64 exit 1
65 fi
66 [ ! -s $tmp.list ] && touch $tmp.list
67 for t in $group_list
68 do
69 if grep -s "^$t\$" $tmp.list >/dev/null
70 then
71 :
72 else
73 echo "$t" >>$tmp.list
74 fi
75 done
76 group=false
77 continue
78
79 elif $xgroup
80 then
81 # arg after -x
82 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
83 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
84s/ .*//p
85}'`
86 if [ -z "$group_list" ]
87 then
88 echo "Group \"$r\" is empty or not defined?"
89 exit 1
90 fi
91 numsed=0
92 rm -f $tmp.sed
93 for t in $group_list
94 do
95 if [ $numsed -gt 100 ]
96 then
97 sed -f $tmp.sed <$tmp.list >$tmp.tmp
98 mv $tmp.tmp $tmp.list
99 numsed=0
100 rm -f $tmp.sed
101 fi
102 echo "/^$t\$/d" >>$tmp.sed
103 numsed=`expr $numsed + 1`
104 done
105 sed -f $tmp.sed <$tmp.list >$tmp.tmp
106 mv $tmp.tmp $tmp.list
107 xgroup=false
108 continue
89004368
KW
109
110 elif $imgopts
111 then
112 IMGOPTS="$r"
113 imgopts=false
114 continue
115
6bf19c94
CH
116 fi
117
118 xpand=true
119 case "$r"
120 in
121
122 -\? | -h | --help) # usage
123 echo "Usage: $0 [options] [testlist]"'
124
125common options
126 -v verbose
127
128check options
129 -raw test raw (default)
130 -cow test cow
131 -qcow test qcow
132 -qcow2 test qcow2
f5a4bbd9 133 -qed test qed
b67f3068 134 -vdi test vdi
6bf19c94
CH
135 -vpc test vpc
136 -vmdk test vmdk
9cdfa1b3
MK
137 -rbd test rbd
138 -sheepdog test sheepdog
6bf19c94
CH
139 -xdiff graphical mode diff
140 -nocache use O_DIRECT on backing file
141 -misalign misalign memory allocations
142 -n show me, do not run tests
89004368 143 -o options -o options to pass to qemu-img create/convert
6bf19c94
CH
144 -T output timestamps
145 -r randomize test order
146
147testlist options
148 -g group[,group...] include tests from these groups
149 -x group[,group...] exclude tests from these groups
150 NNN include test NNN
151 NNN-NNN include test range (eg. 012-021)
152'
153 exit 0
154 ;;
155
156 -raw)
157 IMGFMT=raw
158 xpand=false
159 ;;
160
161 -cow)
162 IMGFMT=cow
163 xpand=false
164 ;;
165
166 -qcow)
167 IMGFMT=qcow
168 xpand=false
169 ;;
170
171 -qcow2)
172 IMGFMT=qcow2
173 xpand=false
174 ;;
175
f5a4bbd9
SH
176 -qed)
177 IMGFMT=qed
178 xpand=false
179 ;;
180
b67f3068
CH
181 -vdi)
182 IMGFMT=vdi
183 xpand=false
184 ;;
185
6bf19c94
CH
186 -vmdk)
187 IMGFMT=vmdk
188 xpand=false
189 ;;
190
191 -vpc)
192 IMGFMT=vpc
193 xpand=false
194 ;;
195
9cdfa1b3
MK
196 -rbd)
197 IMGPROTO=rbd
198 xpand=false
199 ;;
200
201 -sheepdog)
202 IMGPROTO=sheepdog
203 xpand=false
204 ;;
205
6bf19c94
CH
206 -nocache)
207 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
208 xpand=false
209 ;;
210
211 -misalign)
212 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
213 xpand=false
214 ;;
215
2f24e8fb
KW
216 -valgrind)
217 valgrind=true
218 xpand=false
219 ;;
220
6bf19c94
CH
221 -g) # -g group ... pick from group file
222 group=true
223 xpand=false
224 ;;
225
226 -xdiff) # graphical diff mode
227 xpand=false
228
229 if [ ! -z "$DISPLAY" ]
230 then
231 which xdiff >/dev/null 2>&1 && diff=xdiff
232 which gdiff >/dev/null 2>&1 && diff=gdiff
233 which tkdiff >/dev/null 2>&1 && diff=tkdiff
234 which xxdiff >/dev/null 2>&1 && diff=xxdiff
235 fi
236 ;;
237
238 -n) # show me, don't do it
239 showme=true
240 xpand=false
241 ;;
89004368
KW
242 -o)
243 imgopts=true
244 xpand=false
245 ;;
6bf19c94
CH
246 -r) # randomize test order
247 randomize=true
248 xpand=false
249 ;;
250
251 -T) # turn on timestamp output
252 timestamp=true
253 xpand=false
254 ;;
255
256 -v)
257 verbose=true
258 xpand=false
259 ;;
260 -x) # -x group ... exclude from group file
261 xgroup=true
262 xpand=false
263 ;;
264 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
265 echo "No tests?"
266 status=1
267 exit $status
268 ;;
269
270 [0-9]*-[0-9]*)
271 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
272 ;;
273
274 [0-9]*-)
275 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
276 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/.* //'`
277 if [ -z "$end" ]
278 then
279 echo "No tests in range \"$r\"?"
280 status=1
281 exit $status
282 fi
283 ;;
284
285 *)
286 start=$r
287 end=$r
288 ;;
289
290 esac
291
292 # get rid of leading 0s as can be interpreted as octal
293 start=`echo $start | sed 's/^0*//'`
294 end=`echo $end | sed 's/^0*//'`
295
296 if $xpand
297 then
298 have_test_arg=true
299 $AWK_PROG </dev/null '
300BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
301 | while read id
302 do
303 if grep -s "^$id " group >/dev/null
304 then
305 # in group file ... OK
306 echo $id >>$tmp.list
307 else
308 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
309 then
310 # expunged ... will be reported, but not run, later
311 echo $id >>$tmp.list
312 else
313 # oops
314 echo "$id - unknown test, ignored"
315 fi
316 fi
317 done
318 fi
319
320done
321
89004368
KW
322# Set default options for qemu-img create -o if they were not specified
323_set_default_imgopts
324
6bf19c94
CH
325if [ -s $tmp.list ]
326then
327 # found some valid test numbers ... this is good
328 :
329else
330 if $have_test_arg
331 then
332 # had test numbers, but none in group file ... do nothing
333 touch $tmp.list
334 else
335 # no test numbers, do everything from group file
336 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
337 fi
338fi
339
340# should be sort -n, but this did not work for Linux when this
341# was ported from IRIX
342#
343list=`sort $tmp.list`
344rm -f $tmp.list $tmp.tmp $tmp.sed
345
346if $randomize
347then
348 list=`echo $list | awk -f randomize.awk`
349fi
350
351[ "$QEMU" = "" ] && _fatal "qemu not found"
352[ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
353[ "$QEMU_IO" = "" ] && _fatal "qemu-img not found"
2f24e8fb
KW
354
355if $valgrind; then
356 export REAL_QEMU_IO="$QEMU_IO_PROG"
357 export QEMU_IO_PROG=valgrind_qemu_io
358fi