|
| 1 | +import re |
1 | 2 | import time |
2 | 3 | from copy import deepcopy |
3 | 4 | from datetime import timedelta |
|
21 | 22 | simple_requirement, |
22 | 23 | ) |
23 | 24 | from lisa.operating_system import BSD, CpuArchitecture, Redhat, Suse, Windows |
24 | | -from lisa.tools import Cat, Chrony, Dmesg, Hwclock, Ls, Lscpu, Ntp, Ntpstat, Service |
| 25 | +from lisa.tools import ( |
| 26 | + Cat, |
| 27 | + Chrony, |
| 28 | + Dmesg, |
| 29 | + Hwclock, |
| 30 | + Ls, |
| 31 | + Lscpu, |
| 32 | + Ntp, |
| 33 | + Ntpstat, |
| 34 | + Service, |
| 35 | + Sysctl, |
| 36 | +) |
25 | 37 | from lisa.tools.date import Date |
26 | 38 | from lisa.tools.lscpu import CpuType |
27 | 39 | from lisa.util import constants |
@@ -74,6 +86,9 @@ class TimeSync(TestSuite): |
74 | 86 | ) |
75 | 87 | current_clockevent = "/sys/devices/system/clockevents/clockevent0/current_device" |
76 | 88 | unbind_clockevent = "/sys/devices/system/clockevents/clockevent0/unbind_device" |
| 89 | + # Positive Example: |
| 90 | + # Features=0x1c77b221<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT> |
| 91 | + __freebsd_tsc_filter = re.compile(r"Features=.*<.*,TSC,.*>") |
77 | 92 |
|
78 | 93 | @TestCaseMetadata( |
79 | 94 | description=""" |
@@ -167,41 +182,70 @@ def verify_timesync_unbind_clocksource(self, node: Node, log: Logger) -> None: |
167 | 182 | "lis_hyperv_clocksource_tsc_page", |
168 | 183 | "hyperv_clocksource", |
169 | 184 | "tsc", |
| 185 | + "Hyper-V-TSC", |
170 | 186 | ], |
171 | 187 | CpuArchitecture.ARM64: [ |
172 | 188 | "arch_sys_counter", |
| 189 | + "ARM MPCore Timecounter", |
173 | 190 | ], |
174 | 191 | } |
| 192 | + cat = node.tools[Cat] |
175 | 193 | lscpu = node.tools[Lscpu] |
176 | 194 | arch = lscpu.get_architecture() |
177 | 195 | clocksource = clocksource_map.get(arch, None) |
178 | 196 | if not clocksource: |
179 | 197 | raise UnsupportedCpuArchitectureException(arch) |
180 | | - cat = node.tools[Cat] |
181 | | - clock_source_result = cat.run(self.current_clocksource) |
| 198 | + if not isinstance(node.os, BSD): |
| 199 | + clock_source_result = cat.run(self.current_clocksource) |
| 200 | + else: |
| 201 | + sysctl = node.tools[Sysctl] |
| 202 | + clock_source_result = sysctl.run( |
| 203 | + "-n kern.timecounter.hardware", |
| 204 | + force_run=True, |
| 205 | + sudo=True, |
| 206 | + expected_exit_code=0, |
| 207 | + expected_exit_code_failure_message="fail to get hardware value", |
| 208 | + ) |
182 | 209 | assert_that([clock_source_result.stdout]).described_as( |
183 | | - f"Expected clocksource name is one of {clocksource}," |
184 | | - f" but actual it is {clock_source_result.stdout}." |
| 210 | + f"Expected clocksource name is one of {clocksource}, " |
| 211 | + f"but actually it is {clock_source_result.stdout}." |
185 | 212 | ).is_subset_of(clocksource) |
186 | 213 |
|
187 | 214 | # 2. Check CPU flag contains constant_tsc from /proc/cpuinfo. |
| 215 | + dmesg = node.tools[Dmesg] |
188 | 216 | if CpuArchitecture.X64 == arch: |
189 | | - cpu_info_result = cat.run("/proc/cpuinfo") |
190 | | - if CpuType.Intel == lscpu.get_cpu_type(): |
191 | | - expected_tsc_str = " constant_tsc " |
192 | | - elif CpuType.AMD == lscpu.get_cpu_type(): |
193 | | - expected_tsc_str = " tsc " |
194 | | - shown_up_times = cpu_info_result.stdout.count(expected_tsc_str) |
195 | | - assert_that(shown_up_times).described_as( |
196 | | - f"Expected {expected_tsc_str} shown up times in cpu flags is" |
197 | | - " equal to cpu count." |
198 | | - ).is_equal_to(lscpu.get_core_count()) |
| 217 | + if not isinstance(node.os, BSD): |
| 218 | + cpu_info_result = cat.run("/proc/cpuinfo") |
| 219 | + if CpuType.Intel == lscpu.get_cpu_type(): |
| 220 | + expected_tsc_str = " constant_tsc " |
| 221 | + elif CpuType.AMD == lscpu.get_cpu_type(): |
| 222 | + expected_tsc_str = " tsc " |
| 223 | + shown_up_times = cpu_info_result.stdout.count(expected_tsc_str) |
| 224 | + assert_that(shown_up_times).described_as( |
| 225 | + f"Expected {expected_tsc_str} shown up times in cpu flags is" |
| 226 | + f" equal to cpu count." |
| 227 | + ).is_equal_to(lscpu.get_core_count()) |
| 228 | + else: |
| 229 | + cpu_info_results = self.__freebsd_tsc_filter.findall( |
| 230 | + dmesg.get_output() |
| 231 | + ) |
| 232 | + count_of_results = len(cpu_info_results) |
| 233 | + assert_that(count_of_results).described_as( |
| 234 | + "Expected TSC shown up times in cpu flags is" |
| 235 | + " equal to cpu count." |
| 236 | + ).is_equal_to(lscpu.get_core_count()) |
199 | 237 |
|
200 | 238 | # 3. Check clocksource name shown up in dmesg. |
201 | | - dmesg = node.tools[Dmesg] |
202 | | - assert_that(dmesg.get_output()).described_as( |
203 | | - f"Expected clocksource {clock_source_result.stdout} shown up in dmesg." |
204 | | - ).contains(f"clocksource {clock_source_result.stdout}") |
| 239 | + if not isinstance(node.os, BSD): |
| 240 | + assert_that(dmesg.get_output()).described_as( |
| 241 | + f"Expected clocksource {clock_source_result.stdout}" |
| 242 | + f" shown up in dmesg." |
| 243 | + ).contains(f"clocksource {clock_source_result.stdout}") |
| 244 | + else: |
| 245 | + assert_that(dmesg.get_output()).described_as( |
| 246 | + f'Expected Timecounter "{clock_source_result.stdout}"' |
| 247 | + f" shown up in dmesg." |
| 248 | + ).contains(f'Timecounter "{clock_source_result.stdout}"') |
205 | 249 |
|
206 | 250 | # 4. Unbind current clock source if there are 2+ clock sources, |
207 | 251 | # check current clock source can be switched to a different one. |
|
0 commit comments