]>
Commit | Line | Data |
---|---|---|
7c41f217 AF |
1 | /* |
2 | * QTest testcase for QOM | |
3 | * | |
4 | * Copyright (c) 2013 SUSE LINUX Products GmbH | |
5 | * | |
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 | */ | |
7c41f217 AF |
9 | |
10 | #include <glib.h> | |
11 | #include <string.h> | |
91f32b0c | 12 | |
dc06cbd2 | 13 | #include "qemu-common.h" |
91f32b0c | 14 | #include "libqtest.h" |
7c41f217 | 15 | #include "qemu/osdep.h" |
5c1904f1 MA |
16 | #include "qapi/qmp/types.h" |
17 | ||
18 | static const char *blacklist_x86[] = { | |
19 | "xenfv", "xenpv", NULL | |
20 | }; | |
21 | ||
22 | static const struct { | |
23 | const char *arch; | |
24 | const char **machine; | |
25 | } blacklists[] = { | |
26 | { "i386", blacklist_x86 }, | |
27 | { "x86_64", blacklist_x86 }, | |
28 | }; | |
29 | ||
30 | static bool is_blacklisted(const char *arch, const char *mach) | |
31 | { | |
32 | int i; | |
33 | const char **p; | |
34 | ||
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)) { | |
39 | return true; | |
40 | } | |
41 | } | |
42 | } | |
43 | } | |
44 | return false; | |
45 | } | |
7c41f217 | 46 | |
dc06cbd2 AF |
47 | static void test_properties(const char *path) |
48 | { | |
49 | char *child_path; | |
50 | QDict *response, *tuple; | |
51 | QList *list; | |
52 | QListEntry *entry; | |
53 | ||
54 | g_test_message("Obtaining properties of %s", path); | |
55 | response = qmp("{ 'execute': 'qom-list'," | |
56 | " 'arguments': { 'path': '%s' } }", path); | |
57 | g_assert(response); | |
58 | ||
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); | |
67 | g_free(child_path); | |
68 | } else { | |
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' } }", | |
74 | path, prop); | |
75 | /* qom-get may fail but should not, e.g., segfault. */ | |
76 | g_assert(response); | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
bb6c5e3c | 81 | static void test_machine(gconstpointer data) |
7c41f217 | 82 | { |
7c41f217 AF |
83 | const char *machine = data; |
84 | char *args; | |
bb6c5e3c | 85 | QDict *response; |
7c41f217 | 86 | |
2ad645d2 | 87 | args = g_strdup_printf("-machine %s", machine); |
bb6c5e3c | 88 | qtest_start(args); |
dc06cbd2 AF |
89 | |
90 | test_properties("/machine"); | |
91 | ||
bb6c5e3c MA |
92 | response = qmp("{ 'execute': 'quit' }"); |
93 | g_assert(qdict_haskey(response, "return")); | |
dc06cbd2 | 94 | |
bb6c5e3c | 95 | qtest_end(); |
7c41f217 AF |
96 | g_free(args); |
97 | } | |
98 | ||
5c1904f1 | 99 | static void add_machine_test_cases(void) |
7c41f217 | 100 | { |
5c1904f1 MA |
101 | const char *arch = qtest_get_arch(); |
102 | QDict *response, *minfo; | |
103 | QList *list; | |
104 | const QListEntry *p; | |
105 | QObject *qobj; | |
106 | QString *qstr; | |
107 | const char *mname, *path; | |
108 | ||
109 | qtest_start("-machine none"); | |
110 | response = qmp("{ 'execute': 'query-machines' }"); | |
111 | g_assert(response); | |
112 | list = qdict_get_qlist(response, "return"); | |
113 | g_assert(list); | |
114 | ||
115 | for (p = qlist_first(list); p; p = qlist_next(p)) { | |
116 | minfo = qobject_to_qdict(qlist_entry_obj(p)); | |
117 | g_assert(minfo); | |
118 | qobj = qdict_get(minfo, "name"); | |
119 | g_assert(qobj); | |
120 | qstr = qobject_to_qstring(qobj); | |
121 | g_assert(qstr); | |
122 | mname = qstring_get_str(qstr); | |
123 | if (!is_blacklisted(arch, mname)) { | |
124 | path = g_strdup_printf("/%s/qom/%s", arch, mname); | |
bb6c5e3c | 125 | g_test_add_data_func(path, mname, test_machine); |
5c1904f1 MA |
126 | } |
127 | } | |
128 | qtest_end(); | |
7c41f217 AF |
129 | } |
130 | ||
7c41f217 AF |
131 | int main(int argc, char **argv) |
132 | { | |
7c41f217 AF |
133 | g_test_init(&argc, &argv, NULL); |
134 | ||
5c1904f1 | 135 | add_machine_test_cases(); |
7c41f217 AF |
136 | |
137 | return g_test_run(); | |
138 | } |