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 BUILD_DIR
8 from avocado_qemu
import QemuSystemTest
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
.utils
import kvm_available
20 def pick_default_vug_bin():
21 relative_path
= "./contrib/vhost-user-gpu/vhost-user-gpu"
22 if is_readable_executable_file(relative_path
):
25 bld_dir_path
= os
.path
.join(BUILD_DIR
, relative_path
)
26 if is_readable_executable_file(bld_dir_path
):
30 class VirtioGPUx86(QemuSystemTest
):
32 :avocado: tags=virtio-gpu
33 :avocado: tags=arch:x86_64
34 :avocado: tags=cpu:host
37 KERNEL_COMMAND_LINE
= "printk.time=0 console=ttyS0 rdinit=/bin/bash"
39 "https://archives.fedoraproject.org/pub/archive/fedora"
40 "/linux/releases/33/Everything/x86_64/os/images"
43 KERNEL_HASH
= '1433cfe3f2ffaa44de4ecfb57ec25dc2399cdecf'
45 "https://archives.fedoraproject.org/pub/archive/fedora"
46 "/linux/releases/33/Everything/x86_64/os/images"
49 INITRD_HASH
= 'c828d68a027b53e5220536585efe03412332c2d9'
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=device:virtio-vga-gl
63 # FIXME: should check presence of virtio, virgl etc
64 self
.require_accelerator('kvm')
66 kernel_path
= self
.fetch_asset(self
.KERNEL_URL
, self
.KERNEL_HASH
)
67 initrd_path
= self
.fetch_asset(self
.INITRD_URL
, self
.INITRD_HASH
)
70 self
.vm
.add_args("-m", "2G")
71 self
.vm
.add_args("-machine", "pc,accel=kvm")
72 self
.vm
.add_args("-device", "virtio-vga-gl")
73 self
.vm
.add_args("-display", "egl-headless")
80 self
.KERNEL_COMMAND_LINE
,
85 # TODO: probably fails because we are missing the VirGL features
86 self
.cancel("VirGL not enabled?")
88 self
.wait_for_console_pattern("as init process")
89 exec_command_and_wait_for_pattern(
90 self
, "/usr/sbin/modprobe virtio_gpu", ""
92 self
.wait_for_console_pattern("features: +virgl +edid")
94 def test_vhost_user_vga_virgl(self
):
96 :avocado: tags=device:vhost-user-vga
98 # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
99 self
.require_accelerator('kvm')
101 vug
= pick_default_vug_bin()
103 self
.cancel("Could not find vhost-user-gpu")
105 kernel_path
= self
.fetch_asset(self
.KERNEL_URL
, self
.KERNEL_HASH
)
106 initrd_path
= self
.fetch_asset(self
.INITRD_URL
, self
.INITRD_HASH
)
108 # Create socketpair to connect proxy and remote processes
109 qemu_sock
, vug_sock
= socket
.socketpair(
110 socket
.AF_UNIX
, socket
.SOCK_STREAM
112 os
.set_inheritable(qemu_sock
.fileno(), True)
113 os
.set_inheritable(vug_sock
.fileno(), True)
115 self
._vug
_log
_path
= os
.path
.join(
116 self
.logdir
, "vhost-user-gpu.log"
118 self
._vug
_log
_file
= open(self
._vug
_log
_path
, "wb")
119 self
.log
.info('Complete vhost-user-gpu.log file can be '
120 'found at %s', self
._vug
_log
_path
)
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
,
131 self
.vm
.set_console()
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")
144 self
.KERNEL_COMMAND_LINE
,
149 # TODO: probably fails because we are missing the VirGL features
150 self
.cancel("VirGL not enabled?")
151 self
.wait_for_console_pattern("as init process")
152 exec_command_and_wait_for_pattern(self
, "/usr/sbin/modprobe virtio_gpu",
153 "features: +virgl +edid")