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