From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Laurent Vivier <lvivier@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [PATCH for-7.0 3/4] tests/qtest: Add a function that gets a list with available machine types
Date: Wed, 1 Dec 2021 11:43:46 +0100 [thread overview]
Message-ID: <20211201104347.51922-4-thuth@redhat.com> (raw)
In-Reply-To: <20211201104347.51922-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.
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-01 10:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-01 10:43 [PATCH for-7.0 0/4] qtest patches for binaries with reduced machines Thomas Huth
2021-12-01 10:43 ` [PATCH for-7.0 1/4] tests/qtest: Run the PPC 32-bit tests with the 64-bit target binary, too Thomas Huth
2021-12-01 10:43 ` [PATCH for-7.0 2/4] tests/qtest: Fence the tests that need xlnx-zcu102 with CONFIG_XLNX_ZYNQMP_ARM Thomas Huth
2021-12-01 10:43 ` Thomas Huth [this message]
2021-12-01 10:43 ` [PATCH for-7.0 4/4] tests/qtest: Add a function to check whether a machine is available Thomas Huth
2021-12-06 20:02 ` John Snow
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=20211201104347.51922-4-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=jsnow@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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).