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
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
):
29 bld_dir_path
= os
.path
.join(BUILD_DIR
, relative_path
)
30 if is_readable_executable_file(bld_dir_path
):
34 class VirtioGPUx86(Test
):
36 :avocado: tags=virtio-gpu
39 KERNEL_COMMON_COMMAND_LINE
= "printk.time=0 "
41 "https://archives.fedoraproject.org/pub/fedora"
42 "/linux/releases/33/Everything/x86_64/os/images"
46 "https://archives.fedoraproject.org/pub/fedora"
47 "/linux/releases/33/Everything/x86_64/os/images"
51 def wait_for_console_pattern(self
, success_message
, vm
=None):
52 wait_for_console_pattern(
55 failure_message
="Kernel panic - not syncing",
59 def test_virtio_vga_virgl(self
):
61 :avocado: tags=arch:x86_64
62 :avocado: tags=device:virtio-vga
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
)
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")
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()
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
,
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")
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")