]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/210
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[mirror_qemu.git] / tests / qemu-iotests / 210
1 #!/bin/bash
2 #
3 # Test luks 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
22 owner=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 status=1 # failure is the default!
29
30 # get standard environment, filters and checks
31 . ./common.rc
32 . ./common.filter
33
34 _supported_fmt luks
35 _supported_proto file
36 _supported_os Linux
37
38 function do_run_qemu()
39 {
40 echo Testing: "$@"
41 $QEMU -nographic -qmp stdio -serial none "$@"
42 echo
43 }
44
45 function 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
52 echo
53 echo "=== Successful image creation (defaults) ==="
54 echo
55
56 size=$((128 * 1024 * 1024))
57
58 run_qemu -object secret,id=keysec0,data="foo" <<EOF
59 { "execute": "qmp_capabilities" }
60 { "execute": "x-blockdev-create",
61 "arguments": {
62 "driver": "file",
63 "filename": "$TEST_IMG_FILE",
64 "size": 0
65 }
66 }
67 { "execute": "blockdev-add",
68 "arguments": {
69 "driver": "file",
70 "node-name": "imgfile",
71 "filename": "$TEST_IMG_FILE"
72 }
73 }
74 { "execute": "x-blockdev-create",
75 "arguments": {
76 "driver": "$IMGFMT",
77 "file": "imgfile",
78 "key-secret": "keysec0",
79 "size": $size,
80 "iter-time": 10
81 }
82 }
83 { "execute": "quit" }
84 EOF
85
86 _img_info --format-specific | _filter_img_info --format-specific
87
88 echo
89 echo "=== Successful image creation (with non-default options) ==="
90 echo
91
92 # Choose a different size to show that we got a new image
93 size=$((64 * 1024 * 1024))
94
95 run_qemu -object secret,id=keysec0,data="foo" <<EOF
96 { "execute": "qmp_capabilities" }
97 { "execute": "x-blockdev-create",
98 "arguments": {
99 "driver": "file",
100 "filename": "$TEST_IMG_FILE",
101 "size": 0
102 }
103 }
104 { "execute": "x-blockdev-create",
105 "arguments": {
106 "driver": "$IMGFMT",
107 "file": {
108 "driver": "file",
109 "filename": "$TEST_IMG_FILE"
110 },
111 "size": $size,
112 "key-secret": "keysec0",
113 "cipher-alg": "twofish-128",
114 "cipher-mode": "ctr",
115 "ivgen-alg": "plain64",
116 "ivgen-hash-alg": "md5",
117 "hash-alg": "sha1",
118 "iter-time": 10
119 }
120 }
121 { "execute": "quit" }
122 EOF
123
124 _img_info --format-specific | _filter_img_info --format-specific
125
126 echo
127 echo "=== Invalid BlockdevRef ==="
128 echo
129
130 run_qemu <<EOF
131 { "execute": "qmp_capabilities" }
132 { "execute": "x-blockdev-create",
133 "arguments": {
134 "driver": "$IMGFMT",
135 "file": "this doesn't exist",
136 "size": $size
137 }
138 }
139 { "execute": "quit" }
140 EOF
141
142 echo
143 echo "=== Zero size ==="
144 echo
145
146 run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \
147 -object secret,id=keysec0,data="foo" <<EOF
148 { "execute": "qmp_capabilities" }
149 { "execute": "x-blockdev-create",
150 "arguments": {
151 "driver": "$IMGFMT",
152 "file": "node0",
153 "key-secret": "keysec0",
154 "size": 0,
155 "iter-time": 10
156 }
157 }
158 { "execute": "quit" }
159 EOF
160
161 _img_info | _filter_img_info
162
163
164 echo
165 echo "=== Invalid sizes ==="
166 echo
167
168 # TODO Negative image sizes aren't handled correctly, but this is a problem
169 # with QAPI's implementation of the 'size' type and affects other commands as
170 # well. Once this is fixed, we may want to add a test case here.
171
172 # 1. 2^64 - 512
173 # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
174 # 3. 2^63 - 512 (generally valid, but with the crypto header the file will
175 # exceed 63 bits)
176
177 run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \
178 -object secret,id=keysec0,data="foo" <<EOF
179 { "execute": "qmp_capabilities" }
180 { "execute": "x-blockdev-create",
181 "arguments": {
182 "driver": "$IMGFMT",
183 "file": "node0",
184 "key-secret": "keysec0",
185 "size": 18446744073709551104
186 }
187 }
188 { "execute": "x-blockdev-create",
189 "arguments": {
190 "driver": "$IMGFMT",
191 "file": "node0",
192 "key-secret": "keysec0",
193 "size": 9223372036854775808
194 }
195 }
196 { "execute": "x-blockdev-create",
197 "arguments": {
198 "driver": "$IMGFMT",
199 "file": "node0",
200 "key-secret": "keysec0",
201 "size": 9223372036854775296
202 }
203 }
204 { "execute": "quit" }
205 EOF
206
207 # success, all done
208 echo "*** done"
209 rm -f $seq.full
210 status=0