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