]> git.proxmox.com Git - qemu.git/blob - tests/qemu-iotests/common
Merge remote-tracking branch 'kwolf/for-anthony' 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 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 showme=false
39 sortme=false
40 expunge=true
41 have_test_arg=false
42 randomize=false
43 rm -f $tmp.list $tmp.tmp $tmp.sed
44
45 export IMGFMT=raw
46 export IMGPROTO=file
47 export QEMU_IO_OPTIONS=""
48
49 for r
50 do
51
52 if $group
53 then
54 # arg after -g
55 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
56 s/ .*//p
57 }'`
58 if [ -z "$group_list" ]
59 then
60 echo "Group \"$r\" is empty or not defined?"
61 exit 1
62 fi
63 [ ! -s $tmp.list ] && touch $tmp.list
64 for t in $group_list
65 do
66 if grep -s "^$t\$" $tmp.list >/dev/null
67 then
68 :
69 else
70 echo "$t" >>$tmp.list
71 fi
72 done
73 group=false
74 continue
75
76 elif $xgroup
77 then
78 # arg after -x
79 [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
80 group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
81 s/ .*//p
82 }'`
83 if [ -z "$group_list" ]
84 then
85 echo "Group \"$r\" is empty or not defined?"
86 exit 1
87 fi
88 numsed=0
89 rm -f $tmp.sed
90 for t in $group_list
91 do
92 if [ $numsed -gt 100 ]
93 then
94 sed -f $tmp.sed <$tmp.list >$tmp.tmp
95 mv $tmp.tmp $tmp.list
96 numsed=0
97 rm -f $tmp.sed
98 fi
99 echo "/^$t\$/d" >>$tmp.sed
100 numsed=`expr $numsed + 1`
101 done
102 sed -f $tmp.sed <$tmp.list >$tmp.tmp
103 mv $tmp.tmp $tmp.list
104 xgroup=false
105 continue
106 fi
107
108 xpand=true
109 case "$r"
110 in
111
112 -\? | -h | --help) # usage
113 echo "Usage: $0 [options] [testlist]"'
114
115 common options
116 -v verbose
117
118 check options
119 -raw test raw (default)
120 -cow test cow
121 -qcow test qcow
122 -qcow2 test qcow2
123 -qed test qed
124 -vdi test vdi
125 -vpc test vpc
126 -vmdk test vmdk
127 -rbd test rbd
128 -sheepdog test sheepdog
129 -xdiff graphical mode diff
130 -nocache use O_DIRECT on backing file
131 -misalign misalign memory allocations
132 -n show me, do not run tests
133 -T output timestamps
134 -r randomize test order
135
136 testlist options
137 -g group[,group...] include tests from these groups
138 -x group[,group...] exclude tests from these groups
139 NNN include test NNN
140 NNN-NNN include test range (eg. 012-021)
141 '
142 exit 0
143 ;;
144
145 -raw)
146 IMGFMT=raw
147 xpand=false
148 ;;
149
150 -cow)
151 IMGFMT=cow
152 xpand=false
153 ;;
154
155 -qcow)
156 IMGFMT=qcow
157 xpand=false
158 ;;
159
160 -qcow2)
161 IMGFMT=qcow2
162 xpand=false
163 ;;
164
165 -qed)
166 IMGFMT=qed
167 xpand=false
168 ;;
169
170 -vdi)
171 IMGFMT=vdi
172 xpand=false
173 ;;
174
175 -vmdk)
176 IMGFMT=vmdk
177 xpand=false
178 ;;
179
180 -vpc)
181 IMGFMT=vpc
182 xpand=false
183 ;;
184
185 -rbd)
186 IMGPROTO=rbd
187 xpand=false
188 ;;
189
190 -sheepdog)
191 IMGPROTO=sheepdog
192 xpand=false
193 ;;
194
195 -nocache)
196 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache"
197 xpand=false
198 ;;
199
200 -misalign)
201 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
202 xpand=false
203 ;;
204
205 -g) # -g group ... pick from group file
206 group=true
207 xpand=false
208 ;;
209
210 -xdiff) # graphical diff mode
211 xpand=false
212
213 if [ ! -z "$DISPLAY" ]
214 then
215 which xdiff >/dev/null 2>&1 && diff=xdiff
216 which gdiff >/dev/null 2>&1 && diff=gdiff
217 which tkdiff >/dev/null 2>&1 && diff=tkdiff
218 which xxdiff >/dev/null 2>&1 && diff=xxdiff
219 fi
220 ;;
221
222 -n) # show me, don't do it
223 showme=true
224 xpand=false
225 ;;
226 -r) # randomize test order
227 randomize=true
228 xpand=false
229 ;;
230
231 -T) # turn on timestamp output
232 timestamp=true
233 xpand=false
234 ;;
235
236 -v)
237 verbose=true
238 xpand=false
239 ;;
240 -x) # -x group ... exclude from group file
241 xgroup=true
242 xpand=false
243 ;;
244 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
245 echo "No tests?"
246 status=1
247 exit $status
248 ;;
249
250 [0-9]*-[0-9]*)
251 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
252 ;;
253
254 [0-9]*-)
255 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
256 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/.* //'`
257 if [ -z "$end" ]
258 then
259 echo "No tests in range \"$r\"?"
260 status=1
261 exit $status
262 fi
263 ;;
264
265 *)
266 start=$r
267 end=$r
268 ;;
269
270 esac
271
272 # get rid of leading 0s as can be interpreted as octal
273 start=`echo $start | sed 's/^0*//'`
274 end=`echo $end | sed 's/^0*//'`
275
276 if $xpand
277 then
278 have_test_arg=true
279 $AWK_PROG </dev/null '
280 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
281 | while read id
282 do
283 if grep -s "^$id " group >/dev/null
284 then
285 # in group file ... OK
286 echo $id >>$tmp.list
287 else
288 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
289 then
290 # expunged ... will be reported, but not run, later
291 echo $id >>$tmp.list
292 else
293 # oops
294 echo "$id - unknown test, ignored"
295 fi
296 fi
297 done
298 fi
299
300 done
301
302 if [ -s $tmp.list ]
303 then
304 # found some valid test numbers ... this is good
305 :
306 else
307 if $have_test_arg
308 then
309 # had test numbers, but none in group file ... do nothing
310 touch $tmp.list
311 else
312 # no test numbers, do everything from group file
313 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list
314 fi
315 fi
316
317 # should be sort -n, but this did not work for Linux when this
318 # was ported from IRIX
319 #
320 list=`sort $tmp.list`
321 rm -f $tmp.list $tmp.tmp $tmp.sed
322
323 if $randomize
324 then
325 list=`echo $list | awk -f randomize.awk`
326 fi
327
328 [ "$QEMU" = "" ] && _fatal "qemu not found"
329 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
330 [ "$QEMU_IO" = "" ] && _fatal "qemu-img not found"