MAINTAINERS: Cover docs/igd-assign.txt in VFIO section
[qemu/ar7.git] / tests / acceptance / virtio-gpu.py
blobab18cddbb735a7ab809d55e07ef7cbcc362736b4
1 # virtio-gpu tests
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.
7 from avocado_qemu import Test
8 from avocado_qemu import BUILD_DIR
9 from avocado_qemu import wait_for_console_pattern
10 from avocado_qemu import exec_command_and_wait_for_pattern
11 from avocado_qemu import is_readable_executable_file
13 from qemu.accel import kvm_available
15 import os
16 import socket
17 import subprocess
20 ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"
21 KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM"
24 def 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
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
34 class VirtioGPUx86(Test):
35 """
36 :avocado: tags=virtio-gpu
37 """
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"
45 INITRD_URL = (
46 "https://archives.fedoraproject.org/pub/fedora"
47 "/linux/releases/33/Everything/x86_64/os/images"
48 "/pxeboot/initrd.img"
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,
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"
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)
71 kernel_path = self.fetch_asset(self.KERNEL_URL)
72 initrd_path = self.fetch_asset(self.INITRD_URL)
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,
88 try:
89 self.vm.launch()
90 except:
91 # TODO: probably fails because we are missing the VirGL features
92 self.cancel("VirGL not enabled?")
94 self.wait_for_console_pattern("as init process")
95 exec_command_and_wait_for_pattern(
96 self, "/usr/sbin/modprobe virtio_gpu", ""
98 self.wait_for_console_pattern("features: +virgl +edid")
100 def test_vhost_user_vga_virgl(self):
102 :avocado: tags=arch:x86_64
103 :avocado: tags=device:vhost-user-vga
105 kernel_command_line = (
106 self.KERNEL_COMMON_COMMAND_LINE + "console=ttyS0 rdinit=/bin/bash"
108 # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
109 if not kvm_available(self.arch, self.qemu_bin):
110 self.cancel(KVM_NOT_AVAILABLE)
112 vug = pick_default_vug_bin()
113 if not vug:
114 self.cancel("Could not find vhost-user-gpu")
116 kernel_path = self.fetch_asset(self.KERNEL_URL)
117 initrd_path = self.fetch_asset(self.INITRD_URL)
119 # Create socketpair to connect proxy and remote processes
120 qemu_sock, vug_sock = socket.socketpair(
121 socket.AF_UNIX, socket.SOCK_STREAM
123 os.set_inheritable(qemu_sock.fileno(), True)
124 os.set_inheritable(vug_sock.fileno(), True)
126 self._vug_log_path = os.path.join(
127 self.logdir, "vhost-user-gpu.log"
129 self._vug_log_file = open(self._vug_log_path, "wb")
130 self.log.info('Complete vhost-user-gpu.log file can be '
131 'found at %s', self._vug_log_path)
133 vugp = subprocess.Popen(
134 [vug, "--virgl", "--fd=%d" % vug_sock.fileno()],
135 stdin=subprocess.DEVNULL,
136 stdout=self._vug_log_file,
137 stderr=subprocess.STDOUT,
138 shell=False,
139 close_fds=False,
142 self.vm.set_console()
143 self.vm.add_args("-cpu", "host")
144 self.vm.add_args("-m", "2G")
145 self.vm.add_args("-object", "memory-backend-memfd,id=mem,size=2G")
146 self.vm.add_args("-machine", "pc,memory-backend=mem,accel=kvm")
147 self.vm.add_args("-chardev", "socket,id=vug,fd=%d" % qemu_sock.fileno())
148 self.vm.add_args("-device", "vhost-user-vga,chardev=vug")
149 self.vm.add_args("-display", "egl-headless")
150 self.vm.add_args(
151 "-kernel",
152 kernel_path,
153 "-initrd",
154 initrd_path,
155 "-append",
156 kernel_command_line,
158 self.vm.launch()
159 self.wait_for_console_pattern("as init process")
160 exec_command_and_wait_for_pattern(
161 self, "/usr/sbin/modprobe virtio_gpu", ""
163 self.wait_for_console_pattern("features: +virgl -edid")
164 self.vm.shutdown()
165 qemu_sock.close()
166 vugp.terminate()
167 vugp.wait()