3 # Test VDI 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/>.
22 owner
=kwolf@redhat.com
25 echo "QA output created by $seq"
28 status
=1 # failure is the default!
30 # get standard environment, filters and checks
38 function do_run_qemu
()
41 $QEMU -nographic -qmp stdio
-serial none
"$@"
47 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qmp \
48 | _filter_qemu | _filter_imgfmt \
49 | _filter_actual_image_size
53 echo "=== Successful image creation (defaults) ==="
56 size
=$
((128 * 1024 * 1024))
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
63 "filename": "$TEST_IMG",
67 { "execute": "blockdev-add",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG"
74 { "execute": "x-blockdev-create",
84 _img_info
--format-specific | _filter_img_info
--format-specific
85 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map
88 echo "=== Successful image creation (explicit defaults) ==="
91 # Choose a different size to show that we got a new image
92 size
=$
((64 * 1024 * 1024))
95 { "execute": "qmp_capabilities" }
96 { "execute": "x-blockdev-create",
99 "filename": "$TEST_IMG",
103 { "execute": "x-blockdev-create",
108 "filename": "$TEST_IMG"
111 "preallocation": "off"
114 { "execute": "quit" }
117 _img_info
--format-specific | _filter_img_info
--format-specific
118 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map
121 echo "=== Successful image creation (with non-default options) ==="
124 # Choose a different size to show that we got a new image
125 size
=$
((32 * 1024 * 1024))
128 { "execute": "qmp_capabilities" }
129 { "execute": "x-blockdev-create",
132 "filename": "$TEST_IMG",
136 { "execute": "x-blockdev-create",
141 "filename": "$TEST_IMG"
144 "preallocation": "metadata"
147 { "execute": "quit" }
150 _img_info
--format-specific | _filter_img_info
--format-specific
151 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map
154 echo "=== Invalid BlockdevRef ==="
158 { "execute": "qmp_capabilities" }
159 { "execute": "x-blockdev-create",
162 "file": "this doesn't exist",
166 { "execute": "quit" }
170 echo "=== Zero size ==="
173 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
174 { "execute": "qmp_capabilities" }
175 { "execute": "x-blockdev-create",
182 { "execute": "quit" }
185 _img_info | _filter_img_info
188 echo "=== Maximum size ==="
191 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
192 { "execute": "qmp_capabilities" }
193 { "execute": "x-blockdev-create",
197 "size": 562949819203584
200 { "execute": "quit" }
203 _img_info | _filter_img_info
206 echo "=== Invalid sizes ==="
209 # TODO Negative image sizes aren't handled correctly, but this is a problem
210 # with QAPI's implementation of the 'size' type and affects other commands as
211 # well. Once this is fixed, we may want to add a test case here.
214 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
215 # 3. 0x1fffff8000001 (one byte more than maximum image size for VDI)
217 run_qemu
-blockdev driver
=file,filename
="$TEST_IMG",node-name
=node0
<<EOF
218 { "execute": "qmp_capabilities" }
219 { "execute": "x-blockdev-create",
223 "size": 18446744073709551104
226 { "execute": "x-blockdev-create",
230 "size": 9223372036854775808
233 { "execute": "x-blockdev-create",
237 "size": 562949819203585
240 { "execute": "quit" }