|
3 | 3 | """Tests for the CPU features for aarch64."""
|
4 | 4 |
|
5 | 5 | import os
|
6 |
| -import platform |
7 |
| -import re |
8 | 6 |
|
9 | 7 | import pytest
|
10 | 8 |
|
11 |
| -import framework.utils_cpuid as cpuid_utils |
12 | 9 | from framework import utils
|
13 | 10 | from framework.properties import global_props
|
14 | 11 | from framework.utils_cpuid import CPU_FEATURES_CMD, CpuModel
|
15 | 12 |
|
16 |
| -PLATFORM = platform.machine() |
| 13 | +pytestmark = pytest.mark.skipif( |
| 14 | + global_props.cpu_architecture != "aarch64", reason="Only run in aarch64" |
| 15 | +) |
17 | 16 |
|
18 |
| -DEFAULT_G2_FEATURES = set( |
| 17 | +G2_FEATS = set( |
19 | 18 | (
|
20 | 19 | "fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp "
|
21 | 20 | "asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs"
|
22 |
| - ).split(" ") |
| 21 | + ).split() |
23 | 22 | )
|
24 | 23 |
|
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() |
29 | 26 | )
|
30 | 27 |
|
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()) |
34 | 29 |
|
35 |
| -DEFAULT_G3_FEATURES_V1N1 = DEFAULT_G2_FEATURES |
36 | 30 |
|
| 31 | +def test_guest_cpu_features(uvm_any): |
| 32 | + """Check the CPU features for a microvm with different CPU templates""" |
37 | 33 |
|
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 |
45 | 41 |
|
46 | 42 | # [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 |
57 | 49 |
|
| 50 | + guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split()) |
| 51 | + assert guest_feats == expected_cpu_features |
58 | 52 |
|
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. |
64 | 53 |
|
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): |
74 | 55 | """Check CPU features host vs guest"""
|
75 | 56 |
|
76 | 57 | vm = uvm_nano
|
77 | 58 | vm.add_net_iface()
|
78 | 59 | 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 |
83 | 63 | match cpu_model:
|
84 | 64 | case CpuModel.ARM_NEOVERSE_N1:
|
85 | 65 | expected_guest_minus_host = set()
|
@@ -141,79 +121,6 @@ def test_host_vs_guest_cpu_features_aarch64(uvm_nano):
|
141 | 121 | assert guest_feats - host_feats == expected_guest_minus_host
|
142 | 122 | case _:
|
143 | 123 | 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