1# Functional test that boots a Linux kernel and checks the console
2#
3# Copyright (c) 2022 Linaro Ltd.
4#
5# Author:
6#  Alex Bennée <alex.bennee@linaro.org>
7#
8# SPDX-License-Identifier: GPL-2.0-or-later
9
10import time
11
12from avocado_qemu import QemuSystemTest
13from avocado_qemu import wait_for_console_pattern
14from avocado_qemu import exec_command
15
16class Aarch64VirtMachine(QemuSystemTest):
17    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
18
19    def wait_for_console_pattern(self, success_message, vm=None):
20        wait_for_console_pattern(self, success_message,
21                                 failure_message='Kernel panic - not syncing',
22                                 vm=vm)
23
24    def test_aarch64_virt(self):
25        """
26        :avocado: tags=arch:aarch64
27        :avocado: tags=machine:virt
28        :avocado: tags=accel:tcg
29        :avocado: tags=cpu:max
30        """
31        kernel_url = ('https://fileserver.linaro.org/s/'
32                      'z6B2ARM7DQT3HWN/download')
33
34        kernel_hash = 'ed11daab50c151dde0e1e9c9cb8b2d9bd3215347'
35        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
36
37        self.vm.set_console()
38        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
39                               'console=ttyAMA0')
40        self.require_accelerator("tcg")
41        self.vm.add_args('-cpu', 'max,pauth-impdef=on',
42                         '-accel', 'tcg',
43                         '-kernel', kernel_path,
44                         '-append', kernel_command_line)
45        self.vm.launch()
46        self.wait_for_console_pattern('Welcome to Buildroot')
47        time.sleep(0.1)
48        exec_command(self, 'root')
49        time.sleep(0.1)
50        exec_command(self, 'cat /proc/self/maps')
51        time.sleep(0.1)
52