xref: /openbmc/qemu/tests/qemu-iotests/212 (revision fbf32752)
1#!/bin/bash
2#
3# Test parallels 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 parallels
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      "cluster-size": 1048576
111  }
112}
113{ "execute": "quit" }
114EOF
115
116_img_info --format-specific | _filter_img_info --format-specific
117
118echo
119echo "=== Successful image creation (with non-default options) ==="
120echo
121
122# Choose a different size to show that we got a new image
123size=$((32 * 1024 * 1024))
124
125run_qemu <<EOF
126{ "execute": "qmp_capabilities" }
127{ "execute": "x-blockdev-create",
128  "arguments": {
129      "driver": "file",
130      "filename": "$TEST_IMG",
131      "size": 0
132  }
133}
134{ "execute": "x-blockdev-create",
135  "arguments": {
136      "driver": "$IMGFMT",
137      "file": {
138          "driver": "file",
139          "filename": "$TEST_IMG"
140      },
141      "size": $size,
142      "cluster-size": 65536
143  }
144}
145{ "execute": "quit" }
146EOF
147
148_img_info --format-specific | _filter_img_info --format-specific
149
150echo
151echo "=== Invalid BlockdevRef ==="
152echo
153
154run_qemu <<EOF
155{ "execute": "qmp_capabilities" }
156{ "execute": "x-blockdev-create",
157  "arguments": {
158      "driver": "$IMGFMT",
159      "file": "this doesn't exist",
160      "size": $size
161  }
162}
163{ "execute": "quit" }
164EOF
165
166echo
167echo "=== Zero size ==="
168echo
169
170run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
171{ "execute": "qmp_capabilities" }
172{ "execute": "x-blockdev-create",
173  "arguments": {
174      "driver": "$IMGFMT",
175      "file": "node0",
176      "size": 0
177  }
178}
179{ "execute": "quit" }
180EOF
181
182_img_info | _filter_img_info
183
184echo
185echo "=== Maximum size ==="
186echo
187
188run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
189{ "execute": "qmp_capabilities" }
190{ "execute": "x-blockdev-create",
191  "arguments": {
192      "driver": "$IMGFMT",
193      "file": "node0",
194      "size": 4503599627369984
195  }
196}
197{ "execute": "quit" }
198EOF
199
200_img_info | _filter_img_info
201
202echo
203echo "=== Invalid sizes ==="
204echo
205
206# TODO Negative image sizes aren't handled correctly, but this is a problem
207# with QAPI's implementation of the 'size' type and affects other commands as
208# well. Once this is fixed, we may want to add a test case here.
209
210# 1. Misaligned image size
211# 2. 2^64 - 512
212# 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
213# 4. 2^63 - 512 (generally valid, but with the image header the file will
214#                exceed 63 bits)
215# 5. 2^52 (512 bytes more than maximum image size)
216
217run_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": 1234
224  }
225}
226{ "execute": "x-blockdev-create",
227  "arguments": {
228      "driver": "$IMGFMT",
229      "file": "node0",
230      "size": 18446744073709551104
231  }
232}
233{ "execute": "x-blockdev-create",
234  "arguments": {
235      "driver": "$IMGFMT",
236      "file": "node0",
237      "size": 9223372036854775808
238  }
239}
240{ "execute": "x-blockdev-create",
241  "arguments": {
242      "driver": "$IMGFMT",
243      "file": "node0",
244      "size": 9223372036854775296
245  }
246}
247{ "execute": "x-blockdev-create",
248  "arguments": {
249      "driver": "$IMGFMT",
250      "file": "node0",
251      "size": 4503599627370497
252  }
253}
254{ "execute": "quit" }
255EOF
256
257echo
258echo "=== Invalid cluster size ==="
259echo
260
261run_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF
262{ "execute": "qmp_capabilities" }
263{ "execute": "x-blockdev-create",
264  "arguments": {
265      "driver": "$IMGFMT",
266      "file": "node0",
267      "size": 67108864,
268      "cluster-size": 1234
269  }
270}
271{ "execute": "x-blockdev-create",
272  "arguments": {
273      "driver": "$IMGFMT",
274      "file": "node0",
275      "size": 67108864,
276      "cluster-size": 128
277  }
278}
279{ "execute": "x-blockdev-create",
280  "arguments": {
281      "driver": "$IMGFMT",
282      "file": "node0",
283      "size": 67108864,
284      "cluster-size": 4294967296
285  }
286}
287{ "execute": "x-blockdev-create",
288  "arguments": {
289      "driver": "$IMGFMT",
290      "file": "node0",
291      "size": 67108864,
292      "cluster-size": 9223372036854775808
293  }
294}
295{ "execute": "x-blockdev-create",
296  "arguments": {
297      "driver": "$IMGFMT",
298      "file": "node0",
299      "size": 67108864,
300      "cluster-size": 18446744073709551104
301  }
302}
303{ "execute": "x-blockdev-create",
304  "arguments": {
305      "driver": "$IMGFMT",
306      "file": "node0",
307      "size": 67108864,
308      "cluster-size": 0
309  }
310}
311{ "execute": "x-blockdev-create",
312  "arguments": {
313      "driver": "$IMGFMT",
314      "file": "node0",
315      "size": 281474976710656,
316      "cluster-size": 512
317  }
318}
319{ "execute": "quit" }
320EOF
321
322
323# success, all done
324echo "*** done"
325rm -f $seq.full
326status=0
327