From 02ef6e878f4c013889767ef239901962600de545 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Thu, 30 Mar 2017 09:50:06 +0200 Subject: libqtest: Add a generic function to run a callback function for every machine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Message-Id: <1490860207-8302-3-git-send-email-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Dr. David Alan Gilbert --- tests/qom-test.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'tests/qom-test.c') 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(); } -- cgit v1.2.3