blkdebug: reschedule coroutine on the AioContext it is running on
[qemu/ar7.git] / tests / device-introspect-test.c
blobc5637cc406963320ef9ad16772ca93ba1aac305a
1 /*
2 * Device introspection test cases
4 * Copyright (c) 2015 Red Hat Inc.
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 * Covers QMP device-list-properties and HMP device_add help. We
15 * currently don't check that their output makes sense, only that QEMU
16 * survives. Useful since we've had an astounding number of crash
17 * bugs around here.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "qapi/qmp/qstring.h"
23 #include "qapi/qmp/qbool.h"
24 #include "qapi/qmp/qdict.h"
25 #include "libqtest.h"
27 const char common_args[] = "-nodefaults -machine none";
29 static QList *qom_list_types(const char *implements, bool abstract)
31 QDict *resp;
32 QList *ret;
33 QDict *args = qdict_new();
35 qdict_put(args, "abstract", qbool_from_bool(abstract));
36 if (implements) {
37 qdict_put(args, "implements", qstring_from_str(implements));
39 resp = qmp("{'execute': 'qom-list-types',"
40 " 'arguments': %p }", args);
41 g_assert(qdict_haskey(resp, "return"));
42 ret = qdict_get_qlist(resp, "return");
43 QINCREF(ret);
44 QDECREF(resp);
45 return ret;
48 static QList *device_type_list(bool abstract)
50 return qom_list_types("device", abstract);
53 static void test_one_device(const char *type)
55 QDict *resp;
56 char *help, *qom_tree;
58 resp = qmp("{'execute': 'device-list-properties',"
59 " 'arguments': {'typename': %s}}",
60 type);
61 QDECREF(resp);
63 help = hmp("device_add \"%s,help\"", type);
64 g_free(help);
67 * Some devices leave dangling pointers in QOM behind.
68 * "info qom-tree" has a good chance at crashing then
70 qom_tree = hmp("info qom-tree");
71 g_free(qom_tree);
74 static void test_device_intro_list(void)
76 QList *types;
77 char *help;
79 qtest_start(common_args);
81 types = device_type_list(true);
82 QDECREF(types);
84 help = hmp("device_add help");
85 g_free(help);
87 qtest_end();
90 static void test_device_intro_none(void)
92 qtest_start(common_args);
93 test_one_device("nonexistent");
94 qtest_end();
97 static void test_device_intro_abstract(void)
99 qtest_start(common_args);
100 test_one_device("device");
101 qtest_end();
104 static void test_device_intro_concrete(void)
106 QList *types;
107 QListEntry *entry;
108 const char *type;
110 qtest_start(common_args);
111 types = device_type_list(false);
113 QLIST_FOREACH_ENTRY(types, entry) {
114 type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)),
115 "name");
116 g_assert(type);
117 test_one_device(type);
120 QDECREF(types);
121 qtest_end();
124 static void test_abstract_interfaces(void)
126 QList *all_types;
127 QList *obj_types;
128 QListEntry *ae;
130 qtest_start(common_args);
131 /* qom-list-types implements=interface would return any type
132 * that implements _any_ interface (not just interface types),
133 * so use a trick to find the interface type names:
134 * - list all object types
135 * - list all types, and look for items that are not
136 * on the first list
138 all_types = qom_list_types(NULL, false);
139 obj_types = qom_list_types("object", false);
141 QLIST_FOREACH_ENTRY(all_types, ae) {
142 QDict *at = qobject_to_qdict(qlist_entry_obj(ae));
143 const char *aname = qdict_get_str(at, "name");
144 QListEntry *oe;
145 const char *found = NULL;
147 QLIST_FOREACH_ENTRY(obj_types, oe) {
148 QDict *ot = qobject_to_qdict(qlist_entry_obj(oe));
149 const char *oname = qdict_get_str(ot, "name");
150 if (!strcmp(aname, oname)) {
151 found = oname;
152 break;
156 /* Using g_assert_cmpstr() will give more useful failure
157 * messages than g_assert(found) */
158 g_assert_cmpstr(aname, ==, found);
161 QDECREF(all_types);
162 QDECREF(obj_types);
163 qtest_end();
166 int main(int argc, char **argv)
168 g_test_init(&argc, &argv, NULL);
170 qtest_add_func("device/introspect/list", test_device_intro_list);
171 qtest_add_func("device/introspect/none", test_device_intro_none);
172 qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
173 qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
174 qtest_add_func("device/introspect/abstract-interfaces", test_abstract_interfaces);
176 return g_test_run();