aboutsummaryrefslogtreecommitdiff
path: root/tests/libqtest.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2017-03-30 09:50:06 +0200
committerDr. David Alan Gilbert <dgilbert@redhat.com>2017-04-26 14:42:31 +0100
commit02ef6e878f4c013889767ef239901962600de545 (patch)
tree729c2017da62bbca1100cb763871ef4885a2beb6 /tests/libqtest.c
parent6bb87be8938691fa5cf989b7517d7d2084b8c141 (diff)
libqtest: Add a generic function to run a callback function for every machine
Some tests need to run single tests for every available machine of the current QEMU binary. To avoid code duplication, let's extract this code that deals with 'query-machines' into a separate function. Signed-off-by: Thomas Huth <thuth@redhat.com> Message-Id: <1490860207-8302-3-git-send-email-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'tests/libqtest.c')
-rw-r--r--tests/libqtest.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 0b0bf1d460..512c150266 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -946,3 +946,33 @@ bool qtest_big_endian(QTestState *s)
{
return s->big_endian;
}
+
+void qtest_cb_for_every_machine(void (*cb)(const char *machine))
+{
+ QDict *response, *minfo;
+ QList *list;
+ const QListEntry *p;
+ QObject *qobj;
+ QString *qstr;
+ const char *mname;
+
+ qtest_start("-machine none");
+ response = qmp("{ 'execute': 'query-machines' }");
+ g_assert(response);
+ list = qdict_get_qlist(response, "return");
+ g_assert(list);
+
+ for (p = qlist_first(list); p; p = qlist_next(p)) {
+ 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);
+ cb(mname);
+ }
+
+ qtest_end();
+ QDECREF(response);
+}