]> git.proxmox.com Git - mirror_qemu.git/blame - tests/avocado/virtio-gpu.py
tests/avocado/machine_aspeed.py: Update buildroot images to 2023.11
[mirror_qemu.git] / tests / avocado / virtio-gpu.py
CommitLineData
73240f10
MAL
1# virtio-gpu tests
2#
3# This work is licensed under the terms of the GNU GPL, version 2 or
4# later. See the COPYING file in the top-level directory.
5
6
73240f10 7from avocado_qemu import BUILD_DIR
2283b627 8from avocado_qemu import QemuSystemTest
73240f10
MAL
9from avocado_qemu import wait_for_console_pattern
10from avocado_qemu import exec_command_and_wait_for_pattern
11from avocado_qemu import is_readable_executable_file
12
beb6b57b 13from qemu.utils import kvm_available
73240f10
MAL
14
15import os
16import socket
17import subprocess
18
19
73240f10
MAL
20def pick_default_vug_bin():
21 relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
22 if is_readable_executable_file(relative_path):
23 return relative_path
24
25 bld_dir_path = os.path.join(BUILD_DIR, relative_path)
26 if is_readable_executable_file(bld_dir_path):
27 return bld_dir_path
28
29
2283b627 30class VirtioGPUx86(QemuSystemTest):
73240f10
MAL
31 """
32 :avocado: tags=virtio-gpu
cc6a2457 33 :avocado: tags=arch:x86_64
3c6eb9c6 34 :avocado: tags=cpu:host
73240f10
MAL
35 """
36
532835d0 37 KERNEL_COMMAND_LINE = "printk.time=0 console=ttyS0 rdinit=/bin/bash"
73240f10 38 KERNEL_URL = (
57822f71 39 "https://archives.fedoraproject.org/pub/archive/fedora"
73240f10
MAL
40 "/linux/releases/33/Everything/x86_64/os/images"
41 "/pxeboot/vmlinuz"
42 )
074fca10 43 KERNEL_HASH = '1433cfe3f2ffaa44de4ecfb57ec25dc2399cdecf'
73240f10 44 INITRD_URL = (
57822f71 45 "https://archives.fedoraproject.org/pub/archive/fedora"
73240f10
MAL
46 "/linux/releases/33/Everything/x86_64/os/images"
47 "/pxeboot/initrd.img"
48 )
074fca10 49 INITRD_HASH = 'c828d68a027b53e5220536585efe03412332c2d9'
73240f10
MAL
50
51 def wait_for_console_pattern(self, success_message, vm=None):
52 wait_for_console_pattern(
53 self,
54 success_message,
55 failure_message="Kernel panic - not syncing",
56 vm=vm,
57 )
58
59 def test_virtio_vga_virgl(self):
60 """
3a05eee2 61 :avocado: tags=device:virtio-vga-gl
73240f10 62 """
73240f10 63 # FIXME: should check presence of virtio, virgl etc
8ee6e281 64 self.require_accelerator('kvm')
73240f10 65
074fca10
CR
66 kernel_path = self.fetch_asset(self.KERNEL_URL, self.KERNEL_HASH)
67 initrd_path = self.fetch_asset(self.INITRD_URL, self.INITRD_HASH)
73240f10
MAL
68
69 self.vm.set_console()
73240f10
MAL
70 self.vm.add_args("-m", "2G")
71 self.vm.add_args("-machine", "pc,accel=kvm")
3a05eee2 72 self.vm.add_args("-device", "virtio-vga-gl")
73240f10
MAL
73 self.vm.add_args("-display", "egl-headless")
74 self.vm.add_args(
75 "-kernel",
76 kernel_path,
77 "-initrd",
78 initrd_path,
79 "-append",
532835d0 80 self.KERNEL_COMMAND_LINE,
73240f10 81 )
d9894645
AB
82 try:
83 self.vm.launch()
84 except:
85 # TODO: probably fails because we are missing the VirGL features
86 self.cancel("VirGL not enabled?")
87
73240f10
MAL
88 self.wait_for_console_pattern("as init process")
89 exec_command_and_wait_for_pattern(
90 self, "/usr/sbin/modprobe virtio_gpu", ""
91 )
92 self.wait_for_console_pattern("features: +virgl +edid")
93
94 def test_vhost_user_vga_virgl(self):
95 """
73240f10
MAL
96 :avocado: tags=device:vhost-user-vga
97 """
73240f10 98 # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
8ee6e281 99 self.require_accelerator('kvm')
73240f10
MAL
100
101 vug = pick_default_vug_bin()
102 if not vug:
103 self.cancel("Could not find vhost-user-gpu")
104
074fca10
CR
105 kernel_path = self.fetch_asset(self.KERNEL_URL, self.KERNEL_HASH)
106 initrd_path = self.fetch_asset(self.INITRD_URL, self.INITRD_HASH)
73240f10
MAL
107
108 # Create socketpair to connect proxy and remote processes
109 qemu_sock, vug_sock = socket.socketpair(
110 socket.AF_UNIX, socket.SOCK_STREAM
111 )
112 os.set_inheritable(qemu_sock.fileno(), True)
113 os.set_inheritable(vug_sock.fileno(), True)
114
115 self._vug_log_path = os.path.join(
cdcc50bf 116 self.logdir, "vhost-user-gpu.log"
73240f10
MAL
117 )
118 self._vug_log_file = open(self._vug_log_path, "wb")
cdcc50bf
CR
119 self.log.info('Complete vhost-user-gpu.log file can be '
120 'found at %s', self._vug_log_path)
73240f10
MAL
121
122 vugp = subprocess.Popen(
123 [vug, "--virgl", "--fd=%d" % vug_sock.fileno()],
124 stdin=subprocess.DEVNULL,
125 stdout=self._vug_log_file,
126 stderr=subprocess.STDOUT,
127 shell=False,
128 close_fds=False,
129 )
130
131 self.vm.set_console()
73240f10
MAL
132 self.vm.add_args("-m", "2G")
133 self.vm.add_args("-object", "memory-backend-memfd,id=mem,size=2G")
134 self.vm.add_args("-machine", "pc,memory-backend=mem,accel=kvm")
135 self.vm.add_args("-chardev", "socket,id=vug,fd=%d" % qemu_sock.fileno())
136 self.vm.add_args("-device", "vhost-user-vga,chardev=vug")
137 self.vm.add_args("-display", "egl-headless")
138 self.vm.add_args(
139 "-kernel",
140 kernel_path,
141 "-initrd",
142 initrd_path,
143 "-append",
532835d0 144 self.KERNEL_COMMAND_LINE,
73240f10 145 )
7f027ee0
TH
146 try:
147 self.vm.launch()
148 except:
149 # TODO: probably fails because we are missing the VirGL features
150 self.cancel("VirGL not enabled?")
73240f10 151 self.wait_for_console_pattern("as init process")
ffab603b
TH
152 exec_command_and_wait_for_pattern(self, "/usr/sbin/modprobe virtio_gpu",
153 "features: +virgl +edid")
73240f10
MAL
154 self.vm.shutdown()
155 qemu_sock.close()
156 vugp.terminate()
157 vugp.wait()