diff options
author | Thomas Huth <thuth@redhat.com> | 2017-03-30 09:50:06 +0200 |
---|---|---|
committer | Dr. David Alan Gilbert <dgilbert@redhat.com> | 2017-04-26 14:42:31 +0100 |
commit | 02ef6e878f4c013889767ef239901962600de545 (patch) | |
tree | 729c2017da62bbca1100cb763871ef4885a2beb6 /tests/libqtest.c | |
parent | 6bb87be8938691fa5cf989b7517d7d2084b8c141 (diff) | |
download | qemu-02ef6e878f4c013889767ef239901962600de545.zip qemu-02ef6e878f4c013889767ef239901962600de545.tar.gz qemu-02ef6e878f4c013889767ef239901962600de545.tar.bz2 |
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.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/libqtest.c b/tests/libqtest.c index 0b0bf1d..512c150 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); +} |