]>
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 | |
35 | group=false | |
36 | xgroup=false | |
89004368 | 37 | imgopts=false |
6bf19c94 CH |
38 | showme=false |
39 | sortme=false | |
40 | expunge=true | |
41 | have_test_arg=false | |
42 | randomize=false | |
2f24e8fb | 43 | valgrind=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 |
6bf19c94 CH |
54 | |
55 | for r | |
56 | do | |
57 | ||
58 | if $group | |
59 | then | |
79e40ab1 | 60 | # arg after -g |
e8f8624d | 61 | group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ |
6bf19c94 CH |
62 | s/ .*//p |
63 | }'` | |
79e40ab1 KW |
64 | if [ -z "$group_list" ] |
65 | then | |
66 | echo "Group \"$r\" is empty or not defined?" | |
67 | exit 1 | |
68 | fi | |
69 | [ ! -s $tmp.list ] && touch $tmp.list | |
70 | for t in $group_list | |
71 | do | |
72 | if grep -s "^$t\$" $tmp.list >/dev/null | |
73 | then | |
74 | : | |
75 | else | |
76 | echo "$t" >>$tmp.list | |
77 | fi | |
78 | done | |
79 | group=false | |
80 | continue | |
6bf19c94 CH |
81 | |
82 | elif $xgroup | |
83 | then | |
79e40ab1 KW |
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 | |
e8f8624d | 86 | group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ |
6bf19c94 CH |
87 | s/ .*//p |
88 | }'` | |
79e40ab1 KW |
89 | if [ -z "$group_list" ] |
90 | then | |
91 | echo "Group \"$r\" is empty or not defined?" | |
92 | exit 1 | |
93 | fi | |
94 | numsed=0 | |
95 | rm -f $tmp.sed | |
96 | for t in $group_list | |
97 | do | |
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 | |
104 | fi | |
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 | |
89004368 KW |
112 | |
113 | elif $imgopts | |
114 | then | |
115 | IMGOPTS="$r" | |
116 | imgopts=false | |
117 | continue | |
3baa8449 FZ |
118 | elif $cachemode |
119 | then | |
120 | CACHEMODE="$r" | |
121 | CACHEMODE_IS_DEFAULT=false | |
122 | cachemode=false | |
123 | continue | |
6bf19c94 CH |
124 | fi |
125 | ||
126 | xpand=true | |
127 | case "$r" | |
128 | in | |
129 | ||
79e40ab1 KW |
130 | -\? | -h | --help) # usage |
131 | echo "Usage: $0 [options] [testlist]"' | |
6bf19c94 CH |
132 | |
133 | common options | |
236c7964 | 134 | -v verbose |
6bf19c94 CH |
135 | |
136 | check options | |
137 | -raw test raw (default) | |
24f3078a | 138 | -bochs test bochs |
6bf19c94 | 139 | -cow test cow |
47f73da0 | 140 | -cloop test cloop |
afbcc40b | 141 | -parallels test parallels |
6bf19c94 CH |
142 | -qcow test qcow |
143 | -qcow2 test qcow2 | |
f5a4bbd9 | 144 | -qed test qed |
b67f3068 | 145 | -vdi test vdi |
6bf19c94 | 146 | -vpc test vpc |
89e91181 | 147 | -vhdx test vhdx |
6bf19c94 | 148 | -vmdk test vmdk |
170632db | 149 | -file test file (default) |
9cdfa1b3 MK |
150 | -rbd test rbd |
151 | -sheepdog test sheepdog | |
a9660664 | 152 | -nbd test nbd |
342809e8 | 153 | -ssh test ssh |
170632db | 154 | -nfs test nfs |
236c7964 FZ |
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 | |
89004368 | 159 | -o options -o options to pass to qemu-img create/convert |
236c7964 FZ |
160 | -T output timestamps |
161 | -r randomize test order | |
3baa8449 | 162 | -c mode cache mode |
79e40ab1 | 163 | |
6bf19c94 | 164 | testlist options |
79e40ab1 KW |
165 | -g group[,group...] include tests from these groups |
166 | -x group[,group...] exclude tests from these groups | |
167 | NNN include test NNN | |
236c7964 | 168 | NNN-NNN include test range (eg. 012-021) |
6bf19c94 | 169 | ' |
79e40ab1 KW |
170 | exit 0 |
171 | ;; | |
172 | ||
173 | -raw) | |
174 | IMGFMT=raw | |
175 | xpand=false | |
176 | ;; | |
177 | ||
24f3078a KW |
178 | -bochs) |
179 | IMGFMT=bochs | |
180 | IMGFMT_GENERIC=false | |
181 | xpand=false | |
182 | ;; | |
183 | ||
79e40ab1 KW |
184 | -cow) |
185 | IMGFMT=cow | |
186 | xpand=false | |
187 | ;; | |
188 | ||
47f73da0 SH |
189 | -cloop) |
190 | IMGFMT=cloop | |
191 | IMGFMT_GENERIC=false | |
192 | xpand=false | |
193 | ;; | |
194 | ||
afbcc40b KW |
195 | -parallels) |
196 | IMGFMT=parallels | |
197 | IMGFMT_GENERIC=false | |
198 | xpand=false | |
199 | ;; | |
200 | ||
79e40ab1 KW |
201 | -qcow) |
202 | IMGFMT=qcow | |
203 | xpand=false | |
204 | ;; | |
205 | ||
206 | -qcow2) | |
207 | IMGFMT=qcow2 | |
208 | xpand=false | |
209 | ;; | |
210 | ||
211 | -qed) | |
212 | IMGFMT=qed | |
213 | xpand=false | |
214 | ;; | |
215 | ||
216 | -vdi) | |
217 | IMGFMT=vdi | |
218 | xpand=false | |
219 | ;; | |
220 | ||
221 | -vmdk) | |
222 | IMGFMT=vmdk | |
223 | xpand=false | |
224 | ;; | |
225 | ||
226 | -vpc) | |
227 | IMGFMT=vpc | |
228 | xpand=false | |
229 | ;; | |
230 | ||
89e91181 JC |
231 | -vhdx) |
232 | IMGFMT=vhdx | |
233 | xpand=false | |
89e91181 JC |
234 | ;; |
235 | ||
170632db PL |
236 | -file) |
237 | IMGPROTO=file | |
238 | xpand=false | |
239 | ;; | |
240 | ||
79e40ab1 KW |
241 | -rbd) |
242 | IMGPROTO=rbd | |
243 | xpand=false | |
244 | ;; | |
170632db | 245 | |
79e40ab1 KW |
246 | -sheepdog) |
247 | IMGPROTO=sheepdog | |
248 | xpand=false | |
249 | ;; | |
170632db | 250 | |
79e40ab1 KW |
251 | -nbd) |
252 | IMGPROTO=nbd | |
253 | xpand=false | |
254 | ;; | |
170632db | 255 | |
342809e8 RJ |
256 | -ssh) |
257 | IMGPROTO=ssh | |
258 | xpand=false | |
259 | ;; | |
170632db PL |
260 | |
261 | -nfs) | |
262 | IMGPROTO=nfs | |
263 | xpand=false | |
264 | ;; | |
265 | ||
79e40ab1 | 266 | -nocache) |
3baa8449 FZ |
267 | CACHEMODE="none" |
268 | CACHEMODE_IS_DEFAULT=false | |
79e40ab1 KW |
269 | xpand=false |
270 | ;; | |
6bf19c94 | 271 | |
79e40ab1 KW |
272 | -misalign) |
273 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | |
274 | xpand=false | |
275 | ;; | |
6bf19c94 | 276 | |
170632db PL |
277 | -valgrind) |
278 | valgrind=true | |
79e40ab1 | 279 | xpand=false |
170632db | 280 | ;; |
2f24e8fb | 281 | |
79e40ab1 KW |
282 | -g) # -g group ... pick from group file |
283 | group=true | |
284 | xpand=false | |
285 | ;; | |
286 | ||
287 | -xdiff) # graphical diff mode | |
288 | xpand=false | |
289 | ||
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 | |
296 | fi | |
297 | ;; | |
298 | ||
299 | -n) # show me, don't do it | |
300 | showme=true | |
301 | xpand=false | |
302 | ;; | |
89004368 KW |
303 | -o) |
304 | imgopts=true | |
305 | xpand=false | |
306 | ;; | |
3baa8449 FZ |
307 | -c) |
308 | cachemode=true | |
309 | xpand=false | |
310 | ;; | |
79e40ab1 KW |
311 | -r) # randomize test order |
312 | randomize=true | |
313 | xpand=false | |
314 | ;; | |
315 | ||
316 | -T) # turn on timestamp output | |
317 | timestamp=true | |
318 | xpand=false | |
319 | ;; | |
320 | ||
321 | -v) | |
322 | verbose=true | |
323 | xpand=false | |
324 | ;; | |
325 | -x) # -x group ... exclude from group file | |
326 | xgroup=true | |
327 | xpand=false | |
328 | ;; | |
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 | |
333 | ;; | |
334 | ||
335 | [0-9]*-[0-9]*) | |
336 | eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | |
337 | ;; | |
338 | ||
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 | |
347 | fi | |
348 | ;; | |
349 | ||
350 | *) | |
351 | start=$r | |
352 | end=$r | |
353 | ;; | |
6bf19c94 CH |
354 | |
355 | esac | |
356 | ||
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*//'` | |
360 | ||
361 | if $xpand | |
362 | then | |
79e40ab1 KW |
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 | |
367 | do | |
e8f8624d | 368 | if grep -s "^$id " "$source_iotests/group" >/dev/null |
79e40ab1 KW |
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 | echo "$id - unknown test, ignored" | |
380 | fi | |
381 | fi | |
382 | done | |
6bf19c94 CH |
383 | fi |
384 | ||
385 | done | |
386 | ||
3baa8449 FZ |
387 | # Set qemu-io cache mode with $CACHEMODE we have |
388 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE" | |
389 | ||
89004368 KW |
390 | # Set default options for qemu-img create -o if they were not specified |
391 | _set_default_imgopts | |
392 | ||
6bf19c94 CH |
393 | if [ -s $tmp.list ] |
394 | then | |
395 | # found some valid test numbers ... this is good | |
396 | : | |
397 | else | |
398 | if $have_test_arg | |
399 | then | |
79e40ab1 KW |
400 | # had test numbers, but none in group file ... do nothing |
401 | touch $tmp.list | |
6bf19c94 | 402 | else |
79e40ab1 | 403 | # no test numbers, do everything from group file |
e8f8624d | 404 | sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list |
6bf19c94 CH |
405 | fi |
406 | fi | |
407 | ||
408 | # should be sort -n, but this did not work for Linux when this | |
409 | # was ported from IRIX | |
410 | # | |
411 | list=`sort $tmp.list` | |
412 | rm -f $tmp.list $tmp.tmp $tmp.sed | |
413 | ||
414 | if $randomize | |
415 | then | |
416 | list=`echo $list | awk -f randomize.awk` | |
417 | fi | |
418 | ||
419 | [ "$QEMU" = "" ] && _fatal "qemu not found" | |
420 | [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | |
a9660664 NT |
421 | [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found" |
422 | ||
423 | if [ "$IMGPROTO" = "nbd" ] ; then | |
424 | [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found" | |
425 | fi | |
2f24e8fb KW |
426 | |
427 | if $valgrind; then | |
428 | export REAL_QEMU_IO="$QEMU_IO_PROG" | |
429 | export QEMU_IO_PROG=valgrind_qemu_io | |
430 | fi |