Remove empty dummy file "loaders.cache" during uninstall (bug #1766841)
[qemu/ar7.git] / tests / qemu-iotests / 206
blob0a18b2b19a081976c5378958ca8a8e039bb72d8c
1 #!/bin/bash
3 # Test qcow2 and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 status=1 # failure is the default!
30 # get standard environment, filters and checks
31 . ./common.rc
32 . ./common.filter
34 _supported_fmt qcow2
35 _supported_proto file
36 _supported_os Linux
38 function do_run_qemu()
40 echo Testing: "$@"
41 $QEMU -nographic -qmp stdio -serial none "$@"
42 echo
45 function run_qemu()
47 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
48 | _filter_qemu | _filter_imgfmt \
49 | _filter_actual_image_size
52 echo
53 echo "=== Successful image creation (defaults) ==="
54 echo
56 size=$((128 * 1024 * 1024))
58 run_qemu <<EOF
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
61 "arguments": {
62 "driver": "file",
63 "filename": "$TEST_IMG",
64 "size": 0
67 { "execute": "blockdev-add",
68 "arguments": {
69 "driver": "file",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG"
74 { "execute": "x-blockdev-create",
75 "arguments": {
76 "driver": "$IMGFMT",
77 "file": "imgfile",
78 "size": $size
81 { "execute": "quit" }
82 EOF
84 _img_info --format-specific
86 echo
87 echo "=== Successful image creation (inline blockdev-add, explicit defaults) ==="
88 echo
90 # Choose a different size to show that we got a new image
91 size=$((64 * 1024 * 1024))
93 run_qemu <<EOF
94 { "execute": "qmp_capabilities" }
95 { "execute": "x-blockdev-create",
96 "arguments": {
97 "driver": "file",
98 "filename": "$TEST_IMG",
99 "size": 0,
100 "preallocation": "off",
101 "nocow": false
104 { "execute": "x-blockdev-create",
105 "arguments": {
106 "driver": "$IMGFMT",
107 "file": {
108 "driver": "file",
109 "filename": "$TEST_IMG"
111 "size": $size,
112 "version": "v3",
113 "cluster-size": 65536,
114 "preallocation": "off",
115 "lazy-refcounts": false,
116 "refcount-bits": 16
119 { "execute": "quit" }
122 _img_info --format-specific
124 echo
125 echo "=== Successful image creation (v3 non-default options) ==="
126 echo
128 # Choose a different size to show that we got a new image
129 size=$((32 * 1024 * 1024))
131 run_qemu <<EOF
132 { "execute": "qmp_capabilities" }
133 { "execute": "x-blockdev-create",
134 "arguments": {
135 "driver": "file",
136 "filename": "$TEST_IMG",
137 "size": 0,
138 "preallocation": "falloc",
139 "nocow": true
142 { "execute": "x-blockdev-create",
143 "arguments": {
144 "driver": "$IMGFMT",
145 "file": {
146 "driver": "file",
147 "filename": "$TEST_IMG"
149 "size": $size,
150 "version": "v3",
151 "cluster-size": 2097152,
152 "preallocation": "metadata",
153 "lazy-refcounts": true,
154 "refcount-bits": 1
157 { "execute": "quit" }
160 _img_info --format-specific
162 echo
163 echo "=== Successful image creation (v2 non-default options) ==="
164 echo
166 mv $TEST_IMG $TEST_IMG.base
168 run_qemu <<EOF
169 { "execute": "qmp_capabilities" }
170 { "execute": "x-blockdev-create",
171 "arguments": {
172 "driver": "file",
173 "filename": "$TEST_IMG",
174 "size": 0
177 { "execute": "x-blockdev-create",
178 "arguments": {
179 "driver": "$IMGFMT",
180 "file": {
181 "driver": "file",
182 "filename": "$TEST_IMG"
184 "size": $size,
185 "backing-file": "$TEST_IMG.base",
186 "backing-fmt": "qcow2",
187 "version": "v2",
188 "cluster-size": 512
191 { "execute": "quit" }
194 _img_info --format-specific
196 echo
197 echo "=== Successful image creation (encrypted) ==="
198 echo
200 run_qemu -object secret,id=keysec0,data="foo" <<EOF
201 { "execute": "qmp_capabilities" }
202 { "execute": "x-blockdev-create",
203 "arguments": {
204 "driver": "$IMGFMT",
205 "file": {
206 "driver": "file",
207 "filename": "$TEST_IMG"
209 "size": $size,
210 "encrypt": {
211 "format": "luks",
212 "key-secret": "keysec0",
213 "cipher-alg": "twofish-128",
214 "cipher-mode": "ctr",
215 "ivgen-alg": "plain64",
216 "ivgen-hash-alg": "md5",
217 "hash-alg": "sha1",
218 "iter-time": 10
222 { "execute": "quit" }
225 _img_info --format-specific | _filter_img_info --format-specific
227 echo
228 echo "=== Invalid BlockdevRef ==="
229 echo
231 run_qemu <<EOF
232 { "execute": "qmp_capabilities" }
233 { "execute": "x-blockdev-create",
234 "arguments": {
235 "driver": "$IMGFMT",
236 "file": "this doesn't exist",
237 "size": $size
240 { "execute": "quit" }
244 echo
245 echo "=== Invalid sizes ==="
246 echo
248 # TODO Negative image sizes aren't handled correctly, but this is a problem
249 # with QAPI's implementation of the 'size' type and affects other commands as
250 # well. Once this is fixed, we may want to add a test case here.
252 # 1. Misaligned image size
253 # 2. 2^64 - 512
254 # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
255 # 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size)
257 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
258 { "execute": "qmp_capabilities" }
259 { "execute": "x-blockdev-create",
260 "arguments": {
261 "driver": "$IMGFMT",
262 "file": "node0",
263 "size": 1234
266 { "execute": "x-blockdev-create",
267 "arguments": {
268 "driver": "$IMGFMT",
269 "file": "node0",
270 "size": 18446744073709551104
273 { "execute": "x-blockdev-create",
274 "arguments": {
275 "driver": "$IMGFMT",
276 "file": "node0",
277 "size": 9223372036854775808
280 { "execute": "x-blockdev-create",
281 "arguments": {
282 "driver": "$IMGFMT",
283 "file": "node0",
284 "size": 9223372036854775296
287 { "execute": "quit" }
290 echo
291 echo "=== Invalid version ==="
292 echo
294 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
295 { "execute": "qmp_capabilities" }
296 { "execute": "x-blockdev-create",
297 "arguments": {
298 "driver": "$IMGFMT",
299 "file": "node0",
300 "size": 67108864,
301 "version": "v1"
304 { "execute": "x-blockdev-create",
305 "arguments": {
306 "driver": "$IMGFMT",
307 "file": "node0",
308 "size": 67108864,
309 "version": "v2",
310 "lazy-refcounts": true
313 { "execute": "x-blockdev-create",
314 "arguments": {
315 "driver": "$IMGFMT",
316 "file": "node0",
317 "size": 67108864,
318 "version": "v2",
319 "refcount-bits": 8
322 { "execute": "quit" }
325 echo
326 echo "=== Invalid backing file options ==="
327 echo
329 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
330 { "execute": "qmp_capabilities" }
331 { "execute": "x-blockdev-create",
332 "arguments": {
333 "driver": "$IMGFMT",
334 "file": "node0",
335 "size": 67108864,
336 "backing-file": "/dev/null",
337 "preallocation": "full"
340 { "execute": "x-blockdev-create",
341 "arguments": {
342 "driver": "$IMGFMT",
343 "file": "node0",
344 "size": 67108864,
345 "backing-fmt": "$IMGFMT"
348 { "execute": "quit" }
351 echo
352 echo "=== Invalid cluster size ==="
353 echo
355 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
356 { "execute": "qmp_capabilities" }
357 { "execute": "x-blockdev-create",
358 "arguments": {
359 "driver": "$IMGFMT",
360 "file": "node0",
361 "size": 67108864,
362 "cluster-size": 1234
365 { "execute": "x-blockdev-create",
366 "arguments": {
367 "driver": "$IMGFMT",
368 "file": "node0",
369 "size": 67108864,
370 "cluster-size": 128
373 { "execute": "x-blockdev-create",
374 "arguments": {
375 "driver": "$IMGFMT",
376 "file": "node0",
377 "size": 67108864,
378 "cluster-size": 4194304
381 { "execute": "x-blockdev-create",
382 "arguments": {
383 "driver": "$IMGFMT",
384 "file": "node0",
385 "size": 67108864,
386 "cluster-size": 0
389 { "execute": "x-blockdev-create",
390 "arguments": {
391 "driver": "$IMGFMT",
392 "file": "node0",
393 "size": 281474976710656,
394 "cluster-size": 512
397 { "execute": "quit" }
400 echo
401 echo "=== Invalid refcount width ==="
402 echo
404 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
405 { "execute": "qmp_capabilities" }
406 { "execute": "x-blockdev-create",
407 "arguments": {
408 "driver": "$IMGFMT",
409 "file": "node0",
410 "size": 67108864,
411 "refcount-bits": 128
414 { "execute": "x-blockdev-create",
415 "arguments": {
416 "driver": "$IMGFMT",
417 "file": "node0",
418 "size": 67108864,
419 "refcount-bits": 0
422 { "execute": "x-blockdev-create",
423 "arguments": {
424 "driver": "$IMGFMT",
425 "file": "node0",
426 "size": 67108864,
427 "refcount-bits": 7
430 { "execute": "quit" }
433 # success, all done
434 echo "*** done"
435 rm -f $seq.full
436 status=0