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 "qemu-common.h"
13 #include "qapi/qmp/qdict.h"
14 #include "qapi/qmp/qlist.h"
15 #include "qemu/cutils.h"
18 static const char *blacklist_x86
[] = {
19 "xenfv", "xenpv", NULL
26 { "i386", blacklist_x86
},
27 { "x86_64", blacklist_x86
},
30 static bool is_blacklisted(const char *arch
, const char *mach
)
35 for (i
= 0; i
< ARRAY_SIZE(blacklists
); i
++) {
36 if (!strcmp(blacklists
[i
].arch
, arch
)) {
37 for (p
= blacklists
[i
].machine
; *p
; p
++) {
38 if (!strcmp(*p
, mach
)) {
47 static void test_properties(QTestState
*qts
, const char *path
, bool recurse
)
50 QDict
*response
, *tuple
, *tmp
;
54 g_test_message("Obtaining properties of %s", path
);
55 response
= qtest_qmp(qts
, "{ 'execute': 'qom-list',"
56 " 'arguments': { 'path': %s } }", path
);
60 qobject_unref(response
);
64 g_assert(qdict_haskey(response
, "return"));
65 list
= qobject_to(QList
, qdict_get(response
, "return"));
66 QLIST_FOREACH_ENTRY(list
, entry
) {
67 tuple
= qobject_to(QDict
, qlist_entry_obj(entry
));
68 bool is_child
= strstart(qdict_get_str(tuple
, "type"), "child<", NULL
);
69 bool is_link
= strstart(qdict_get_str(tuple
, "type"), "link<", NULL
);
71 if (is_child
|| is_link
) {
72 child_path
= g_strdup_printf("%s/%s",
73 path
, qdict_get_str(tuple
, "name"));
74 test_properties(qts
, child_path
, is_child
);
77 const char *prop
= qdict_get_str(tuple
, "name");
78 g_test_message("Testing property %s.%s", path
, prop
);
80 "{ 'execute': 'qom-get',"
81 " 'arguments': { 'path': %s, 'property': %s } }",
83 /* qom-get may fail but should not, e.g., segfault. */
88 qobject_unref(response
);
91 static void test_machine(gconstpointer data
)
93 const char *machine
= data
;
97 qts
= qtest_initf("-machine %s", machine
);
99 test_properties(qts
, "/machine", true);
101 response
= qtest_qmp(qts
, "{ 'execute': 'quit' }");
102 g_assert(qdict_haskey(response
, "return"));
103 qobject_unref(response
);
106 g_free((void *)machine
);
109 static void add_machine_test_case(const char *mname
)
111 const char *arch
= qtest_get_arch();
113 if (!is_blacklisted(arch
, mname
)) {
114 char *path
= g_strdup_printf("qom/%s", mname
);
115 qtest_add_data_func(path
, g_strdup(mname
), test_machine
);
120 int main(int argc
, char **argv
)
122 g_test_init(&argc
, &argv
, NULL
);
124 qtest_cb_for_every_machine(add_machine_test_case
, g_test_quick());