megasas: Implement DCMD_CLUSTER_RESET_LD
[qemu/ar7.git] / tests / qemu-iotests / common
blob9e12bec2bf581584c8524ec3c8224cebdb8136cf
1 #!/bin/bash
3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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/>.
19 # common procedures for QA scripts
22 _setenvironment()
24 MSGVERB="text:action"
25 export MSGVERB
28 rm -f "$OUTPUT_DIR/$iam.out"
29 _setenvironment
31 check=${check-true}
33 diff="diff -u"
34 verbose=false
35 group=false
36 xgroup=false
37 imgopts=false
38 showme=false
39 sortme=false
40 expunge=true
41 have_test_arg=false
42 randomize=false
43 valgrind=false
44 cachemode=false
45 rm -f $tmp.list $tmp.tmp $tmp.sed
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
55 for r
58 if $group
59 then
60 # arg after -g
61 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
62 s/ .*//p
63 }'`
64 if [ -z "$group_list" ]
65 then
66 echo "Group \"$r\" is empty or not defined?"
67 exit 1
69 [ ! -s $tmp.list ] && touch $tmp.list
70 for t in $group_list
72 if grep -s "^$t\$" $tmp.list >/dev/null
73 then
75 else
76 echo "$t" >>$tmp.list
78 done
79 group=false
80 continue
82 elif $xgroup
83 then
84 # arg after -x
85 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
86 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
87 s/ .*//p
88 }'`
89 if [ -z "$group_list" ]
90 then
91 echo "Group \"$r\" is empty or not defined?"
92 exit 1
94 numsed=0
95 rm -f $tmp.sed
96 for t in $group_list
98 if [ $numsed -gt 100 ]
99 then
100 sed -f $tmp.sed <$tmp.list >$tmp.tmp
101 mv $tmp.tmp $tmp.list
102 numsed=0
103 rm -f $tmp.sed
105 echo "/^$t\$/d" >>$tmp.sed
106 numsed=`expr $numsed + 1`
107 done
108 sed -f $tmp.sed <$tmp.list >$tmp.tmp
109 mv $tmp.tmp $tmp.list
110 xgroup=false
111 continue
113 elif $imgopts
114 then
115 IMGOPTS="$r"
116 imgopts=false
117 continue
118 elif $cachemode
119 then
120 CACHEMODE="$r"
121 CACHEMODE_IS_DEFAULT=false
122 cachemode=false
123 continue
126 xpand=true
127 case "$r"
130 -\? | -h | --help) # usage
131 echo "Usage: $0 [options] [testlist]"'
133 common options
134 -v verbose
136 check options
137 -raw test raw (default)
138 -bochs test bochs
139 -cloop test cloop
140 -parallels test parallels
141 -qcow test qcow
142 -qcow2 test qcow2
143 -qed test qed
144 -vdi test vdi
145 -vpc test vpc
146 -vhdx test vhdx
147 -vmdk test vmdk
148 -file test file (default)
149 -rbd test rbd
150 -sheepdog test sheepdog
151 -nbd test nbd
152 -ssh test ssh
153 -nfs test nfs
154 -archipelago test archipelago
155 -xdiff graphical mode diff
156 -nocache use O_DIRECT on backing file
157 -misalign misalign memory allocations
158 -n show me, do not run tests
159 -o options -o options to pass to qemu-img create/convert
160 -T output timestamps
161 -r randomize test order
162 -c mode cache mode
164 testlist options
165 -g group[,group...] include tests from these groups
166 -x group[,group...] exclude tests from these groups
167 NNN include test NNN
168 NNN-NNN include test range (eg. 012-021)
170 exit 0
173 -raw)
174 IMGFMT=raw
175 xpand=false
178 -bochs)
179 IMGFMT=bochs
180 IMGFMT_GENERIC=false
181 xpand=false
184 -cloop)
185 IMGFMT=cloop
186 IMGFMT_GENERIC=false
187 xpand=false
190 -parallels)
191 IMGFMT=parallels
192 IMGFMT_GENERIC=false
193 xpand=false
196 -qcow)
197 IMGFMT=qcow
198 xpand=false
201 -qcow2)
202 IMGFMT=qcow2
203 xpand=false
206 -qed)
207 IMGFMT=qed
208 xpand=false
211 -vdi)
212 IMGFMT=vdi
213 xpand=false
216 -vmdk)
217 IMGFMT=vmdk
218 xpand=false
221 -vpc)
222 IMGFMT=vpc
223 xpand=false
226 -vhdx)
227 IMGFMT=vhdx
228 xpand=false
231 -file)
232 IMGPROTO=file
233 xpand=false
236 -rbd)
237 IMGPROTO=rbd
238 xpand=false
241 -sheepdog)
242 IMGPROTO=sheepdog
243 xpand=false
246 -nbd)
247 IMGPROTO=nbd
248 xpand=false
251 -ssh)
252 IMGPROTO=ssh
253 xpand=false
256 -nfs)
257 IMGPROTO=nfs
258 xpand=false
261 -archipelago)
262 IMGPROTO=archipelago
263 xpand=false
266 -nocache)
267 CACHEMODE="none"
268 CACHEMODE_IS_DEFAULT=false
269 xpand=false
272 -misalign)
273 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
274 xpand=false
277 -valgrind)
278 valgrind=true
279 xpand=false
282 -g) # -g group ... pick from group file
283 group=true
284 xpand=false
287 -xdiff) # graphical diff mode
288 xpand=false
290 if [ ! -z "$DISPLAY" ]
291 then
292 which xdiff >/dev/null 2>&1 && diff=xdiff
293 which gdiff >/dev/null 2>&1 && diff=gdiff
294 which tkdiff >/dev/null 2>&1 && diff=tkdiff
295 which xxdiff >/dev/null 2>&1 && diff=xxdiff
299 -n) # show me, don't do it
300 showme=true
301 xpand=false
304 imgopts=true
305 xpand=false
308 cachemode=true
309 xpand=false
311 -r) # randomize test order
312 randomize=true
313 xpand=false
316 -T) # turn on timestamp output
317 timestamp=true
318 xpand=false
322 verbose=true
323 xpand=false
325 -x) # -x group ... exclude from group file
326 xgroup=true
327 xpand=false
329 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
330 echo "No tests?"
331 status=1
332 exit $status
335 [0-9]*-[0-9]*)
336 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
339 [0-9]*-)
340 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
341 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/.* //'`
342 if [ -z "$end" ]
343 then
344 echo "No tests in range \"$r\"?"
345 status=1
346 exit $status
351 start=$r
352 end=$r
355 esac
357 # get rid of leading 0s as can be interpreted as octal
358 start=`echo $start | sed 's/^0*//'`
359 end=`echo $end | sed 's/^0*//'`
361 if $xpand
362 then
363 have_test_arg=true
364 $AWK_PROG </dev/null '
365 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
366 | while read id
368 if grep -s "^$id " "$source_iotests/group" >/dev/null
369 then
370 # in group file ... OK
371 echo $id >>$tmp.list
372 else
373 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
374 then
375 # expunged ... will be reported, but not run, later
376 echo $id >>$tmp.list
377 else
378 # oops
379 if [ "$start" == "$end" -a "$id" == "$end" ]
380 then
381 echo "$id - unknown test"
382 exit 1
383 else
384 echo "$id - unknown test, ignored"
388 done || exit 1
391 done
393 # Set qemu-io cache mode with $CACHEMODE we have
394 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
396 # Set default options for qemu-img create -o if they were not specified
397 _set_default_imgopts
399 if [ -s $tmp.list ]
400 then
401 # found some valid test numbers ... this is good
403 else
404 if $have_test_arg
405 then
406 # had test numbers, but none in group file ... do nothing
407 touch $tmp.list
408 else
409 # no test numbers, do everything from group file
410 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
414 # should be sort -n, but this did not work for Linux when this
415 # was ported from IRIX
417 list=`sort $tmp.list`
418 rm -f $tmp.list $tmp.tmp $tmp.sed
420 if $randomize
421 then
422 list=`echo $list | awk -f randomize.awk`
425 [ "$QEMU" = "" ] && _fatal "qemu not found"
426 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
427 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
429 if [ "$IMGPROTO" = "nbd" ] ; then
430 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
433 if $valgrind; then
434 export REAL_QEMU_IO="$QEMU_IO_PROG"
435 export QEMU_IO_PROG=valgrind_qemu_io