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