tests: fix a memory in test_socket_unix_abstract_good
[qemu/ar7.git] / tests / qemu-iotests / 211
blob4969edb00c517ad327e054277ccf197f30397b5a
1 #!/usr/bin/env python3
3 # Test VDI 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=['vdi'],
28     supported_protocols=['file'],
31 def blockdev_create(vm, options):
32     error = vm.blockdev_create(options)
33     if error and 'Could not allocate bmap' in error:
34         iotests.notrun('Insufficient memory')
36 with iotests.FilePath('t.vdi') as disk_path, \
37      iotests.VM() as vm:
39     #
40     # Successful image creation (defaults)
41     #
42     iotests.log("=== Successful image creation (defaults) ===")
43     iotests.log("")
45     size = 128 * 1024 * 1024
47     vm.launch()
48     blockdev_create(vm, { 'driver': 'file',
49                           'filename': disk_path,
50                           'size': 0 })
52     vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
53                node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
55     blockdev_create(vm, { 'driver': imgfmt,
56                           'file': 'imgfile',
57                           'size': size })
58     vm.shutdown()
60     iotests.img_info_log(disk_path)
61     iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))
63     #
64     # Successful image creation (explicit defaults)
65     #
66     iotests.log("=== Successful image creation (explicit defaults) ===")
67     iotests.log("")
69     size = 64 * 1024 * 1024
71     vm.launch()
72     blockdev_create(vm, { 'driver': 'file',
73                           'filename': disk_path,
74                           'size': 0 })
75     blockdev_create(vm, { 'driver': imgfmt,
76                           'file': {
77                               'driver': 'file',
78                               'filename': disk_path,
79                           },
80                           'size': size,
81                           'preallocation': 'off' })
82     vm.shutdown()
84     iotests.img_info_log(disk_path)
85     iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))
87     #
88     # Successful image creation (with non-default options)
89     #
90     iotests.log("=== Successful image creation (with non-default options) ===")
91     iotests.log("")
93     size = 32 * 1024 * 1024
95     vm.launch()
96     blockdev_create(vm, { 'driver': 'file',
97                           'filename': disk_path,
98                           'size': 0 })
99     blockdev_create(vm, { 'driver': imgfmt,
100                           'file': {
101                               'driver': 'file',
102                               'filename': disk_path,
103                           },
104                           'size': size,
105                           'preallocation': 'metadata' })
106     vm.shutdown()
108     iotests.img_info_log(disk_path)
109     iotests.log(iotests.qemu_img_pipe('map', '--output=json', disk_path))
111     #
112     # Invalid BlockdevRef
113     #
114     iotests.log("=== Invalid BlockdevRef ===")
115     iotests.log("")
117     vm.launch()
118     blockdev_create(vm, { 'driver': imgfmt,
119                           'file': "this doesn't exist",
120                           'size': size })
121     vm.shutdown()
123     #
124     # Zero size
125     #
126     iotests.log("=== Zero size ===")
127     iotests.log("")
129     vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
130     vm.launch()
131     blockdev_create(vm, { 'driver': imgfmt,
132                           'file': 'node0',
133                           'size': 0 })
134     vm.shutdown()
136     iotests.img_info_log(disk_path)
138     #
139     # Maximum size
140     #
141     iotests.log("=== Maximum size ===")
142     iotests.log("")
144     vm.launch()
145     blockdev_create(vm, { 'driver': imgfmt,
146                           'file': 'node0',
147                           'size': 562949819203584 })
148     vm.shutdown()
150     iotests.img_info_log(disk_path)
152     #
153     # Invalid sizes
154     #
156     # TODO Negative image sizes aren't handled correctly, but this is a problem
157     # with QAPI's implementation of the 'size' type and affects other commands
158     # as well. Once this is fixed, we may want to add a test case here.
160     # 1. 2^64 - 512
161     # 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
162     # 3. 0x1fffff8000001 (one byte more than maximum image size for VDI)
164     iotests.log("=== Invalid sizes ===")
165     iotests.log("")
167     vm.launch()
168     for size in [ 18446744073709551104, 9223372036854775808, 562949819203585 ]:
169         blockdev_create(vm, { 'driver': imgfmt,
170                               'file': 'node0',
171                               'size': size })
172     vm.shutdown()