diff mbox series

[RFC] tests/functional: Generic method to check required devices availability

Message ID 20250219142412.77536-1-philmd@linaro.org (mailing list archive)
State New
Headers show
Series [RFC] tests/functional: Generic method to check required devices availability | expand

Commit Message

Philippe Mathieu-Daudé Feb. 19, 2025, 2:24 p.m. UTC
Not all binaries contain the same set of devices. Since some
tests depend on specific devices, we need to check their
availability in the binary.

QemuSystemTest::require_device() allows for system tests to
explicitly check for a particular device. Add a similar
check_required_devices() method which check all devices
requested on the command line. If a device is missing, the
test is skipped.

Example running test_aarch64_virt.py on macOS:

  ok 1 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_with_gpu # SKIP no support for device virtio-gpu-gl-pci

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Just an idea to see if we can avoid manual require_device() calls.
However not having a device in binary might also be a bug, so RFC...
---
 python/qemu/machine/machine.py         | 10 ++++++++++
 tests/functional/qemu_test/testcase.py |  8 ++++++++
 tests/functional/test_aarch64_virt.py  |  2 ++
 3 files changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index ebb58d5b68c..ff1ff066823 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -468,6 +468,16 @@  def launch(self) -> None:
             # that exception. However, we still want to clean up.
             raise
 
+    def get_command_arguments(self, command) -> List[str]:
+        """
+        Return a list of arguments used with one kind of command
+        """
+        args = []
+        for index, element in enumerate(self._args):
+            if element == command:
+                args += [self._args[index + 1]]
+        return args
+
     def _launch(self) -> None:
         """
         Launch the VM and establish a QMP connection
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 869f3949fe9..7e3288f452c 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -335,6 +335,14 @@  def require_device(self, devicename):
         if help.find(devicename) < 0:
             self.skipTest('no support for device ' + devicename)
 
+    def check_required_devices(self):
+        """
+        Check the devices requested on the command line are available
+        in the binary. To be used before the VM launch() call.
+        """
+        for device in self.vm.get_command_arguments('-device'):
+            self.require_device(device.split(',')[0])
+
     def _new_vm(self, name, *args):
         vm = QEMUMachine(self.qemu_bin,
                          name=name,
diff --git a/tests/functional/test_aarch64_virt.py b/tests/functional/test_aarch64_virt.py
index 95f5ce8b4c0..589680a44c5 100755
--- a/tests/functional/test_aarch64_virt.py
+++ b/tests/functional/test_aarch64_virt.py
@@ -180,6 +180,8 @@  def test_aarch64_virt_with_gpu(self):
                          f"file.filename={image_path}")
         self.vm.add_args("-snapshot")
 
+        self.check_required_devices()
+
         try:
             self.vm.launch()
         except VMLaunchFailure as excp: