Repository: firecracker-microvm/firecracker
File: tests/integration_tests/functional/test_cpu_features_aarch64.py (Python)

Code before:
    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(" "))

    cpu_model = cpuid_utils.get_cpu_model_name()
    match cpu_model:
        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"Cpu model {cpu_model} is not supported"


@pytest.mark.skipif(
    PLATFORM != "aarch64",
    reason="This is aarch64 specific test.",
)
def test_default_cpu_features(microvm_factory, guest_kernel, rootfs_ubuntu_22):
    """
    Check the CPU features for a microvm with the specified config.
    """

    vm = microvm_factory.build(guest_kernel, rootfs_ubuntu_22, monitor_memory=False)
    vm.spawn()
    vm.basic_config()
    vm.add_net_iface()
    vm.start()
    guest_kv = re.search(r"vmlinux-(\d+\.\d+)", guest_kernel.name).group(1)
    _check_cpu_features_arm(vm, guest_kv)


@pytest.mark.skipif(
    PLATFORM != "aarch64",
    reason="This is aarch64 specific test.",
)
def test_cpu_features_with_static_template(
    microvm_factory, guest_kernel, rootfs_ubuntu_22, cpu_template
):
    """
    Check the CPU features for a microvm with the specified config.
    """


Review comment (bug):
Let's not have tests that fail unconditionally locally. Can we have this be behind a sort of `if env.get("buildkite") is not None:`?

Code after:
    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(" "))

    cpu_model = cpuid_utils.get_cpu_model_name()
    match cpu_model:
        case CpuModel.ARM_NEOVERSE_N1:
            assert host_feats - guest_feats == set()
            # Kernel should hide this feature, but our guest kernel
            # currently lacks the commit with this change.
            # The commit that introduces the change:
            # https://github.com/torvalds/linux/commit/7187bb7d0b5c7dfa18ca82e9e5c75e13861b1d88
            assert guest_feats - host_feats == {"ssbs"}
        case CpuModel.ARM_NEOVERSE_V1:
            # KVM does not enable PAC or SVE features by default
            # and Firecracker does not enable them either.
            assert host_feats - guest_feats == {
                "paca",
                "pacg",
                "sve",
                "svebf16",
                "svei8mm",
            }
            # kernel should hide this feature, but our guest kernel
            # is not recent enough for this.
            assert guest_feats - host_feats == {"ssbs"}
        case _:
            if os.environ.get("BUILDKITE") is not None:
                assert False, f"Cpu model {cpu_model} is not supported"


@pytest.mark.skipif(
    PLATFORM != "aarch64",
    reason="This is aarch64 specific test.",
)
def test_default_cpu_features(microvm_factory, guest_kernel, rootfs_ubuntu_22):
    """
    Check the CPU features for a microvm with the specified config.
    """

    vm = microvm_factory.build(guest_kernel, rootfs_ubuntu_22, monitor_memory=False)
    vm.spawn()
    vm.basic_config()
    vm.add_net_iface()
    vm.start()
    guest_kv = re.search(r"vmlinux-(\d+\.\d+)", guest_kernel.name).group(1)
    _check_cpu_features_arm(vm, guest_kv)


@pytest.mark.skipif(