build: remove extra parentheses causing missing rebuilds
[qemu.git] / tests / qtest / qom-test.c
blob7b871b2a3107ce88632f0d23246228115086daff
1 /*
2 * QTest testcase for QOM
4 * Copyright (c) 2013 SUSE LINUX Products GmbH
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
12 #include "qapi/qmp/qdict.h"
13 #include "qapi/qmp/qlist.h"
14 #include "qemu/cutils.h"
15 #include "libqtest.h"
17 static void test_properties(QTestState *qts, const char *path, bool recurse)
19 char *child_path;
20 QDict *response, *tuple, *tmp;
21 QList *list;
22 QListEntry *entry;
24 g_test_message("Obtaining properties of %s", path);
25 response = qtest_qmp(qts, "{ 'execute': 'qom-list',"
26 " 'arguments': { 'path': %s } }", path);
27 g_assert(response);
29 if (!recurse) {
30 qobject_unref(response);
31 return;
34 g_assert(qdict_haskey(response, "return"));
35 list = qobject_to(QList, qdict_get(response, "return"));
36 QLIST_FOREACH_ENTRY(list, entry) {
37 tuple = qobject_to(QDict, qlist_entry_obj(entry));
38 bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL);
39 bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL);
41 if (is_child || is_link) {
42 child_path = g_strdup_printf("%s/%s",
43 path, qdict_get_str(tuple, "name"));
44 test_properties(qts, child_path, is_child);
45 g_free(child_path);
46 } else {
47 const char *prop = qdict_get_str(tuple, "name");
48 g_test_message("Testing property %s.%s", path, prop);
49 tmp = qtest_qmp(qts,
50 "{ 'execute': 'qom-get',"
51 " 'arguments': { 'path': %s, 'property': %s } }",
52 path, prop);
53 /* qom-get may fail but should not, e.g., segfault. */
54 g_assert(tmp);
55 qobject_unref(tmp);
58 qobject_unref(response);
61 static void test_machine(gconstpointer data)
63 const char *machine = data;
64 QDict *response;
65 QTestState *qts;
67 qts = qtest_initf("-machine %s", machine);
69 test_properties(qts, "/machine", true);
71 response = qtest_qmp(qts, "{ 'execute': 'quit' }");
72 g_assert(qdict_haskey(response, "return"));
73 qobject_unref(response);
75 qtest_quit(qts);
76 g_free((void *)machine);
79 static void add_machine_test_case(const char *mname)
81 char *path;
83 path = g_strdup_printf("qom/%s", mname);
84 qtest_add_data_func(path, g_strdup(mname), test_machine);
85 g_free(path);
88 int main(int argc, char **argv)
90 g_test_init(&argc, &argv, NULL);
92 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
94 return g_test_run();