3 # Basic validation of x86 versioned CPU models and CPU model aliases
5 # Copyright (c) 2019 Red Hat Inc
8 # Eduardo Habkost <ehabkost@redhat.com>
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2 of the License, or (at your option) any later version.
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 def get_cpu_prop(vm
, prop
):
29 cpu_path
= vm
.command('query-cpus')[0].get('qom_path')
30 return vm
.command('qom-get', path
=cpu_path
, property=prop
)
32 class X86CPUModelAliases(avocado_qemu
.Test
):
34 Validation of PC CPU model versions and CPU model aliases
36 :avocado: tags=arch:x86_64
38 def validate_aliases(self
, cpus
):
39 for c
in cpus
.values():
41 # all aliases must point to a valid CPU model name:
42 self
.assertIn(c
['alias-of'], cpus
,
43 '%s.alias-of (%s) is not a valid CPU model name' % (c
['name'], c
['alias-of']))
44 # aliases must not point to aliases
45 self
.assertNotIn('alias-of', cpus
[c
['alias-of']],
46 '%s.alias-of (%s) points to another alias' % (c
['name'], c
['alias-of']))
48 # aliases must not be static
49 self
.assertFalse(c
['static'])
51 def validate_variant_aliases(self
, cpus
):
52 # -noTSX, -IBRS and -IBPB variants of CPU models are special:
53 # they shouldn't have their own versions:
54 self
.assertNotIn("Haswell-noTSX-v1", cpus
,
55 "Haswell-noTSX shouldn't be versioned")
56 self
.assertNotIn("Broadwell-noTSX-v1", cpus
,
57 "Broadwell-noTSX shouldn't be versioned")
58 self
.assertNotIn("Nehalem-IBRS-v1", cpus
,
59 "Nehalem-IBRS shouldn't be versioned")
60 self
.assertNotIn("Westmere-IBRS-v1", cpus
,
61 "Westmere-IBRS shouldn't be versioned")
62 self
.assertNotIn("SandyBridge-IBRS-v1", cpus
,
63 "SandyBridge-IBRS shouldn't be versioned")
64 self
.assertNotIn("IvyBridge-IBRS-v1", cpus
,
65 "IvyBridge-IBRS shouldn't be versioned")
66 self
.assertNotIn("Haswell-noTSX-IBRS-v1", cpus
,
67 "Haswell-noTSX-IBRS shouldn't be versioned")
68 self
.assertNotIn("Haswell-IBRS-v1", cpus
,
69 "Haswell-IBRS shouldn't be versioned")
70 self
.assertNotIn("Broadwell-noTSX-IBRS-v1", cpus
,
71 "Broadwell-noTSX-IBRS shouldn't be versioned")
72 self
.assertNotIn("Broadwell-IBRS-v1", cpus
,
73 "Broadwell-IBRS shouldn't be versioned")
74 self
.assertNotIn("Skylake-Client-IBRS-v1", cpus
,
75 "Skylake-Client-IBRS shouldn't be versioned")
76 self
.assertNotIn("Skylake-Server-IBRS-v1", cpus
,
77 "Skylake-Server-IBRS shouldn't be versioned")
78 self
.assertNotIn("EPYC-IBPB-v1", cpus
,
79 "EPYC-IBPB shouldn't be versioned")
81 def test_4_0_alias_compatibility(self
):
82 """Check if pc-*-4.0 unversioned CPU model won't be reported as aliases"""
83 # pc-*-4.0 won't expose non-versioned CPU models as aliases
84 # We do this to help management software to keep compatibility
85 # with older QEMU versions that didn't have the versioned CPU model
86 self
.vm
.add_args('-S')
87 self
.vm
.set_machine('pc-i440fx-4.0')
89 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
91 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
92 'unversioned Cascadelake-Server CPU model must not be static')
93 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server'],
94 'Cascadelake-Server must not be an alias')
95 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
96 'Cascadelake-Server-v1 must not be an alias')
98 self
.assertFalse(cpus
['qemu64']['static'],
99 'unversioned qemu64 CPU model must not be static')
100 self
.assertNotIn('alias-of', cpus
['qemu64'],
101 'qemu64 must not be an alias')
102 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
103 'qemu64-v1 must not be an alias')
105 self
.validate_variant_aliases(cpus
)
107 # On pc-*-4.0, no CPU model should be reported as an alias:
108 for name
,c
in cpus
.items():
109 self
.assertNotIn('alias-of', c
, "%s shouldn't be an alias" % (name
))
111 def test_4_1_alias(self
):
112 """Check if unversioned CPU model is an alias pointing to right version"""
113 self
.vm
.add_args('-S')
114 self
.vm
.set_machine('pc-i440fx-4.1')
117 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
119 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
120 'unversioned Cascadelake-Server CPU model must not be static')
121 self
.assertEquals(cpus
['Cascadelake-Server'].get('alias-of'), 'Cascadelake-Server-v1',
122 'Cascadelake-Server must be an alias of Cascadelake-Server-v1')
123 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
124 'Cascadelake-Server-v1 must not be an alias')
126 self
.assertFalse(cpus
['qemu64']['static'],
127 'unversioned qemu64 CPU model must not be static')
128 self
.assertEquals(cpus
['qemu64'].get('alias-of'), 'qemu64-v1',
129 'qemu64 must be an alias of qemu64-v1')
130 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
131 'qemu64-v1 must not be an alias')
133 self
.validate_variant_aliases(cpus
)
135 # On pc-*-4.1, -noTSX and -IBRS models should be aliases:
136 self
.assertEquals(cpus
["Haswell"].get('alias-of'),
138 "Haswell must be an alias")
139 self
.assertEquals(cpus
["Haswell-noTSX"].get('alias-of'),
141 "Haswell-noTSX must be an alias")
142 self
.assertEquals(cpus
["Haswell-IBRS"].get('alias-of'),
144 "Haswell-IBRS must be an alias")
145 self
.assertEquals(cpus
["Haswell-noTSX-IBRS"].get('alias-of'),
147 "Haswell-noTSX-IBRS must be an alias")
149 self
.assertEquals(cpus
["Broadwell"].get('alias-of'),
151 "Broadwell must be an alias")
152 self
.assertEquals(cpus
["Broadwell-noTSX"].get('alias-of'),
154 "Broadwell-noTSX must be an alias")
155 self
.assertEquals(cpus
["Broadwell-IBRS"].get('alias-of'),
157 "Broadwell-IBRS must be an alias")
158 self
.assertEquals(cpus
["Broadwell-noTSX-IBRS"].get('alias-of'),
160 "Broadwell-noTSX-IBRS must be an alias")
162 self
.assertEquals(cpus
["Nehalem"].get('alias-of'),
164 "Nehalem must be an alias")
165 self
.assertEquals(cpus
["Nehalem-IBRS"].get('alias-of'),
167 "Nehalem-IBRS must be an alias")
169 self
.assertEquals(cpus
["Westmere"].get('alias-of'),
171 "Westmere must be an alias")
172 self
.assertEquals(cpus
["Westmere-IBRS"].get('alias-of'),
174 "Westmere-IBRS must be an alias")
176 self
.assertEquals(cpus
["SandyBridge"].get('alias-of'),
178 "SandyBridge must be an alias")
179 self
.assertEquals(cpus
["SandyBridge-IBRS"].get('alias-of'),
181 "SandyBridge-IBRS must be an alias")
183 self
.assertEquals(cpus
["IvyBridge"].get('alias-of'),
185 "IvyBridge must be an alias")
186 self
.assertEquals(cpus
["IvyBridge-IBRS"].get('alias-of'),
188 "IvyBridge-IBRS must be an alias")
190 self
.assertEquals(cpus
["Skylake-Client"].get('alias-of'),
192 "Skylake-Client must be an alias")
193 self
.assertEquals(cpus
["Skylake-Client-IBRS"].get('alias-of'),
195 "Skylake-Client-IBRS must be an alias")
197 self
.assertEquals(cpus
["Skylake-Server"].get('alias-of'),
199 "Skylake-Server must be an alias")
200 self
.assertEquals(cpus
["Skylake-Server-IBRS"].get('alias-of'),
202 "Skylake-Server-IBRS must be an alias")
204 self
.assertEquals(cpus
["EPYC"].get('alias-of'),
206 "EPYC must be an alias")
207 self
.assertEquals(cpus
["EPYC-IBPB"].get('alias-of'),
209 "EPYC-IBPB must be an alias")
211 self
.validate_aliases(cpus
)
213 def test_none_alias(self
):
214 """Check if unversioned CPU model is an alias pointing to some version"""
215 self
.vm
.add_args('-S')
216 self
.vm
.set_machine('none')
219 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
221 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
222 'unversioned Cascadelake-Server CPU model must not be static')
223 self
.assertTrue(re
.match('Cascadelake-Server-v[0-9]+', cpus
['Cascadelake-Server']['alias-of']),
224 'Cascadelake-Server must be an alias of versioned CPU model')
225 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
226 'Cascadelake-Server-v1 must not be an alias')
228 self
.assertFalse(cpus
['qemu64']['static'],
229 'unversioned qemu64 CPU model must not be static')
230 self
.assertTrue(re
.match('qemu64-v[0-9]+', cpus
['qemu64']['alias-of']),
231 'qemu64 must be an alias of versioned CPU model')
232 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
233 'qemu64-v1 must not be an alias')
235 self
.validate_aliases(cpus
)
238 class CascadelakeArchCapabilities(avocado_qemu
.Test
):
240 Validation of Cascadelake arch-capabilities
242 :avocado: tags=arch:x86_64
248 vm
.set_machine('pc-i440fx-4.1')
249 vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off')
251 self
.assertFalse(get_cpu_prop(vm
, 'arch-capabilities'),
252 'pc-i440fx-4.1 + Cascadelake-Server should not have arch-capabilities')
257 vm
.set_machine('pc-i440fx-4.0')
258 vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off')
260 self
.assertFalse(get_cpu_prop(vm
, 'arch-capabilities'),
261 'pc-i440fx-4.0 + Cascadelake-Server should not have arch-capabilities')
263 def test_set_4_0(self
):
264 # command line must override machine-type if CPU model is not versioned:
267 vm
.set_machine('pc-i440fx-4.0')
268 vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off,+arch-capabilities')
270 self
.assertTrue(get_cpu_prop(vm
, 'arch-capabilities'),
271 'pc-i440fx-4.0 + Cascadelake-Server,+arch-capabilities should have arch-capabilities')
273 def test_unset_4_1(self
):
276 vm
.set_machine('pc-i440fx-4.1')
277 vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off,-arch-capabilities')
279 self
.assertFalse(get_cpu_prop(vm
, 'arch-capabilities'),
280 'pc-i440fx-4.1 + Cascadelake-Server,-arch-capabilities should not have arch-capabilities')
282 def test_v1_4_0(self
):
283 # versioned CPU model overrides machine-type:
286 vm
.set_machine('pc-i440fx-4.0')
287 vm
.add_args('-cpu', 'Cascadelake-Server-v1,x-force-features=on,check=off,enforce=off')
289 self
.assertFalse(get_cpu_prop(vm
, 'arch-capabilities'),
290 'pc-i440fx-4.0 + Cascadelake-Server-v1 should not have arch-capabilities')
292 def test_v2_4_0(self
):
295 vm
.set_machine('pc-i440fx-4.0')
296 vm
.add_args('-cpu', 'Cascadelake-Server-v2,x-force-features=on,check=off,enforce=off')
298 self
.assertTrue(get_cpu_prop(vm
, 'arch-capabilities'),
299 'pc-i440fx-4.0 + Cascadelake-Server-v2 should have arch-capabilities')
301 def test_v1_set_4_0(self
):
302 # command line must override machine-type and versioned CPU model:
305 vm
.set_machine('pc-i440fx-4.0')
306 vm
.add_args('-cpu', 'Cascadelake-Server-v1,x-force-features=on,check=off,enforce=off,+arch-capabilities')
308 self
.assertTrue(get_cpu_prop(vm
, 'arch-capabilities'),
309 'pc-i440fx-4.0 + Cascadelake-Server-v1,+arch-capabilities should have arch-capabilities')
311 def test_v2_unset_4_1(self
):
314 vm
.set_machine('pc-i440fx-4.1')
315 vm
.add_args('-cpu', 'Cascadelake-Server-v2,x-force-features=on,check=off,enforce=off,-arch-capabilities')
317 self
.assertFalse(get_cpu_prop(vm
, 'arch-capabilities'),
318 'pc-i440fx-4.1 + Cascadelake-Server-v2,-arch-capabilities should not have arch-capabilities')