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.
13 #include "qemu-common.h"
15 #include "qemu/osdep.h"
16 #include "qapi/qmp/types.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(const char *path
, bool recurse
)
50 QDict
*response
, *tuple
;
54 g_test_message("Obtaining properties of %s", path
);
55 response
= qmp("{ 'execute': 'qom-list',"
56 " 'arguments': { 'path': %s } }", path
);
63 g_assert(qdict_haskey(response
, "return"));
64 list
= qobject_to_qlist(qdict_get(response
, "return"));
65 QLIST_FOREACH_ENTRY(list
, entry
) {
66 tuple
= qobject_to_qdict(qlist_entry_obj(entry
));
67 bool is_child
= strstart(qdict_get_str(tuple
, "type"), "child<", NULL
);
68 bool is_link
= strstart(qdict_get_str(tuple
, "type"), "link<", NULL
);
70 if (is_child
|| is_link
) {
71 child_path
= g_strdup_printf("%s/%s",
72 path
, qdict_get_str(tuple
, "name"));
73 test_properties(child_path
, is_child
);
76 const char *prop
= qdict_get_str(tuple
, "name");
77 g_test_message("Testing property %s.%s", path
, prop
);
78 response
= qmp("{ 'execute': 'qom-get',"
79 " 'arguments': { 'path': %s,"
80 " 'property': %s } }",
82 /* qom-get may fail but should not, e.g., segfault. */
88 static void test_machine(gconstpointer data
)
90 const char *machine
= data
;
94 args
= g_strdup_printf("-machine %s", machine
);
97 test_properties("/machine", true);
99 response
= qmp("{ 'execute': 'quit' }");
100 g_assert(qdict_haskey(response
, "return"));
106 static void add_machine_test_cases(void)
108 const char *arch
= qtest_get_arch();
109 QDict
*response
, *minfo
;
114 const char *mname
, *path
;
116 qtest_start("-machine none");
117 response
= qmp("{ 'execute': 'query-machines' }");
119 list
= qdict_get_qlist(response
, "return");
122 for (p
= qlist_first(list
); p
; p
= qlist_next(p
)) {
123 minfo
= qobject_to_qdict(qlist_entry_obj(p
));
125 qobj
= qdict_get(minfo
, "name");
127 qstr
= qobject_to_qstring(qobj
);
129 mname
= qstring_get_str(qstr
);
130 if (!is_blacklisted(arch
, mname
)) {
131 path
= g_strdup_printf("qom/%s", mname
);
132 qtest_add_data_func(path
, mname
, test_machine
);
138 int main(int argc
, char **argv
)
140 g_test_init(&argc
, &argv
, NULL
);
142 add_machine_test_cases();