]>
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 |
6bf19c94 CH |
45 | rm -f $tmp.list $tmp.tmp $tmp.sed |
46 | ||
47 | export IMGFMT=raw | |
9cdfa1b3 | 48 | export IMGPROTO=file |
89004368 | 49 | export IMGOPTS="" |
6bf19c94 CH |
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 | |
89004368 KW |
109 | |
110 | elif $imgopts | |
111 | then | |
112 | IMGOPTS="$r" | |
113 | imgopts=false | |
114 | continue | |
115 | ||
6bf19c94 CH |
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 | |
f5a4bbd9 | 133 | -qed test qed |
b67f3068 | 134 | -vdi test vdi |
6bf19c94 CH |
135 | -vpc test vpc |
136 | -vmdk test vmdk | |
9cdfa1b3 MK |
137 | -rbd test rbd |
138 | -sheepdog test sheepdog | |
a9660664 | 139 | -nbd test nbd |
6bf19c94 CH |
140 | -xdiff graphical mode diff |
141 | -nocache use O_DIRECT on backing file | |
142 | -misalign misalign memory allocations | |
143 | -n show me, do not run tests | |
89004368 | 144 | -o options -o options to pass to qemu-img create/convert |
6bf19c94 CH |
145 | -T output timestamps |
146 | -r randomize test order | |
147 | ||
148 | testlist options | |
149 | -g group[,group...] include tests from these groups | |
150 | -x group[,group...] exclude tests from these groups | |
151 | NNN include test NNN | |
152 | NNN-NNN include test range (eg. 012-021) | |
153 | ' | |
154 | exit 0 | |
155 | ;; | |
156 | ||
157 | -raw) | |
158 | IMGFMT=raw | |
159 | xpand=false | |
160 | ;; | |
161 | ||
162 | -cow) | |
163 | IMGFMT=cow | |
164 | xpand=false | |
165 | ;; | |
166 | ||
167 | -qcow) | |
168 | IMGFMT=qcow | |
169 | xpand=false | |
170 | ;; | |
171 | ||
172 | -qcow2) | |
173 | IMGFMT=qcow2 | |
174 | xpand=false | |
175 | ;; | |
176 | ||
f5a4bbd9 SH |
177 | -qed) |
178 | IMGFMT=qed | |
179 | xpand=false | |
180 | ;; | |
181 | ||
b67f3068 CH |
182 | -vdi) |
183 | IMGFMT=vdi | |
184 | xpand=false | |
185 | ;; | |
186 | ||
6bf19c94 CH |
187 | -vmdk) |
188 | IMGFMT=vmdk | |
189 | xpand=false | |
190 | ;; | |
191 | ||
192 | -vpc) | |
193 | IMGFMT=vpc | |
194 | xpand=false | |
195 | ;; | |
196 | ||
9cdfa1b3 MK |
197 | -rbd) |
198 | IMGPROTO=rbd | |
199 | xpand=false | |
200 | ;; | |
9cdfa1b3 MK |
201 | -sheepdog) |
202 | IMGPROTO=sheepdog | |
203 | xpand=false | |
204 | ;; | |
a9660664 NT |
205 | -nbd) |
206 | IMGPROTO=nbd | |
207 | xpand=false | |
208 | ;; | |
6bf19c94 CH |
209 | -nocache) |
210 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache" | |
211 | xpand=false | |
212 | ;; | |
213 | ||
214 | -misalign) | |
215 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | |
216 | xpand=false | |
217 | ;; | |
218 | ||
2f24e8fb KW |
219 | -valgrind) |
220 | valgrind=true | |
221 | xpand=false | |
222 | ;; | |
223 | ||
6bf19c94 CH |
224 | -g) # -g group ... pick from group file |
225 | group=true | |
226 | xpand=false | |
227 | ;; | |
228 | ||
229 | -xdiff) # graphical diff mode | |
230 | xpand=false | |
231 | ||
232 | if [ ! -z "$DISPLAY" ] | |
233 | then | |
234 | which xdiff >/dev/null 2>&1 && diff=xdiff | |
235 | which gdiff >/dev/null 2>&1 && diff=gdiff | |
236 | which tkdiff >/dev/null 2>&1 && diff=tkdiff | |
237 | which xxdiff >/dev/null 2>&1 && diff=xxdiff | |
238 | fi | |
239 | ;; | |
240 | ||
241 | -n) # show me, don't do it | |
242 | showme=true | |
243 | xpand=false | |
244 | ;; | |
89004368 KW |
245 | -o) |
246 | imgopts=true | |
247 | xpand=false | |
248 | ;; | |
6bf19c94 CH |
249 | -r) # randomize test order |
250 | randomize=true | |
251 | xpand=false | |
252 | ;; | |
253 | ||
254 | -T) # turn on timestamp output | |
255 | timestamp=true | |
256 | xpand=false | |
257 | ;; | |
258 | ||
259 | -v) | |
260 | verbose=true | |
261 | xpand=false | |
262 | ;; | |
263 | -x) # -x group ... exclude from group file | |
264 | xgroup=true | |
265 | xpand=false | |
266 | ;; | |
267 | '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') | |
268 | echo "No tests?" | |
269 | status=1 | |
270 | exit $status | |
271 | ;; | |
272 | ||
273 | [0-9]*-[0-9]*) | |
274 | eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | |
275 | ;; | |
276 | ||
277 | [0-9]*-) | |
278 | eval `echo $r | sed -e 's/^/start=/' -e 's/-//'` | |
279 | 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/.* //'` | |
280 | if [ -z "$end" ] | |
281 | then | |
282 | echo "No tests in range \"$r\"?" | |
283 | status=1 | |
284 | exit $status | |
285 | fi | |
286 | ;; | |
287 | ||
288 | *) | |
289 | start=$r | |
290 | end=$r | |
291 | ;; | |
292 | ||
293 | esac | |
294 | ||
295 | # get rid of leading 0s as can be interpreted as octal | |
296 | start=`echo $start | sed 's/^0*//'` | |
297 | end=`echo $end | sed 's/^0*//'` | |
298 | ||
299 | if $xpand | |
300 | then | |
301 | have_test_arg=true | |
302 | $AWK_PROG </dev/null ' | |
303 | BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | |
304 | | while read id | |
305 | do | |
306 | if grep -s "^$id " group >/dev/null | |
307 | then | |
308 | # in group file ... OK | |
309 | echo $id >>$tmp.list | |
310 | else | |
311 | if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null | |
312 | then | |
313 | # expunged ... will be reported, but not run, later | |
314 | echo $id >>$tmp.list | |
315 | else | |
316 | # oops | |
317 | echo "$id - unknown test, ignored" | |
318 | fi | |
319 | fi | |
320 | done | |
321 | fi | |
322 | ||
323 | done | |
324 | ||
89004368 KW |
325 | # Set default options for qemu-img create -o if they were not specified |
326 | _set_default_imgopts | |
327 | ||
6bf19c94 CH |
328 | if [ -s $tmp.list ] |
329 | then | |
330 | # found some valid test numbers ... this is good | |
331 | : | |
332 | else | |
333 | if $have_test_arg | |
334 | then | |
335 | # had test numbers, but none in group file ... do nothing | |
336 | touch $tmp.list | |
337 | else | |
338 | # no test numbers, do everything from group file | |
339 | sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list | |
340 | fi | |
341 | fi | |
342 | ||
343 | # should be sort -n, but this did not work for Linux when this | |
344 | # was ported from IRIX | |
345 | # | |
346 | list=`sort $tmp.list` | |
347 | rm -f $tmp.list $tmp.tmp $tmp.sed | |
348 | ||
349 | if $randomize | |
350 | then | |
351 | list=`echo $list | awk -f randomize.awk` | |
352 | fi | |
353 | ||
354 | [ "$QEMU" = "" ] && _fatal "qemu not found" | |
355 | [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | |
a9660664 NT |
356 | [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found" |
357 | ||
358 | if [ "$IMGPROTO" = "nbd" ] ; then | |
359 | [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found" | |
360 | fi | |
2f24e8fb KW |
361 | |
362 | if $valgrind; then | |
363 | export REAL_QEMU_IO="$QEMU_IO_PROG" | |
364 | export QEMU_IO_PROG=valgrind_qemu_io | |
365 | fi |