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,44 @@ 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+ # is not recent enough for this.
87+ assert guest_feats - host_feats == {"ssbs" }
88+ case CpuModel .ARM_NEOVERSE_V1 :
89+ # KVM does not enable PAC or SVE features by default
90+ # and Firecracker does not enable them either.
91+ assert host_feats - guest_feats == {
92+ "paca" ,
93+ "pacg" ,
94+ "sve" ,
95+ "svebf16" ,
96+ "svei8mm" ,
97+ }
98+ # kernel should hide this feature, but our guest kernel
99+ # is not recent enough for this.
100+ assert guest_feats - host_feats == {"ssbs" }
101+ case _:
102+ if os .environ .get ("BUILDKITE" ) is not None :
103+ assert False , f"Cpu model { cpu_model } is not supported"
104+
105+
66106@pytest .mark .skipif (
67107 PLATFORM != "aarch64" ,
68108 reason = "This is aarch64 specific test." ,
0 commit comments