1#!/usr/bin/env python3
2#
3# Functional test that boots a kernel and checks the console
4#
5# SPDX-FileCopyrightText: 2023-2024 Linaro Ltd.
6# SPDX-FileContributor: Philippe Mathieu-Daudé <philmd@linaro.org>
7# SPDX-FileContributor: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
8#
9# SPDX-License-Identifier: GPL-2.0-or-later
10
11import os
12
13from qemu_test import QemuSystemTest, Asset
14from qemu_test import wait_for_console_pattern
15from qemu_test import interrupt_interactive_console_until_pattern
16from unittest import skipUnless
17from test_aarch64_sbsaref import fetch_firmware
18
19
20class Aarch64SbsarefAlpine(QemuSystemTest):
21
22    ASSET_ALPINE_ISO = Asset(
23        ('https://dl-cdn.alpinelinux.org/'
24         'alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso'),
25        '5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027')
26
27    # This tests the whole boot chain from EFI to Userspace
28    # We only boot a whole OS for the current top level CPU and GIC
29    # Other test profiles should use more minimal boots
30    def boot_alpine_linux(self, cpu=None):
31        fetch_firmware(self)
32
33        iso_path = self.ASSET_ALPINE_ISO.fetch()
34
35        self.vm.set_console()
36        self.vm.add_args(
37            "-drive", f"file={iso_path},media=cdrom,format=raw",
38        )
39        if cpu:
40            self.vm.add_args("-cpu", cpu)
41
42        self.vm.launch()
43        wait_for_console_pattern(self, "Welcome to Alpine Linux 3.17")
44
45    def test_sbsaref_alpine_linux_cortex_a57(self):
46        self.boot_alpine_linux("cortex-a57")
47
48    def test_sbsaref_alpine_linux_default_cpu(self):
49        self.boot_alpine_linux()
50
51    def test_sbsaref_alpine_linux_max_pauth_off(self):
52        self.boot_alpine_linux("max,pauth=off")
53
54    def test_sbsaref_alpine_linux_max_pauth_impdef(self):
55        self.boot_alpine_linux("max,pauth-impdef=on")
56
57    @skipUnless(os.getenv('QEMU_TEST_TIMEOUT_EXPECTED'),
58                'Test might timeout due to PAuth emulation')
59    def test_sbsaref_alpine_linux_max(self):
60        self.boot_alpine_linux("max")
61
62
63if __name__ == '__main__':
64    QemuSystemTest.main()
65