vhost: Allow adjoining regions
[qemu/ar7.git] / tests / qemu-iotests / 211
blob1edec26517158bce319cc9b2b8b134f23a28d3cf
1 #!/bin/bash
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/>.
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 vdi
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 | _filter_img_info --format-specific
85 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
87 echo
88 echo "=== Successful image creation (explicit defaults) ==="
89 echo
91 # Choose a different size to show that we got a new image
92 size=$((64 * 1024 * 1024))
94 run_qemu <<EOF
95 { "execute": "qmp_capabilities" }
96 { "execute": "x-blockdev-create",
97 "arguments": {
98 "driver": "file",
99 "filename": "$TEST_IMG",
100 "size": 0
103 { "execute": "x-blockdev-create",
104 "arguments": {
105 "driver": "$IMGFMT",
106 "file": {
107 "driver": "file",
108 "filename": "$TEST_IMG"
110 "size": $size,
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
120 echo
121 echo "=== Successful image creation (with non-default options) ==="
122 echo
124 # Choose a different size to show that we got a new image
125 size=$((32 * 1024 * 1024))
127 run_qemu <<EOF
128 { "execute": "qmp_capabilities" }
129 { "execute": "x-blockdev-create",
130 "arguments": {
131 "driver": "file",
132 "filename": "$TEST_IMG",
133 "size": 0
136 { "execute": "x-blockdev-create",
137 "arguments": {
138 "driver": "$IMGFMT",
139 "file": {
140 "driver": "file",
141 "filename": "$TEST_IMG"
143 "size": $size,
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
153 echo
154 echo "=== Invalid BlockdevRef ==="
155 echo
157 run_qemu <<EOF
158 { "execute": "qmp_capabilities" }
159 { "execute": "x-blockdev-create",
160 "arguments": {
161 "driver": "$IMGFMT",
162 "file": "this doesn't exist",
163 "size": $size
166 { "execute": "quit" }
169 echo
170 echo "=== Zero size ==="
171 echo
173 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
174 { "execute": "qmp_capabilities" }
175 { "execute": "x-blockdev-create",
176 "arguments": {
177 "driver": "$IMGFMT",
178 "file": "node0",
179 "size": 0
182 { "execute": "quit" }
185 _img_info | _filter_img_info
187 echo
188 echo "=== Maximum size ==="
189 echo
191 run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
192 { "execute": "qmp_capabilities" }
193 { "execute": "x-blockdev-create",
194 "arguments": {
195 "driver": "$IMGFMT",
196 "file": "node0",
197 "size": 562949819203584
200 { "execute": "quit" }
203 _img_info | _filter_img_info
205 echo
206 echo "=== Invalid sizes ==="
207 echo
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.
213 # 1. 2^64 - 512
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",
220 "arguments": {
221 "driver": "$IMGFMT",
222 "file": "node0",
223 "size": 18446744073709551104
226 { "execute": "x-blockdev-create",
227 "arguments": {
228 "driver": "$IMGFMT",
229 "file": "node0",
230 "size": 9223372036854775808
233 { "execute": "x-blockdev-create",
234 "arguments": {
235 "driver": "$IMGFMT",
236 "file": "node0",
237 "size": 562949819203585
240 { "execute": "quit" }
243 # success, all done
244 echo "*** done"
245 rm -f $seq.full
246 status=0