]> git.proxmox.com Git - qemu.git/blob - tests/qemu-iotests/common
Merge remote-tracking branch 'jliu/or32' into staging
[qemu.git] / tests / qemu-iotests / common
1 #!/bin/bash
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
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 #
19 # common procedures for QA scripts
20 #
21
22 _setenvironment()
23 {
24 MSGVERB="text:action"
25 export MSGVERB
26 }
27
28 here=`pwd`
29 rm -f $here/$iam.out
30 _setenvironment
31
32 check=${check-true}
33
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 rm -f $tmp.list $tmp.tmp $tmp.sed
46
47 export IMGFMT=raw
48 export IMGFMT_GENERIC=true
49 export IMGPROTO=file
50 export IMGOPTS=""
51 export QEMU_IO_OPTIONS=""
52
53 for r
54 do
55
56 if $group
57 then
58 # arg after -g
59 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
60 s/ .*//p
61 }'`
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
79
80 elif $xgroup
81 then
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 /"'{
85 s/ .*//p
86 }'`
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
110
111 elif $imgopts
112 then
113 IMGOPTS="$r"
114 imgopts=false
115 continue
116
117 fi
118
119 xpand=true
120 case "$r"
121 in
122
123 -\? | -h | --help) # usage
124 echo "Usage: $0 [options] [testlist]"'
125
126 common options
127 -v verbose
128
129 check options
130 -raw test raw (default)
131 -cow test cow
132 -qcow test qcow
133 -qcow2 test qcow2
134 -qed test qed
135 -vdi test vdi
136 -vpc test vpc
137 -vhdx test vhdx
138 -vmdk test vmdk
139 -rbd test rbd
140 -sheepdog test sheepdog
141 -nbd test nbd
142 -ssh test ssh
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
147 -o options -o options to pass to qemu-img create/convert
148 -T output timestamps
149 -r randomize test order
150
151 testlist options
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)
156 '
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
200 -vhdx)
201 IMGFMT=vhdx
202 xpand=false
203 IMGFMT_GENERIC=false
204 ;;
205
206 -rbd)
207 IMGPROTO=rbd
208 xpand=false
209 ;;
210 -sheepdog)
211 IMGPROTO=sheepdog
212 xpand=false
213 ;;
214 -nbd)
215 IMGPROTO=nbd
216 xpand=false
217 ;;
218 -ssh)
219 IMGPROTO=ssh
220 xpand=false
221 ;;
222 -nocache)
223 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
224 xpand=false
225 ;;
226
227 -misalign)
228 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
229 xpand=false
230 ;;
231
232 -valgrind)
233 valgrind=true
234 xpand=false
235 ;;
236
237 -g) # -g group ... pick from group file
238 group=true
239 xpand=false
240 ;;
241
242 -xdiff) # graphical diff mode
243 xpand=false
244
245 if [ ! -z "$DISPLAY" ]
246 then
247 which xdiff >/dev/null 2>&1 && diff=xdiff
248 which gdiff >/dev/null 2>&1 && diff=gdiff
249 which tkdiff >/dev/null 2>&1 && diff=tkdiff
250 which xxdiff >/dev/null 2>&1 && diff=xxdiff
251 fi
252 ;;
253
254 -n) # show me, don't do it
255 showme=true
256 xpand=false
257 ;;
258 -o)
259 imgopts=true
260 xpand=false
261 ;;
262 -r) # randomize test order
263 randomize=true
264 xpand=false
265 ;;
266
267 -T) # turn on timestamp output
268 timestamp=true
269 xpand=false
270 ;;
271
272 -v)
273 verbose=true
274 xpand=false
275 ;;
276 -x) # -x group ... exclude from group file
277 xgroup=true
278 xpand=false
279 ;;
280 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
281 echo "No tests?"
282 status=1
283 exit $status
284 ;;
285
286 [0-9]*-[0-9]*)
287 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
288 ;;
289
290 [0-9]*-)
291 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
292 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/.* //'`
293 if [ -z "$end" ]
294 then
295 echo "No tests in range \"$r\"?"
296 status=1
297 exit $status
298 fi
299 ;;
300
301 *)
302 start=$r
303 end=$r
304 ;;
305
306 esac
307
308 # get rid of leading 0s as can be interpreted as octal
309 start=`echo $start | sed 's/^0*//'`
310 end=`echo $end | sed 's/^0*//'`
311
312 if $xpand
313 then
314 have_test_arg=true
315 $AWK_PROG </dev/null '
316 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
317 | while read id
318 do
319 if grep -s "^$id " group >/dev/null
320 then
321 # in group file ... OK
322 echo $id >>$tmp.list
323 else
324 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
325 then
326 # expunged ... will be reported, but not run, later
327 echo $id >>$tmp.list
328 else
329 # oops
330 echo "$id - unknown test, ignored"
331 fi
332 fi
333 done
334 fi
335
336 done
337
338 # Set default options for qemu-img create -o if they were not specified
339 _set_default_imgopts
340
341 if [ -s $tmp.list ]
342 then
343 # found some valid test numbers ... this is good
344 :
345 else
346 if $have_test_arg
347 then
348 # had test numbers, but none in group file ... do nothing
349 touch $tmp.list
350 else
351 # no test numbers, do everything from group file
352 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
353 fi
354 fi
355
356 # should be sort -n, but this did not work for Linux when this
357 # was ported from IRIX
358 #
359 list=`sort $tmp.list`
360 rm -f $tmp.list $tmp.tmp $tmp.sed
361
362 if $randomize
363 then
364 list=`echo $list | awk -f randomize.awk`
365 fi
366
367 [ "$QEMU" = "" ] && _fatal "qemu not found"
368 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
369 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
370
371 if [ "$IMGPROTO" = "nbd" ] ; then
372 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
373 fi
374
375 if $valgrind; then
376 export REAL_QEMU_IO="$QEMU_IO_PROG"
377 export QEMU_IO_PROG=valgrind_qemu_io
378 fi