aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/libqtest.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2021-12-01 11:43:46 +0100
committerThomas Huth <thuth@redhat.com>2021-12-15 08:08:59 +0100
commit5516a3b592def4de7fa78153912470f160814e5a (patch)
treed0b6b12944c18bca5bf7d6159c53f0f79b83464a /tests/qtest/libqtest.c
parentbf22f15114b2a1d5eefbcbc18f939d5006d77f72 (diff)
tests/qtest: Add a function that gets a list with available machine types
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>
Diffstat (limited to 'tests/qtest/libqtest.c')
-rw-r--r--tests/qtest/libqtest.c64
1 files 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);
+ }
+ }
}
/*