Skip to content

Commit 604e3d7

Browse files
committed
test: add functional tests for booting secret free VMs
Add a test that we can boot VMs and initrds with secret freedom enabled. Signed-off-by: Patrick Roy <[email protected]>
1 parent 68008a2 commit 604e3d7

File tree

5 files changed

+112
-7
lines changed

5 files changed

+112
-7
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Test secret-freedom related functionality."""
4+
5+
import pytest
6+
7+
from framework import defs
8+
from framework.microvm import Serial
9+
from framework.properties import global_props
10+
from integration_tests.performance.test_initrd import INITRD_FILESYSTEM
11+
12+
pytestmark = [
13+
pytest.mark.skipif(
14+
global_props.host_linux_version_metrics != "next",
15+
reason="Secret Freedom is only supported on the in-dev upstream kernels for now",
16+
),
17+
pytest.mark.skipif(
18+
global_props.instance == "m6g.metal",
19+
reason="Secret Freedom currently only works on ARM hardware conforming to at least ARMv8.4 as absense of ARM64_HAS_STAGE2_FWB causes kernel panics because of dcache flushing during stage2 page table entry installation",
20+
),
21+
]
22+
23+
24+
def test_secret_free_boot(microvm_factory, guest_kernel, rootfs):
25+
"""Tests that a VM can boot if all virtio devices are bound to a swiotlb region, and
26+
that this swiotlb region is actually discovered by the guest."""
27+
vm = microvm_factory.build(guest_kernel, rootfs)
28+
vm.spawn()
29+
vm.memory_monitor = None
30+
vm.basic_config(
31+
memory_config={"secret_free": True},
32+
)
33+
vm.add_net_iface()
34+
vm.start()
35+
36+
37+
def test_secret_free_initrd(microvm_factory, guest_kernel):
38+
"""
39+
Test that we can boot a secret hidden initrd (e.g. a VM with no I/O devices)
40+
"""
41+
fs = defs.ARTIFACT_DIR / "initramfs.cpio"
42+
uvm = microvm_factory.build(guest_kernel)
43+
uvm.initrd_file = fs
44+
uvm.help.enable_console()
45+
uvm.spawn()
46+
uvm.memory_monitor = None
47+
48+
uvm.basic_config(
49+
add_root_device=False,
50+
vcpu_count=1,
51+
boot_args="console=ttyS0 reboot=k panic=1 pci=off",
52+
use_initrd=True,
53+
memory_config={"secret_free": True},
54+
)
55+
56+
uvm.start()
57+
serial = Serial(uvm)
58+
serial.open()
59+
serial.rx(token="# ")
60+
serial.tx("mount |grep rootfs")
61+
serial.rx(token=f"rootfs on / type {INITRD_FILESYSTEM}")
62+
63+
64+
def test_secret_free_snapshot_creation(microvm_factory, guest_kernel, rootfs):
65+
"""Test that snapshot creation works for secret hidden VMs"""
66+
vm = microvm_factory.build(guest_kernel, rootfs)
67+
vm.spawn()
68+
vm.memory_monitor = None
69+
vm.basic_config(
70+
memory_config={"secret_free": True},
71+
)
72+
vm.add_net_iface()
73+
vm.start()
74+
75+
snapshot = vm.snapshot_full()
76+
77+
# After restoration, the VM will not be secret hidden anymore, as that's not supported yet.
78+
# But we can at least test that in principle, the snapshot creation worked.
79+
vm = microvm_factory.build_from_snapshot(snapshot)
80+
vm.ssh.check_output("true")

tests/integration_tests/performance/test_block_ab.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,22 @@ def test_block_performance(
169169
"""
170170
Execute block device emulation benchmarking scenarios.
171171
"""
172-
if memory_config is not None and "6.1" not in guest_kernel_acpi.name:
172+
if (
173+
memory_config is not None
174+
and memory_config["initial_swiotlb_size"] != 0
175+
and "6.1" not in guest_kernel_acpi.name
176+
):
173177
pytest.skip("swiotlb only supported on aarch64/6.1")
174178

179+
if memory_config is not None and io_engine == "Async":
180+
pytest.skip("userspace bounce buffers not supported with async block engine")
181+
175182
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
176183
vm.spawn(log_level="Info", emit_metrics=True)
177184
vm.basic_config(
178-
vcpu_count=vcpus, mem_size_mib=GUEST_MEM_MIB, memory_config=memory_config
185+
vcpu_count=vcpus,
186+
mem_size_mib=GUEST_MEM_MIB,
187+
memory_config=memory_config,
179188
)
180189
vm.add_net_iface()
181190
# Add a secondary block device for benchmark tests.

tests/integration_tests/performance/test_boottime.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def test_boottime(
7575
):
7676
"""Test boot time with different guest configurations"""
7777

78-
if memory_config is not None and "6.1" not in guest_kernel_acpi.name:
78+
if (
79+
memory_config is not None
80+
and memory_config["initial_swiotlb_size"] != 0
81+
and "6.1" not in guest_kernel_acpi.name
82+
):
7983
pytest.skip("swiotlb only supported on aarch64/6.1")
8084

8185
for _ in range(10):

tests/integration_tests/performance/test_network_ab.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ def network_microvm(request, microvm_factory, guest_kernel_acpi, rootfs, memory_
4040
"""Creates a microvm with the networking setup used by the performance tests in this file.
4141
This fixture receives its vcpu count via indirect parameterization"""
4242

43-
if memory_config is not None and "6.1" not in guest_kernel_acpi.name:
43+
if (
44+
memory_config is not None
45+
and memory_config["initial_swiotlb_size"] != 0
46+
and "6.1" not in guest_kernel_acpi.name
47+
):
4448
pytest.skip("swiotlb only supported on aarch64/6.1")
4549

4650
guest_mem_mib = 1024
@@ -49,7 +53,9 @@ def network_microvm(request, microvm_factory, guest_kernel_acpi, rootfs, memory_
4953
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
5054
vm.spawn(log_level="Info", emit_metrics=True)
5155
vm.basic_config(
52-
vcpu_count=guest_vcpus, mem_size_mib=guest_mem_mib, memory_config=memory_config
56+
vcpu_count=guest_vcpus,
57+
mem_size_mib=guest_mem_mib,
58+
memory_config=memory_config,
5359
)
5460
vm.add_net_iface()
5561
vm.start()

tests/integration_tests/performance/test_vsock_ab.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ def test_vsock_throughput(
9191
if mode == "bd" and vcpus < 2:
9292
pytest.skip("bidrectional test only done with at least 2 vcpus")
9393

94-
if memory_config is not None and "6.1" not in guest_kernel_acpi.name:
94+
if (
95+
memory_config is not None
96+
and memory_config["initial_swiotlb_size"] != 0
97+
and "6.1" not in guest_kernel_acpi.name
98+
):
9599
pytest.skip("swiotlb only supported on aarch64/6.1")
96100

97101
mem_size_mib = 1024
98102
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
99103
vm.spawn(log_level="Info", emit_metrics=True)
100104
vm.basic_config(
101-
vcpu_count=vcpus, mem_size_mib=mem_size_mib, memory_config=memory_config
105+
vcpu_count=vcpus,
106+
mem_size_mib=mem_size_mib,
107+
memory_config=memory_config,
102108
)
103109
vm.add_net_iface()
104110
# Create a vsock device

0 commit comments

Comments
 (0)