@@ -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
@@ -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,
@@ -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:
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(+)