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