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/qom-test.c | |
parent | 6bb87be8938691fa5cf989b7517d7d2084b8c141 (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/qom-test.c')
-rw-r--r-- | tests/qom-test.c | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/tests/qom-test.c b/tests/qom-test.c index d48f890e84..ab0595dc75 100644 --- a/tests/qom-test.c +++ b/tests/qom-test.c @@ -107,46 +107,22 @@ static void test_machine(gconstpointer data) g_free((void *)machine); } -static void add_machine_test_cases(void) +static void add_machine_test_case(const char *mname) { const char *arch = qtest_get_arch(); - 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); - if (!is_blacklisted(arch, mname)) { - char *path = g_strdup_printf("qom/%s", mname); - qtest_add_data_func(path, g_strdup(mname), test_machine); - g_free(path); - } + if (!is_blacklisted(arch, mname)) { + char *path = g_strdup_printf("qom/%s", mname); + qtest_add_data_func(path, g_strdup(mname), test_machine); + g_free(path); } - - qtest_end(); - QDECREF(response); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); - add_machine_test_cases(); + qtest_cb_for_every_machine(add_machine_test_case); return g_test_run(); } |