xref: /openbmc/qemu/tests/qemu-iotests/212 (revision f0984d40)
1#!/usr/bin/env python3
2# group: rw quick
3#
4# Test parallels 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
24import iotests
25from iotests import imgfmt
26
27iotests.script_initialize(
28    supported_fmts=['parallels'],
29    supported_protocols=['file'],
30)
31
32with iotests.FilePath('t.parallels') 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                         'cluster-size': 1048576 })
78    vm.shutdown()
79
80    iotests.img_info_log(disk_path)
81
82    #
83    # Successful image creation (with non-default options)
84    #
85    iotests.log("=== Successful image creation (with non-default options) ===")
86    iotests.log("")
87
88    # Choose a different size to show that we got a new image
89    size = 32 * 1024 * 1024
90
91    vm.launch()
92    vm.blockdev_create({ 'driver': 'file',
93                         'filename': disk_path,
94                         'size': 0 })
95    vm.blockdev_create({ 'driver': imgfmt,
96                         'file': {
97                             'driver': 'file',
98                             'filename': disk_path,
99                         },
100                         'size': size,
101                         'cluster-size': 65536 })
102    vm.shutdown()
103
104    iotests.img_info_log(disk_path)
105
106    #
107    # Invalid BlockdevRef
108    #
109    iotests.log("=== Invalid BlockdevRef ===")
110    iotests.log("")
111
112    vm.launch()
113    vm.blockdev_create({ 'driver': imgfmt,
114                         'file': "this doesn't exist",
115                         'size': size })
116    vm.shutdown()
117
118    #
119    # Zero size
120    #
121    iotests.log("=== Zero size ===")
122    iotests.log("")
123
124    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
125    vm.launch()
126    vm.blockdev_create({ 'driver': imgfmt,
127                         'file': 'node0',
128                         'size': 0 })
129    vm.shutdown()
130
131    iotests.img_info_log(disk_path)
132
133    #
134    # Maximum size
135    #
136    iotests.log("=== Maximum size ===")
137    iotests.log("")
138
139    vm.launch()
140    vm.blockdev_create({ 'driver': imgfmt,
141                         'file': 'node0',
142                         'size': 4503599627369984})
143    vm.shutdown()
144
145    iotests.img_info_log(disk_path)
146
147    #
148    # Invalid sizes
149    #
150
151    # TODO Negative image sizes aren't handled correctly, but this is a problem
152    # with QAPI's implementation of the 'size' type and affects other commands
153    # as well. Once this is fixed, we may want to add a test case here.
154
155    # 1. Misaligned image size
156    # 2. 2^64 - 512
157    # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
158    # 4. 2^63 - 512 (generally valid, but with the image header the file will
159    #                exceed 63 bits)
160    # 5. 2^52 (512 bytes more than maximum image size)
161
162    iotests.log("=== Invalid sizes ===")
163    iotests.log("")
164
165    vm.launch()
166    for size in [ 1234, 18446744073709551104, 9223372036854775808,
167                  9223372036854775296, 4503599627370497 ]:
168        vm.blockdev_create({ 'driver': imgfmt,
169                             'file': 'node0',
170                             'size': size })
171    vm.shutdown()
172
173    #
174    # Invalid cluster size
175    #
176    iotests.log("=== Invalid cluster size ===")
177    iotests.log("")
178
179    vm.launch()
180    for csize in [ 1234, 128, 4294967296, 9223372036854775808,
181                   18446744073709551104, 0 ]:
182        vm.blockdev_create({ 'driver': imgfmt,
183                             'file': 'node0',
184                             'size': 67108864,
185                             'cluster-size': csize })
186    vm.blockdev_create({ 'driver': imgfmt,
187                         'file': 'node0',
188                         'size': 281474976710656,
189                         'cluster-size': 512 })
190    vm.shutdown()
191