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