Standardize CpuArchitecture enum (#3456)

* CpuArchitecture: standardize use of arch enum
This commit is contained in:
mcgov 2024-10-03 14:05:41 -07:00 коммит произвёл GitHub
Родитель b3be1ce23f
Коммит 06a74eeb4a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 32 добавлений и 33 удалений

Просмотреть файл

@ -62,6 +62,7 @@ _get_init_logger = partial(get_logger, name="os")
class CpuArchitecture(str, Enum):
X64 = "x86_64"
ARM64 = "aarch64"
I386 = "i386"
class AzureCoreRepo(str, Enum):

Просмотреть файл

@ -9,7 +9,7 @@ from xml import etree
from assertpy import assert_that
from lisa.executable import Tool
from lisa.operating_system import FreeBSD, Posix
from lisa.operating_system import CpuArchitecture, FreeBSD, Posix
from lisa.tools.powershell import PowerShell
from lisa.util import LisaException, find_group_in_lines, find_groups_in_lines
@ -53,8 +53,12 @@ class CPUInfo:
return self.__str__()
ARCH_X86_64 = "x86_64"
ARCH_AARCH64 = "aarch64"
ArchitectureNames = {
"x86_64": CpuArchitecture.X64,
"aarch64": CpuArchitecture.ARM64,
"amd64": CpuArchitecture.X64,
"arm64": CpuArchitecture.ARM64,
}
class Lscpu(Tool):
@ -79,12 +83,7 @@ class Lscpu(Tool):
__clusters = re.compile(r"^Cluster\(s\):[ ]+([\d]+)\r?$", re.M)
# Architecture: x86_64
__architecture_pattern = re.compile(r"^Architecture:\s+(.*)?\r$", re.M)
__architecture_dict = {
"x86_64": ARCH_X86_64,
"aarch64": ARCH_AARCH64,
"amd64": ARCH_X86_64,
"arm64": ARCH_AARCH64,
}
# 0 0 0 0:0:0:0
# 96 0 10 1:1:1:0
_core_numa_mappings = re.compile(
@ -131,7 +130,7 @@ class Lscpu(Tool):
)
return self._check_exists()
def get_architecture(self, force_run: bool = False) -> str:
def get_architecture(self, force_run: bool = False) -> CpuArchitecture:
architecture: str = ""
result = self.run(force_run=force_run)
matched = self.__architecture_pattern.findall(result.stdout)
@ -143,9 +142,9 @@ class Lscpu(Tool):
assert_that(
[architecture],
f"architecture {architecture} must be one of "
f"{self.__architecture_dict.keys()}.",
).is_subset_of(self.__architecture_dict.keys())
return self.__architecture_dict[architecture]
f"{ArchitectureNames.keys()}.",
).is_subset_of(ArchitectureNames.keys())
return ArchitectureNames[architecture]
def get_core_count(self, force_run: bool = False) -> int:
result = self.run(force_run=force_run)
@ -373,13 +372,6 @@ class WindowsLscpu(Lscpu):
class BSDLscpu(Lscpu):
__architecture_dict = {
"x86_64": "x86_64",
"aarch64": "aarch64",
"amd64": "x86_64",
"arm64": "aarch64",
}
# FreeBSD/SMP: 1 package(s) x 4 core(s) x 2 hardware threads
__cpu_info = re.compile(r"FreeBSD/SMP: (?P<package_count>\d+) package\(s\) .*")
@ -392,16 +384,16 @@ class BSDLscpu(Lscpu):
core_count = int(output.stdout.strip())
return core_count
def get_architecture(self, force_run: bool = False) -> str:
def get_architecture(self, force_run: bool = False) -> CpuArchitecture:
architecture = self.run(
"-n hw.machine_arch", force_run=force_run
).stdout.strip()
assert_that(
[architecture],
f"architecture {architecture} must be one of "
f"{self.__architecture_dict.keys()}.",
).is_subset_of(self.__architecture_dict.keys())
return self.__architecture_dict[architecture]
f"{ArchitectureNames.keys()}.",
).is_subset_of(ArchitectureNames.keys())
return ArchitectureNames[architecture]
def get_cluster_count(self, force_run: bool = False) -> int:
output = self.run(

Просмотреть файл

@ -580,7 +580,7 @@ class AzureImageStandard(TestSuite):
}
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
repo_url = repo_url_map.get(CpuArchitecture(arch), None)
repo_url = repo_url_map.get(arch, None)
contains_security_keyword = any(
[
"-security" in repository.name
@ -823,7 +823,7 @@ class AzureImageStandard(TestSuite):
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
current_console_device = console_device[CpuArchitecture(arch)]
current_console_device = console_device[arch]
console_enabled_pattern = re.compile(
rf"^(.*console \[{current_console_device}\] enabled.*)$", re.M
)

Просмотреть файл

@ -12,10 +12,16 @@ from lisa import (
TestSuiteMetadata,
simple_requirement,
)
from lisa.operating_system import CBLMariner, Debian, Fedora, Linux, Suse
from lisa.operating_system import (
CBLMariner,
CpuArchitecture,
Debian,
Fedora,
Linux,
Suse,
)
from lisa.sut_orchestrator import AZURE
from lisa.tools import Lscpu, Modprobe
from lisa.tools.lscpu import ARCH_AARCH64, ARCH_X86_64
from lisa.util import MissingPackagesException
# See docs for hypercall spec, sharing os info
@ -44,8 +50,8 @@ class HvOsPlatformInfo:
# HV_REGISTER_GUEST_OSID constant declared in linus kernel source:
# arch/{ARCH_NAME}/include/asm/hyperv-tlfs.h
HV_REGISTER_GUEST_OSID = {
ARCH_AARCH64: "0x00090002",
ARCH_X86_64: "0x40000000",
CpuArchitecture.ARM64: "0x00090002",
CpuArchitecture.X64: "0x40000000",
}
OS_ID_UNDEFINED = 0
OS_ID_MSDOS = 1

Просмотреть файл

@ -159,7 +159,7 @@ class TimeSync(TestSuite):
}
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
clocksource = clocksource_map.get(CpuArchitecture(arch), None)
clocksource = clocksource_map.get(arch, None)
if not clocksource:
raise UnsupportedCpuArchitectureException(arch)
cat = node.tools[Cat]
@ -250,7 +250,7 @@ class TimeSync(TestSuite):
}
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
clock_event_name = clockevent_map.get(CpuArchitecture(arch), None)
clock_event_name = clockevent_map.get(arch, None)
if not clock_event_name:
raise UnsupportedCpuArchitectureException(arch)
cat = node.tools[Cat]
@ -382,7 +382,7 @@ class TimeSync(TestSuite):
def verify_pmu_disabled_for_arm64(self, node: Node) -> None:
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
if CpuArchitecture(arch) != "aarch64":
if arch != CpuArchitecture.ARM64:
raise SkippedException(
f"This test case does not support {arch}. "
"This validation is only for ARM64."