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