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