xref: /openbmc/qemu/tests/qemu-iotests/213 (revision 4a4ff4c5)
1#!/bin/bash
2#
3# Test vhdx and file image creation
4#
5# Copyright (C) 2018 Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20
21# creator
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28status=1	# failure is the default!
29
30# get standard environment, filters and checks
31. ./common.rc
32. ./common.filter
33
34_supported_fmt vhdx
35_supported_proto file
36_supported_os Linux
37
38function do_run_qemu()
39{
40    echo Testing: "$@"
41    $QEMU -nographic -qmp stdio -serial none "$@"
42    echo
43}
44
45function run_qemu()
46{
47    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
48                          | _filter_qemu | _filter_imgfmt \
49                          | _filter_actual_image_size
50}
51
52echo
53echo "=== Successful image creation (defaults) ==="
54echo
55
56size=$((128 * 1024 * 1024))
57
58run_qemu <<EOF
59{ "execute": "qmp_capabilities" }
60{ "execute": "x-blockdev-create",
61  "arguments": {
62      "driver": "file",
63      "filename": "$TEST_IMG",
64      "size": 0
65  }
66}
67{ "execute": "blockdev-add",
68  "arguments": {
69      "driver": "file",
70      "node-name": "imgfile",
71      "filename": "$TEST_IMG"
72  }
73}
74{ "execute": "x-blockdev-create",
75  "arguments": {
76      "driver": "$IMGFMT",
77      "file": "imgfile",
78      "size": $size
79  }
80}
81{ "execute": "quit" }
82EOF
83
84_img_info --format-specific | _filter_img_info --format-specific
85
86echo
87echo "=== Successful image creation (explicit defaults) ==="
88echo
89
90# Choose a different size to show that we got a new image
91size=$((64 * 1024 * 1024))
92
93run_qemu <<EOF
94{ "execute": "qmp_capabilities" }
95{ "execute": "x-blockdev-create",
96  "arguments": {
97      "driver": "file",
98      "filename": "$TEST_IMG",
99      "size": 0
100  }
101}
102{ "execute": "x-blockdev-create",
103  "arguments": {
104      "driver": "$IMGFMT",
105      "file": {
106          "driver": "file",
107          "filename": "$TEST_IMG"
108      },
109      "size": $size,
110      "log-size": 1048576,
111      "block-size": 8388608,
112      "subformat": "dynamic",
113      "block-state-zero": true
114  }
115}
116{ "execute": "quit" }
117EOF
118
119_img_info --format-specific | _filter_img_info --format-specific
120
121echo
122echo "=== Successful image creation (with non-default options) ==="
123echo
124
125# Choose a different size to show that we got a new image
126size=$((32 * 1024 * 1024))
127
128run_qemu <<EOF
129{ "execute": "qmp_capabilities" }
130{ "execute": "x-blockdev-create",
131  "arguments": {
132      "driver": "file",
133      "filename": "$TEST_IMG",
134      "size": 0
135  }
136}
137{ "execute": "x-blockdev-create",
138  "arguments": {
139      "driver": "$IMGFMT",
140      "file": {
141          "driver": "file",
142          "filename": "$TEST_IMG"
143      },
144      "size": $size,
145      "log-size": 8388608,
146      "block-size": 268435456,
147      "subformat": "fixed",
148      "block-state-zero": false
149  }
150}
151{ "execute": "quit" }
152EOF
153
154_img_info --format-specific | _filter_img_info --format-specific
155
156echo
157echo "=== Invalid BlockdevRef ==="
158echo
159
160run_qemu <<EOF
161{ "execute": "qmp_capabilities" }
162{ "execute": "x-blockdev-create",
163  "arguments": {
164      "driver": "$IMGFMT",
165      "file": "this doesn't exist",
166      "size": $size
167  }
168}
169{ "execute": "quit" }
170EOF
171
172echo
173echo "=== Zero size ==="
174echo
175
176run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
177{ "execute": "qmp_capabilities" }
178{ "execute": "x-blockdev-create",
179  "arguments": {
180      "driver": "$IMGFMT",
181      "file": "node0",
182      "size": 0
183  }
184}
185{ "execute": "quit" }
186EOF
187
188_img_info | _filter_img_info
189
190echo
191echo "=== Maximum size ==="
192echo
193
194run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
195{ "execute": "qmp_capabilities" }
196{ "execute": "x-blockdev-create",
197  "arguments": {
198      "driver": "$IMGFMT",
199      "file": "node0",
200      "size": 70368744177664
201  }
202}
203{ "execute": "quit" }
204EOF
205
206_img_info | _filter_img_info
207
208echo
209echo "=== Invalid sizes ==="
210echo
211
212# TODO Negative image sizes aren't handled correctly, but this is a problem
213# with QAPI's implementation of the 'size' type and affects other commands as
214# well. Once this is fixed, we may want to add a test case here.
215
216# 1. 2^64 - 512
217# 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
218# 3. 2^63 - 512 (generally valid, but with the image header the file will
219#                exceed 63 bits)
220# 4. 2^46 + 1 (one byte more than maximum image size)
221
222run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
223{ "execute": "qmp_capabilities" }
224{ "execute": "x-blockdev-create",
225  "arguments": {
226      "driver": "$IMGFMT",
227      "file": "node0",
228      "size": 18446744073709551104
229  }
230}
231{ "execute": "x-blockdev-create",
232  "arguments": {
233      "driver": "$IMGFMT",
234      "file": "node0",
235      "size": 9223372036854775808
236  }
237}
238{ "execute": "x-blockdev-create",
239  "arguments": {
240      "driver": "$IMGFMT",
241      "file": "node0",
242      "size": 9223372036854775296
243  }
244}
245{ "execute": "x-blockdev-create",
246  "arguments": {
247      "driver": "$IMGFMT",
248      "file": "node0",
249      "size": 70368744177665
250  }
251}
252{ "execute": "quit" }
253EOF
254
255echo
256echo "=== Invalid block size ==="
257echo
258
259run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
260{ "execute": "qmp_capabilities" }
261{ "execute": "x-blockdev-create",
262  "arguments": {
263      "driver": "$IMGFMT",
264      "file": "node0",
265      "size": 67108864,
266      "block-size": 1234567
267  }
268}
269{ "execute": "x-blockdev-create",
270  "arguments": {
271      "driver": "$IMGFMT",
272      "file": "node0",
273      "size": 67108864,
274      "block-size": 128
275  }
276}
277{ "execute": "x-blockdev-create",
278  "arguments": {
279      "driver": "$IMGFMT",
280      "file": "node0",
281      "size": 67108864,
282      "block-size": 3145728
283  }
284}
285{ "execute": "x-blockdev-create",
286  "arguments": {
287      "driver": "$IMGFMT",
288      "file": "node0",
289      "size": 67108864,
290      "block-size": 536870912
291  }
292}
293{ "execute": "x-blockdev-create",
294  "arguments": {
295      "driver": "$IMGFMT",
296      "file": "node0",
297      "size": 67108864,
298      "block-size": 0
299  }
300}
301{ "execute": "quit" }
302EOF
303
304echo
305echo "=== Invalid log size ==="
306echo
307
308run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
309{ "execute": "qmp_capabilities" }
310{ "execute": "x-blockdev-create",
311  "arguments": {
312      "driver": "$IMGFMT",
313      "file": "node0",
314      "size": 67108864,
315      "log-size": 1234567
316  }
317}
318{ "execute": "x-blockdev-create",
319  "arguments": {
320      "driver": "$IMGFMT",
321      "file": "node0",
322      "size": 67108864,
323      "log-size": 128
324  }
325}
326{ "execute": "x-blockdev-create",
327  "arguments": {
328      "driver": "$IMGFMT",
329      "file": "node0",
330      "size": 67108864,
331      "log-size": 4294967296
332  }
333}
334{ "execute": "x-blockdev-create",
335  "arguments": {
336      "driver": "$IMGFMT",
337      "file": "node0",
338      "size": 67108864,
339      "log-size": 0
340  }
341}
342{ "execute": "quit" }
343EOF
344
345
346# success, all done
347echo "*** done"
348rm -f $seq.full
349status=0
350