]> Git Repo - qemu.git/blame - tests/qemu-iotests/common
block: add support for encryption secrets in block I/O tests
[qemu.git] / tests / qemu-iotests / common
CommitLineData
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 28rm -f "$OUTPUT_DIR/$iam.out"
6bf19c94
CH
29_setenvironment
30
31check=${check-true}
32
33diff="diff -u"
34verbose=false
aa4f592a 35debug=false
6bf19c94
CH
36group=false
37xgroup=false
89004368 38imgopts=false
6bf19c94
CH
39showme=false
40sortme=false
41expunge=true
42have_test_arg=false
43randomize=false
3baa8449 44cachemode=false
6bf19c94
CH
45rm -f $tmp.list $tmp.tmp $tmp.sed
46
47export IMGFMT=raw
89e91181 48export IMGFMT_GENERIC=true
9cdfa1b3 49export IMGPROTO=file
89004368 50export IMGOPTS=""
e14fb913 51export CACHEMODE="writeback"
6bf19c94 52export QEMU_IO_OPTIONS=""
3baa8449 53export CACHEMODE_IS_DEFAULT=true
2711fd33 54export QEMU_OPTIONS="-nodefaults"
e6c17669 55export VALGRIND_QEMU=
b7e875b2 56export IMGKEYSECRET=
076003f5 57export IMGOPTSSYNTAX=false
6bf19c94
CH
58
59for r
60do
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
66s/ .*//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
91s/ .*//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
137common options
236c7964 138 -v verbose
aa4f592a 139 -d debug
6bf19c94
CH
140
141check 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 170testlist 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
212 -qed)
213 IMGFMT=qed
214 xpand=false
215 ;;
216
217 -vdi)
218 IMGFMT=vdi
219 xpand=false
220 ;;
221
222 -vmdk)
223 IMGFMT=vmdk
224 xpand=false
225 ;;
226
227 -vpc)
228 IMGFMT=vpc
229 xpand=false
230 ;;
231
89e91181
JC
232 -vhdx)
233 IMGFMT=vhdx
234 xpand=false
89e91181
JC
235 ;;
236
170632db
PL
237 -file)
238 IMGPROTO=file
239 xpand=false
240 ;;
241
79e40ab1
KW
242 -rbd)
243 IMGPROTO=rbd
244 xpand=false
245 ;;
170632db 246
79e40ab1
KW
247 -sheepdog)
248 IMGPROTO=sheepdog
249 xpand=false
250 ;;
170632db 251
79e40ab1
KW
252 -nbd)
253 IMGPROTO=nbd
254 xpand=false
255 ;;
170632db 256
342809e8
RJ
257 -ssh)
258 IMGPROTO=ssh
259 xpand=false
260 ;;
170632db
PL
261
262 -nfs)
263 IMGPROTO=nfs
264 xpand=false
265 ;;
266
746ebfa7
CN
267 -archipelago)
268 IMGPROTO=archipelago
269 xpand=false
270 ;;
271
79e40ab1 272 -nocache)
3baa8449
FZ
273 CACHEMODE="none"
274 CACHEMODE_IS_DEFAULT=false
79e40ab1
KW
275 xpand=false
276 ;;
6bf19c94 277
79e40ab1
KW
278 -misalign)
279 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
280 xpand=false
281 ;;
6bf19c94 282
170632db 283 -valgrind)
e6c17669 284 VALGRIND_QEMU='y'
79e40ab1 285 xpand=false
170632db 286 ;;
2f24e8fb 287
79e40ab1
KW
288 -g) # -g group ... pick from group file
289 group=true
290 xpand=false
291 ;;
292
293 -xdiff) # graphical diff mode
294 xpand=false
295
296 if [ ! -z "$DISPLAY" ]
297 then
e465ce7d
FZ
298 command -v xdiff >/dev/null 2>&1 && diff=xdiff
299 command -v gdiff >/dev/null 2>&1 && diff=gdiff
300 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
301 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
79e40ab1
KW
302 fi
303 ;;
304
305 -n) # show me, don't do it
306 showme=true
307 xpand=false
308 ;;
89004368
KW
309 -o)
310 imgopts=true
311 xpand=false
312 ;;
3baa8449
FZ
313 -c)
314 cachemode=true
315 xpand=false
316 ;;
79e40ab1
KW
317 -r) # randomize test order
318 randomize=true
319 xpand=false
320 ;;
321
322 -T) # turn on timestamp output
323 timestamp=true
324 xpand=false
325 ;;
326
327 -v)
328 verbose=true
329 xpand=false
330 ;;
aa4f592a
FZ
331 -d)
332 debug=true
333 xpand=false
334 ;;
79e40ab1
KW
335 -x) # -x group ... exclude from group file
336 xgroup=true
337 xpand=false
338 ;;
339 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
340 echo "No tests?"
341 status=1
342 exit $status
343 ;;
344
345 [0-9]*-[0-9]*)
346 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
347 ;;
348
349 [0-9]*-)
350 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
351 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/.* //'`
352 if [ -z "$end" ]
353 then
354 echo "No tests in range \"$r\"?"
355 status=1
356 exit $status
357 fi
358 ;;
359
360 *)
361 start=$r
362 end=$r
363 ;;
6bf19c94
CH
364
365 esac
366
367 # get rid of leading 0s as can be interpreted as octal
368 start=`echo $start | sed 's/^0*//'`
369 end=`echo $end | sed 's/^0*//'`
370
371 if $xpand
372 then
79e40ab1
KW
373 have_test_arg=true
374 $AWK_PROG </dev/null '
375BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
376 | while read id
377 do
e8f8624d 378 if grep -s "^$id " "$source_iotests/group" >/dev/null
79e40ab1
KW
379 then
380 # in group file ... OK
381 echo $id >>$tmp.list
382 else
383 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
384 then
385 # expunged ... will be reported, but not run, later
386 echo $id >>$tmp.list
387 else
388 # oops
c9d17ad0
FZ
389 if [ "$start" == "$end" -a "$id" == "$end" ]
390 then
391 echo "$id - unknown test"
392 exit 1
393 else
394 echo "$id - unknown test, ignored"
395 fi
79e40ab1
KW
396 fi
397 fi
c9d17ad0 398 done || exit 1
6bf19c94
CH
399 fi
400
401done
402
3baa8449 403# Set qemu-io cache mode with $CACHEMODE we have
076003f5
DB
404if [ "$IMGOPTSSYNTAX" = "true" ]; then
405 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
406else
407 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT --cache $CACHEMODE"
408fi
3baa8449 409
89004368
KW
410# Set default options for qemu-img create -o if they were not specified
411_set_default_imgopts
412
6bf19c94
CH
413if [ -s $tmp.list ]
414then
415 # found some valid test numbers ... this is good
416 :
417else
418 if $have_test_arg
419 then
79e40ab1
KW
420 # had test numbers, but none in group file ... do nothing
421 touch $tmp.list
6bf19c94 422 else
79e40ab1 423 # no test numbers, do everything from group file
e8f8624d 424 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
6bf19c94
CH
425 fi
426fi
427
428# should be sort -n, but this did not work for Linux when this
429# was ported from IRIX
430#
431list=`sort $tmp.list`
432rm -f $tmp.list $tmp.tmp $tmp.sed
433
434if $randomize
435then
436 list=`echo $list | awk -f randomize.awk`
437fi
438
439[ "$QEMU" = "" ] && _fatal "qemu not found"
440[ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
a9660664
NT
441[ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
442
443if [ "$IMGPROTO" = "nbd" ] ; then
444 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"
445fi
This page took 0.432661 seconds and 4 git commands to generate.