| 
 | 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 platform  | 
 | 6 | + | 
 | 7 | +import pytest  | 
 | 8 | + | 
 | 9 | +from framework import defs  | 
 | 10 | +from framework.microvm import Serial  | 
 | 11 | +from framework.properties import global_props  | 
 | 12 | +from integration_tests.performance.test_initrd import INITRD_FILESYSTEM  | 
 | 13 | + | 
 | 14 | +pytestmark = pytest.mark.skipif(  | 
 | 15 | +    global_props.host_linux_version_metrics != "next",  | 
 | 16 | +    reason="Secret Freedom is only supported on the in-dev upstream kernels for now",  | 
 | 17 | +)  | 
 | 18 | + | 
 | 19 | + | 
 | 20 | +@pytest.mark.skipif(  | 
 | 21 | +    platform.machine() != "aarch64",  | 
 | 22 | +    reason="only ARM can boot secret free VMs with I/O devices",  | 
 | 23 | +)  | 
 | 24 | +def test_secret_free_boot(microvm_factory, guest_kernel_linux_6_1, 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_linux_6_1, rootfs)  | 
 | 28 | +    vm.spawn()  | 
 | 29 | +    vm.memory_monitor = None  | 
 | 30 | +    vm.basic_config(memory_config={"initial_swiotlb_size": 64, "secret_free": True})  | 
 | 31 | +    vm.add_net_iface()  | 
 | 32 | +    vm.start()  | 
 | 33 | + | 
 | 34 | + | 
 | 35 | +def test_secret_free_initrd(microvm_factory, guest_kernel_linux_6_1):  | 
 | 36 | +    """  | 
 | 37 | +    Test that we can boot a secret hidden initrd (e.g. a VM with no I/O devices)  | 
 | 38 | +    """  | 
 | 39 | +    fs = defs.ARTIFACT_DIR / "initramfs.cpio"  | 
 | 40 | +    uvm = microvm_factory.build(guest_kernel_linux_6_1)  | 
 | 41 | +    uvm.initrd_file = fs  | 
 | 42 | +    uvm.help.enable_console()  | 
 | 43 | +    uvm.spawn()  | 
 | 44 | +    uvm.memory_monitor = None  | 
 | 45 | + | 
 | 46 | +    uvm.basic_config(  | 
 | 47 | +        add_root_device=False,  | 
 | 48 | +        vcpu_count=1,  | 
 | 49 | +        boot_args="console=ttyS0 reboot=k panic=1 pci=off",  | 
 | 50 | +        use_initrd=True,  | 
 | 51 | +        memory_config={"initial_swiotlb_size": 64, "secret_free": True},  | 
 | 52 | +    )  | 
 | 53 | + | 
 | 54 | +    uvm.start()  | 
 | 55 | +    serial = Serial(uvm)  | 
 | 56 | +    serial.open()  | 
 | 57 | +    serial.rx(token="# ")  | 
 | 58 | +    serial.tx("mount |grep rootfs")  | 
 | 59 | +    serial.rx(token=f"rootfs on / type {INITRD_FILESYSTEM}")  | 
0 commit comments