1*1255f5e4SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2*1255f5e4SPhilippe Mathieu-Daudé# 3*1255f5e4SPhilippe Mathieu-Daudé# Functional test that boots a various Linux systems and checks the 4*1255f5e4SPhilippe Mathieu-Daudé# console output. 5*1255f5e4SPhilippe Mathieu-Daudé# 6*1255f5e4SPhilippe Mathieu-Daudé# Copyright (c) 2022 Linaro Ltd. 7*1255f5e4SPhilippe Mathieu-Daudé# 8*1255f5e4SPhilippe Mathieu-Daudé# Author: 9*1255f5e4SPhilippe Mathieu-Daudé# Alex Bennée <alex.bennee@linaro.org> 10*1255f5e4SPhilippe Mathieu-Daudé# 11*1255f5e4SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 12*1255f5e4SPhilippe Mathieu-Daudé 13*1255f5e4SPhilippe Mathieu-Daudéimport time 14*1255f5e4SPhilippe Mathieu-Daudéimport os 15*1255f5e4SPhilippe Mathieu-Daudéimport logging 16*1255f5e4SPhilippe Mathieu-Daudé 17*1255f5e4SPhilippe Mathieu-Daudéfrom qemu_test import BUILD_DIR 18*1255f5e4SPhilippe Mathieu-Daudéfrom qemu_test import QemuSystemTest, Asset 19*1255f5e4SPhilippe Mathieu-Daudéfrom qemu_test import exec_command, wait_for_console_pattern 20*1255f5e4SPhilippe Mathieu-Daudéfrom qemu_test import get_qemu_img, run_cmd 21*1255f5e4SPhilippe Mathieu-Daudé 22*1255f5e4SPhilippe Mathieu-Daudé 23*1255f5e4SPhilippe Mathieu-Daudéclass Aarch64VirtMachine(QemuSystemTest): 24*1255f5e4SPhilippe Mathieu-Daudé KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 25*1255f5e4SPhilippe Mathieu-Daudé timeout = 360 26*1255f5e4SPhilippe Mathieu-Daudé 27*1255f5e4SPhilippe Mathieu-Daudé def wait_for_console_pattern(self, success_message, vm=None): 28*1255f5e4SPhilippe Mathieu-Daudé wait_for_console_pattern(self, success_message, 29*1255f5e4SPhilippe Mathieu-Daudé failure_message='Kernel panic - not syncing', 30*1255f5e4SPhilippe Mathieu-Daudé vm=vm) 31*1255f5e4SPhilippe Mathieu-Daudé 32*1255f5e4SPhilippe Mathieu-Daudé ASSET_ALPINE_ISO = Asset( 33*1255f5e4SPhilippe Mathieu-Daudé ('https://dl-cdn.alpinelinux.org/' 34*1255f5e4SPhilippe Mathieu-Daudé 'alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso'), 35*1255f5e4SPhilippe Mathieu-Daudé '5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027') 36*1255f5e4SPhilippe Mathieu-Daudé 37*1255f5e4SPhilippe Mathieu-Daudé # This tests the whole boot chain from EFI to Userspace 38*1255f5e4SPhilippe Mathieu-Daudé # We only boot a whole OS for the current top level CPU and GIC 39*1255f5e4SPhilippe Mathieu-Daudé # Other test profiles should use more minimal boots 40*1255f5e4SPhilippe Mathieu-Daudé def test_alpine_virt_tcg_gic_max(self): 41*1255f5e4SPhilippe Mathieu-Daudé iso_path = self.ASSET_ALPINE_ISO.fetch() 42*1255f5e4SPhilippe Mathieu-Daudé 43*1255f5e4SPhilippe Mathieu-Daudé self.set_machine('virt') 44*1255f5e4SPhilippe Mathieu-Daudé self.vm.set_console() 45*1255f5e4SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 46*1255f5e4SPhilippe Mathieu-Daudé 'console=ttyAMA0') 47*1255f5e4SPhilippe Mathieu-Daudé self.require_accelerator("tcg") 48*1255f5e4SPhilippe Mathieu-Daudé 49*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args("-accel", "tcg") 50*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args("-cpu", "max,pauth-impdef=on") 51*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args("-machine", 52*1255f5e4SPhilippe Mathieu-Daudé "virt,acpi=on," 53*1255f5e4SPhilippe Mathieu-Daudé "virtualization=on," 54*1255f5e4SPhilippe Mathieu-Daudé "mte=on," 55*1255f5e4SPhilippe Mathieu-Daudé "gic-version=max,iommu=smmuv3") 56*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args("-smp", "2", "-m", "1024") 57*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios', 58*1255f5e4SPhilippe Mathieu-Daudé 'edk2-aarch64-code.fd')) 59*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args("-drive", f"file={iso_path},media=cdrom,format=raw") 60*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0') 61*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-object', 'rng-random,id=rng0,filename=/dev/urandom') 62*1255f5e4SPhilippe Mathieu-Daudé 63*1255f5e4SPhilippe Mathieu-Daudé self.vm.launch() 64*1255f5e4SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Welcome to Alpine Linux 3.17') 65*1255f5e4SPhilippe Mathieu-Daudé 66*1255f5e4SPhilippe Mathieu-Daudé 67*1255f5e4SPhilippe Mathieu-Daudé ASSET_KERNEL = Asset( 68*1255f5e4SPhilippe Mathieu-Daudé ('https://fileserver.linaro.org/s/' 69*1255f5e4SPhilippe Mathieu-Daudé 'z6B2ARM7DQT3HWN/download'), 70*1255f5e4SPhilippe Mathieu-Daudé '12a54d4805cda6ab647cb7c7bbdb16fafb3df400e0d6f16445c1a0436100ef8d') 71*1255f5e4SPhilippe Mathieu-Daudé 72*1255f5e4SPhilippe Mathieu-Daudé def common_aarch64_virt(self, machine): 73*1255f5e4SPhilippe Mathieu-Daudé """ 74*1255f5e4SPhilippe Mathieu-Daudé Common code to launch basic virt machine with kernel+initrd 75*1255f5e4SPhilippe Mathieu-Daudé and a scratch disk. 76*1255f5e4SPhilippe Mathieu-Daudé """ 77*1255f5e4SPhilippe Mathieu-Daudé logger = logging.getLogger('aarch64_virt') 78*1255f5e4SPhilippe Mathieu-Daudé 79*1255f5e4SPhilippe Mathieu-Daudé kernel_path = self.ASSET_KERNEL.fetch() 80*1255f5e4SPhilippe Mathieu-Daudé 81*1255f5e4SPhilippe Mathieu-Daudé self.set_machine('virt') 82*1255f5e4SPhilippe Mathieu-Daudé self.vm.set_console() 83*1255f5e4SPhilippe Mathieu-Daudé kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 84*1255f5e4SPhilippe Mathieu-Daudé 'console=ttyAMA0') 85*1255f5e4SPhilippe Mathieu-Daudé self.require_accelerator("tcg") 86*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-cpu', 'max,pauth-impdef=on', 87*1255f5e4SPhilippe Mathieu-Daudé '-machine', machine, 88*1255f5e4SPhilippe Mathieu-Daudé '-accel', 'tcg', 89*1255f5e4SPhilippe Mathieu-Daudé '-kernel', kernel_path, 90*1255f5e4SPhilippe Mathieu-Daudé '-append', kernel_command_line) 91*1255f5e4SPhilippe Mathieu-Daudé 92*1255f5e4SPhilippe Mathieu-Daudé # A RNG offers an easy way to generate a few IRQs 93*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0') 94*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-object', 95*1255f5e4SPhilippe Mathieu-Daudé 'rng-random,id=rng0,filename=/dev/urandom') 96*1255f5e4SPhilippe Mathieu-Daudé 97*1255f5e4SPhilippe Mathieu-Daudé # Also add a scratch block device 98*1255f5e4SPhilippe Mathieu-Daudé logger.info('creating scratch qcow2 image') 99*1255f5e4SPhilippe Mathieu-Daudé image_path = os.path.join(self.workdir, 'scratch.qcow2') 100*1255f5e4SPhilippe Mathieu-Daudé qemu_img = get_qemu_img(self) 101*1255f5e4SPhilippe Mathieu-Daudé run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M']) 102*1255f5e4SPhilippe Mathieu-Daudé 103*1255f5e4SPhilippe Mathieu-Daudé # Add the device 104*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-blockdev', 105*1255f5e4SPhilippe Mathieu-Daudé f"driver=qcow2,file.driver=file,file.filename={image_path},node-name=scratch") 106*1255f5e4SPhilippe Mathieu-Daudé self.vm.add_args('-device', 107*1255f5e4SPhilippe Mathieu-Daudé 'virtio-blk-device,drive=scratch') 108*1255f5e4SPhilippe Mathieu-Daudé 109*1255f5e4SPhilippe Mathieu-Daudé self.vm.launch() 110*1255f5e4SPhilippe Mathieu-Daudé self.wait_for_console_pattern('Welcome to Buildroot') 111*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 112*1255f5e4SPhilippe Mathieu-Daudé exec_command(self, 'root') 113*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 114*1255f5e4SPhilippe Mathieu-Daudé exec_command(self, 'dd if=/dev/hwrng of=/dev/vda bs=512 count=4') 115*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 116*1255f5e4SPhilippe Mathieu-Daudé exec_command(self, 'md5sum /dev/vda') 117*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 118*1255f5e4SPhilippe Mathieu-Daudé exec_command(self, 'cat /proc/interrupts') 119*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 120*1255f5e4SPhilippe Mathieu-Daudé exec_command(self, 'cat /proc/self/maps') 121*1255f5e4SPhilippe Mathieu-Daudé time.sleep(0.1) 122*1255f5e4SPhilippe Mathieu-Daudé 123*1255f5e4SPhilippe Mathieu-Daudé def test_aarch64_virt_gicv3(self): 124*1255f5e4SPhilippe Mathieu-Daudé self.common_aarch64_virt("virt,gic_version=3") 125*1255f5e4SPhilippe Mathieu-Daudé 126*1255f5e4SPhilippe Mathieu-Daudé def test_aarch64_virt_gicv2(self): 127*1255f5e4SPhilippe Mathieu-Daudé self.common_aarch64_virt("virt,gic-version=2") 128*1255f5e4SPhilippe Mathieu-Daudé 129*1255f5e4SPhilippe Mathieu-Daudé 130*1255f5e4SPhilippe Mathieu-Daudéif __name__ == '__main__': 131*1255f5e4SPhilippe Mathieu-Daudé QemuSystemTest.main() 132