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 Aarch64SbsarefFreeBSD(QemuSystemTest):
21
22    ASSET_FREEBSD_ISO = Asset(
23        ('https://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/'
24         '14.1/FreeBSD-14.1-RELEASE-arm64-aarch64-bootonly.iso'),
25        '44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461')
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_freebsd14(self, cpu=None):
31        fetch_firmware(self)
32
33        img_path = self.ASSET_FREEBSD_ISO.fetch()
34
35        self.vm.set_console()
36        self.vm.add_args(
37            "-drive", f"file={img_path},format=raw,snapshot=on",
38        )
39        if cpu:
40            self.vm.add_args("-cpu", cpu)
41
42        self.vm.launch()
43        wait_for_console_pattern(self, 'Welcome to FreeBSD!')
44
45    def test_sbsaref_freebsd14_cortex_a57(self):
46        self.boot_freebsd14("cortex-a57")
47
48    def test_sbsaref_freebsd14_default_cpu(self):
49        self.boot_freebsd14()
50
51    def test_sbsaref_freebsd14_max_pauth_off(self):
52        self.boot_freebsd14("max,pauth=off")
53
54    @skipUnless(os.getenv('QEMU_TEST_TIMEOUT_EXPECTED'),
55                'Test might timeout due to PAuth emulation')
56    def test_sbsaref_freebsd14_max_pauth_impdef(self):
57        self.boot_freebsd14("max,pauth-impdef=on")
58
59    @skipUnless(os.getenv('QEMU_TEST_TIMEOUT_EXPECTED'),
60                'Test might timeout due to PAuth emulation')
61    def test_sbsaref_freebsd14_max(self):
62        self.boot_freebsd14("max")
63
64
65if __name__ == '__main__':
66    QemuSystemTest.main()
67