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