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