Skip to content

Commit 033402e

Browse files
committed
tests: refactor test_cpu_features_aarch64 to use uvm_any
Use the new uvm_any fixture to make the tests simpler Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 1882a3d commit 033402e

File tree

2 files changed

+34
-133
lines changed

2 files changed

+34
-133
lines changed

tests/framework/utils_cpu_templates.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323

2424
def get_supported_cpu_templates():
25-
"""
26-
Return the list of CPU templates supported by the platform.
27-
"""
25+
"""Return the list of static CPU templates supported by the platform."""
2826
host_linux = global_props.host_linux_version_tpl
2927
match get_cpu_vendor(), global_props.cpu_codename:
3028
# T2CL template is only supported on Cascade Lake and newer CPUs.
@@ -44,12 +42,8 @@ def get_supported_cpu_templates():
4442

4543

4644
def get_supported_custom_cpu_templates():
47-
"""
48-
Return the list of custom CPU templates supported by the platform.
49-
"""
50-
# pylint:disable=too-many-return-statements
45+
"""Return the list of custom CPU templates supported by the platform."""
5146
host_linux = global_props.host_linux_version_tpl
52-
5347
match get_cpu_vendor(), global_props.cpu_codename:
5448
# T2CL template is only supported on Cascade Lake and newer CPUs.
5549
case CpuVendor.INTEL, CpuModel.INTEL_SKYLAKE:

tests/integration_tests/functional/test_cpu_features_aarch64.py

Lines changed: 32 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,63 @@
33
"""Tests for the CPU features for aarch64."""
44

55
import os
6-
import platform
7-
import re
86

97
import pytest
108

11-
import framework.utils_cpuid as cpuid_utils
129
from framework import utils
1310
from framework.properties import global_props
1411
from framework.utils_cpuid import CPU_FEATURES_CMD, CpuModel
1512

16-
PLATFORM = platform.machine()
13+
pytestmark = pytest.mark.skipif(
14+
global_props.cpu_architecture != "aarch64", reason="Only run in aarch64"
15+
)
1716

18-
DEFAULT_G2_FEATURES = set(
17+
G2_FEATS = set(
1918
(
2019
"fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp "
2120
"asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs"
22-
).split(" ")
21+
).split()
2322
)
2423

25-
DEFAULT_G3_FEATURES_5_10 = DEFAULT_G2_FEATURES | set(
26-
"sha512 asimdfhm dit uscat ilrcpc flagm jscvt fcma sha3 sm3 sm4 rng dcpodp i8mm bf16 dgh".split(
27-
" "
28-
)
24+
G3_FEATS = G2_FEATS | set(
25+
"sha512 asimdfhm dit uscat ilrcpc flagm jscvt fcma sha3 sm3 sm4 rng dcpodp i8mm bf16 dgh".split()
2926
)
3027

31-
DEFAULT_G3_FEATURES_WITH_SVE_AND_PAC_5_10 = DEFAULT_G3_FEATURES_5_10 | set(
32-
"paca pacg sve svebf16 svei8mm".split(" ")
33-
)
28+
G3_SVE_AND_PAC = set("paca pacg sve svebf16 svei8mm".split())
3429

35-
DEFAULT_G3_FEATURES_V1N1 = DEFAULT_G2_FEATURES
3630

31+
def test_guest_cpu_features(uvm_any):
32+
"""Check the CPU features for a microvm with different CPU templates"""
3733

38-
def _check_cpu_features_arm(test_microvm, guest_kv, template_name=None):
39-
expected_cpu_features = {"Flags": []}
40-
match cpuid_utils.get_cpu_model_name(), guest_kv, template_name:
41-
case CpuModel.ARM_NEOVERSE_N1, _, "v1n1":
42-
expected_cpu_features = DEFAULT_G2_FEATURES
43-
case CpuModel.ARM_NEOVERSE_N1, _, None:
44-
expected_cpu_features = DEFAULT_G2_FEATURES
34+
vm = uvm_any
35+
expected_cpu_features = set()
36+
match global_props.cpu_model, vm.cpu_template_name:
37+
case CpuModel.ARM_NEOVERSE_N1, "v1n1":
38+
expected_cpu_features = G2_FEATS
39+
case CpuModel.ARM_NEOVERSE_N1, None:
40+
expected_cpu_features = G2_FEATS
4541

4642
# [cm]7g with guest kernel 5.10 and later
47-
case CpuModel.ARM_NEOVERSE_V1, _, "v1n1":
48-
expected_cpu_features = DEFAULT_G3_FEATURES_V1N1
49-
case CpuModel.ARM_NEOVERSE_V1, _, "aarch64_with_sve_and_pac":
50-
expected_cpu_features = DEFAULT_G3_FEATURES_WITH_SVE_AND_PAC_5_10
51-
case CpuModel.ARM_NEOVERSE_V1, _, None:
52-
expected_cpu_features = DEFAULT_G3_FEATURES_5_10
53-
54-
_, stdout, _ = test_microvm.ssh.check_output(CPU_FEATURES_CMD)
55-
flags = set(stdout.strip().split(" "))
56-
assert flags == expected_cpu_features
43+
case CpuModel.ARM_NEOVERSE_V1, "v1n1":
44+
expected_cpu_features = G2_FEATS
45+
case CpuModel.ARM_NEOVERSE_V1, "aarch64_with_sve_and_pac":
46+
expected_cpu_features = G3_FEATS | G3_SVE_AND_PAC
47+
case CpuModel.ARM_NEOVERSE_V1, None:
48+
expected_cpu_features = G3_FEATS
5749

50+
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split())
51+
assert guest_feats == expected_cpu_features
5852

59-
def get_cpu_template_dir(cpu_template):
60-
"""
61-
Utility function to return a valid string which will be used as
62-
name of the directory where snapshot artifacts are stored during
63-
snapshot test and loaded from during restore test.
6453

65-
"""
66-
return cpu_template if cpu_template else "none"
67-
68-
69-
@pytest.mark.skipif(
70-
PLATFORM != "aarch64",
71-
reason="This is aarch64 specific test.",
72-
)
73-
def test_host_vs_guest_cpu_features_aarch64(uvm_nano):
54+
def test_host_vs_guest_cpu_features(uvm_nano):
7455
"""Check CPU features host vs guest"""
7556

7657
vm = uvm_nano
7758
vm.add_net_iface()
7859
vm.start()
79-
host_feats = set(utils.check_output(CPU_FEATURES_CMD).stdout.strip().split(" "))
80-
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.strip().split(" "))
81-
82-
cpu_model = cpuid_utils.get_cpu_model_name()
60+
host_feats = set(utils.check_output(CPU_FEATURES_CMD).stdout.split())
61+
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split())
62+
cpu_model = global_props.cpu_model
8363
match cpu_model:
8464
case CpuModel.ARM_NEOVERSE_N1:
8565
expected_guest_minus_host = set()
@@ -141,79 +121,6 @@ def test_host_vs_guest_cpu_features_aarch64(uvm_nano):
141121
assert guest_feats - host_feats == expected_guest_minus_host
142122
case _:
143123
if os.environ.get("BUILDKITE") is not None:
144-
assert False, f"Cpu model {cpu_model} is not supported"
145-
146-
147-
@pytest.mark.skipif(
148-
PLATFORM != "aarch64",
149-
reason="This is aarch64 specific test.",
150-
)
151-
def test_default_cpu_features(microvm_factory, guest_kernel, rootfs):
152-
"""
153-
Check the CPU features for a microvm with the specified config.
154-
"""
155-
156-
vm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False)
157-
vm.spawn()
158-
vm.basic_config()
159-
vm.add_net_iface()
160-
vm.start()
161-
guest_kv = re.search(r"vmlinux-(\d+\.\d+)", guest_kernel.name).group(1)
162-
_check_cpu_features_arm(vm, guest_kv)
163-
164-
165-
@pytest.mark.skipif(
166-
PLATFORM != "aarch64",
167-
reason="This is aarch64 specific test.",
168-
)
169-
def test_cpu_features_with_static_template(
170-
microvm_factory, guest_kernel, rootfs, cpu_template
171-
):
172-
"""
173-
Check the CPU features for a microvm with the specified config.
174-
"""
175-
176-
vm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False)
177-
vm.spawn()
178-
vm.basic_config(cpu_template=cpu_template)
179-
vm.add_net_iface()
180-
vm.start()
181-
guest_kv = re.search(r"vmlinux-(\d+\.\d+)", guest_kernel.name).group(1)
182-
_check_cpu_features_arm(vm, guest_kv, "v1n1")
183-
184-
# Check that cpu features are still correct
185-
# after snap/restore cycle.
186-
snapshot = vm.snapshot_full()
187-
restored_vm = microvm_factory.build()
188-
restored_vm.spawn()
189-
restored_vm.restore_from_snapshot(snapshot, resume=True)
190-
_check_cpu_features_arm(restored_vm, guest_kv, "v1n1")
191-
192-
193-
@pytest.mark.skipif(
194-
PLATFORM != "aarch64",
195-
reason="This is aarch64 specific test.",
196-
)
197-
def test_cpu_features_with_custom_template(
198-
microvm_factory, guest_kernel, rootfs, custom_cpu_template
199-
):
200-
"""
201-
Check the CPU features for a microvm with the specified config.
202-
"""
203-
204-
vm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False)
205-
vm.spawn()
206-
vm.basic_config()
207-
vm.api.cpu_config.put(**custom_cpu_template["template"])
208-
vm.add_net_iface()
209-
vm.start()
210-
guest_kv = re.search(r"vmlinux-(\d+\.\d+)", guest_kernel.name).group(1)
211-
_check_cpu_features_arm(vm, guest_kv, custom_cpu_template["name"])
212-
213-
# Check that cpu features are still correct
214-
# after snap/restore cycle.
215-
snapshot = vm.snapshot_full()
216-
restored_vm = microvm_factory.build()
217-
restored_vm.spawn()
218-
restored_vm.restore_from_snapshot(snapshot, resume=True)
219-
_check_cpu_features_arm(restored_vm, guest_kv, custom_cpu_template["name"])
124+
assert (
125+
False
126+
), f"Cpu model {cpu_model} is not supported, please onboard it."

0 commit comments

Comments
 (0)