]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/common
dataplane: Fix startup race.
[mirror_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
a9660664 139 -nbd test nbd
342809e8 140 -ssh test ssh
6bf19c94
CH
141 -xdiff graphical mode diff
142 -nocache use O_DIRECT on backing file
143 -misalign misalign memory allocations
144 -n show me, do not run tests
89004368 145 -o options -o options to pass to qemu-img create/convert
6bf19c94
CH
146 -T output timestamps
147 -r randomize test order
148
149testlist options
150 -g group[,group...] include tests from these groups
151 -x group[,group...] exclude tests from these groups
152 NNN include test NNN
153 NNN-NNN include test range (eg. 012-021)
154'
155 exit 0
156 ;;
157
158 -raw)
159 IMGFMT=raw
160 xpand=false
161 ;;
162
163 -cow)
164 IMGFMT=cow
165 xpand=false
166 ;;
167
168 -qcow)
169 IMGFMT=qcow
170 xpand=false
171 ;;
172
173 -qcow2)
174 IMGFMT=qcow2
175 xpand=false
176 ;;
177
f5a4bbd9
SH
178 -qed)
179 IMGFMT=qed
180 xpand=false
181 ;;
182
b67f3068
CH
183 -vdi)
184 IMGFMT=vdi
185 xpand=false
186 ;;
187
6bf19c94
CH
188 -vmdk)
189 IMGFMT=vmdk
190 xpand=false
191 ;;
192
193 -vpc)
194 IMGFMT=vpc
195 xpand=false
196 ;;
197
9cdfa1b3
MK
198 -rbd)
199 IMGPROTO=rbd
200 xpand=false
201 ;;
9cdfa1b3
MK
202 -sheepdog)
203 IMGPROTO=sheepdog
204 xpand=false
205 ;;
a9660664
NT
206 -nbd)
207 IMGPROTO=nbd
208 xpand=false
209 ;;
342809e8
RJ
210 -ssh)
211 IMGPROTO=ssh
212 xpand=false
213 ;;
6bf19c94
CH
214 -nocache)
215 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
216 xpand=false
217 ;;
218
219 -misalign)
220 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
221 xpand=false
222 ;;
223
2f24e8fb
KW
224 -valgrind)
225 valgrind=true
226 xpand=false
227 ;;
228
6bf19c94
CH
229 -g) # -g group ... pick from group file
230 group=true
231 xpand=false
232 ;;
233
234 -xdiff) # graphical diff mode
235 xpand=false
236
237 if [ ! -z "$DISPLAY" ]
238 then
239 which xdiff >/dev/null 2>&1 && diff=xdiff
240 which gdiff >/dev/null 2>&1 && diff=gdiff
241 which tkdiff >/dev/null 2>&1 && diff=tkdiff
242 which xxdiff >/dev/null 2>&1 && diff=xxdiff
243 fi
244 ;;
245
246 -n) # show me, don't do it
247 showme=true
248 xpand=false
249 ;;
89004368
KW
250 -o)
251 imgopts=true
252 xpand=false
253 ;;
6bf19c94
CH
254 -r) # randomize test order
255 randomize=true
256 xpand=false
257 ;;
258
259 -T) # turn on timestamp output
260 timestamp=true
261 xpand=false
262 ;;
263
264 -v)
265 verbose=true
266 xpand=false
267 ;;
268 -x) # -x group ... exclude from group file
269 xgroup=true
270 xpand=false
271 ;;
272 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
273 echo "No tests?"
274 status=1
275 exit $status
276 ;;
277
278 [0-9]*-[0-9]*)
279 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
280 ;;
281
282 [0-9]*-)
283 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
284 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/.* //'`
285 if [ -z "$end" ]
286 then
287 echo "No tests in range \"$r\"?"
288 status=1
289 exit $status
290 fi
291 ;;
292
293 *)
294 start=$r
295 end=$r
296 ;;
297
298 esac
299
300 # get rid of leading 0s as can be interpreted as octal
301 start=`echo $start | sed 's/^0*//'`
302 end=`echo $end | sed 's/^0*//'`
303
304 if $xpand
305 then
306 have_test_arg=true
307 $AWK_PROG </dev/null '
308BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
309 | while read id
310 do
311 if grep -s "^$id " group >/dev/null
312 then
313 # in group file ... OK
314 echo $id >>$tmp.list
315 else
316 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
317 then
318 # expunged ... will be reported, but not run, later
319 echo $id >>$tmp.list
320 else
321 # oops
322 echo "$id - unknown test, ignored"
323 fi
324 fi
325 done
326 fi
327
328done
329
89004368
KW
330# Set default options for qemu-img create -o if they were not specified
331_set_default_imgopts
332
6bf19c94
CH
333if [ -s $tmp.list ]
334then
335 # found some valid test numbers ... this is good
336 :
337else
338 if $have_test_arg
339 then
340 # had test numbers, but none in group file ... do nothing
341 touch $tmp.list
342 else
343 # no test numbers, do everything from group file
344 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
345 fi
346fi
347
348# should be sort -n, but this did not work for Linux when this
349# was ported from IRIX
350#
351list=`sort $tmp.list`
352rm -f $tmp.list $tmp.tmp $tmp.sed
353
354if $randomize
355then
356 list=`echo $list | awk -f randomize.awk`
357fi
358
359[ "$QEMU" = "" ] && _fatal "qemu not found"
360[ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
a9660664
NT
361[ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
362
363if [ "$IMGPROTO" = "nbd" ] ; then
364 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
365fi
2f24e8fb
KW
366
367if $valgrind; then
368 export REAL_QEMU_IO="$QEMU_IO_PROG"
369 export QEMU_IO_PROG=valgrind_qemu_io
370fi