xref: /openbmc/qemu/tests/functional/test_aarch64_virt_gpu.py (revision 9dbc842e9ab0790df34ed5111785b713a18daaad)
1#!/usr/bin/env python3
2#
3# Functional tests for the various graphics modes we can support.
4#
5# Copyright (c) 2024, 2025 Linaro Ltd.
6#
7# Author:
8#  Alex Bennée <alex.bennee@linaro.org>
9#
10# SPDX-License-Identifier: GPL-2.0-or-later
11
12from qemu.machine.machine import VMLaunchFailure
13
14from qemu_test import Asset
15from qemu_test import exec_command_and_wait_for_pattern as ec_and_wait
16from qemu_test import skipIfMissingCommands
17
18from qemu_test.linuxkernel import LinuxKernelTest
19
20from re import search
21from subprocess import check_output, CalledProcessError
22
23class Aarch64VirtGPUMachine(LinuxKernelTest):
24
25    ASSET_VIRT_GPU_KERNEL = Asset(
26        'https://share.linaro.org/downloadFile?id=lL8wgnMmSXZo7Co',
27        '7888c51c55d37e86bbbdeb5acea9f08c34e6b0f03c1f5b2463285f6a6f6eec8b')
28
29    ASSET_VIRT_GPU_ROOTFS = Asset(
30        'https://share.linaro.org/downloadFile?id=qOn1wbfKmS6KVHZ',
31        'd45118c899420b7e673f1539a37a35480134b3e36e3a59e2cb69b1781cbb14ef')
32
33    def _launch_virt_gpu(self, gpu_device):
34
35        self.set_machine('virt')
36        self.require_accelerator("tcg")
37
38        kernel_path = self.ASSET_VIRT_GPU_KERNEL.fetch()
39        image_path = self.uncompress(self.ASSET_VIRT_GPU_ROOTFS, format="zstd")
40
41        self.vm.set_console()
42        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
43                               'console=ttyAMA0 root=/dev/vda')
44
45        self.vm.add_args("-accel", "tcg")
46        self.vm.add_args("-cpu", "cortex-a72")
47        self.vm.add_args("-machine", "virt,gic-version=max",
48                         '-kernel', kernel_path,
49                         '-append', kernel_command_line)
50        self.vm.add_args("-smp", "2", "-m", "2048")
51        self.vm.add_args("-device", gpu_device)
52        self.vm.add_args("-display", "egl-headless")
53        self.vm.add_args("-display", "dbus,gl=on")
54
55        self.vm.add_args("-device", "virtio-blk-device,drive=hd0")
56        self.vm.add_args("-blockdev",
57                         "driver=raw,file.driver=file,"
58                         "node-name=hd0,read-only=on,"
59                         f"file.filename={image_path}")
60        self.vm.add_args("-snapshot")
61
62        try:
63            self.vm.launch()
64        except VMLaunchFailure as excp:
65            if "old virglrenderer, blob resources unsupported" in excp.output:
66                self.skipTest("No blob support for virtio-gpu")
67            elif "old virglrenderer, venus unsupported" in excp.output:
68                self.skipTest("No venus support for virtio-gpu")
69            elif "egl: no drm render node available" in excp.output:
70                self.skipTest("Can't access host DRM render node")
71            elif "'type' does not accept value 'egl-headless'" in excp.output:
72                self.skipTest("egl-headless support is not available")
73            elif "'type' does not accept value 'dbus'" in excp.output:
74                self.skipTest("dbus display support is not available")
75            else:
76                self.log.info("unhandled launch failure: %s", excp.output)
77                raise excp
78
79        self.wait_for_console_pattern('buildroot login:')
80        ec_and_wait(self, 'root', '#')
81
82    def _run_virt_weston_test(self, cmd, fail = None):
83
84        # make it easier to detect successful return to shell
85        PS1 = 'RES=[$?] # '
86        OK_CMD = 'RES=[0] # '
87
88        ec_and_wait(self, 'export XDG_RUNTIME_DIR=/tmp', '#')
89        ec_and_wait(self, f"export PS1='{PS1}'", OK_CMD)
90        full_cmd = f"weston -B headless --renderer gl --shell kiosk -- {cmd}"
91        ec_and_wait(self, full_cmd, OK_CMD, fail)
92
93    @skipIfMissingCommands('zstd')
94    def test_aarch64_virt_with_virgl_gpu(self):
95
96        self.require_device('virtio-gpu-gl-pci')
97
98        self._launch_virt_gpu("virtio-gpu-gl-pci")
99
100        # subset of the glmark tests
101        tests = " ".join([f"-b {test}" for test in
102                          ["build", "texture", "shading",
103                           "bump", "desktop", "buffer"]])
104
105        self._run_virt_weston_test("glmark2-wayland --validate " + tests)
106
107    @skipIfMissingCommands('zstd')
108    def test_aarch64_virt_with_virgl_blobs_gpu(self):
109
110        self.require_device('virtio-gpu-gl-pci')
111
112        self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on")
113        self._run_virt_weston_test("glmark2-wayland -b:duration=1.0")
114
115    @skipIfMissingCommands('zstd')
116    @skipIfMissingCommands('vulkaninfo')
117    def test_aarch64_virt_with_vulkan_gpu(self):
118
119        self.require_device('virtio-gpu-gl-pci')
120
121        try:
122            vk_info = check_output(["vulkaninfo", "--summary"],
123                                   encoding="utf-8")
124        except CalledProcessError as excp:
125            self.skipTest(f"Miss-configured host Vulkan: {excp.output}")
126
127        if search(r"driverID\s+=\s+DRIVER_ID_NVIDIA_PROPRIETARY", vk_info):
128            self.skipTest("Test skipped on NVIDIA proprietary driver")
129
130        self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on,venus=on")
131        self._run_virt_weston_test("vkmark -b:duration=1.0",
132                                   "debug: stuck in fence wait with iter at")
133
134
135if __name__ == '__main__':
136    LinuxKernelTest.main()
137