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