Skip to content

Commit d88ddae

Browse files
Jonathan Woollett-LightJonathanWoollett-Light
authored andcommitted
refactor(test): Use structured matching on cpu properties
Uses structured matching on cpu properties to clarify the different cases. Signed-off-by: Jonathan Woollett-Light <[email protected]>
1 parent d761b01 commit d88ddae

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

tests/framework/utils_cpu_templates.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import pytest
1010

11-
import framework.utils_cpuid as cpuid_utils
1211
from framework.properties import global_props
12+
from framework.utils_cpuid import CpuModel, CpuVendor, get_cpu_vendor
1313

1414
# All existing CPU templates available on Intel
1515
INTEL_TEMPLATES = ["C3", "T2", "T2CL", "T2S"]
@@ -24,23 +24,20 @@ def get_supported_cpu_templates():
2424
Return the list of CPU templates supported by the platform.
2525
"""
2626
# pylint:disable=too-many-return-statements
27-
match cpuid_utils.get_cpu_vendor():
28-
case cpuid_utils.CpuVendor.INTEL:
29-
# T2CL template is only supported on Cascade Lake and newer CPUs.
30-
if global_props.cpu_codename == cpuid_utils.CpuModel.INTEL_SKYLAKE:
31-
return sorted(set(INTEL_TEMPLATES) - set(["T2CL"]))
27+
host_linux = global_props.host_linux_version_tpl
28+
29+
match get_cpu_vendor(), global_props.cpu_codename:
30+
# T2CL template is only supported on Cascade Lake and newer CPUs.
31+
case CpuVendor.INTEL, CpuModel.INTEL_SKYLAKE:
32+
return sorted(set(INTEL_TEMPLATES) - set(["T2CL"]))
33+
case CpuVendor.INTEL, _:
3234
return INTEL_TEMPLATES
33-
case cpuid_utils.CpuVendor.AMD:
35+
case CpuVendor.AMD, _:
3436
return AMD_TEMPLATES
35-
case cpuid_utils.CpuVendor.ARM:
36-
if global_props.host_linux_version_tpl < (6, 1):
37-
return []
38-
match global_props.cpu_model:
39-
case cpuid_utils.CpuModel.ARM_NEOVERSE_N1:
40-
return []
41-
case cpuid_utils.CpuModel.ARM_NEOVERSE_V1:
42-
return ARM_TEMPLATES
43-
return []
37+
case CpuVendor.ARM, CpuModel.ARM_NEOVERSE_V1 if host_linux >= (6, 1):
38+
return ARM_TEMPLATES
39+
case _:
40+
return []
4441

4542

4643
SUPPORTED_CPU_TEMPLATES = get_supported_cpu_templates()
@@ -57,23 +54,22 @@ def get_supported_custom_cpu_templates():
5754
"""
5855
Return the list of custom CPU templates supported by the platform.
5956
"""
57+
host_linux = global_props.host_linux_version_tpl
6058

61-
match cpuid_utils.get_cpu_vendor():
62-
case cpuid_utils.CpuVendor.INTEL:
63-
# T2CL template is only supported on Cascade Lake and newer CPUs.
64-
if global_props.cpu_codename == cpuid_utils.CpuModel.INTEL_SKYLAKE:
65-
return set(INTEL_TEMPLATES) - {"T2CL"}
59+
match get_cpu_vendor(), global_props.cpu_codename:
60+
# T2CL template is only supported on Cascade Lake and newer CPUs.
61+
case CpuVendor.INTEL, CpuModel.INTEL_SKYLAKE:
62+
return set(INTEL_TEMPLATES) - {"T2CL"}
63+
case CpuVendor.INTEL, _:
6664
return INTEL_TEMPLATES
67-
case cpuid_utils.CpuVendor.AMD:
65+
case CpuVendor.AMD, _:
6866
return AMD_TEMPLATES
69-
case cpuid_utils.CpuVendor.ARM:
70-
if global_props.host_linux_version_tpl < (6, 1):
71-
return []
72-
match global_props.cpu_model:
73-
case cpuid_utils.CpuModel.ARM_NEOVERSE_N1:
74-
return AARCH64_CUSTOM_CPU_TEMPLATES_G2
75-
case cpuid_utils.CpuModel.ARM_NEOVERSE_V1:
76-
return AARCH64_CUSTOM_CPU_TEMPLATES_G3
67+
case CpuVendor.ARM, CpuModel.ARM_NEOVERSE_N1 if host_linux >= (6, 1):
68+
return AARCH64_CUSTOM_CPU_TEMPLATES_G2
69+
case CpuVendor.ARM, CpuModel.ARM_NEOVERSE_V1 if host_linux >= (6, 1):
70+
return AARCH64_CUSTOM_CPU_TEMPLATES_G3
71+
case _:
72+
return []
7773

7874

7975
def custom_cpu_templates_params():

0 commit comments

Comments
 (0)