hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler
[qemu/ar7.git] / tests / qemu-iotests / 212
blob45d08842bb45711cae784e4dd7824b41ec47b36e
1 #!/usr/bin/env python3
3 # Test parallels and file image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 import iotests
24 from iotests import imgfmt
26 iotests.script_initialize(
27     supported_fmts=['parallels'],
28     supported_protocols=['file'],
31 with iotests.FilePath('t.parallels') as disk_path, \
32      iotests.VM() as vm:
34     #
35     # Successful image creation (defaults)
36     #
37     iotests.log("=== Successful image creation (defaults) ===")
38     iotests.log("")
40     size = 128 * 1024 * 1024
42     vm.launch()
43     vm.blockdev_create({ 'driver': 'file',
44                          'filename': disk_path,
45                          'size': 0 })
47     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
48                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
50     vm.blockdev_create({ 'driver': imgfmt,
51                          'file': 'imgfile',
52                          'size': size })
53     vm.shutdown()
55     iotests.img_info_log(disk_path)
57     #
58     # Successful image creation (explicit defaults)
59     #
60     iotests.log("=== Successful image creation (explicit defaults) ===")
61     iotests.log("")
63     # Choose a different size to show that we got a new image
64     size = 64 * 1024 * 1024
66     vm.launch()
67     vm.blockdev_create({ 'driver': 'file',
68                          'filename': disk_path,
69                          'size': 0 })
70     vm.blockdev_create({ 'driver': imgfmt,
71                          'file': {
72                              'driver': 'file',
73                              'filename': disk_path,
74                          },
75                          'size': size,
76                          'cluster-size': 1048576 })
77     vm.shutdown()
79     iotests.img_info_log(disk_path)
81     #
82     # Successful image creation (with non-default options)
83     #
84     iotests.log("=== Successful image creation (with non-default options) ===")
85     iotests.log("")
87     # Choose a different size to show that we got a new image
88     size = 32 * 1024 * 1024
90     vm.launch()
91     vm.blockdev_create({ 'driver': 'file',
92                          'filename': disk_path,
93                          'size': 0 })
94     vm.blockdev_create({ 'driver': imgfmt,
95                          'file': {
96                              'driver': 'file',
97                              'filename': disk_path,
98                          },
99                          'size': size,
100                          'cluster-size': 65536 })
101     vm.shutdown()
103     iotests.img_info_log(disk_path)
105     #
106     # Invalid BlockdevRef
107     #
108     iotests.log("=== Invalid BlockdevRef ===")
109     iotests.log("")
111     vm.launch()
112     vm.blockdev_create({ 'driver': imgfmt,
113                          'file': "this doesn't exist",
114                          'size': size })
115     vm.shutdown()
117     #
118     # Zero size
119     #
120     iotests.log("=== Zero size ===")
121     iotests.log("")
123     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
124     vm.launch()
125     vm.blockdev_create({ 'driver': imgfmt,
126                          'file': 'node0',
127                          'size': 0 })
128     vm.shutdown()
130     iotests.img_info_log(disk_path)
132     #
133     # Maximum size
134     #
135     iotests.log("=== Maximum size ===")
136     iotests.log("")
138     vm.launch()
139     vm.blockdev_create({ 'driver': imgfmt,
140                          'file': 'node0',
141                          'size': 4503599627369984})
142     vm.shutdown()
144     iotests.img_info_log(disk_path)
146     #
147     # Invalid sizes
148     #
150     # TODO Negative image sizes aren't handled correctly, but this is a problem
151     # with QAPI's implementation of the 'size' type and affects other commands
152     # as well. Once this is fixed, we may want to add a test case here.
154     # 1. Misaligned image size
155     # 2. 2^64 - 512
156     # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
157     # 4. 2^63 - 512 (generally valid, but with the image header the file will
158     #                exceed 63 bits)
159     # 5. 2^52 (512 bytes more than maximum image size)
161     iotests.log("=== Invalid sizes ===")
162     iotests.log("")
164     vm.launch()
165     for size in [ 1234, 18446744073709551104, 9223372036854775808,
166                   9223372036854775296, 4503599627370497 ]:
167         vm.blockdev_create({ 'driver': imgfmt,
168                              'file': 'node0',
169                              'size': size })
170     vm.shutdown()
172     #
173     # Invalid cluster size
174     #
175     iotests.log("=== Invalid cluster size ===")
176     iotests.log("")
178     vm.launch()
179     for csize in [ 1234, 128, 4294967296, 9223372036854775808,
180                    18446744073709551104, 0 ]:
181         vm.blockdev_create({ 'driver': imgfmt,
182                              'file': 'node0',
183                              'size': 67108864,
184                              'cluster-size': csize })
185     vm.blockdev_create({ 'driver': imgfmt,
186                          'file': 'node0',
187                          'size': 281474976710656,
188                          'cluster-size': 512 })
189     vm.shutdown()