xref: /openbmc/qemu/tests/qemu-iotests/212 (revision 65a117da)
1#!/usr/bin/env python3
2#
3# Test parallels and file image creation
4#
5# Copyright (C) 2018 Red Hat, Inc.
6#
7# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
8#
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.
13#
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.
18#
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/>.
21#
22
23import iotests
24from iotests import imgfmt
25
26iotests.script_initialize(
27    supported_fmts=['parallels'],
28    supported_protocols=['file'],
29)
30
31with iotests.FilePath('t.parallels') as disk_path, \
32     iotests.VM() as vm:
33
34    #
35    # Successful image creation (defaults)
36    #
37    iotests.log("=== Successful image creation (defaults) ===")
38    iotests.log("")
39
40    size = 128 * 1024 * 1024
41
42    vm.launch()
43    vm.blockdev_create({ 'driver': 'file',
44                         'filename': disk_path,
45                         'size': 0 })
46
47    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
48               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
49
50    vm.blockdev_create({ 'driver': imgfmt,
51                         'file': 'imgfile',
52                         'size': size })
53    vm.shutdown()
54
55    iotests.img_info_log(disk_path)
56
57    #
58    # Successful image creation (explicit defaults)
59    #
60    iotests.log("=== Successful image creation (explicit defaults) ===")
61    iotests.log("")
62
63    # Choose a different size to show that we got a new image
64    size = 64 * 1024 * 1024
65
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()
78
79    iotests.img_info_log(disk_path)
80
81    #
82    # Successful image creation (with non-default options)
83    #
84    iotests.log("=== Successful image creation (with non-default options) ===")
85    iotests.log("")
86
87    # Choose a different size to show that we got a new image
88    size = 32 * 1024 * 1024
89
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()
102
103    iotests.img_info_log(disk_path)
104
105    #
106    # Invalid BlockdevRef
107    #
108    iotests.log("=== Invalid BlockdevRef ===")
109    iotests.log("")
110
111    vm.launch()
112    vm.blockdev_create({ 'driver': imgfmt,
113                         'file': "this doesn't exist",
114                         'size': size })
115    vm.shutdown()
116
117    #
118    # Zero size
119    #
120    iotests.log("=== Zero size ===")
121    iotests.log("")
122
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()
129
130    iotests.img_info_log(disk_path)
131
132    #
133    # Maximum size
134    #
135    iotests.log("=== Maximum size ===")
136    iotests.log("")
137
138    vm.launch()
139    vm.blockdev_create({ 'driver': imgfmt,
140                         'file': 'node0',
141                         'size': 4503599627369984})
142    vm.shutdown()
143
144    iotests.img_info_log(disk_path)
145
146    #
147    # Invalid sizes
148    #
149
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.
153
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)
160
161    iotests.log("=== Invalid sizes ===")
162    iotests.log("")
163
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()
171
172    #
173    # Invalid cluster size
174    #
175    iotests.log("=== Invalid cluster size ===")
176    iotests.log("")
177
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()
190