mirror of
https://github.com/qemu/qemu.git
synced 2024-12-03 00:33:39 +08:00
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user