From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 07/16] tests/qtest: Add a function that gets a list with available machine types
Date: Wed, 15 Dec 2021 08:33:53 +0100 [thread overview]
Message-ID: <20211215073402.144286-8-thuth@redhat.com> (raw)
In-Reply-To: <20211215073402.144286-1-thuth@redhat.com>
For the upcoming patches, we will need a way to gets a list with all
available machine types. Refactor the qtest_cb_for_every_machine()
to split the related code out into a separate new function, and
gather the aliases of the various machine types, too.
Message-Id: <20211201104347.51922-4-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/libqtest.c | 64 ++++++++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 11 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 25aeea385b..7ae2dc4e1d 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1321,16 +1321,29 @@ static bool qtest_is_old_versioned_machine(const char *mname)
return res;
}
-void qtest_cb_for_every_machine(void (*cb)(const char *machine),
- bool skip_old_versioned)
+struct MachInfo {
+ char *name;
+ char *alias;
+};
+
+/*
+ * Returns an array with pointers to the available machine names.
+ * The terminating entry has the name set to NULL.
+ */
+static struct MachInfo *qtest_get_machines(void)
{
+ static struct MachInfo *machines;
QDict *response, *minfo;
QList *list;
const QListEntry *p;
QObject *qobj;
QString *qstr;
- const char *mname;
QTestState *qts;
+ int idx;
+
+ if (machines) {
+ return machines;
+ }
qts = qtest_init("-machine none");
response = qtest_qmp(qts, "{ 'execute': 'query-machines' }");
@@ -1338,25 +1351,54 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
list = qdict_get_qlist(response, "return");
g_assert(list);
- for (p = qlist_first(list); p; p = qlist_next(p)) {
+ machines = g_new(struct MachInfo, qlist_size(list) + 1);
+
+ for (p = qlist_first(list), idx = 0; p; p = qlist_next(p), idx++) {
minfo = qobject_to(QDict, qlist_entry_obj(p));
g_assert(minfo);
+
qobj = qdict_get(minfo, "name");
g_assert(qobj);
qstr = qobject_to(QString, qobj);
g_assert(qstr);
- mname = qstring_get_str(qstr);
- /* Ignore machines that cannot be used for qtests */
- if (!strncmp("xenfv", mname, 5) || g_str_equal("xenpv", mname)) {
- continue;
- }
- if (!skip_old_versioned || !qtest_is_old_versioned_machine(mname)) {
- cb(mname);
+ machines[idx].name = g_strdup(qstring_get_str(qstr));
+
+ qobj = qdict_get(minfo, "alias");
+ if (qobj) { /* The alias is optional */
+ qstr = qobject_to(QString, qobj);
+ g_assert(qstr);
+ machines[idx].alias = g_strdup(qstring_get_str(qstr));
+ } else {
+ machines[idx].alias = NULL;
}
}
qtest_quit(qts);
qobject_unref(response);
+
+ memset(&machines[idx], 0, sizeof(struct MachInfo)); /* Terminating entry */
+ return machines;
+}
+
+void qtest_cb_for_every_machine(void (*cb)(const char *machine),
+ bool skip_old_versioned)
+{
+ struct MachInfo *machines;
+ int i;
+
+ machines = qtest_get_machines();
+
+ for (i = 0; machines[i].name != NULL; i++) {
+ /* Ignore machines that cannot be used for qtests */
+ if (!strncmp("xenfv", machines[i].name, 5) ||
+ g_str_equal("xenpv", machines[i].name)) {
+ continue;
+ }
+ if (!skip_old_versioned ||
+ !qtest_is_old_versioned_machine(machines[i].name)) {
+ cb(machines[i].name);
+ }
+ }
}
/*
--
2.27.0
next prev parent reply other threads:[~2021-12-15 7:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 7:33 [PULL 00/16] qtest and gitlab-CI improvements Thomas Huth
2021-12-15 7:33 ` [PULL 01/16] qtest/libqos: add a function to initialize secondary PCI buses Thomas Huth
2021-12-15 7:33 ` [PULL 02/16] tests/qtest: add some tests for virtio-net failover Thomas Huth
2021-12-15 7:33 ` [PULL 03/16] tests/libqtest: add some virtio-net failover migration cancelling tests Thomas Huth
2021-12-15 7:33 ` [PULL 04/16] tests/libqtest: add a migration test with two couples of failover devices Thomas Huth
2021-12-15 7:33 ` [PULL 05/16] tests/qtest: Run the PPC 32-bit tests with the 64-bit target binary, too Thomas Huth
2021-12-15 7:33 ` [PULL 06/16] tests/qtest: Fence the tests that need xlnx-zcu102 with CONFIG_XLNX_ZYNQMP_ARM Thomas Huth
2021-12-15 7:33 ` Thomas Huth [this message]
2021-12-15 7:33 ` [PULL 08/16] tests/qtest: Add a function to check whether a machine is available Thomas Huth
2021-12-15 7:33 ` [PULL 09/16] Move the libssh setup from configure to meson.build Thomas Huth
2021-12-15 7:33 ` [PULL 10/16] gitlab-ci.d/buildtest: Add jobs that run the device-crash-test Thomas Huth
2021-12-15 7:33 ` [PULL 11/16] gitlab-ci: Add cirrus-ci based tests for NetBSD and OpenBSD Thomas Huth
2021-12-15 7:33 ` [PULL 12/16] virtio-iommu: Remove set_config callback Thomas Huth
2021-12-15 7:33 ` [PULL 13/16] virtio-iommu: Fix endianness in get_config Thomas Huth
2021-12-15 7:34 ` [PULL 14/16] virtio-iommu: Fix the domain_range end Thomas Huth
2021-12-15 7:34 ` [PULL 15/16] tests: qtest: Add virtio-iommu test Thomas Huth
2021-12-15 7:34 ` [PULL 16/16] gitlab-ci: Test compilation on Windows with MSYS2 Thomas Huth
2021-12-15 17:14 ` [PULL 00/16] qtest and gitlab-CI improvements Richard Henderson
2021-12-15 20:33 ` Thomas Huth
2021-12-18 16:33 ` Philippe Mathieu-Daudé
2021-12-20 6:52 ` Thomas Huth
2021-12-20 9:24 ` Philippe Mathieu-Daudé
2021-12-20 9:53 ` Thomas Huth
2021-12-20 13:11 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211215073402.144286-8-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).