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