Skip to contentSkip to conversation

tests/functional: Generic method to check required devices availability

RFC PATCH In review Philippe Mathieu-Daudé 2 participants 2 messages Feb 19, 2025 – Apr 14, 2025

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 tests/functional: Generic method to check required devices availability

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

---
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(+)
python/qemu/machine/machine.py +10 -0
index ebb58d5b68c..ff1ff066823 100644
@@ -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
tests/functional/qemu_test/testcase.py +8 -0
index 869f3949fe9..7e3288f452c 100644
@@ -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,
tests/functional/test_aarch64_virt.py +2 -0
index 95f5ce8b4c0..589680a44c5 100755
@@ -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:
Signature · 1 line
2.47.1
#1 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé

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.

Quoted 8 lines

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

---
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...

I'm also a little bit torn by this question ... let's keep it explicit for now, but if the require_device() calls get too annoying one day, we can reconsider.

Thomas