Skip to content

Commit

Permalink
feat(aarch64): add host vs guest cpu feature test
Browse files Browse the repository at this point in the history
Add test comparing host and guest default cpu features.
Currently only available for aarch64.

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Oct 31, 2024
1 parent 5a18ede commit 99ef749
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/framework/utils_cpuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from framework.utils import check_output
from framework.utils_imdsv2 import imdsv2_get

CPU_FEATURES_CMD = r"lscpu |grep -oP '^Flags:\s+\K.+'"


class CpuVendor(Enum):
"""CPU vendors enum."""
Expand Down
35 changes: 33 additions & 2 deletions tests/integration_tests/functional/test_cpu_features_aarch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import pytest

import framework.utils_cpuid as cpuid_utils
from framework.utils_cpuid import CpuModel
from framework import utils
from framework.utils_cpuid import CpuModel, CPU_FEATURES_CMD

PLATFORM = platform.machine()

Expand Down Expand Up @@ -48,7 +49,7 @@ def _check_cpu_features_arm(test_microvm, guest_kv, template_name=None):
case CpuModel.ARM_NEOVERSE_V1, _, None:
expected_cpu_features = DEFAULT_G3_FEATURES_5_10

_, stdout, _ = test_microvm.ssh.check_output(r"lscpu |grep -oP '^Flags:\s+\K.+'")
_, stdout, _ = test_microvm.ssh.check_output(CPU_FEATURES_CMD)
flags = set(stdout.strip().split(" "))
assert flags == expected_cpu_features

Expand All @@ -63,6 +64,36 @@ def get_cpu_template_dir(cpu_template):
return cpu_template if cpu_template else "none"


@pytest.mark.skipif(
PLATFORM != "aarch64",
reason="This is aarch64 specific test.",
)
def test_host_vs_guest_cpu_features_aarch64(uvm_nano):
"""Check CPU features host vs guest"""

vm = uvm_nano
vm.add_net_iface()
vm.start()
host_feats = set(utils.check_output(CPU_FEATURES_CMD).stdout.strip().split(" "))
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.strip().split(" "))

match cpuid_utils.get_cpu_model_name():
case CpuModel.ARM_NEOVERSE_N1:
assert host_feats - guest_feats == set()
assert guest_feats - host_feats == {"ssbs"}
case CpuModel.ARM_NEOVERSE_V1:
assert host_feats - guest_feats == {
"pacg",
"sve",
"paca",
"svebf16",
"svei8mm",
}
assert guest_feats - host_feats == {"ssbs"}
case _:
assert False, f"Please onboard new CpuModel {global_props.cpu_model}"


@pytest.mark.skipif(
PLATFORM != "aarch64",
reason="This is aarch64 specific test.",
Expand Down

0 comments on commit 99ef749

Please sign in to comment.