OSDN Git Service

Merge tag 'pull-halloween-omnibus-311023-2' of https://gitlab.com/stsquad/qemu into...
[qmiga/qemu.git] / tests / qemu-iotests / 213
1 #!/usr/bin/env python3
2 # group: rw quick
3 #
4 # Test vhdx and file image creation
5 #
6 # Copyright (C) 2018 Red Hat, Inc.
7 #
8 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 import iotests
25 from iotests import imgfmt
26
27 iotests.script_initialize(
28     supported_fmts=['vhdx'],
29     supported_protocols=['file'],
30 )
31
32 with iotests.FilePath('t.vhdx') as disk_path, \
33      iotests.VM() as vm:
34
35     #
36     # Successful image creation (defaults)
37     #
38     iotests.log("=== Successful image creation (defaults) ===")
39     iotests.log("")
40
41     size = 128 * 1024 * 1024
42
43     vm.launch()
44     vm.blockdev_create({ 'driver': 'file',
45                          'filename': disk_path,
46                          'size': 0 })
47
48     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
50
51     vm.blockdev_create({ 'driver': imgfmt,
52                          'file': 'imgfile',
53                          'size': size })
54     vm.shutdown()
55
56     iotests.img_info_log(disk_path)
57
58     #
59     # Successful image creation (explicit defaults)
60     #
61     iotests.log("=== Successful image creation (explicit defaults) ===")
62     iotests.log("")
63
64     # Choose a different size to show that we got a new image
65     size = 64 * 1024 * 1024
66
67     vm.launch()
68     vm.blockdev_create({ 'driver': 'file',
69                          'filename': disk_path,
70                          'size': 0 })
71     vm.blockdev_create({ 'driver': imgfmt,
72                          'file': {
73                              'driver': 'file',
74                              'filename': disk_path,
75                          },
76                          'size': size,
77                          'log-size': 1048576,
78                          'block-size': 8388608,
79                          'subformat': 'dynamic',
80                          'block-state-zero': True })
81     vm.shutdown()
82
83     iotests.img_info_log(disk_path)
84
85     #
86     # Successful image creation (with non-default options)
87     #
88     iotests.log("=== Successful image creation (with non-default options) ===")
89     iotests.log("")
90
91     # Choose a different size to show that we got a new image
92     size = 32 * 1024 * 1024
93
94     vm.launch()
95     vm.blockdev_create({ 'driver': 'file',
96                          'filename': disk_path,
97                          'size': 0 })
98     vm.blockdev_create({ 'driver': imgfmt,
99                          'file': {
100                              'driver': 'file',
101                              'filename': disk_path,
102                          },
103                          'size': size,
104                          'log-size': 8388608,
105                          'block-size': 268435456,
106                          'subformat': 'fixed',
107                          'block-state-zero': False })
108     vm.shutdown()
109
110     iotests.img_info_log(disk_path)
111
112     #
113     # Invalid BlockdevRef
114     #
115     iotests.log("=== Invalid BlockdevRef ===")
116     iotests.log("")
117
118     vm.launch()
119     vm.blockdev_create({ 'driver': imgfmt,
120                          'file': "this doesn't exist",
121                          'size': size })
122     vm.shutdown()
123
124     #
125     # Zero size
126     #
127     iotests.log("=== Zero size ===")
128     iotests.log("")
129
130     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
131     vm.launch()
132     vm.blockdev_create({ 'driver': imgfmt,
133                          'file': 'node0',
134                          'size': 0 })
135     vm.shutdown()
136
137     iotests.img_info_log(disk_path)
138
139     #
140     # Maximum size
141     #
142     iotests.log("=== Maximum size ===")
143     iotests.log("")
144
145     vm.launch()
146     vm.blockdev_create({ 'driver': imgfmt,
147                          'file': 'node0',
148                          'size': 70368744177664 })
149     vm.shutdown()
150
151     iotests.img_info_log(disk_path)
152
153     #
154     # Invalid sizes
155     #
156
157     # TODO Negative image sizes aren't handled correctly, but this is a problem
158     # with QAPI's implementation of the 'size' type and affects other commands
159     # as well. Once this is fixed, we may want to add a test case here.
160
161     # 1. 2^64 - 512
162     # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
163     # 3. 2^63 - 512 (generally valid, but with the image header the file will
164     #                exceed 63 bits)
165     # 4. 2^46 + 1 (one byte more than maximum image size)
166
167     iotests.log("=== Invalid sizes ===")
168     iotests.log("")
169
170     vm.launch()
171     for size in [ 18446744073709551104, 9223372036854775808,
172                   9223372036854775296, 70368744177665 ]:
173         vm.blockdev_create({ 'driver': imgfmt,
174                              'file': 'node0',
175                              'size': size })
176     vm.shutdown()
177
178     #
179     # Invalid block size
180     #
181     iotests.log("=== Invalid block size ===")
182     iotests.log("")
183
184     vm.launch()
185     for bsize in [ 1234567, 128, 3145728, 536870912, 0 ]:
186         vm.blockdev_create({ 'driver': imgfmt,
187                              'file': 'node0',
188                              'size': 67108864,
189                              'block-size': bsize })
190     vm.shutdown()
191
192     #
193     # Invalid log size
194     #
195     iotests.log("=== Invalid log size ===")
196     iotests.log("")
197
198     vm.launch()
199     for lsize in [ 1234567, 128, 4294967296, 0 ]:
200         vm.blockdev_create({ 'driver': imgfmt,
201                              'file': 'node0',
202                              'size': 67108864,
203                              'log-size': lsize })
204     vm.shutdown()