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>
This commit is contained in:
parent
bf22f15114
commit
5516a3b592
|
@ -1321,16 +1321,29 @@ static bool qtest_is_old_versioned_machine(const char *mname)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qtest_cb_for_every_machine(void (*cb)(const char *machine),
|
struct MachInfo {
|
||||||
bool skip_old_versioned)
|
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;
|
QDict *response, *minfo;
|
||||||
QList *list;
|
QList *list;
|
||||||
const QListEntry *p;
|
const QListEntry *p;
|
||||||
QObject *qobj;
|
QObject *qobj;
|
||||||
QString *qstr;
|
QString *qstr;
|
||||||
const char *mname;
|
|
||||||
QTestState *qts;
|
QTestState *qts;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
if (machines) {
|
||||||
|
return machines;
|
||||||
|
}
|
||||||
|
|
||||||
qts = qtest_init("-machine none");
|
qts = qtest_init("-machine none");
|
||||||
response = qtest_qmp(qts, "{ 'execute': 'query-machines' }");
|
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");
|
list = qdict_get_qlist(response, "return");
|
||||||
g_assert(list);
|
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));
|
minfo = qobject_to(QDict, qlist_entry_obj(p));
|
||||||
g_assert(minfo);
|
g_assert(minfo);
|
||||||
|
|
||||||
qobj = qdict_get(minfo, "name");
|
qobj = qdict_get(minfo, "name");
|
||||||
g_assert(qobj);
|
g_assert(qobj);
|
||||||
qstr = qobject_to(QString, qobj);
|
qstr = qobject_to(QString, qobj);
|
||||||
g_assert(qstr);
|
g_assert(qstr);
|
||||||
mname = qstring_get_str(qstr);
|
machines[idx].name = g_strdup(qstring_get_str(qstr));
|
||||||
/* Ignore machines that cannot be used for qtests */
|
|
||||||
if (!strncmp("xenfv", mname, 5) || g_str_equal("xenpv", mname)) {
|
qobj = qdict_get(minfo, "alias");
|
||||||
continue;
|
if (qobj) { /* The alias is optional */
|
||||||
}
|
qstr = qobject_to(QString, qobj);
|
||||||
if (!skip_old_versioned || !qtest_is_old_versioned_machine(mname)) {
|
g_assert(qstr);
|
||||||
cb(mname);
|
machines[idx].alias = g_strdup(qstring_get_str(qstr));
|
||||||
|
} else {
|
||||||
|
machines[idx].alias = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qtest_quit(qts);
|
qtest_quit(qts);
|
||||||
qobject_unref(response);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue