xref: /qemu/tests/functional/test_aarch64_virt_gpu.py (revision 3a0ff62431d297eadc7213cc5b2abda9d1bfce7a)
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://fileserver.linaro.org/s/ce5jXBFinPxtEdx/'
27        'download?path=%2F&files='
28        'Image.6.12.16.aarch64',
29        '7888c51c55d37e86bbbdeb5acea9f08c34e6b0f03c1f5b2463285f6a6f6eec8b')
30
31    ASSET_VIRT_GPU_ROOTFS = Asset(
32        'https://fileserver.linaro.org/s/ce5jXBFinPxtEdx/'
33        'download?path=%2F&files='
34        'rootfs.aarch64.ext2.zstd',
35        'd45118c899420b7e673f1539a37a35480134b3e36e3a59e2cb69b1781cbb14ef')
36
37    def _launch_virt_gpu(self, gpu_device):
38
39        self.set_machine('virt')
40        self.require_accelerator("tcg")
41
42        kernel_path = self.ASSET_VIRT_GPU_KERNEL.fetch()
43        image_path = self.uncompress(self.ASSET_VIRT_GPU_ROOTFS, format="zstd")
44
45        self.vm.set_console()
46        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
47                               'console=ttyAMA0 root=/dev/vda')
48
49        self.vm.add_args("-accel", "tcg")
50        self.vm.add_args("-cpu", "cortex-a72")
51        self.vm.add_args("-machine", "virt,gic-version=max",
52                         '-kernel', kernel_path,
53                         '-append', kernel_command_line)
54        self.vm.add_args("-smp", "2", "-m", "2048")
55        self.vm.add_args("-device", gpu_device)
56        self.vm.add_args("-display", "egl-headless")
57        self.vm.add_args("-display", "dbus,gl=on")
58
59        self.vm.add_args("-device", "virtio-blk-device,drive=hd0")
60        self.vm.add_args("-blockdev",
61                         "driver=raw,file.driver=file,"
62                         "node-name=hd0,read-only=on,"
63                         f"file.filename={image_path}")
64        self.vm.add_args("-snapshot")
65
66        try:
67            self.vm.launch()
68        except VMLaunchFailure as excp:
69            if "old virglrenderer, blob resources unsupported" in excp.output:
70                self.skipTest("No blob support for virtio-gpu")
71            elif "old virglrenderer, venus unsupported" in excp.output:
72                self.skipTest("No venus support for virtio-gpu")
73            elif "egl: no drm render node available" in excp.output:
74                self.skipTest("Can't access host DRM render node")
75            elif "'type' does not accept value 'egl-headless'" in excp.output:
76                self.skipTest("egl-headless support is not available")
77            elif "'type' does not accept value 'dbus'" in excp.output:
78                self.skipTest("dbus display support is not available")
79            else:
80                self.log.info("unhandled launch failure: %s", excp.output)
81                raise excp
82
83        self.wait_for_console_pattern('buildroot login:')
84        ec_and_wait(self, 'root', '#')
85
86    def _run_virt_weston_test(self, cmd, fail = None):
87
88        # make it easier to detect successful return to shell
89        PS1 = 'RES=[$?] # '
90        OK_CMD = 'RES=[0] # '
91
92        ec_and_wait(self, 'export XDG_RUNTIME_DIR=/tmp', '#')
93        ec_and_wait(self, f"export PS1='{PS1}'", OK_CMD)
94        full_cmd = f"weston -B headless --renderer gl --shell kiosk -- {cmd}"
95        ec_and_wait(self, full_cmd, OK_CMD, fail)
96
97    @skipIfMissingCommands('zstd')
98    def test_aarch64_virt_with_virgl_gpu(self):
99
100        self.require_device('virtio-gpu-gl-pci')
101
102        self._launch_virt_gpu("virtio-gpu-gl-pci")
103
104        # subset of the glmark tests
105        tests = " ".join([f"-b {test}" for test in
106                          ["build", "texture", "shading",
107                           "bump", "desktop", "buffer"]])
108
109        self._run_virt_weston_test("glmark2-wayland --validate " + tests)
110
111    @skipIfMissingCommands('zstd')
112    def test_aarch64_virt_with_virgl_blobs_gpu(self):
113
114        self.require_device('virtio-gpu-gl-pci')
115
116        self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on")
117        self._run_virt_weston_test("glmark2-wayland -b:duration=1.0")
118
119    @skipIfMissingCommands('zstd')
120    @skipIfMissingCommands('vulkaninfo')
121    def test_aarch64_virt_with_vulkan_gpu(self):
122
123        self.require_device('virtio-gpu-gl-pci')
124
125        try:
126            vk_info = check_output(["vulkaninfo", "--summary"],
127                                   encoding="utf-8")
128        except CalledProcessError as excp:
129            self.skipTest(f"Miss-configured host Vulkan: {excp.output}")
130
131        if search(r"driverID\s+=\s+DRIVER_ID_NVIDIA_PROPRIETARY", vk_info):
132            self.skipTest("Test skipped on NVIDIA proprietary driver")
133
134        self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on,venus=on")
135        self._run_virt_weston_test("vkmark -b:duration=1.0",
136                                   "debug: stuck in fence wait with iter at")
137
138
139if __name__ == '__main__':
140    LinuxKernelTest.main()
141