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