target/arm: Set ISSIs16Bit in make_issinfo
[qemu/ar7.git] / tests / acceptance / virtio_seg_max_adjust.py
blob5458573138738df09804a9b8117fc7dae76e52a5
1 #!/usr/bin/env python
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/>.
21 import sys
22 import os
23 import re
25 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
26 from qemu.machine import QEMUMachine
27 from avocado_qemu import Test
29 #list of machine types and virtqueue properties to test
30 VIRTIO_SCSI_PROPS = {'seg_max_adjust': 'seg_max_adjust'}
31 VIRTIO_BLK_PROPS = {'seg_max_adjust': 'seg-max-adjust'}
33 DEV_TYPES = {'virtio-scsi-pci': VIRTIO_SCSI_PROPS,
34 'virtio-blk-pci': VIRTIO_BLK_PROPS}
36 VM_DEV_PARAMS = {'virtio-scsi-pci': ['-device', 'virtio-scsi-pci,id=scsi0'],
37 'virtio-blk-pci': ['-device',
38 'virtio-blk-pci,id=scsi0,drive=drive0',
39 '-drive',
40 'driver=null-co,id=drive0,if=none']}
43 class VirtioMaxSegSettingsCheck(Test):
44 @staticmethod
45 def make_pattern(props):
46 pattern_items = ['{0} = \w+'.format(prop) for prop in props]
47 return '|'.join(pattern_items)
49 def query_virtqueue(self, vm, dev_type_name):
50 query_ok = False
51 error = None
52 props = None
54 output = vm.command('human-monitor-command',
55 command_line = 'info qtree')
56 props_list = DEV_TYPES[dev_type_name].values();
57 pattern = self.make_pattern(props_list)
58 res = re.findall(pattern, output)
60 if len(res) != len(props_list):
61 props_list = set(props_list)
62 res = set(res)
63 not_found = props_list.difference(res)
64 not_found = ', '.join(not_found)
65 error = '({0}): The following properties not found: {1}'\
66 .format(dev_type_name, not_found)
67 else:
68 query_ok = True
69 props = dict()
70 for prop in res:
71 p = prop.split(' = ')
72 props[p[0]] = p[1]
73 return query_ok, props, error
75 def check_mt(self, mt, dev_type_name):
76 with QEMUMachine(self.qemu_bin) as vm:
77 vm.set_machine(mt["name"])
78 for s in VM_DEV_PARAMS[dev_type_name]:
79 vm.add_args(s)
80 vm.launch()
81 query_ok, props, error = self.query_virtqueue(vm, dev_type_name)
83 if not query_ok:
84 self.fail('machine type {0}: {1}'.format(mt['name'], error))
86 for prop_name, prop_val in props.items():
87 expected_val = mt[prop_name]
88 self.assertEqual(expected_val, prop_val)
90 @staticmethod
91 def seg_max_adjust_enabled(mt):
92 # machine types >= 5.0 should have seg_max_adjust = true
93 # others seg_max_adjust = false
94 mt = mt.split("-")
96 # machine types with one line name and name like pc-x.x
97 if len(mt) <= 2:
98 return False
100 # machine types like pc-<chip_name>-x.x[.x]
101 ver = mt[2]
102 ver = ver.split(".");
104 # versions >= 5.0 goes with seg_max_adjust enabled
105 major = int(ver[0])
107 if major >= 5:
108 return True
109 return False
111 def test_machine_types(self):
112 # collect all machine types except 'none', 'isapc', 'microvm'
113 with QEMUMachine(self.qemu_bin) as vm:
114 vm.launch()
115 machines = [m['name'] for m in vm.command('query-machines')]
116 vm.shutdown()
117 machines.remove('none')
118 machines.remove('isapc')
119 machines.remove('microvm')
121 for dev_type in DEV_TYPES:
122 # create the list of machine types and their parameters.
123 mtypes = list()
124 for m in machines:
125 if self.seg_max_adjust_enabled(m):
126 enabled = 'true'
127 else:
128 enabled = 'false'
129 mtypes.append({'name': m,
130 DEV_TYPES[dev_type]['seg_max_adjust']: enabled})
132 # test each machine type for a device type
133 for mt in mtypes:
134 self.check_mt(mt, dev_type)