* [PATCH] tests/functional: use QMP to query available machines
@ 2026-06-25 16:53 Ganesh Harshan
2026-06-26 10:12 ` Daniel P. Berrangé
2026-07-03 19:21 ` Thomas Huth
0 siblings, 2 replies; 4+ messages in thread
From: Ganesh Harshan @ 2026-06-25 16:53 UTC (permalink / raw)
To: th.huth+qemu; +Cc: philmd, berrange, qemu-devel, Ganesh Harshan
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/functional: use QMP to query available machines
2026-06-25 16:53 [PATCH] tests/functional: use QMP to query available machines Ganesh Harshan
@ 2026-06-26 10:12 ` Daniel P. Berrangé
2026-07-03 19:21 ` Thomas Huth
1 sibling, 0 replies; 4+ messages in thread
From: Daniel P. Berrangé @ 2026-06-26 10:12 UTC (permalink / raw)
To: Ganesh Harshan; +Cc: th.huth+qemu, philmd, qemu-devel
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 :|
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/functional: use QMP to query available machines
2026-06-25 16:53 [PATCH] tests/functional: use QMP to query available machines Ganesh Harshan
2026-06-26 10:12 ` Daniel P. Berrangé
@ 2026-07-03 19:21 ` Thomas Huth
2026-07-07 6:13 ` Thomas Huth
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2026-07-03 19:21 UTC (permalink / raw)
To: Ganesh Harshan; +Cc: philmd, berrange, qemu-devel
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):
> """
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/functional: use QMP to query available machines
2026-07-03 19:21 ` Thomas Huth
@ 2026-07-07 6:13 ` Thomas Huth
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2026-07-07 6:13 UTC (permalink / raw)
To: Ganesh Harshan; +Cc: philmd, berrange, qemu-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-07 6:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 16:53 [PATCH] tests/functional: use QMP to query available machines Ganesh Harshan
2026-06-26 10:12 ` Daniel P. Berrangé
2026-07-03 19:21 ` Thomas Huth
2026-07-07 6:13 ` Thomas Huth
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.