3 # Test virtio-scsi and virtio-blk queue settings for all machine types
5 # Copyright (c) 2019 Virtuozzo International GmbH
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.
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.
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/>.
26 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..', '..', 'python'))
27 from qemu
.machine
import QEMUMachine
28 from avocado_qemu
import Test
29 from avocado
import skip
31 #list of machine types and virtqueue properties to test
32 VIRTIO_SCSI_PROPS
= {'seg_max_adjust': 'seg_max_adjust'}
33 VIRTIO_BLK_PROPS
= {'seg_max_adjust': 'seg-max-adjust'}
35 DEV_TYPES
= {'virtio-scsi-pci': VIRTIO_SCSI_PROPS
,
36 'virtio-blk-pci': VIRTIO_BLK_PROPS
}
38 VM_DEV_PARAMS
= {'virtio-scsi-pci': ['-device', 'virtio-scsi-pci,id=scsi0'],
39 'virtio-blk-pci': ['-device',
40 'virtio-blk-pci,id=scsi0,drive=drive0',
42 'driver=null-co,id=drive0,if=none']}
45 class VirtioMaxSegSettingsCheck(Test
):
47 def make_pattern(props
):
48 pattern_items
= ['{0} = \w+'.format(prop
) for prop
in props
]
49 return '|'.join(pattern_items
)
51 def query_virtqueue(self
, vm
, dev_type_name
):
56 output
= vm
.command('human-monitor-command',
57 command_line
= 'info qtree')
58 props_list
= DEV_TYPES
[dev_type_name
].values();
59 pattern
= self
.make_pattern(props_list
)
60 res
= re
.findall(pattern
, output
)
62 if len(res
) != len(props_list
):
63 props_list
= set(props_list
)
65 not_found
= props_list
.difference(res
)
66 not_found
= ', '.join(not_found
)
67 error
= '({0}): The following properties not found: {1}'\
68 .format(dev_type_name
, not_found
)
75 return query_ok
, props
, error
77 def check_mt(self
, mt
, dev_type_name
):
78 mt
['device'] = dev_type_name
# Only for the debug() call.
79 logger
= logging
.getLogger('machine')
81 with
QEMUMachine(self
.qemu_bin
) as vm
:
82 vm
.set_machine(mt
["name"])
83 vm
.add_args('-nodefaults')
84 for s
in VM_DEV_PARAMS
[dev_type_name
]:
88 query_ok
, props
, error
= self
.query_virtqueue(vm
, dev_type_name
)
91 error
= sys
.exc_info()[0]
94 self
.fail('machine type {0}: {1}'.format(mt
['name'], error
))
96 for prop_name
, prop_val
in props
.items():
97 expected_val
= mt
[prop_name
]
98 self
.assertEqual(expected_val
, prop_val
)
101 def seg_max_adjust_enabled(mt
):
102 # machine types >= 5.0 should have seg_max_adjust = true
103 # others seg_max_adjust = false
106 # machine types with one line name and name like pc-x.x
110 # machine types like pc-<chip_name>-x.x[.x]
112 ver
= ver
.split(".");
114 # versions >= 5.0 goes with seg_max_adjust enabled
121 @skip("break multi-arch CI")
122 def test_machine_types(self
):
123 # collect all machine types except 'none', 'isapc', 'microvm'
124 with
QEMUMachine(self
.qemu_bin
) as vm
:
126 machines
= [m
['name'] for m
in vm
.command('query-machines')]
128 machines
.remove('none')
129 machines
.remove('isapc')
130 machines
.remove('microvm')
132 for dev_type
in DEV_TYPES
:
133 # create the list of machine types and their parameters.
136 if self
.seg_max_adjust_enabled(m
):
140 mtypes
.append({'name': m
,
141 DEV_TYPES
[dev_type
]['seg_max_adjust']: enabled
})
143 # test each machine type for a device type
145 self
.check_mt(mt
, dev_type
)