xref: /openbmc/qemu/tests/qemu-iotests/212 (revision 88cd34ee)
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.verify_image_format(supported_fmts=['parallels'])
27iotests.verify_protocol(supported=['file'])
28
29with iotests.FilePath('t.parallels') as disk_path, \
30     iotests.VM() as vm:
31
32    #
33    # Successful image creation (defaults)
34    #
35    iotests.log("=== Successful image creation (defaults) ===")
36    iotests.log("")
37
38    size = 128 * 1024 * 1024
39
40    vm.launch()
41    vm.blockdev_create({ 'driver': 'file',
42                         'filename': disk_path,
43                         'size': 0 })
44
45    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
46               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
47
48    vm.blockdev_create({ 'driver': imgfmt,
49                         'file': 'imgfile',
50                         'size': size })
51    vm.shutdown()
52
53    iotests.img_info_log(disk_path)
54
55    #
56    # Successful image creation (explicit defaults)
57    #
58    iotests.log("=== Successful image creation (explicit defaults) ===")
59    iotests.log("")
60
61    # Choose a different size to show that we got a new image
62    size = 64 * 1024 * 1024
63
64    vm.launch()
65    vm.blockdev_create({ 'driver': 'file',
66                         'filename': disk_path,
67                         'size': 0 })
68    vm.blockdev_create({ 'driver': imgfmt,
69                         'file': {
70                             'driver': 'file',
71                             'filename': disk_path,
72                         },
73                         'size': size,
74                         'cluster-size': 1048576 })
75    vm.shutdown()
76
77    iotests.img_info_log(disk_path)
78
79    #
80    # Successful image creation (with non-default options)
81    #
82    iotests.log("=== Successful image creation (with non-default options) ===")
83    iotests.log("")
84
85    # Choose a different size to show that we got a new image
86    size = 32 * 1024 * 1024
87
88    vm.launch()
89    vm.blockdev_create({ 'driver': 'file',
90                         'filename': disk_path,
91                         'size': 0 })
92    vm.blockdev_create({ 'driver': imgfmt,
93                         'file': {
94                             'driver': 'file',
95                             'filename': disk_path,
96                         },
97                         'size': size,
98                         'cluster-size': 65536 })
99    vm.shutdown()
100
101    iotests.img_info_log(disk_path)
102
103    #
104    # Invalid BlockdevRef
105    #
106    iotests.log("=== Invalid BlockdevRef ===")
107    iotests.log("")
108
109    vm.launch()
110    vm.blockdev_create({ 'driver': imgfmt,
111                         'file': "this doesn't exist",
112                         'size': size })
113    vm.shutdown()
114
115    #
116    # Zero size
117    #
118    iotests.log("=== Zero size ===")
119    iotests.log("")
120
121    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
122    vm.launch()
123    vm.blockdev_create({ 'driver': imgfmt,
124                         'file': 'node0',
125                         'size': 0 })
126    vm.shutdown()
127
128    iotests.img_info_log(disk_path)
129
130    #
131    # Maximum size
132    #
133    iotests.log("=== Maximum size ===")
134    iotests.log("")
135
136    vm.launch()
137    vm.blockdev_create({ 'driver': imgfmt,
138                         'file': 'node0',
139                         'size': 4503599627369984})
140    vm.shutdown()
141
142    iotests.img_info_log(disk_path)
143
144    #
145    # Invalid sizes
146    #
147
148    # TODO Negative image sizes aren't handled correctly, but this is a problem
149    # with QAPI's implementation of the 'size' type and affects other commands
150    # as well. Once this is fixed, we may want to add a test case here.
151
152    # 1. Misaligned image size
153    # 2. 2^64 - 512
154    # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
155    # 4. 2^63 - 512 (generally valid, but with the image header the file will
156    #                exceed 63 bits)
157    # 5. 2^52 (512 bytes more than maximum image size)
158
159    iotests.log("=== Invalid sizes ===")
160    iotests.log("")
161
162    vm.launch()
163    for size in [ 1234, 18446744073709551104, 9223372036854775808,
164                  9223372036854775296, 4503599627370497 ]:
165        vm.blockdev_create({ 'driver': imgfmt,
166                             'file': 'node0',
167                             'size': size })
168    vm.shutdown()
169
170    #
171    # Invalid cluster size
172    #
173    iotests.log("=== Invalid cluster size ===")
174    iotests.log("")
175
176    vm.launch()
177    for csize in [ 1234, 128, 4294967296, 9223372036854775808,
178                   18446744073709551104, 0 ]:
179        vm.blockdev_create({ 'driver': imgfmt,
180                             'file': 'node0',
181                             'size': 67108864,
182                             'cluster-size': csize })
183    vm.blockdev_create({ 'driver': imgfmt,
184                         'file': 'node0',
185                         'size': 281474976710656,
186                         'cluster-size': 512 })
187    vm.shutdown()
188