]> Git Repo - qemu.git/blame - tests/acceptance/virtio-gpu.py
tests/acceptance: Increase the timeout in the replay tests
[qemu.git] / tests / acceptance / 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
7from avocado_qemu import Test
8from avocado_qemu import BUILD_DIR
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
13from qemu.accel import kvm_available
14
15import os
16import socket
17import subprocess
18
19
20ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"
21KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM"
22
23
24def pick_default_vug_bin():
25 relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
26 if is_readable_executable_file(relative_path):
27 return relative_path
28
29 bld_dir_path = os.path.join(BUILD_DIR, relative_path)
30 if is_readable_executable_file(bld_dir_path):
31 return bld_dir_path
32
33
34class VirtioGPUx86(Test):
35 """
36 :avocado: tags=virtio-gpu
37 """
38
39 KERNEL_COMMON_COMMAND_LINE = "printk.time=0 "
40 KERNEL_URL = (
41 "https://archives.fedoraproject.org/pub/fedora"
42 "/linux/releases/33/Everything/x86_64/os/images"
43 "/pxeboot/vmlinuz"
44 )
45 INITRD_URL = (
46 "https://archives.fedoraproject.org/pub/fedora"
47 "/linux/releases/33/Everything/x86_64/os/images"
48 "/pxeboot/initrd.img"
49 )
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 """
61 :avocado: tags=arch:x86_64
62 :avocado: tags=device:virtio-vga
63 """
64 kernel_command_line = (
65 self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
66 )
67 # FIXME: should check presence of virtio, virgl etc
68 if not kvm_available(self.arch, self.qemu_bin):
69 self.cancel(KVM_NOT_AVAILABLE)
70
71 kernel_path = self.fetch_asset(self.KERNEL_URL)
72 initrd_path = self.fetch_asset(self.INITRD_URL)
73
74 self.vm.set_console()
75 self.vm.add_args("-cpu", "host")
76 self.vm.add_args("-m", "2G")
77 self.vm.add_args("-machine", "pc,accel=kvm")
78 self.vm.add_args("-device", "virtio-vga,virgl=on")
79 self.vm.add_args("-display", "egl-headless")
80 self.vm.add_args(
81 "-kernel",
82 kernel_path,
83 "-initrd",
84 initrd_path,
85 "-append",
86 kernel_command_line,
87 )
88 self.vm.launch()
89 self.wait_for_console_pattern("as init process")
90 exec_command_and_wait_for_pattern(
91 self, "/usr/sbin/modprobe virtio_gpu", ""
92 )
93 self.wait_for_console_pattern("features: +virgl +edid")
94
95 def test_vhost_user_vga_virgl(self):
96 """
97 :avocado: tags=arch:x86_64
98 :avocado: tags=device:vhost-user-vga
99 """
100 kernel_command_line = (
101 self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
102 )
103 # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
104 if not kvm_available(self.arch, self.qemu_bin):
105 self.cancel(KVM_NOT_AVAILABLE)
106
107 vug = pick_default_vug_bin()
108 if not vug:
109 self.cancel("Could not find vhost-user-gpu")
110
111 kernel_path = self.fetch_asset(self.KERNEL_URL)
112 initrd_path = self.fetch_asset(self.INITRD_URL)
113
114 # Create socketpair to connect proxy and remote processes
115 qemu_sock, vug_sock = socket.socketpair(
116 socket.AF_UNIX, socket.SOCK_STREAM
117 )
118 os.set_inheritable(qemu_sock.fileno(), True)
119 os.set_inheritable(vug_sock.fileno(), True)
120
121 self._vug_log_path = os.path.join(
122 self.vm._test_dir, "vhost-user-gpu.log"
123 )
124 self._vug_log_file = open(self._vug_log_path, "wb")
125 print(self._vug_log_path)
126
127 vugp = subprocess.Popen(
128 [vug, "--virgl", "--fd=%d" % vug_sock.fileno()],
129 stdin=subprocess.DEVNULL,
130 stdout=self._vug_log_file,
131 stderr=subprocess.STDOUT,
132 shell=False,
133 close_fds=False,
134 )
135
136 self.vm.set_console()
137 self.vm.add_args("-cpu", "host")
138 self.vm.add_args("-m", "2G")
139 self.vm.add_args("-object", "memory-backend-memfd,id=mem,size=2G")
140 self.vm.add_args("-machine", "pc,memory-backend=mem,accel=kvm")
141 self.vm.add_args("-chardev", "socket,id=vug,fd=%d" % qemu_sock.fileno())
142 self.vm.add_args("-device", "vhost-user-vga,chardev=vug")
143 self.vm.add_args("-display", "egl-headless")
144 self.vm.add_args(
145 "-kernel",
146 kernel_path,
147 "-initrd",
148 initrd_path,
149 "-append",
150 kernel_command_line,
151 )
152 self.vm.launch()
153 self.wait_for_console_pattern("as init process")
154 exec_command_and_wait_for_pattern(
155 self, "/usr/sbin/modprobe virtio_gpu", ""
156 )
157 self.wait_for_console_pattern("features: +virgl -edid")
158 self.vm.shutdown()
159 qemu_sock.close()
160 vugp.terminate()
161 vugp.wait()
This page took 0.039014 seconds and 4 git commands to generate.