Skip to content

Commit

Permalink
Add arm64 arch check for clocksource clcokevent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lubaihua33 committed Jan 21, 2022
1 parent 8123d4d commit 5798bbe
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lisa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PassedException,
SkippedException,
TcpConnetionException,
UnsupportedCpuArchitectureException,
UnsupportedDistroException,
UnsupportedOperationException,
constants,
Expand All @@ -41,6 +42,7 @@
"TestSuiteMetadata",
"TestCaseMetadata",
"TestSuite",
"UnsupportedCpuArchitectureException",
"UnsupportedDistroException",
"UnsupportedOperationException",
"create_timer",
Expand Down
7 changes: 6 additions & 1 deletion lisa/operating_system.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import re
import time
from dataclasses import dataclass
from enum import Enum
from functools import partial
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -44,6 +44,11 @@
_get_init_logger = partial(get_logger, name="os")


class CpuArchitecture(str, Enum):
X64 = "x86_64"
ARM64 = "aarch64"


@dataclass
# stores information about repository in Posix operating systems
class RepositoryInfo(object):
Expand Down
2 changes: 1 addition & 1 deletion lisa/tools/lscpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Lscpu(Tool):
__sockets = re.compile(r"^Socket\(s\):[ ]+([\d]+)\r?$", re.M)
# Architecture: x86_64
__architecture_pattern = re.compile(r"^Architecture:\s+(.*)?\r$", re.M)
__valid_architecture_list = ["x86_64"]
__valid_architecture_list = ["x86_64", "aarch64"]
# 0 0 0 0:0:0:0
# 96 0 10 1:1:1:0
_core_numa_mappings = re.compile(
Expand Down
13 changes: 13 additions & 0 deletions lisa/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def __str__(self) -> str:
return message


class UnsupportedCpuArchitectureException(LisaException):
"""
This exception is used to indicate that a test case does not support the
Architecture.
"""

def __init__(self, arch: str = "") -> None:
self.arch = arch

def __str__(self) -> str:
return f"Unsupported CPU architecture {self.arch}"


class SkippedException(LisaException):
"""
A test case can be skipped based on runtime information.
Expand Down
48 changes: 34 additions & 14 deletions microsoft/testsuites/core/timesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
TestCaseMetadata,
TestSuite,
TestSuiteMetadata,
UnsupportedCpuArchitectureException,
create_timer,
)
from lisa.operating_system import Redhat
from lisa.operating_system import CpuArchitecture, Redhat
from lisa.tools import Cat, Chrony, Dmesg, Hwclock, Lscpu, Ntp, Ntpstat, Service
from lisa.tools.lscpu import CpuType

Expand Down Expand Up @@ -115,7 +116,8 @@ def timesync_validate_ptp(self, node: Node) -> None:
description="""
This test is to check -
1. Check clock source name is one of hyperv_clocksource_tsc_page,
lis_hv_clocksource_tsc_page, hyperv_clocksource, tsc.
lis_hv_clocksource_tsc_page, hyperv_clocksource, tsc,
arch_sys_counter(arm64).
(there’s a new feature in the AH2021 host that allows Linux guests so use
the plain "tsc" instead of the "hyperv_clocksource_tsc_page",
which produces a modest performance benefit when reading the clock.)
Expand All @@ -129,12 +131,22 @@ def timesync_validate_ptp(self, node: Node) -> None:
def timesync_check_unbind_clocksource(self, node: Node) -> None:
# 1. Check clock source name is one of hyperv_clocksource_tsc_page,
# lis_hv_clocksource_tsc_page, hyperv_clocksource.
clocksource = [
"hyperv_clocksource_tsc_page",
"lis_hyperv_clocksource_tsc_page",
"hyperv_clocksource",
"tsc",
]
clocksource_map = {
CpuArchitecture.X64: [
"hyperv_clocksource_tsc_page",
"lis_hyperv_clocksource_tsc_page",
"hyperv_clocksource",
"tsc",
],
CpuArchitecture.ARM64: [
"arch_sys_counter",
],
}
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
clocksource = clocksource_map.get(CpuArchitecture(arch), None)
if not clocksource:
raise UnsupportedCpuArchitectureException(arch)
cat = node.tools[Cat]
clock_source_result = cat.run(self.current_clocksource)
assert_that([clock_source_result.stdout]).described_as(
Expand All @@ -143,8 +155,7 @@ def timesync_check_unbind_clocksource(self, node: Node) -> None:
).is_subset_of(clocksource)

# 2. Check CPU flag contains constant_tsc from /proc/cpuinfo.
lscpu = node.tools[Lscpu]
if "x86_64" == lscpu.get_architecture():
if CpuArchitecture.X64 == arch:
cpu_info_result = cat.run("/proc/cpuinfo")
if CpuType.Intel == lscpu.get_cpu_type():
expected_tsc_str = " constant_tsc "
Expand Down Expand Up @@ -188,9 +199,10 @@ def timesync_check_unbind_clocksource(self, node: Node) -> None:
@TestCaseMetadata(
description="""
This test is to check -
1. Current clock event name is 'Hyper-V clockevent'.
2. 'Hyper-V clockevent' and 'hrtimer_interrupt' show up times in
/proc/timer_list should equal to cpu count.
1. Current clock event name is 'Hyper-V clockevent' for x86,
'arch_sys_timer' for arm64.
2. 'Hyper-V clockevent' or 'arch_sys_timer' and 'hrtimer_interrupt'
show up times in /proc/timer_list should equal to cpu count.
3. when cpu count is 1 and cpu type is Intel type, unbind current time
clock event, check current time clock event switch to 'lapic'.
""",
Expand All @@ -199,7 +211,15 @@ def timesync_check_unbind_clocksource(self, node: Node) -> None:
def timesync_check_unbind_clockevent(self, node: Node) -> None:
if node.shell.exists(PurePosixPath(self.current_clockevent)):
# 1. Current clock event name is 'Hyper-V clockevent'.
clock_event_name = "Hyper-V clockevent"
clockevent_map = {
CpuArchitecture.X64: "Hyper-V clockevent",
CpuArchitecture.ARM64: "arch_sys_timer",
}
lscpu = node.tools[Lscpu]
arch = lscpu.get_architecture()
clock_event_name = clockevent_map.get(CpuArchitecture(arch), None)
if not clock_event_name:
raise UnsupportedCpuArchitectureException(arch)
cat = node.tools[Cat]
clock_event_result = cat.run(self.current_clockevent)
assert_that(clock_event_result.stdout).described_as(
Expand Down

0 comments on commit 5798bbe

Please sign in to comment.