blob: d60ea2ce3c9d87a590102d1d827ffbd1b4d4d0c7 [file] [log] [blame]
Stefan Hajnoczi908eaf62010-04-26 11:44:05 +02001#!/bin/bash
Christoph Hellwig6bf19c92009-06-22 18:29:05 +02002#
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
Christoph Hellwige8c212d2009-07-16 19:26:54 +020016# along with this program. If not, see <http://www.gnu.org/licenses/>.
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020017#
18#
19# common procedures for QA scripts
20#
21
22_setenvironment()
23{
24 MSGVERB="text:action"
25 export MSGVERB
26}
27
Max Reitze8f86242014-05-24 23:24:55 +020028rm -f "$OUTPUT_DIR/$iam.out"
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020029_setenvironment
30
31check=${check-true}
32
33diff="diff -u"
34verbose=false
Fam Zhengaa4f5922015-05-18 09:39:12 +080035debug=false
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020036group=false
37xgroup=false
Kevin Wolf89004362012-03-27 13:45:14 +020038imgopts=false
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020039showme=false
40sortme=false
41expunge=true
42have_test_arg=false
43randomize=false
Fam Zheng3baa8442013-12-04 09:06:58 +080044cachemode=false
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020045rm -f $tmp.list $tmp.tmp $tmp.sed
46
47export IMGFMT=raw
Jeff Cody89e91182013-09-27 08:48:15 -040048export IMGFMT_GENERIC=true
MORITA Kazutaka9cdfa1b2011-01-18 02:01:17 +090049export IMGPROTO=file
Kevin Wolf89004362012-03-27 13:45:14 +020050export IMGOPTS=""
Fam Zhenge14fb912013-12-04 09:07:01 +080051export CACHEMODE="writeback"
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020052export QEMU_IO_OPTIONS=""
Fam Zheng3baa8442013-12-04 09:06:58 +080053export CACHEMODE_IS_DEFAULT=true
Bo Tu2711fd32015-07-03 15:28:47 +080054export QEMU_OPTIONS="-nodefaults"
Jeff Codye6c17662015-10-30 15:25:18 -040055export VALGRIND_QEMU=
Daniel P. Berrangeb7e875b2016-05-10 17:11:28 +010056export IMGKEYSECRET=
Daniel P. Berrange076003f2016-05-10 17:11:27 +010057export IMGOPTSSYNTAX=false
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020058
59for r
60do
61
62 if $group
63 then
Kevin Wolf79e40ab2013-09-04 13:16:04 +020064 # arg after -g
Max Reitze8f86242014-05-24 23:24:55 +020065 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020066s/ .*//p
67}'`
Kevin Wolf79e40ab2013-09-04 13:16:04 +020068 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
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020085
86 elif $xgroup
87 then
Kevin Wolf79e40ab2013-09-04 13:16:04 +020088 # 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
Max Reitze8f86242014-05-24 23:24:55 +020090 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
Christoph Hellwig6bf19c92009-06-22 18:29:05 +020091s/ .*//p
92}'`
Kevin Wolf79e40ab2013-09-04 13:16:04 +020093 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
Kevin Wolf89004362012-03-27 13:45:14 +0200116
117 elif $imgopts
118 then
119 IMGOPTS="$r"
120 imgopts=false
121 continue
Fam Zheng3baa8442013-12-04 09:06:58 +0800122 elif $cachemode
123 then
124 CACHEMODE="$r"
125 CACHEMODE_IS_DEFAULT=false
126 cachemode=false
127 continue
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200128 fi
129
130 xpand=true
131 case "$r"
132 in
133
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200134 -\? | -h | --help) # usage
135 echo "Usage: $0 [options] [testlist]"'
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200136
137common options
Fam Zheng236c7962013-12-04 09:07:02 +0800138 -v verbose
Fam Zhengaa4f5922015-05-18 09:39:12 +0800139 -d debug
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200140
141check options
142 -raw test raw (default)
Kevin Wolf24f30782014-03-26 13:05:30 +0100143 -bochs test bochs
Stefan Hajnoczi47f73da2014-03-26 13:05:23 +0100144 -cloop test cloop
Kevin Wolfafbcc402014-03-26 13:06:08 +0100145 -parallels test parallels
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200146 -qcow test qcow
147 -qcow2 test qcow2
Stefan Hajnoczif5a4bbd2010-10-31 16:10:20 -0400148 -qed test qed
Christoph Hellwigb67f3062009-07-06 11:48:30 +0200149 -vdi test vdi
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200150 -vpc test vpc
Jeff Cody89e91182013-09-27 08:48:15 -0400151 -vhdx test vhdx
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200152 -vmdk test vmdk
Peter Lieven170632d2014-02-03 10:26:17 +0100153 -file test file (default)
MORITA Kazutaka9cdfa1b2011-01-18 02:01:17 +0900154 -rbd test rbd
155 -sheepdog test sheepdog
Nick Thomasa9660662012-11-02 13:01:23 +0000156 -nbd test nbd
Richard W.M. Jones342809e2013-04-09 15:30:55 +0100157 -ssh test ssh
Peter Lieven170632d2014-02-03 10:26:17 +0100158 -nfs test nfs
Chrysostomos Nanakos746ebfa2014-07-23 17:07:33 +0300159 -archipelago test archipelago
Daniel P. Berrange6278ae02016-03-21 14:11:52 +0000160 -luks test luks
Fam Zheng236c7962013-12-04 09:07:02 +0800161 -xdiff graphical mode diff
162 -nocache use O_DIRECT on backing file
163 -misalign misalign memory allocations
164 -n show me, do not run tests
Kevin Wolf89004362012-03-27 13:45:14 +0200165 -o options -o options to pass to qemu-img create/convert
Fam Zheng236c7962013-12-04 09:07:02 +0800166 -T output timestamps
167 -r randomize test order
Fam Zheng3baa8442013-12-04 09:06:58 +0800168 -c mode cache mode
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200169
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200170testlist options
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200171 -g group[,group...] include tests from these groups
172 -x group[,group...] exclude tests from these groups
173 NNN include test NNN
Fam Zheng236c7962013-12-04 09:07:02 +0800174 NNN-NNN include test range (eg. 012-021)
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200175'
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200176 exit 0
177 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200178
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200179 -raw)
180 IMGFMT=raw
181 xpand=false
182 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200183
Kevin Wolf24f30782014-03-26 13:05:30 +0100184 -bochs)
185 IMGFMT=bochs
186 IMGFMT_GENERIC=false
187 xpand=false
188 ;;
189
Stefan Hajnoczi47f73da2014-03-26 13:05:23 +0100190 -cloop)
191 IMGFMT=cloop
192 IMGFMT_GENERIC=false
193 xpand=false
194 ;;
195
Kevin Wolfafbcc402014-03-26 13:06:08 +0100196 -parallels)
197 IMGFMT=parallels
198 IMGFMT_GENERIC=false
199 xpand=false
200 ;;
201
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200202 -qcow)
203 IMGFMT=qcow
204 xpand=false
205 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200206
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200207 -qcow2)
208 IMGFMT=qcow2
209 xpand=false
210 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200211
Daniel P. Berrange4e9b25f2016-05-10 17:11:29 +0100212 -luks)
213 IMGOPTSSYNTAX=true
214 IMGFMT=luks
215 IMGKEYSECRET=123456
216 xpand=false
217 ;;
218
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200219 -qed)
220 IMGFMT=qed
221 xpand=false
222 ;;
Stefan Hajnoczif5a4bbd2010-10-31 16:10:20 -0400223
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200224 -vdi)
225 IMGFMT=vdi
226 xpand=false
227 ;;
Christoph Hellwigb67f3062009-07-06 11:48:30 +0200228
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200229 -vmdk)
230 IMGFMT=vmdk
231 xpand=false
232 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200233
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200234 -vpc)
235 IMGFMT=vpc
236 xpand=false
237 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200238
Jeff Cody89e91182013-09-27 08:48:15 -0400239 -vhdx)
240 IMGFMT=vhdx
241 xpand=false
Jeff Cody89e91182013-09-27 08:48:15 -0400242 ;;
243
Peter Lieven170632d2014-02-03 10:26:17 +0100244 -file)
245 IMGPROTO=file
246 xpand=false
247 ;;
248
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200249 -rbd)
250 IMGPROTO=rbd
251 xpand=false
252 ;;
Peter Lieven170632d2014-02-03 10:26:17 +0100253
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200254 -sheepdog)
255 IMGPROTO=sheepdog
256 xpand=false
257 ;;
Peter Lieven170632d2014-02-03 10:26:17 +0100258
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200259 -nbd)
260 IMGPROTO=nbd
261 xpand=false
262 ;;
Peter Lieven170632d2014-02-03 10:26:17 +0100263
Richard W.M. Jones342809e2013-04-09 15:30:55 +0100264 -ssh)
265 IMGPROTO=ssh
266 xpand=false
267 ;;
Peter Lieven170632d2014-02-03 10:26:17 +0100268
269 -nfs)
270 IMGPROTO=nfs
271 xpand=false
272 ;;
273
Chrysostomos Nanakos746ebfa2014-07-23 17:07:33 +0300274 -archipelago)
275 IMGPROTO=archipelago
276 xpand=false
277 ;;
278
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200279 -nocache)
Fam Zheng3baa8442013-12-04 09:06:58 +0800280 CACHEMODE="none"
281 CACHEMODE_IS_DEFAULT=false
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200282 xpand=false
283 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200284
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200285 -misalign)
286 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
287 xpand=false
288 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200289
Peter Lieven170632d2014-02-03 10:26:17 +0100290 -valgrind)
Jeff Codye6c17662015-10-30 15:25:18 -0400291 VALGRIND_QEMU='y'
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200292 xpand=false
Peter Lieven170632d2014-02-03 10:26:17 +0100293 ;;
Kevin Wolf2f24e8f2012-06-28 16:55:54 +0200294
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200295 -g) # -g group ... pick from group file
296 group=true
297 xpand=false
298 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200299
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200300 -xdiff) # graphical diff mode
301 xpand=false
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200302
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200303 if [ ! -z "$DISPLAY" ]
304 then
Fam Zhenge465ce72014-11-19 15:07:12 +0800305 command -v xdiff >/dev/null 2>&1 && diff=xdiff
306 command -v gdiff >/dev/null 2>&1 && diff=gdiff
307 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
308 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200309 fi
310 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200311
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200312 -n) # show me, don't do it
313 showme=true
314 xpand=false
315 ;;
Kevin Wolf89004362012-03-27 13:45:14 +0200316 -o)
317 imgopts=true
318 xpand=false
319 ;;
Fam Zheng3baa8442013-12-04 09:06:58 +0800320 -c)
321 cachemode=true
322 xpand=false
323 ;;
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200324 -r) # randomize test order
325 randomize=true
326 xpand=false
327 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200328
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200329 -T) # turn on timestamp output
330 timestamp=true
331 xpand=false
332 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200333
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200334 -v)
335 verbose=true
336 xpand=false
337 ;;
Fam Zhengaa4f5922015-05-18 09:39:12 +0800338 -d)
339 debug=true
340 xpand=false
341 ;;
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200342 -x) # -x group ... exclude from group file
343 xgroup=true
344 xpand=false
345 ;;
346 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
347 echo "No tests?"
348 status=1
349 exit $status
350 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200351
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200352 [0-9]*-[0-9]*)
353 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
354 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200355
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200356 [0-9]*-)
357 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
358 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/.* //'`
359 if [ -z "$end" ]
360 then
361 echo "No tests in range \"$r\"?"
362 status=1
363 exit $status
364 fi
365 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200366
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200367 *)
368 start=$r
369 end=$r
370 ;;
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200371
372 esac
373
374 # get rid of leading 0s as can be interpreted as octal
375 start=`echo $start | sed 's/^0*//'`
376 end=`echo $end | sed 's/^0*//'`
377
378 if $xpand
379 then
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200380 have_test_arg=true
381 $AWK_PROG </dev/null '
382BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
383 | while read id
384 do
Max Reitze8f86242014-05-24 23:24:55 +0200385 if grep -s "^$id " "$source_iotests/group" >/dev/null
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200386 then
387 # in group file ... OK
388 echo $id >>$tmp.list
389 else
390 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
391 then
392 # expunged ... will be reported, but not run, later
393 echo $id >>$tmp.list
394 else
395 # oops
Fam Zhengc9d17ad2014-09-24 11:05:57 +0800396 if [ "$start" == "$end" -a "$id" == "$end" ]
397 then
398 echo "$id - unknown test"
399 exit 1
400 else
401 echo "$id - unknown test, ignored"
402 fi
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200403 fi
404 fi
Fam Zhengc9d17ad2014-09-24 11:05:57 +0800405 done || exit 1
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200406 fi
407
408done
409
Fam Zheng3baa8442013-12-04 09:06:58 +0800410# Set qemu-io cache mode with $CACHEMODE we have
Daniel P. Berrange076003f2016-05-10 17:11:27 +0100411if [ "$IMGOPTSSYNTAX" = "true" ]; then
412 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
413else
414 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
415fi
Fam Zheng3baa8442013-12-04 09:06:58 +0800416
Kevin Wolf89004362012-03-27 13:45:14 +0200417# Set default options for qemu-img create -o if they were not specified
418_set_default_imgopts
419
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200420if [ -s $tmp.list ]
421then
422 # found some valid test numbers ... this is good
423 :
424else
425 if $have_test_arg
426 then
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200427 # had test numbers, but none in group file ... do nothing
428 touch $tmp.list
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200429 else
Kevin Wolf79e40ab2013-09-04 13:16:04 +0200430 # no test numbers, do everything from group file
Max Reitze8f86242014-05-24 23:24:55 +0200431 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
Christoph Hellwig6bf19c92009-06-22 18:29:05 +0200432 fi
433fi
434
435# should be sort -n, but this did not work for Linux when this
436# was ported from IRIX
437#
438list=`sort $tmp.list`
439rm -f $tmp.list $tmp.tmp $tmp.sed
440
441if $randomize
442then
443 list=`echo $list | awk -f randomize.awk`
444fi
445
446[ "$QEMU" = "" ] && _fatal "qemu not found"
447[ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
Nick Thomasa9660662012-11-02 13:01:23 +0000448[ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
449
450if [ "$IMGPROTO" = "nbd" ] ; then
451 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
452fi