xref: /openbmc/qemu/tests/qemu-iotests/211 (revision 2b108085)
1#!/bin/bash
2#
3# Test VDI 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 vdi
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$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
86
87echo
88echo "=== Successful image creation (explicit defaults) ==="
89echo
90
91# Choose a different size to show that we got a new image
92size=$((64 * 1024 * 1024))
93
94run_qemu <<EOF
95{ "execute": "qmp_capabilities" }
96{ "execute": "x-blockdev-create",
97  "arguments": {
98      "driver": "file",
99      "filename": "$TEST_IMG",
100      "size": 0
101  }
102}
103{ "execute": "x-blockdev-create",
104  "arguments": {
105      "driver": "$IMGFMT",
106      "file": {
107          "driver": "file",
108          "filename": "$TEST_IMG"
109      },
110      "size": $size,
111      "preallocation": "off"
112  }
113}
114{ "execute": "quit" }
115EOF
116
117_img_info --format-specific | _filter_img_info --format-specific
118$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
119
120echo
121echo "=== Successful image creation (with non-default options) ==="
122echo
123
124# Choose a different size to show that we got a new image
125size=$((32 * 1024 * 1024))
126
127run_qemu <<EOF
128{ "execute": "qmp_capabilities" }
129{ "execute": "x-blockdev-create",
130  "arguments": {
131      "driver": "file",
132      "filename": "$TEST_IMG",
133      "size": 0
134  }
135}
136{ "execute": "x-blockdev-create",
137  "arguments": {
138      "driver": "$IMGFMT",
139      "file": {
140          "driver": "file",
141          "filename": "$TEST_IMG"
142      },
143      "size": $size,
144      "preallocation": "metadata"
145  }
146}
147{ "execute": "quit" }
148EOF
149
150_img_info --format-specific | _filter_img_info --format-specific
151$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
152
153echo
154echo "=== Invalid BlockdevRef ==="
155echo
156
157run_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
164  }
165}
166{ "execute": "quit" }
167EOF
168
169echo
170echo "=== Zero size ==="
171echo
172
173run_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
180  }
181}
182{ "execute": "quit" }
183EOF
184
185_img_info | _filter_img_info
186
187echo
188echo "=== Maximum size ==="
189echo
190
191run_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
198  }
199}
200{ "execute": "quit" }
201EOF
202
203_img_info | _filter_img_info
204
205echo
206echo "=== Invalid sizes ==="
207echo
208
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.
212
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)
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": 18446744073709551104
224  }
225}
226{ "execute": "x-blockdev-create",
227  "arguments": {
228      "driver": "$IMGFMT",
229      "file": "node0",
230      "size": 9223372036854775808
231  }
232}
233{ "execute": "x-blockdev-create",
234  "arguments": {
235      "driver": "$IMGFMT",
236      "file": "node0",
237      "size": 562949819203585
238  }
239}
240{ "execute": "quit" }
241EOF
242
243# success, all done
244echo "*** done"
245rm -f $seq.full
246status=0
247