tests/acceptance/migration: Test EXEC transport when migrating
[qemu/ar7.git] / tests / acceptance / virtio_check_params.py
blobc3af8dbf9fde6147aefbc58ef849d44cbeb4ffea
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
24 import logging
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',
41 '-drive',
42 'driver=null-co,id=drive0,if=none']}
45 class VirtioMaxSegSettingsCheck(Test):
46 @staticmethod
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):
52 query_ok = False
53 error = None
54 props = None
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)
64 res = set(res)
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)
69 else:
70 query_ok = True
71 props = dict()
72 for prop in res:
73 p = prop.split(' = ')
74 props[p[0]] = p[1]
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')
80 logger.debug(mt)
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]:
85 vm.add_args(s)
86 try:
87 vm.launch()
88 query_ok, props, error = self.query_virtqueue(vm, dev_type_name)
89 except:
90 query_ok = False
91 error = sys.exc_info()[0]
93 if not query_ok:
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)
100 @staticmethod
101 def seg_max_adjust_enabled(mt):
102 # machine types >= 5.0 should have seg_max_adjust = true
103 # others seg_max_adjust = false
104 mt = mt.split("-")
106 # machine types with one line name and name like pc-x.x
107 if len(mt) <= 2:
108 return False
110 # machine types like pc-<chip_name>-x.x[.x]
111 ver = mt[2]
112 ver = ver.split(".");
114 # versions >= 5.0 goes with seg_max_adjust enabled
115 major = int(ver[0])
117 if major >= 5:
118 return True
119 return False
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:
125 vm.launch()
126 machines = [m['name'] for m in vm.command('query-machines')]
127 vm.shutdown()
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.
134 mtypes = list()
135 for m in machines:
136 if self.seg_max_adjust_enabled(m):
137 enabled = 'true'
138 else:
139 enabled = 'false'
140 mtypes.append({'name': m,
141 DEV_TYPES[dev_type]['seg_max_adjust']: enabled})
143 # test each machine type for a device type
144 for mt in mtypes:
145 self.check_mt(mt, dev_type)