xref: /openbmc/qemu/tests/qemu-iotests/266 (revision ebe15582)
1#!/usr/bin/env python
2#
3# Test VPC and file image creation
4#
5# Copyright (C) 2019 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21import iotests
22from iotests import imgfmt
23
24
25def blockdev_create(vm, options):
26    result = vm.qmp_log('blockdev-create', job_id='job0', options=options,
27                        filters=[iotests.filter_qmp_testfiles])
28
29    if 'return' in result:
30        assert result['return'] == {}
31        vm.run_job('job0')
32
33
34# Successful image creation (defaults)
35def implicit_defaults(vm, file_path):
36    iotests.log("=== Successful image creation (defaults) ===")
37    iotests.log("")
38
39    # 8 heads, 964 cyls/head, 17 secs/cyl
40    # (Close to 64 MB)
41    size = 8 * 964 * 17 * 512
42
43    blockdev_create(vm, { 'driver': imgfmt,
44                          'file': 'protocol-node',
45                          'size': size })
46
47
48# Successful image creation (explicit defaults)
49def explicit_defaults(vm, file_path):
50    iotests.log("=== Successful image creation (explicit defaults) ===")
51    iotests.log("")
52
53    # 16 heads, 964 cyls/head, 17 secs/cyl
54    # (Close to 128 MB)
55    size = 16 * 964 * 17 * 512
56
57    blockdev_create(vm, { 'driver': imgfmt,
58                          'file': 'protocol-node',
59                          'size': size,
60                          'subformat': 'dynamic',
61                          'force-size': False })
62
63
64# Successful image creation (non-default options)
65def non_defaults(vm, file_path):
66    iotests.log("=== Successful image creation (non-default options) ===")
67    iotests.log("")
68
69    # Not representable in CHS (fine with force-size=True)
70    size = 1048576
71
72    blockdev_create(vm, { 'driver': imgfmt,
73                          'file': 'protocol-node',
74                          'size': size,
75                          'subformat': 'fixed',
76                          'force-size': True })
77
78
79# Size not representable in CHS with force-size=False
80def non_chs_size_without_force(vm, file_path):
81    iotests.log("=== Size not representable in CHS ===")
82    iotests.log("")
83
84    # Not representable in CHS (will not work with force-size=False)
85    size = 1048576
86
87    blockdev_create(vm, { 'driver': imgfmt,
88                          'file': 'protocol-node',
89                          'size': size,
90                          'force-size': False })
91
92
93# Zero size
94def zero_size(vm, file_path):
95    iotests.log("=== Zero size===")
96    iotests.log("")
97
98    blockdev_create(vm, { 'driver': imgfmt,
99                          'file': 'protocol-node',
100                          'size': 0 })
101
102
103# Maximum CHS size
104def maximum_chs_size(vm, file_path):
105    iotests.log("=== Maximum CHS size===")
106    iotests.log("")
107
108    blockdev_create(vm, { 'driver': imgfmt,
109                          'file': 'protocol-node',
110                          'size': 16 * 65535 * 255 * 512 })
111
112
113# Actual maximum size
114def maximum_size(vm, file_path):
115    iotests.log("=== Actual maximum size===")
116    iotests.log("")
117
118    blockdev_create(vm, { 'driver': imgfmt,
119                          'file': 'protocol-node',
120                          'size': 0xff000000 * 512,
121                          'force-size': True })
122
123
124def main():
125    for test_func in [implicit_defaults, explicit_defaults, non_defaults,
126                      non_chs_size_without_force, zero_size, maximum_chs_size,
127                      maximum_size]:
128
129        with iotests.FilePath('t.vpc') as file_path, \
130             iotests.VM() as vm:
131
132            vm.launch()
133
134            iotests.log('--- Creating empty file ---')
135            blockdev_create(vm, { 'driver': 'file',
136                                  'filename': file_path,
137                                  'size': 0 })
138
139            vm.qmp_log('blockdev-add', driver='file', filename=file_path,
140                       node_name='protocol-node',
141                       filters=[iotests.filter_qmp_testfiles])
142            iotests.log('')
143
144            print_info = test_func(vm, file_path)
145            iotests.log('')
146
147            vm.shutdown()
148            iotests.img_info_log(file_path)
149
150
151iotests.script_main(main,
152                    supported_fmts=['vpc'],
153                    supported_protocols=['file'])
154