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