1#!/usr/bin/env python3 2# 3# Functional test that boots a Realms environment on sbsa-ref machine and a 4# nested guest VM using it. 5# 6# Copyright (c) 2024 Linaro Ltd. 7# 8# Author: Pierrick Bouvier <pierrick.bouvier@linaro.org> 9# 10# SPDX-License-Identifier: GPL-2.0-or-later 11 12import os 13 14from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern 15from qemu_test import exec_command_and_wait_for_pattern 16from test_aarch64_rme_virt import test_realms_guest 17 18 19class Aarch64RMESbsaRefMachine(QemuSystemTest): 20 21 # Stack is built with OP-TEE build environment from those instructions: 22 # https://linaro.atlassian.net/wiki/spaces/QEMU/pages/29051027459/ 23 # https://github.com/pbo-linaro/qemu-rme-stack 24 ASSET_RME_STACK_SBSA = Asset( 25 ('https://fileserver.linaro.org/s/KJyeBxL82mz2r7F/' 26 'download/rme-stack-op-tee-4.2.0-cca-v4-sbsa.tar.gz'), 27 'dd9ab28ec869bdf3b5376116cb3689103b43433fd5c4bca0f4a8d8b3c104999e') 28 29 # This tests the FEAT_RME cpu implementation, by booting a VM supporting it, 30 # and launching a nested VM using it. 31 def test_aarch64_rme_sbsaref(self): 32 self.set_machine('sbsa-ref') 33 self.require_accelerator('tcg') 34 self.require_netdev('user') 35 36 self.vm.set_console() 37 38 stack_path_tar_gz = self.ASSET_RME_STACK_SBSA.fetch() 39 self.archive_extract(stack_path_tar_gz, format="tar") 40 41 rme_stack = self.scratch_file('rme-stack-op-tee-4.2.0-cca-v4-sbsa') 42 pflash0 = os.path.join(rme_stack, 'images', 'SBSA_FLASH0.fd') 43 pflash1 = os.path.join(rme_stack, 'images', 'SBSA_FLASH1.fd') 44 virtual = os.path.join(rme_stack, 'images', 'disks', 'virtual') 45 drive = os.path.join(rme_stack, 'out-br', 'images', 'rootfs.ext4') 46 47 self.vm.add_args('-cpu', 'max,x-rme=on,pauth-impdef=on') 48 self.vm.add_args('-m', '2G') 49 self.vm.add_args('-M', 'sbsa-ref') 50 self.vm.add_args('-drive', f'file={pflash0},format=raw,if=pflash') 51 self.vm.add_args('-drive', f'file={pflash1},format=raw,if=pflash') 52 self.vm.add_args('-drive', f'file=fat:rw:{virtual},format=raw') 53 self.vm.add_args('-drive', f'format=raw,if=none,file={drive},id=hd0') 54 self.vm.add_args('-device', 'virtio-blk-pci,drive=hd0') 55 self.vm.add_args('-device', 'virtio-9p-pci,fsdev=shr0,mount_tag=shr0') 56 self.vm.add_args('-fsdev', f'local,security_model=none,path={rme_stack},id=shr0') 57 self.vm.add_args('-device', 'virtio-net-pci,netdev=net0') 58 self.vm.add_args('-netdev', 'user,id=net0') 59 60 self.vm.launch() 61 # Wait for host VM boot to complete. 62 wait_for_console_pattern(self, 'Welcome to Buildroot', 63 failure_message='Synchronous Exception at') 64 exec_command_and_wait_for_pattern(self, 'root', '#') 65 66 test_realms_guest(self) 67 68if __name__ == '__main__': 69 QemuSystemTest.main() 70