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)
50 QDict *response, *tuple;
54 g_test_message("Obtaining properties of %s", path);
55 response = qmp("{ 'execute': 'qom-list',"
56 " 'arguments': { 'path': '%s' } }", path);
59 g_assert(qdict_haskey(response, "return"));
60 list = qobject_to_qlist(qdict_get(response, "return"));
61 QLIST_FOREACH_ENTRY(list, entry) {
62 tuple = qobject_to_qdict(qlist_entry_obj(entry));
63 if (strstart(qdict_get_str(tuple, "type"), "child<", NULL)) {
64 child_path = g_strdup_printf("%s/%s",
65 path, qdict_get_str(tuple, "name"));
66 test_properties(child_path);
69 const char *prop = qdict_get_str(tuple, "name");
70 g_test_message("Testing property %s.%s", path, prop);
71 response = qmp("{ 'execute': 'qom-get',"
72 " 'arguments': { 'path': '%s',"
73 " 'property': '%s' } }",
75 /* qom-get may fail but should not, e.g., segfault. */
81 static void test_machine(gconstpointer data)
83 const char *machine = data;
87 args = g_strdup_printf("-machine %s", machine);
90 test_properties("/machine");
92 response = qmp("{ 'execute': 'quit' }");
93 g_assert(qdict_haskey(response, "return"));
99 static void add_machine_test_cases(void)
101 const char *arch = qtest_get_arch();
102 QDict *response, *minfo;
107 const char *mname, *path;
109 qtest_start("-machine none");
110 response = qmp("{ 'execute': 'query-machines' }");
112 list = qdict_get_qlist(response, "return");
115 for (p = qlist_first(list); p; p = qlist_next(p)) {
116 minfo = qobject_to_qdict(qlist_entry_obj(p));
118 qobj = qdict_get(minfo, "name");
120 qstr = qobject_to_qstring(qobj);
122 mname = qstring_get_str(qstr);
123 if (!is_blacklisted(arch, mname)) {
124 path = g_strdup_printf("/%s/qom/%s", arch, mname);
125 g_test_add_data_func(path, mname, test_machine);
131 int main(int argc, char **argv)
133 g_test_init(&argc, &argv, NULL);
135 add_machine_test_cases();