Skip to content

Commit 06a74ee

Browse files
authored
Standardize CpuArchitecture enum (#3456)
* CpuArchitecture: standardize use of arch enum
1 parent b3be1ce commit 06a74ee

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

lisa/operating_system.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
class CpuArchitecture(str, Enum):
6363
X64 = "x86_64"
6464
ARM64 = "aarch64"
65+
I386 = "i386"
6566

6667

6768
class AzureCoreRepo(str, Enum):

lisa/tools/lscpu.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from assertpy import assert_that
1010

1111
from lisa.executable import Tool
12-
from lisa.operating_system import FreeBSD, Posix
12+
from lisa.operating_system import CpuArchitecture, FreeBSD, Posix
1313
from lisa.tools.powershell import PowerShell
1414
from lisa.util import LisaException, find_group_in_lines, find_groups_in_lines
1515

@@ -53,8 +53,12 @@ def __repr__(self) -> str:
5353
return self.__str__()
5454

5555

56-
ARCH_X86_64 = "x86_64"
57-
ARCH_AARCH64 = "aarch64"
56+
ArchitectureNames = {
57+
"x86_64": CpuArchitecture.X64,
58+
"aarch64": CpuArchitecture.ARM64,
59+
"amd64": CpuArchitecture.X64,
60+
"arm64": CpuArchitecture.ARM64,
61+
}
5862

5963

6064
class Lscpu(Tool):
@@ -79,12 +83,7 @@ class Lscpu(Tool):
7983
__clusters = re.compile(r"^Cluster\(s\):[ ]+([\d]+)\r?$", re.M)
8084
# Architecture: x86_64
8185
__architecture_pattern = re.compile(r"^Architecture:\s+(.*)?\r$", re.M)
82-
__architecture_dict = {
83-
"x86_64": ARCH_X86_64,
84-
"aarch64": ARCH_AARCH64,
85-
"amd64": ARCH_X86_64,
86-
"arm64": ARCH_AARCH64,
87-
}
86+
8887
# 0 0 0 0:0:0:0
8988
# 96 0 10 1:1:1:0
9089
_core_numa_mappings = re.compile(
@@ -131,7 +130,7 @@ def _install(self) -> bool:
131130
)
132131
return self._check_exists()
133132

134-
def get_architecture(self, force_run: bool = False) -> str:
133+
def get_architecture(self, force_run: bool = False) -> CpuArchitecture:
135134
architecture: str = ""
136135
result = self.run(force_run=force_run)
137136
matched = self.__architecture_pattern.findall(result.stdout)
@@ -143,9 +142,9 @@ def get_architecture(self, force_run: bool = False) -> str:
143142
assert_that(
144143
[architecture],
145144
f"architecture {architecture} must be one of "
146-
f"{self.__architecture_dict.keys()}.",
147-
).is_subset_of(self.__architecture_dict.keys())
148-
return self.__architecture_dict[architecture]
145+
f"{ArchitectureNames.keys()}.",
146+
).is_subset_of(ArchitectureNames.keys())
147+
return ArchitectureNames[architecture]
149148

150149
def get_core_count(self, force_run: bool = False) -> int:
151150
result = self.run(force_run=force_run)
@@ -373,13 +372,6 @@ def _get_physical_core_count(self, force_run: bool = False) -> int:
373372

374373

375374
class BSDLscpu(Lscpu):
376-
__architecture_dict = {
377-
"x86_64": "x86_64",
378-
"aarch64": "aarch64",
379-
"amd64": "x86_64",
380-
"arm64": "aarch64",
381-
}
382-
383375
# FreeBSD/SMP: 1 package(s) x 4 core(s) x 2 hardware threads
384376
__cpu_info = re.compile(r"FreeBSD/SMP: (?P<package_count>\d+) package\(s\) .*")
385377

@@ -392,16 +384,16 @@ def get_core_count(self, force_run: bool = False) -> int:
392384
core_count = int(output.stdout.strip())
393385
return core_count
394386

395-
def get_architecture(self, force_run: bool = False) -> str:
387+
def get_architecture(self, force_run: bool = False) -> CpuArchitecture:
396388
architecture = self.run(
397389
"-n hw.machine_arch", force_run=force_run
398390
).stdout.strip()
399391
assert_that(
400392
[architecture],
401393
f"architecture {architecture} must be one of "
402-
f"{self.__architecture_dict.keys()}.",
403-
).is_subset_of(self.__architecture_dict.keys())
404-
return self.__architecture_dict[architecture]
394+
f"{ArchitectureNames.keys()}.",
395+
).is_subset_of(ArchitectureNames.keys())
396+
return ArchitectureNames[architecture]
405397

406398
def get_cluster_count(self, force_run: bool = False) -> int:
407399
output = self.run(

microsoft/testsuites/core/azure_image_standard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def verify_repository_installed(self, node: Node) -> None: # noqa: C901
580580
}
581581
lscpu = node.tools[Lscpu]
582582
arch = lscpu.get_architecture()
583-
repo_url = repo_url_map.get(CpuArchitecture(arch), None)
583+
repo_url = repo_url_map.get(arch, None)
584584
contains_security_keyword = any(
585585
[
586586
"-security" in repository.name
@@ -823,7 +823,7 @@ def verify_serial_console_is_enabled(self, node: Node) -> None:
823823

824824
lscpu = node.tools[Lscpu]
825825
arch = lscpu.get_architecture()
826-
current_console_device = console_device[CpuArchitecture(arch)]
826+
current_console_device = console_device[arch]
827827
console_enabled_pattern = re.compile(
828828
rf"^(.*console \[{current_console_device}\] enabled.*)$", re.M
829829
)

microsoft/testsuites/core/msr.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
TestSuiteMetadata,
1313
simple_requirement,
1414
)
15-
from lisa.operating_system import CBLMariner, Debian, Fedora, Linux, Suse
15+
from lisa.operating_system import (
16+
CBLMariner,
17+
CpuArchitecture,
18+
Debian,
19+
Fedora,
20+
Linux,
21+
Suse,
22+
)
1623
from lisa.sut_orchestrator import AZURE
1724
from lisa.tools import Lscpu, Modprobe
18-
from lisa.tools.lscpu import ARCH_AARCH64, ARCH_X86_64
1925
from lisa.util import MissingPackagesException
2026

2127
# See docs for hypercall spec, sharing os info
@@ -44,8 +50,8 @@ class HvOsPlatformInfo:
4450
# HV_REGISTER_GUEST_OSID constant declared in linus kernel source:
4551
# arch/{ARCH_NAME}/include/asm/hyperv-tlfs.h
4652
HV_REGISTER_GUEST_OSID = {
47-
ARCH_AARCH64: "0x00090002",
48-
ARCH_X86_64: "0x40000000",
53+
CpuArchitecture.ARM64: "0x00090002",
54+
CpuArchitecture.X64: "0x40000000",
4955
}
5056
OS_ID_UNDEFINED = 0
5157
OS_ID_MSDOS = 1

microsoft/testsuites/core/timesync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def verify_timesync_unbind_clocksource(self, node: Node, log: Logger) -> None:
159159
}
160160
lscpu = node.tools[Lscpu]
161161
arch = lscpu.get_architecture()
162-
clocksource = clocksource_map.get(CpuArchitecture(arch), None)
162+
clocksource = clocksource_map.get(arch, None)
163163
if not clocksource:
164164
raise UnsupportedCpuArchitectureException(arch)
165165
cat = node.tools[Cat]
@@ -250,7 +250,7 @@ def verify_timesync_unbind_clockevent(self, node: Node) -> None:
250250
}
251251
lscpu = node.tools[Lscpu]
252252
arch = lscpu.get_architecture()
253-
clock_event_name = clockevent_map.get(CpuArchitecture(arch), None)
253+
clock_event_name = clockevent_map.get(arch, None)
254254
if not clock_event_name:
255255
raise UnsupportedCpuArchitectureException(arch)
256256
cat = node.tools[Cat]
@@ -382,7 +382,7 @@ def verify_timesync_chrony(self, node: Node) -> None:
382382
def verify_pmu_disabled_for_arm64(self, node: Node) -> None:
383383
lscpu = node.tools[Lscpu]
384384
arch = lscpu.get_architecture()
385-
if CpuArchitecture(arch) != "aarch64":
385+
if arch != CpuArchitecture.ARM64:
386386
raise SkippedException(
387387
f"This test case does not support {arch}. "
388388
"This validation is only for ARM64."

0 commit comments

Comments
 (0)