2
2
# SPDX-License-Identifier: Apache-2.0
3
3
"""Tests for the CPU features for aarch64."""
4
4
5
+ import os
5
6
import platform
6
7
import re
7
8
8
9
import pytest
9
10
10
11
import framework .utils_cpuid as cpuid_utils
11
- from framework .utils_cpuid import CpuModel
12
+ from framework import utils
13
+ from framework .utils_cpuid import CPU_FEATURES_CMD , CpuModel
12
14
13
15
PLATFORM = platform .machine ()
14
16
@@ -48,7 +50,7 @@ def _check_cpu_features_arm(test_microvm, guest_kv, template_name=None):
48
50
case CpuModel .ARM_NEOVERSE_V1 , _, None :
49
51
expected_cpu_features = DEFAULT_G3_FEATURES_5_10
50
52
51
- _ , stdout , _ = test_microvm .ssh .check_output (r"lscpu |grep -oP '^Flags:\s+\K.+'" )
53
+ _ , stdout , _ = test_microvm .ssh .check_output (CPU_FEATURES_CMD )
52
54
flags = set (stdout .strip ().split (" " ))
53
55
assert flags == expected_cpu_features
54
56
@@ -63,6 +65,46 @@ def get_cpu_template_dir(cpu_template):
63
65
return cpu_template if cpu_template else "none"
64
66
65
67
68
+ @pytest .mark .skipif (
69
+ PLATFORM != "aarch64" ,
70
+ reason = "This is aarch64 specific test." ,
71
+ )
72
+ def test_host_vs_guest_cpu_features_aarch64 (uvm_nano ):
73
+ """Check CPU features host vs guest"""
74
+
75
+ vm = uvm_nano
76
+ vm .add_net_iface ()
77
+ vm .start ()
78
+ host_feats = set (utils .check_output (CPU_FEATURES_CMD ).stdout .strip ().split (" " ))
79
+ guest_feats = set (vm .ssh .check_output (CPU_FEATURES_CMD ).stdout .strip ().split (" " ))
80
+
81
+ cpu_model = cpuid_utils .get_cpu_model_name ()
82
+ match cpu_model :
83
+ case CpuModel .ARM_NEOVERSE_N1 :
84
+ assert host_feats - guest_feats == set ()
85
+ # Kernel should hide this feature, but our guest kernel
86
+ # currently lacks the commit with this change.
87
+ # The commit that introduces the change:
88
+ # https://github.com/torvalds/linux/commit/7187bb7d0b5c7dfa18ca82e9e5c75e13861b1d88
89
+ assert guest_feats - host_feats == {"ssbs" }
90
+ case CpuModel .ARM_NEOVERSE_V1 :
91
+ # KVM does not enable PAC or SVE features by default
92
+ # and Firecracker does not enable them either.
93
+ assert host_feats - guest_feats == {
94
+ "paca" ,
95
+ "pacg" ,
96
+ "sve" ,
97
+ "svebf16" ,
98
+ "svei8mm" ,
99
+ }
100
+ # kernel should hide this feature, but our guest kernel
101
+ # is not recent enough for this.
102
+ assert guest_feats - host_feats == {"ssbs" }
103
+ case _:
104
+ if os .environ .get ("BUILDKITE" ) is not None :
105
+ assert False , f"Cpu model { cpu_model } is not supported"
106
+
107
+
66
108
@pytest .mark .skipif (
67
109
PLATFORM != "aarch64" ,
68
110
reason = "This is aarch64 specific test." ,
0 commit comments