tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-)
Replace parsing of "qemu -M help" in set_machine() with
QMP "query-machines".
The previous approach relied on parsing human-readable CLI
output and substring matching, which is fragile and prone to
incorrect matches. It is also sensitive to output format changes.
Use QMP instead to retrieve structured machine information,
ensuring accurate matching and better maintainability.
Cache the result at the class level to avoid repeated QEMU
startup overhead.
Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com>
---
tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++-----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index eaec1bea13..5920d6a784 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -314,14 +314,34 @@ def setUp(self):
console_log.addHandler(self._console_log_fh)
def set_machine(self, machinename):
- # TODO: We should use QMP to get the list of available machines
- if not self._machinehelp:
- self._machinehelp = run(
- [self.qemu_bin, '-M', 'help'],
- capture_output=True, check=True, encoding='utf8').stdout
- if self._machinehelp.find(machinename) < 0:
+ cls = type(self)
+
+ if not hasattr(cls, "_machines"):
+ tmp_vm = QEMUMachine(self.qemu_bin)
+ tmp_vm.set_machine('none')
+
+ try:
+ tmp_vm.launch()
+ resp = tmp_vm.qmp('query-machines')
+
+ machines = resp.get('return', [])
+ cls._machines = [
+ m.get('name') for m in machines if 'name' in m
+ ]
+
+ finally:
+ try:
+ tmp_vm.shutdown()
+ except Exception:
+ pass
+
+ self._machines = cls._machines
+
+ if machinename not in self._machines:
self.skipTest('no support for machine ' + machinename)
+
self.machine = machinename
+ self.vm.set_machine(machinename)
def require_accelerator(self, accelerator):
"""
--
2.47.3
Am Thu, 25 Jun 2026 12:53:10 -0400
schrieb Ganesh Harshan <ganeshredcobra@gmail.com>:
> Replace parsing of "qemu -M help" in set_machine() with
> QMP "query-machines".
>
> The previous approach relied on parsing human-readable CLI
> output and substring matching, which is fragile and prone to
> incorrect matches. It is also sensitive to output format changes.
>
> Use QMP instead to retrieve structured machine information,
> ensuring accurate matching and better maintainability.
>
> Cache the result at the class level to avoid repeated QEMU
> startup overhead.
>
> Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com>
> ---
> tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++-----
> 1 file changed, 26 insertions(+), 6 deletions(-)
Hi Ganesh,
seems like a bunch of tests are failing when I include this patch in my
source tree:
283/327 qemu:func-thorough+func-riscv64-thorough+thorough / func-riscv64-tuxrun TIMEOUT 120.01s killed by signal 15 SIGTERM
286/327 qemu:func-thorough+func-mipsel-thorough+thorough / func-mipsel-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
289/327 qemu:func-thorough+func-mips-thorough+thorough / func-mips-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
294/327 qemu:func-thorough+func-ppc64-thorough+thorough / func-ppc64-e500 TIMEOUT 90.01s killed by signal 15 SIGTERM
326/327 qemu:func-thorough+func-ppc-thorough+thorough / func-ppc-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
327/327 qemu:func-thorough+func-xtensa-thorough+thorough / func-xtensa-lx60 TIMEOUT 90.01s killed by signal 15 SIGTERM
Are these working for you? Could you please have a look?
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index eaec1bea13..5920d6a784 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -314,14 +314,34 @@ def setUp(self):
...
> + if machinename not in self._machines:
> self.skipTest('no support for machine ' + machinename)
> +
> self.machine = machinename
> + self.vm.set_machine(machinename)
The last line was not there before, why is it required now?
Thomas
> def require_accelerator(self, accelerator):
> """
Am Fri, 3 Jul 2026 21:21:11 +0200
schrieb Thomas Huth <th.huth+qemu@posteo.eu>:
> Am Thu, 25 Jun 2026 12:53:10 -0400
> schrieb Ganesh Harshan <ganeshredcobra@gmail.com>:
>
> > Replace parsing of "qemu -M help" in set_machine() with
> > QMP "query-machines".
> >
> > The previous approach relied on parsing human-readable CLI
> > output and substring matching, which is fragile and prone to
> > incorrect matches. It is also sensitive to output format changes.
> >
> > Use QMP instead to retrieve structured machine information,
> > ensuring accurate matching and better maintainability.
> >
> > Cache the result at the class level to avoid repeated QEMU
> > startup overhead.
> >
> > Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com>
> > ---
> > tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++-----
> > 1 file changed, 26 insertions(+), 6 deletions(-)
>
> Hi Ganesh,
>
> seems like a bunch of tests are failing when I include this patch in my
> source tree:
>
> 283/327 qemu:func-thorough+func-riscv64-thorough+thorough / func-riscv64-tuxrun TIMEOUT 120.01s killed by signal 15 SIGTERM
> 286/327 qemu:func-thorough+func-mipsel-thorough+thorough / func-mipsel-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
> 289/327 qemu:func-thorough+func-mips-thorough+thorough / func-mips-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
> 294/327 qemu:func-thorough+func-ppc64-thorough+thorough / func-ppc64-e500 TIMEOUT 90.01s killed by signal 15 SIGTERM
> 326/327 qemu:func-thorough+func-ppc-thorough+thorough / func-ppc-tuxrun TIMEOUT 90.01s killed by signal 15 SIGTERM
> 327/327 qemu:func-thorough+func-xtensa-thorough+thorough / func-xtensa-lx60 TIMEOUT 90.01s killed by signal 15 SIGTERM
>
> Are these working for you? Could you please have a look?
>
> > diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> > index eaec1bea13..5920d6a784 100644
> > --- a/tests/functional/qemu_test/testcase.py
> > +++ b/tests/functional/qemu_test/testcase.py
> > @@ -314,14 +314,34 @@ def setUp(self):
> ...
> > + if machinename not in self._machines:
> > self.skipTest('no support for machine ' + machinename)
> > +
> > self.machine = machinename
> > + self.vm.set_machine(machinename)
>
> The last line was not there before, why is it required now?
I noticed that the tests work fine again when I drop that line. So I'll go
ahead and pick up this patch without this line.
Thomas
On Thu, Jun 25, 2026 at 12:53:10PM -0400, Ganesh Harshan wrote: > Replace parsing of "qemu -M help" in set_machine() with > QMP "query-machines". > > The previous approach relied on parsing human-readable CLI > output and substring matching, which is fragile and prone to > incorrect matches. It is also sensitive to output format changes. > > Use QMP instead to retrieve structured machine information, > ensuring accurate matching and better maintainability. > > Cache the result at the class level to avoid repeated QEMU > startup overhead. > > Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com> > --- > tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++----- > 1 file changed, 26 insertions(+), 6 deletions(-) Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
© 2016 - 2026 Red Hat, Inc.