22# SPDX-License-Identifier: Apache-2.0
33"""Tests for the CPU features for aarch64."""
44
5+ import os
56import platform
67import re
78
89import pytest
910
1011import 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
1214
1315PLATFORM = platform .machine ()
1416
@@ -48,7 +50,7 @@ def _check_cpu_features_arm(test_microvm, guest_kv, template_name=None):
4850 case CpuModel .ARM_NEOVERSE_V1 , _, None :
4951 expected_cpu_features = DEFAULT_G3_FEATURES_5_10
5052
51- _ , stdout , _ = test_microvm .ssh .check_output (r"lscpu |grep -oP '^Flags:\s+\K.+'" )
53+ _ , stdout , _ = test_microvm .ssh .check_output (CPU_FEATURES_CMD )
5254 flags = set (stdout .strip ().split (" " ))
5355 assert flags == expected_cpu_features
5456
@@ -63,6 +65,46 @@ def get_cpu_template_dir(cpu_template):
6365 return cpu_template if cpu_template else "none"
6466
6567
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+
66108@pytest .mark .skipif (
67109 PLATFORM != "aarch64" ,
68110 reason = "This is aarch64 specific test." ,
0 commit comments