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 class X86CPUModelAliases(avocado_qemu
.Test
):
30 Validation of PC CPU model versions and CPU model aliases
32 :avocado: tags=arch:x86_64
34 def validate_aliases(self
, cpus
):
35 for c
in cpus
.values():
37 # all aliases must point to a valid CPU model name:
38 self
.assertIn(c
['alias-of'], cpus
,
39 '%s.alias-of (%s) is not a valid CPU model name' % (c
['name'], c
['alias-of']))
40 # aliases must not point to aliases
41 self
.assertNotIn('alias-of', cpus
[c
['alias-of']],
42 '%s.alias-of (%s) points to another alias' % (c
['name'], c
['alias-of']))
44 # aliases must not be static
45 self
.assertFalse(c
['static'])
47 def validate_variant_aliases(self
, cpus
):
48 # -noTSX, -IBRS and -IBPB variants of CPU models are special:
49 # they shouldn't have their own versions:
50 self
.assertNotIn("Haswell-noTSX-v1", cpus
,
51 "Haswell-noTSX shouldn't be versioned")
52 self
.assertNotIn("Broadwell-noTSX-v1", cpus
,
53 "Broadwell-noTSX shouldn't be versioned")
54 self
.assertNotIn("Nehalem-IBRS-v1", cpus
,
55 "Nehalem-IBRS shouldn't be versioned")
56 self
.assertNotIn("Westmere-IBRS-v1", cpus
,
57 "Westmere-IBRS shouldn't be versioned")
58 self
.assertNotIn("SandyBridge-IBRS-v1", cpus
,
59 "SandyBridge-IBRS shouldn't be versioned")
60 self
.assertNotIn("IvyBridge-IBRS-v1", cpus
,
61 "IvyBridge-IBRS shouldn't be versioned")
62 self
.assertNotIn("Haswell-noTSX-IBRS-v1", cpus
,
63 "Haswell-noTSX-IBRS shouldn't be versioned")
64 self
.assertNotIn("Haswell-IBRS-v1", cpus
,
65 "Haswell-IBRS shouldn't be versioned")
66 self
.assertNotIn("Broadwell-noTSX-IBRS-v1", cpus
,
67 "Broadwell-noTSX-IBRS shouldn't be versioned")
68 self
.assertNotIn("Broadwell-IBRS-v1", cpus
,
69 "Broadwell-IBRS shouldn't be versioned")
70 self
.assertNotIn("Skylake-Client-IBRS-v1", cpus
,
71 "Skylake-Client-IBRS shouldn't be versioned")
72 self
.assertNotIn("Skylake-Server-IBRS-v1", cpus
,
73 "Skylake-Server-IBRS shouldn't be versioned")
74 self
.assertNotIn("EPYC-IBPB-v1", cpus
,
75 "EPYC-IBPB shouldn't be versioned")
77 def test_4_0_alias_compatibility(self
):
79 Check if pc-*-4.0 unversioned CPU model won't be reported as aliases
81 :avocado: tags=machine:pc-i440fx-4.0
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')
88 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
90 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
91 'unversioned Cascadelake-Server CPU model must not be static')
92 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server'],
93 'Cascadelake-Server must not be an alias')
94 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
95 'Cascadelake-Server-v1 must not be an alias')
97 self
.assertFalse(cpus
['qemu64']['static'],
98 'unversioned qemu64 CPU model must not be static')
99 self
.assertNotIn('alias-of', cpus
['qemu64'],
100 'qemu64 must not be an alias')
101 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
102 'qemu64-v1 must not be an alias')
104 self
.validate_variant_aliases(cpus
)
106 # On pc-*-4.0, no CPU model should be reported as an alias:
107 for name
,c
in cpus
.items():
108 self
.assertNotIn('alias-of', c
, "%s shouldn't be an alias" % (name
))
110 def test_4_1_alias(self
):
112 Check if unversioned CPU model is an alias pointing to right version
114 :avocado: tags=machine:pc-i440fx-4.1
116 self
.vm
.add_args('-S')
119 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
121 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
122 'unversioned Cascadelake-Server CPU model must not be static')
123 self
.assertEquals(cpus
['Cascadelake-Server'].get('alias-of'), 'Cascadelake-Server-v1',
124 'Cascadelake-Server must be an alias of Cascadelake-Server-v1')
125 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
126 'Cascadelake-Server-v1 must not be an alias')
128 self
.assertFalse(cpus
['qemu64']['static'],
129 'unversioned qemu64 CPU model must not be static')
130 self
.assertEquals(cpus
['qemu64'].get('alias-of'), 'qemu64-v1',
131 'qemu64 must be an alias of qemu64-v1')
132 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
133 'qemu64-v1 must not be an alias')
135 self
.validate_variant_aliases(cpus
)
137 # On pc-*-4.1, -noTSX and -IBRS models should be aliases:
138 self
.assertEquals(cpus
["Haswell"].get('alias-of'),
140 "Haswell must be an alias")
141 self
.assertEquals(cpus
["Haswell-noTSX"].get('alias-of'),
143 "Haswell-noTSX must be an alias")
144 self
.assertEquals(cpus
["Haswell-IBRS"].get('alias-of'),
146 "Haswell-IBRS must be an alias")
147 self
.assertEquals(cpus
["Haswell-noTSX-IBRS"].get('alias-of'),
149 "Haswell-noTSX-IBRS must be an alias")
151 self
.assertEquals(cpus
["Broadwell"].get('alias-of'),
153 "Broadwell must be an alias")
154 self
.assertEquals(cpus
["Broadwell-noTSX"].get('alias-of'),
156 "Broadwell-noTSX must be an alias")
157 self
.assertEquals(cpus
["Broadwell-IBRS"].get('alias-of'),
159 "Broadwell-IBRS must be an alias")
160 self
.assertEquals(cpus
["Broadwell-noTSX-IBRS"].get('alias-of'),
162 "Broadwell-noTSX-IBRS must be an alias")
164 self
.assertEquals(cpus
["Nehalem"].get('alias-of'),
166 "Nehalem must be an alias")
167 self
.assertEquals(cpus
["Nehalem-IBRS"].get('alias-of'),
169 "Nehalem-IBRS must be an alias")
171 self
.assertEquals(cpus
["Westmere"].get('alias-of'),
173 "Westmere must be an alias")
174 self
.assertEquals(cpus
["Westmere-IBRS"].get('alias-of'),
176 "Westmere-IBRS must be an alias")
178 self
.assertEquals(cpus
["SandyBridge"].get('alias-of'),
180 "SandyBridge must be an alias")
181 self
.assertEquals(cpus
["SandyBridge-IBRS"].get('alias-of'),
183 "SandyBridge-IBRS must be an alias")
185 self
.assertEquals(cpus
["IvyBridge"].get('alias-of'),
187 "IvyBridge must be an alias")
188 self
.assertEquals(cpus
["IvyBridge-IBRS"].get('alias-of'),
190 "IvyBridge-IBRS must be an alias")
192 self
.assertEquals(cpus
["Skylake-Client"].get('alias-of'),
194 "Skylake-Client must be an alias")
195 self
.assertEquals(cpus
["Skylake-Client-IBRS"].get('alias-of'),
197 "Skylake-Client-IBRS must be an alias")
199 self
.assertEquals(cpus
["Skylake-Server"].get('alias-of'),
201 "Skylake-Server must be an alias")
202 self
.assertEquals(cpus
["Skylake-Server-IBRS"].get('alias-of'),
204 "Skylake-Server-IBRS must be an alias")
206 self
.assertEquals(cpus
["EPYC"].get('alias-of'),
208 "EPYC must be an alias")
209 self
.assertEquals(cpus
["EPYC-IBPB"].get('alias-of'),
211 "EPYC-IBPB must be an alias")
213 self
.validate_aliases(cpus
)
215 def test_none_alias(self
):
217 Check if unversioned CPU model is an alias pointing to some version
219 :avocado: tags=machine:none
221 self
.vm
.add_args('-S')
224 cpus
= dict((m
['name'], m
) for m
in self
.vm
.command('query-cpu-definitions'))
226 self
.assertFalse(cpus
['Cascadelake-Server']['static'],
227 'unversioned Cascadelake-Server CPU model must not be static')
228 self
.assertTrue(re
.match('Cascadelake-Server-v[0-9]+', cpus
['Cascadelake-Server']['alias-of']),
229 'Cascadelake-Server must be an alias of versioned CPU model')
230 self
.assertNotIn('alias-of', cpus
['Cascadelake-Server-v1'],
231 'Cascadelake-Server-v1 must not be an alias')
233 self
.assertFalse(cpus
['qemu64']['static'],
234 'unversioned qemu64 CPU model must not be static')
235 self
.assertTrue(re
.match('qemu64-v[0-9]+', cpus
['qemu64']['alias-of']),
236 'qemu64 must be an alias of versioned CPU model')
237 self
.assertNotIn('alias-of', cpus
['qemu64-v1'],
238 'qemu64-v1 must not be an alias')
240 self
.validate_aliases(cpus
)
243 class CascadelakeArchCapabilities(avocado_qemu
.Test
):
245 Validation of Cascadelake arch-capabilities
247 :avocado: tags=arch:x86_64
249 def get_cpu_prop(self
, prop
):
250 cpu_path
= self
.vm
.command('query-cpus')[0].get('qom_path')
251 return self
.vm
.command('qom-get', path
=cpu_path
, property=prop
)
255 :avocado: tags=machine:pc-i440fx-4.1
258 self
.vm
.add_args('-S')
259 self
.vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off')
261 self
.assertFalse(self
.get_cpu_prop('arch-capabilities'),
262 'pc-i440fx-4.1 + Cascadelake-Server should not have arch-capabilities')
266 :avocado: tags=machine:pc-i440fx-4.0
268 self
.vm
.add_args('-S')
269 self
.vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off')
271 self
.assertFalse(self
.get_cpu_prop('arch-capabilities'),
272 'pc-i440fx-4.0 + Cascadelake-Server should not have arch-capabilities')
274 def test_set_4_0(self
):
276 :avocado: tags=machine:pc-i440fx-4.0
278 # command line must override machine-type if CPU model is not versioned:
279 self
.vm
.add_args('-S')
280 self
.vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off,+arch-capabilities')
282 self
.assertTrue(self
.get_cpu_prop('arch-capabilities'),
283 'pc-i440fx-4.0 + Cascadelake-Server,+arch-capabilities should have arch-capabilities')
285 def test_unset_4_1(self
):
287 :avocado: tags=machine:pc-i440fx-4.1
289 self
.vm
.add_args('-S')
290 self
.vm
.add_args('-cpu', 'Cascadelake-Server,x-force-features=on,check=off,enforce=off,-arch-capabilities')
292 self
.assertFalse(self
.get_cpu_prop('arch-capabilities'),
293 'pc-i440fx-4.1 + Cascadelake-Server,-arch-capabilities should not have arch-capabilities')
295 def test_v1_4_0(self
):
297 :avocado: tags=machine:pc-i440fx-4.0
299 # versioned CPU model overrides machine-type:
300 self
.vm
.add_args('-S')
301 self
.vm
.add_args('-cpu', 'Cascadelake-Server-v1,x-force-features=on,check=off,enforce=off')
303 self
.assertFalse(self
.get_cpu_prop('arch-capabilities'),
304 'pc-i440fx-4.0 + Cascadelake-Server-v1 should not have arch-capabilities')
306 def test_v2_4_0(self
):
308 :avocado: tags=machine:pc-i440fx-4.0
310 self
.vm
.add_args('-S')
311 self
.vm
.add_args('-cpu', 'Cascadelake-Server-v2,x-force-features=on,check=off,enforce=off')
313 self
.assertTrue(self
.get_cpu_prop('arch-capabilities'),
314 'pc-i440fx-4.0 + Cascadelake-Server-v2 should have arch-capabilities')
316 def test_v1_set_4_0(self
):
318 :avocado: tags=machine:pc-i440fx-4.0
320 # command line must override machine-type and versioned CPU model:
321 self
.vm
.add_args('-S')
322 self
.vm
.add_args('-cpu', 'Cascadelake-Server-v1,x-force-features=on,check=off,enforce=off,+arch-capabilities')
324 self
.assertTrue(self
.get_cpu_prop('arch-capabilities'),
325 'pc-i440fx-4.0 + Cascadelake-Server-v1,+arch-capabilities should have arch-capabilities')
327 def test_v2_unset_4_1(self
):
329 :avocado: tags=machine:pc-i440fx-4.1
331 self
.vm
.add_args('-S')
332 self
.vm
.add_args('-cpu', 'Cascadelake-Server-v2,x-force-features=on,check=off,enforce=off,-arch-capabilities')
334 self
.assertFalse(self
.get_cpu_prop('arch-capabilities'),
335 'pc-i440fx-4.1 + Cascadelake-Server-v2,-arch-capabilities should not have arch-capabilities')