]>
Commit | Line | Data |
---|---|---|
908eaf68 | 1 | #!/bin/bash |
6bf19c94 CH |
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 | |
e8c212d6 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6bf19c94 CH |
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 | |
89004368 | 38 | imgopts=false |
6bf19c94 CH |
39 | showme=false |
40 | sortme=false | |
41 | expunge=true | |
42 | have_test_arg=false | |
43 | randomize=false | |
2f24e8fb | 44 | valgrind=false |
3baa8449 | 45 | cachemode=false |
6bf19c94 CH |
46 | rm -f $tmp.list $tmp.tmp $tmp.sed |
47 | ||
48 | export IMGFMT=raw | |
89e91181 | 49 | export IMGFMT_GENERIC=true |
9cdfa1b3 | 50 | export IMGPROTO=file |
89004368 | 51 | export IMGOPTS="" |
e14fb913 | 52 | export CACHEMODE="writeback" |
6bf19c94 | 53 | export QEMU_IO_OPTIONS="" |
3baa8449 | 54 | export CACHEMODE_IS_DEFAULT=true |
6bf19c94 CH |
55 | |
56 | for r | |
57 | do | |
58 | ||
59 | if $group | |
60 | then | |
79e40ab1 KW |
61 | # arg after -g |
62 | group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | |
6bf19c94 CH |
63 | s/ .*//p |
64 | }'` | |
79e40ab1 KW |
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 | |
6bf19c94 CH |
82 | |
83 | elif $xgroup | |
84 | then | |
79e40ab1 KW |
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 /"'{ | |
6bf19c94 CH |
88 | s/ .*//p |
89 | }'` | |
79e40ab1 KW |
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 | |
89004368 KW |
113 | |
114 | elif $imgopts | |
115 | then | |
116 | IMGOPTS="$r" | |
117 | imgopts=false | |
118 | continue | |
3baa8449 FZ |
119 | elif $cachemode |
120 | then | |
121 | CACHEMODE="$r" | |
122 | CACHEMODE_IS_DEFAULT=false | |
123 | cachemode=false | |
124 | continue | |
6bf19c94 CH |
125 | fi |
126 | ||
127 | xpand=true | |
128 | case "$r" | |
129 | in | |
130 | ||
79e40ab1 KW |
131 | -\? | -h | --help) # usage |
132 | echo "Usage: $0 [options] [testlist]"' | |
6bf19c94 CH |
133 | |
134 | common options | |
236c7964 | 135 | -v verbose |
6bf19c94 CH |
136 | |
137 | check options | |
138 | -raw test raw (default) | |
24f3078a | 139 | -bochs test bochs |
6bf19c94 | 140 | -cow test cow |
47f73da0 | 141 | -cloop test cloop |
afbcc40b | 142 | -parallels test parallels |
6bf19c94 CH |
143 | -qcow test qcow |
144 | -qcow2 test qcow2 | |
f5a4bbd9 | 145 | -qed test qed |
b67f3068 | 146 | -vdi test vdi |
6bf19c94 | 147 | -vpc test vpc |
89e91181 | 148 | -vhdx test vhdx |
6bf19c94 | 149 | -vmdk test vmdk |
170632db | 150 | -file test file (default) |
9cdfa1b3 MK |
151 | -rbd test rbd |
152 | -sheepdog test sheepdog | |
a9660664 | 153 | -nbd test nbd |
342809e8 | 154 | -ssh test ssh |
170632db | 155 | -nfs test nfs |
236c7964 FZ |
156 | -xdiff graphical mode diff |
157 | -nocache use O_DIRECT on backing file | |
158 | -misalign misalign memory allocations | |
159 | -n show me, do not run tests | |
89004368 | 160 | -o options -o options to pass to qemu-img create/convert |
236c7964 FZ |
161 | -T output timestamps |
162 | -r randomize test order | |
3baa8449 | 163 | -c mode cache mode |
79e40ab1 | 164 | |
6bf19c94 | 165 | testlist options |
79e40ab1 KW |
166 | -g group[,group...] include tests from these groups |
167 | -x group[,group...] exclude tests from these groups | |
168 | NNN include test NNN | |
236c7964 | 169 | NNN-NNN include test range (eg. 012-021) |
6bf19c94 | 170 | ' |
79e40ab1 KW |
171 | exit 0 |
172 | ;; | |
173 | ||
174 | -raw) | |
175 | IMGFMT=raw | |
176 | xpand=false | |
177 | ;; | |
178 | ||
24f3078a KW |
179 | -bochs) |
180 | IMGFMT=bochs | |
181 | IMGFMT_GENERIC=false | |
182 | xpand=false | |
183 | ;; | |
184 | ||
79e40ab1 KW |
185 | -cow) |
186 | IMGFMT=cow | |
187 | xpand=false | |
188 | ;; | |
189 | ||
47f73da0 SH |
190 | -cloop) |
191 | IMGFMT=cloop | |
192 | IMGFMT_GENERIC=false | |
193 | xpand=false | |
194 | ;; | |
195 | ||
afbcc40b KW |
196 | -parallels) |
197 | IMGFMT=parallels | |
198 | IMGFMT_GENERIC=false | |
199 | xpand=false | |
200 | ;; | |
201 | ||
79e40ab1 KW |
202 | -qcow) |
203 | IMGFMT=qcow | |
204 | xpand=false | |
205 | ;; | |
206 | ||
207 | -qcow2) | |
208 | IMGFMT=qcow2 | |
209 | xpand=false | |
210 | ;; | |
211 | ||
212 | -qed) | |
213 | IMGFMT=qed | |
214 | xpand=false | |
215 | ;; | |
216 | ||
217 | -vdi) | |
218 | IMGFMT=vdi | |
219 | xpand=false | |
220 | ;; | |
221 | ||
222 | -vmdk) | |
223 | IMGFMT=vmdk | |
224 | xpand=false | |
225 | ;; | |
226 | ||
227 | -vpc) | |
228 | IMGFMT=vpc | |
229 | xpand=false | |
230 | ;; | |
231 | ||
89e91181 JC |
232 | -vhdx) |
233 | IMGFMT=vhdx | |
234 | xpand=false | |
89e91181 JC |
235 | ;; |
236 | ||
170632db PL |
237 | -file) |
238 | IMGPROTO=file | |
239 | xpand=false | |
240 | ;; | |
241 | ||
79e40ab1 KW |
242 | -rbd) |
243 | IMGPROTO=rbd | |
244 | xpand=false | |
245 | ;; | |
170632db | 246 | |
79e40ab1 KW |
247 | -sheepdog) |
248 | IMGPROTO=sheepdog | |
249 | xpand=false | |
250 | ;; | |
170632db | 251 | |
79e40ab1 KW |
252 | -nbd) |
253 | IMGPROTO=nbd | |
254 | xpand=false | |
255 | ;; | |
170632db | 256 | |
342809e8 RJ |
257 | -ssh) |
258 | IMGPROTO=ssh | |
259 | xpand=false | |
260 | ;; | |
170632db PL |
261 | |
262 | -nfs) | |
263 | IMGPROTO=nfs | |
264 | xpand=false | |
265 | ;; | |
266 | ||
79e40ab1 | 267 | -nocache) |
3baa8449 FZ |
268 | CACHEMODE="none" |
269 | CACHEMODE_IS_DEFAULT=false | |
79e40ab1 KW |
270 | xpand=false |
271 | ;; | |
6bf19c94 | 272 | |
79e40ab1 KW |
273 | -misalign) |
274 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | |
275 | xpand=false | |
276 | ;; | |
6bf19c94 | 277 | |
170632db PL |
278 | -valgrind) |
279 | valgrind=true | |
79e40ab1 | 280 | xpand=false |
170632db | 281 | ;; |
2f24e8fb | 282 | |
79e40ab1 KW |
283 | -g) # -g group ... pick from group file |
284 | group=true | |
285 | xpand=false | |
286 | ;; | |
287 | ||
288 | -xdiff) # graphical diff mode | |
289 | xpand=false | |
290 | ||
291 | if [ ! -z "$DISPLAY" ] | |
292 | then | |
293 | which xdiff >/dev/null 2>&1 && diff=xdiff | |
294 | which gdiff >/dev/null 2>&1 && diff=gdiff | |
295 | which tkdiff >/dev/null 2>&1 && diff=tkdiff | |
296 | which xxdiff >/dev/null 2>&1 && diff=xxdiff | |
297 | fi | |
298 | ;; | |
299 | ||
300 | -n) # show me, don't do it | |
301 | showme=true | |
302 | xpand=false | |
303 | ;; | |
89004368 KW |
304 | -o) |
305 | imgopts=true | |
306 | xpand=false | |
307 | ;; | |
3baa8449 FZ |
308 | -c) |
309 | cachemode=true | |
310 | xpand=false | |
311 | ;; | |
79e40ab1 KW |
312 | -r) # randomize test order |
313 | randomize=true | |
314 | xpand=false | |
315 | ;; | |
316 | ||
317 | -T) # turn on timestamp output | |
318 | timestamp=true | |
319 | xpand=false | |
320 | ;; | |
321 | ||
322 | -v) | |
323 | verbose=true | |
324 | xpand=false | |
325 | ;; | |
326 | -x) # -x group ... exclude from group file | |
327 | xgroup=true | |
328 | xpand=false | |
329 | ;; | |
330 | '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') | |
331 | echo "No tests?" | |
332 | status=1 | |
333 | exit $status | |
334 | ;; | |
335 | ||
336 | [0-9]*-[0-9]*) | |
337 | eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | |
338 | ;; | |
339 | ||
340 | [0-9]*-) | |
341 | eval `echo $r | sed -e 's/^/start=/' -e 's/-//'` | |
342 | 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/.* //'` | |
343 | if [ -z "$end" ] | |
344 | then | |
345 | echo "No tests in range \"$r\"?" | |
346 | status=1 | |
347 | exit $status | |
348 | fi | |
349 | ;; | |
350 | ||
351 | *) | |
352 | start=$r | |
353 | end=$r | |
354 | ;; | |
6bf19c94 CH |
355 | |
356 | esac | |
357 | ||
358 | # get rid of leading 0s as can be interpreted as octal | |
359 | start=`echo $start | sed 's/^0*//'` | |
360 | end=`echo $end | sed 's/^0*//'` | |
361 | ||
362 | if $xpand | |
363 | then | |
79e40ab1 KW |
364 | have_test_arg=true |
365 | $AWK_PROG </dev/null ' | |
366 | BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | |
367 | | while read id | |
368 | do | |
369 | if grep -s "^$id " group >/dev/null | |
370 | then | |
371 | # in group file ... OK | |
372 | echo $id >>$tmp.list | |
373 | else | |
374 | if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null | |
375 | then | |
376 | # expunged ... will be reported, but not run, later | |
377 | echo $id >>$tmp.list | |
378 | else | |
379 | # oops | |
380 | echo "$id - unknown test, ignored" | |
381 | fi | |
382 | fi | |
383 | done | |
6bf19c94 CH |
384 | fi |
385 | ||
386 | done | |
387 | ||
3baa8449 FZ |
388 | # Set qemu-io cache mode with $CACHEMODE we have |
389 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE" | |
390 | ||
89004368 KW |
391 | # Set default options for qemu-img create -o if they were not specified |
392 | _set_default_imgopts | |
393 | ||
6bf19c94 CH |
394 | if [ -s $tmp.list ] |
395 | then | |
396 | # found some valid test numbers ... this is good | |
397 | : | |
398 | else | |
399 | if $have_test_arg | |
400 | then | |
79e40ab1 KW |
401 | # had test numbers, but none in group file ... do nothing |
402 | touch $tmp.list | |
6bf19c94 | 403 | else |
79e40ab1 KW |
404 | # no test numbers, do everything from group file |
405 | sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list | |
6bf19c94 CH |
406 | fi |
407 | fi | |
408 | ||
409 | # should be sort -n, but this did not work for Linux when this | |
410 | # was ported from IRIX | |
411 | # | |
412 | list=`sort $tmp.list` | |
413 | rm -f $tmp.list $tmp.tmp $tmp.sed | |
414 | ||
415 | if $randomize | |
416 | then | |
417 | list=`echo $list | awk -f randomize.awk` | |
418 | fi | |
419 | ||
420 | [ "$QEMU" = "" ] && _fatal "qemu not found" | |
421 | [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | |
a9660664 NT |
422 | [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found" |
423 | ||
424 | if [ "$IMGPROTO" = "nbd" ] ; then | |
425 | [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found" | |
426 | fi | |
2f24e8fb KW |
427 | |
428 | if $valgrind; then | |
429 | export REAL_QEMU_IO="$QEMU_IO_PROG" | |
430 | export QEMU_IO_PROG=valgrind_qemu_io | |
431 | fi |