xref: /openbmc/qemu/tests/qemu-iotests/266 (revision d1972be1)
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
25# Successful image creation (defaults)
26def implicit_defaults(vm, file_path):
27    iotests.log("=== Successful image creation (defaults) ===")
28    iotests.log("")
29
30    # 8 heads, 964 cyls/head, 17 secs/cyl
31    # (Close to 64 MB)
32    size = 8 * 964 * 17 * 512
33
34    vm.blockdev_create({ 'driver': imgfmt,
35                         'file': 'protocol-node',
36                         'size': size })
37
38
39# Successful image creation (explicit defaults)
40def explicit_defaults(vm, file_path):
41    iotests.log("=== Successful image creation (explicit defaults) ===")
42    iotests.log("")
43
44    # 16 heads, 964 cyls/head, 17 secs/cyl
45    # (Close to 128 MB)
46    size = 16 * 964 * 17 * 512
47
48    vm.blockdev_create({ 'driver': imgfmt,
49                         'file': 'protocol-node',
50                         'size': size,
51                         'subformat': 'dynamic',
52                         'force-size': False })
53
54
55# Successful image creation (non-default options)
56def non_defaults(vm, file_path):
57    iotests.log("=== Successful image creation (non-default options) ===")
58    iotests.log("")
59
60    # Not representable in CHS (fine with force-size=True)
61    size = 1048576
62
63    vm.blockdev_create({ 'driver': imgfmt,
64                         'file': 'protocol-node',
65                         'size': size,
66                         'subformat': 'fixed',
67                         'force-size': True })
68
69
70# Size not representable in CHS with force-size=False
71def non_chs_size_without_force(vm, file_path):
72    iotests.log("=== Size not representable in CHS ===")
73    iotests.log("")
74
75    # Not representable in CHS (will not work with force-size=False)
76    size = 1048576
77
78    vm.blockdev_create({ 'driver': imgfmt,
79                         'file': 'protocol-node',
80                         'size': size,
81                         'force-size': False })
82
83
84# Zero size
85def zero_size(vm, file_path):
86    iotests.log("=== Zero size===")
87    iotests.log("")
88
89    vm.blockdev_create({ 'driver': imgfmt,
90                         'file': 'protocol-node',
91                         'size': 0 })
92
93
94# Maximum CHS size
95def maximum_chs_size(vm, file_path):
96    iotests.log("=== Maximum CHS size===")
97    iotests.log("")
98
99    vm.blockdev_create({ 'driver': imgfmt,
100                         'file': 'protocol-node',
101                         'size': 16 * 65535 * 255 * 512 })
102
103
104# Actual maximum size
105def maximum_size(vm, file_path):
106    iotests.log("=== Actual maximum size===")
107    iotests.log("")
108
109    vm.blockdev_create({ 'driver': imgfmt,
110                         'file': 'protocol-node',
111                         'size': 0xff000000 * 512,
112                         'force-size': True })
113
114
115def main():
116    for test_func in [implicit_defaults, explicit_defaults, non_defaults,
117                      non_chs_size_without_force, zero_size, maximum_chs_size,
118                      maximum_size]:
119
120        with iotests.FilePath('t.vpc') as file_path, \
121             iotests.VM() as vm:
122
123            vm.launch()
124
125            iotests.log('--- Creating empty file ---')
126            vm.blockdev_create({ 'driver': 'file',
127                                 'filename': file_path,
128                                 'size': 0 })
129
130            vm.qmp_log('blockdev-add', driver='file', filename=file_path,
131                       node_name='protocol-node',
132                       filters=[iotests.filter_qmp_testfiles])
133            iotests.log('')
134
135            print_info = test_func(vm, file_path)
136            iotests.log('')
137
138            vm.shutdown()
139            iotests.img_info_log(file_path)
140
141
142iotests.script_main(main,
143                    supported_fmts=['vpc'],
144                    supported_protocols=['file'])
145