]>
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 | |
38 | showme=false | |
39 | sortme=false | |
40 | expunge=true | |
41 | have_test_arg=false | |
42 | randomize=false | |
43 | rm -f $tmp.list $tmp.tmp $tmp.sed | |
44 | ||
45 | export IMGFMT=raw | |
46 | export QEMU_IO_OPTIONS="" | |
47 | ||
48 | for r | |
49 | do | |
50 | ||
51 | if $group | |
52 | then | |
53 | # arg after -g | |
54 | group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | |
55 | s/ .*//p | |
56 | }'` | |
57 | if [ -z "$group_list" ] | |
58 | then | |
59 | echo "Group \"$r\" is empty or not defined?" | |
60 | exit 1 | |
61 | fi | |
62 | [ ! -s $tmp.list ] && touch $tmp.list | |
63 | for t in $group_list | |
64 | do | |
65 | if grep -s "^$t\$" $tmp.list >/dev/null | |
66 | then | |
67 | : | |
68 | else | |
69 | echo "$t" >>$tmp.list | |
70 | fi | |
71 | done | |
72 | group=false | |
73 | continue | |
74 | ||
75 | elif $xgroup | |
76 | then | |
77 | # arg after -x | |
78 | [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null | |
79 | group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | |
80 | s/ .*//p | |
81 | }'` | |
82 | if [ -z "$group_list" ] | |
83 | then | |
84 | echo "Group \"$r\" is empty or not defined?" | |
85 | exit 1 | |
86 | fi | |
87 | numsed=0 | |
88 | rm -f $tmp.sed | |
89 | for t in $group_list | |
90 | do | |
91 | if [ $numsed -gt 100 ] | |
92 | then | |
93 | sed -f $tmp.sed <$tmp.list >$tmp.tmp | |
94 | mv $tmp.tmp $tmp.list | |
95 | numsed=0 | |
96 | rm -f $tmp.sed | |
97 | fi | |
98 | echo "/^$t\$/d" >>$tmp.sed | |
99 | numsed=`expr $numsed + 1` | |
100 | done | |
101 | sed -f $tmp.sed <$tmp.list >$tmp.tmp | |
102 | mv $tmp.tmp $tmp.list | |
103 | xgroup=false | |
104 | continue | |
105 | fi | |
106 | ||
107 | xpand=true | |
108 | case "$r" | |
109 | in | |
110 | ||
111 | -\? | -h | --help) # usage | |
112 | echo "Usage: $0 [options] [testlist]"' | |
113 | ||
114 | common options | |
115 | -v verbose | |
116 | ||
117 | check options | |
118 | -raw test raw (default) | |
119 | -cow test cow | |
120 | -qcow test qcow | |
121 | -qcow2 test qcow2 | |
f5a4bbd9 | 122 | -qed test qed |
b67f3068 | 123 | -vdi test vdi |
6bf19c94 CH |
124 | -vpc test vpc |
125 | -vmdk test vmdk | |
126 | -xdiff graphical mode diff | |
127 | -nocache use O_DIRECT on backing file | |
128 | -misalign misalign memory allocations | |
129 | -n show me, do not run tests | |
130 | -T output timestamps | |
131 | -r randomize test order | |
132 | ||
133 | testlist options | |
134 | -g group[,group...] include tests from these groups | |
135 | -x group[,group...] exclude tests from these groups | |
136 | NNN include test NNN | |
137 | NNN-NNN include test range (eg. 012-021) | |
138 | ' | |
139 | exit 0 | |
140 | ;; | |
141 | ||
142 | -raw) | |
143 | IMGFMT=raw | |
144 | xpand=false | |
145 | ;; | |
146 | ||
147 | -cow) | |
148 | IMGFMT=cow | |
149 | xpand=false | |
150 | ;; | |
151 | ||
152 | -qcow) | |
153 | IMGFMT=qcow | |
154 | xpand=false | |
155 | ;; | |
156 | ||
157 | -qcow2) | |
158 | IMGFMT=qcow2 | |
159 | xpand=false | |
160 | ;; | |
161 | ||
f5a4bbd9 SH |
162 | -qed) |
163 | IMGFMT=qed | |
164 | xpand=false | |
165 | ;; | |
166 | ||
b67f3068 CH |
167 | -vdi) |
168 | IMGFMT=vdi | |
169 | xpand=false | |
170 | ;; | |
171 | ||
6bf19c94 CH |
172 | -vmdk) |
173 | IMGFMT=vmdk | |
174 | xpand=false | |
175 | ;; | |
176 | ||
177 | -vpc) | |
178 | IMGFMT=vpc | |
179 | xpand=false | |
180 | ;; | |
181 | ||
182 | -nocache) | |
183 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --nocache" | |
184 | xpand=false | |
185 | ;; | |
186 | ||
187 | -misalign) | |
188 | QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | |
189 | xpand=false | |
190 | ;; | |
191 | ||
192 | -g) # -g group ... pick from group file | |
193 | group=true | |
194 | xpand=false | |
195 | ;; | |
196 | ||
197 | -xdiff) # graphical diff mode | |
198 | xpand=false | |
199 | ||
200 | if [ ! -z "$DISPLAY" ] | |
201 | then | |
202 | which xdiff >/dev/null 2>&1 && diff=xdiff | |
203 | which gdiff >/dev/null 2>&1 && diff=gdiff | |
204 | which tkdiff >/dev/null 2>&1 && diff=tkdiff | |
205 | which xxdiff >/dev/null 2>&1 && diff=xxdiff | |
206 | fi | |
207 | ;; | |
208 | ||
209 | -n) # show me, don't do it | |
210 | showme=true | |
211 | xpand=false | |
212 | ;; | |
213 | -r) # randomize test order | |
214 | randomize=true | |
215 | xpand=false | |
216 | ;; | |
217 | ||
218 | -T) # turn on timestamp output | |
219 | timestamp=true | |
220 | xpand=false | |
221 | ;; | |
222 | ||
223 | -v) | |
224 | verbose=true | |
225 | xpand=false | |
226 | ;; | |
227 | -x) # -x group ... exclude from group file | |
228 | xgroup=true | |
229 | xpand=false | |
230 | ;; | |
231 | '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') | |
232 | echo "No tests?" | |
233 | status=1 | |
234 | exit $status | |
235 | ;; | |
236 | ||
237 | [0-9]*-[0-9]*) | |
238 | eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | |
239 | ;; | |
240 | ||
241 | [0-9]*-) | |
242 | eval `echo $r | sed -e 's/^/start=/' -e 's/-//'` | |
243 | 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/.* //'` | |
244 | if [ -z "$end" ] | |
245 | then | |
246 | echo "No tests in range \"$r\"?" | |
247 | status=1 | |
248 | exit $status | |
249 | fi | |
250 | ;; | |
251 | ||
252 | *) | |
253 | start=$r | |
254 | end=$r | |
255 | ;; | |
256 | ||
257 | esac | |
258 | ||
259 | # get rid of leading 0s as can be interpreted as octal | |
260 | start=`echo $start | sed 's/^0*//'` | |
261 | end=`echo $end | sed 's/^0*//'` | |
262 | ||
263 | if $xpand | |
264 | then | |
265 | have_test_arg=true | |
266 | $AWK_PROG </dev/null ' | |
267 | BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | |
268 | | while read id | |
269 | do | |
270 | if grep -s "^$id " group >/dev/null | |
271 | then | |
272 | # in group file ... OK | |
273 | echo $id >>$tmp.list | |
274 | else | |
275 | if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null | |
276 | then | |
277 | # expunged ... will be reported, but not run, later | |
278 | echo $id >>$tmp.list | |
279 | else | |
280 | # oops | |
281 | echo "$id - unknown test, ignored" | |
282 | fi | |
283 | fi | |
284 | done | |
285 | fi | |
286 | ||
287 | done | |
288 | ||
289 | if [ -s $tmp.list ] | |
290 | then | |
291 | # found some valid test numbers ... this is good | |
292 | : | |
293 | else | |
294 | if $have_test_arg | |
295 | then | |
296 | # had test numbers, but none in group file ... do nothing | |
297 | touch $tmp.list | |
298 | else | |
299 | # no test numbers, do everything from group file | |
300 | sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <group >$tmp.list | |
301 | fi | |
302 | fi | |
303 | ||
304 | # should be sort -n, but this did not work for Linux when this | |
305 | # was ported from IRIX | |
306 | # | |
307 | list=`sort $tmp.list` | |
308 | rm -f $tmp.list $tmp.tmp $tmp.sed | |
309 | ||
310 | if $randomize | |
311 | then | |
312 | list=`echo $list | awk -f randomize.awk` | |
313 | fi | |
314 | ||
315 | [ "$QEMU" = "" ] && _fatal "qemu not found" | |
316 | [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | |
317 | [ "$QEMU_IO" = "" ] && _fatal "qemu-img not found" |