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.
10 #include "qemu/osdep.h"
12 #include "qapi/qmp/qdict.h"
13 #include "qapi/qmp/qlist.h"
14 #include "qemu/cutils.h"
17 static void test_properties(QTestState
*qts
, const char *path
, bool recurse
)
20 QDict
*response
, *tuple
, *tmp
;
24 g_test_message("Obtaining properties of %s", path
);
25 response
= qtest_qmp(qts
, "{ 'execute': 'qom-list',"
26 " 'arguments': { 'path': %s } }", path
);
30 qobject_unref(response
);
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
);
47 const char *prop
= qdict_get_str(tuple
, "name");
48 g_test_message("Testing property %s.%s", path
, prop
);
50 "{ 'execute': 'qom-get',"
51 " 'arguments': { 'path': %s, 'property': %s } }",
53 /* qom-get may fail but should not, e.g., segfault. */
58 qobject_unref(response
);
61 static void test_machine(gconstpointer data
)
63 const char *machine
= data
;
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
);
76 g_free((void *)machine
);
79 static void add_machine_test_case(const char *mname
)
83 path
= g_strdup_printf("qom/%s", mname
);
84 qtest_add_data_func(path
, g_strdup(mname
), test_machine
);
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());