Skip to content

Commit

Permalink
qemudriver: Handle Virtio GL change in 6.1.0
Browse files Browse the repository at this point in the history
Starting with version 6.1.0, the QEMU command line argument to enable
virtio with VirGL support was changed from "-vga virtio" to "-device
virtio-vgal-gl". To correctly handle this, scrape the QEMU version
number from the command output and use it to pass the correct arguments.

Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
[bst: cherry-picked from commit df4f6a9]
Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
JoshuaWatt authored and Bastian-Krause committed Jul 3, 2023
1 parent b1f68a7 commit 6ae99e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
22 changes: 20 additions & 2 deletions labgrid/driver/qemudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import socket
import subprocess
import re
import tempfile
import time

Expand Down Expand Up @@ -108,6 +109,17 @@ def _atexit(self):
self._child.kill()
self._child.communicate(timeout=1)

def get_qemu_version(self, qemu_bin):
p = subprocess.run([qemu_bin, "-version"], stdout=subprocess.PIPE, encoding="utf-8")
if p.returncode != 0:
raise ExecutionError(f"Unable to get QEMU version. QEMU exited with: {p.returncode}")

m = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)', p.stdout.splitlines()[0])
if m is None:
raise ExecutionError(f"Unable to find QEMU version in: {p.stdout.splitlines()[0]}")

return (int(m.group('major')), int(m.group('minor')), int(m.group('micro')))

def on_activate(self):
self._tempdir = tempfile.mkdtemp(prefix="labgrid-qemu-tmp-")
sockpath = f"{self._tempdir}/serialrw"
Expand All @@ -121,6 +133,8 @@ def on_activate(self):
"QEMU Binary Path not configured in tools configuration key")
self._cmd = [qemu_bin]

self._qemu_version = self.get_qemu_version(qemu_bin)

boot_args = []

if self.kernel is not None:
Expand Down Expand Up @@ -190,8 +204,12 @@ def on_activate(self):
self._cmd.append("-display")
self._cmd.append("none")
elif self.display == "egl-headless":
self._cmd.append("-vga")
self._cmd.append("virtio")
if self._qemu_version >= (6, 1, 0):
self._cmd.append("-device")
self._cmd.append("virtio-vga-gl")
else:
self._cmd.append("-vga")
self._cmd.append("virtio")
self._cmd.append("-display")
self._cmd.append("egl-headless")
else:
Expand Down
12 changes: 9 additions & 3 deletions tests/test_qemudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,28 @@ def qemu_mock(mocker):
socket_mock = mocker.patch('socket.socket')
socket_mock.return_value.accept.return_value = mocker.MagicMock(), ''

@pytest.fixture
def qemu_version_mock(mocker):
run_mock = mocker.patch('subprocess.run')
run_mock.return_value.returncode = 0
run_mock.return_value.stdout = "QEMU emulator version 4.2.1"

def test_qemu_instance(qemu_target, qemu_driver):
assert (isinstance(qemu_driver, QEMUDriver))

def test_qemu_activate_deactivate(qemu_target, qemu_driver):
def test_qemu_activate_deactivate(qemu_target, qemu_driver, qemu_version_mock):
qemu_target.activate(qemu_driver)
qemu_target.deactivate(qemu_driver)

def test_qemu_on_off(qemu_target, qemu_driver, qemu_mock):
def test_qemu_on_off(qemu_target, qemu_driver, qemu_mock, qemu_version_mock):
qemu_target.activate(qemu_driver)

qemu_driver.on()
qemu_driver.off()

qemu_target.deactivate(qemu_driver)

def test_qemu_read_write(qemu_target, qemu_driver, qemu_mock):
def test_qemu_read_write(qemu_target, qemu_driver, qemu_mock, qemu_version_mock):
qemu_target.activate(qemu_driver)

qemu_driver.on()
Expand Down

0 comments on commit 6ae99e9

Please sign in to comment.