net: cadence_gem: Make phy respond to broadcast
[qemu.git] / tests / qom-test.c
blob6d9a00b44887db3bdcfe2163e117ff33603a6faf
1 /*
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.
8 */
10 #include <glib.h>
11 #include <string.h>
13 #include "qemu-common.h"
14 #include "libqtest.h"
15 #include "qemu/osdep.h"
16 #include "qapi/qmp/types.h"
18 static const char *blacklist_x86[] = {
19 "xenfv", "xenpv", NULL
22 static const struct {
23 const char *arch;
24 const char **machine;
25 } blacklists[] = {
26 { "i386", blacklist_x86 },
27 { "x86_64", blacklist_x86 },
30 static bool is_blacklisted(const char *arch, const char *mach)
32 int i;
33 const char **p;
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;
44 return false;
47 static void test_properties(const char *path)
49 char *child_path;
50 QDict *response, *tuple;
51 QList *list;
52 QListEntry *entry;
54 g_test_message("Obtaining properties of %s", path);
55 response = qmp("{ 'execute': 'qom-list',"
56 " 'arguments': { 'path': '%s' } }", path);
57 g_assert(response);
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);
81 static void test_machine(gconstpointer data)
83 const char *machine = data;
84 char *args;
85 QDict *response;
87 args = g_strdup_printf("-machine %s", machine);
88 qtest_start(args);
90 test_properties("/machine");
92 response = qmp("{ 'execute': 'quit' }");
93 g_assert(qdict_haskey(response, "return"));
95 qtest_end();
96 g_free(args);
99 static void add_machine_test_cases(void)
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;
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);
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);
125 g_test_add_data_func(path, mname, test_machine);
128 qtest_end();
131 int main(int argc, char **argv)
133 g_test_init(&argc, &argv, NULL);
135 add_machine_test_cases();
137 return g_test_run();