master
py 138 lines 5.18 KB
Raw
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
12 from re import search
13 from subprocess import check_output, CalledProcessError
14
15 from qemu_test import Asset, skipIfMissingCommands
16 from qemu_test import exec_command_and_wait_for_pattern as ec_and_wait
17
18 from qemu_test.linuxkernel import LinuxKernelTest
19
20 from qemu.machine.machine import VMLaunchFailure
21
22
23 class 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 elif "eglInitialize failed: EGL_NOT_INITIALIZED" in excp.output:
76 self.skipTest("EGL failed to initialize on this host")
77 else:
78 self.log.info("unhandled launch failure: %s", excp.output)
79 raise excp
80
81 self.wait_for_console_pattern('buildroot login:')
82 ec_and_wait(self, 'root', '#')
83
84 def _run_virt_weston_test(self, cmd, fail=None):
85
86 # make it easier to detect successful return to shell
87 ps1 = 'RES=[$?] # '
88 ok_cmd = 'RES=[0] # '
89
90 ec_and_wait(self, 'export XDG_RUNTIME_DIR=/tmp', '#')
91 ec_and_wait(self, f"export PS1='{ps1}'", ok_cmd)
92 full_cmd = f"weston -B headless --renderer gl --shell kiosk -- {cmd}"
93 ec_and_wait(self, full_cmd, ok_cmd, fail)
94
95 @skipIfMissingCommands('zstd')
96 def test_aarch64_virt_with_virgl_gpu(self):
97
98 self.require_device('virtio-gpu-gl-pci')
99
100 self._launch_virt_gpu("virtio-gpu-gl-pci")
101
102 # subset of the glmark tests
103 tests = " ".join([f"-b {test}" for test in
104 ["build", "texture", "shading",
105 "bump", "desktop", "buffer"]])
106
107 self._run_virt_weston_test("glmark2-wayland --validate " + tests)
108
109 @skipIfMissingCommands('zstd')
110 def test_aarch64_virt_with_virgl_blobs_gpu(self):
111
112 self.require_device('virtio-gpu-gl-pci')
113
114 self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on")
115 self._run_virt_weston_test("glmark2-wayland -b:duration=1.0")
116
117 @skipIfMissingCommands('zstd')
118 @skipIfMissingCommands('vulkaninfo')
119 def test_aarch64_virt_with_vulkan_gpu(self):
120
121 self.require_device('virtio-gpu-gl-pci')
122
123 try:
124 vk_info = check_output(["vulkaninfo", "--summary"],
125 encoding="utf-8")
126 except CalledProcessError as excp:
127 self.skipTest(f"Miss-configured host Vulkan: {excp.output}")
128
129 if search(r"driverID\s+=\s+DRIVER_ID_NVIDIA_PROPRIETARY", vk_info):
130 self.skipTest("Test skipped on NVIDIA proprietary driver")
131
132 self._launch_virt_gpu("virtio-gpu-gl-pci,hostmem=4G,blob=on,venus=on")
133 self._run_virt_weston_test("vkmark -b:duration=1.0",
134 "debug: stuck in fence wait with iter at")
135
136
137 if __name__ == '__main__':
138 LinuxKernelTest.main()