2 * Device introspection test cases
4 * Copyright (c) 2015 Red Hat Inc.
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
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"
27 const char common_args
[] = "-nodefaults -machine none";
29 static QList
*qom_list_types(const char *implements
, bool abstract
)
33 QDict
*args
= qdict_new();
35 qdict_put_bool(args
, "abstract", abstract
);
37 qdict_put_str(args
, "implements", 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");
48 /* Find an entry on a list returned by qom-list-types */
49 static QDict
*type_list_find(QList
*types
, const char *name
)
53 QLIST_FOREACH_ENTRY(types
, e
) {
54 QDict
*d
= qobject_to_qdict(qlist_entry_obj(e
));
55 const char *ename
= qdict_get_str(d
, "name");
56 if (!strcmp(ename
, name
)) {
64 static QList
*device_type_list(bool abstract
)
66 return qom_list_types("device", abstract
);
69 static void test_one_device(const char *type
)
72 char *help
, *qom_tree
;
74 resp
= qmp("{'execute': 'device-list-properties',"
75 " 'arguments': {'typename': %s}}",
79 help
= hmp("device_add \"%s,help\"", type
);
83 * Some devices leave dangling pointers in QOM behind.
84 * "info qom-tree" has a good chance at crashing then
86 qom_tree
= hmp("info qom-tree");
90 static void test_device_intro_list(void)
95 qtest_start(common_args
);
97 types
= device_type_list(true);
100 help
= hmp("device_add help");
106 static void test_device_intro_none(void)
108 qtest_start(common_args
);
109 test_one_device("nonexistent");
113 static void test_device_intro_abstract(void)
115 qtest_start(common_args
);
116 test_one_device("device");
120 static void test_device_intro_concrete(void)
126 qtest_start(common_args
);
127 types
= device_type_list(false);
129 QLIST_FOREACH_ENTRY(types
, entry
) {
130 type
= qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry
)),
133 test_one_device(type
);
140 static void test_abstract_interfaces(void)
146 qtest_start(common_args
);
147 /* qom-list-types implements=interface would return any type
148 * that implements _any_ interface (not just interface types),
149 * so use a trick to find the interface type names:
150 * - list all object types
151 * - list all types, and look for items that are not
154 all_types
= qom_list_types(NULL
, false);
155 obj_types
= qom_list_types("object", false);
157 QLIST_FOREACH_ENTRY(all_types
, e
) {
158 QDict
*d
= qobject_to_qdict(qlist_entry_obj(e
));
161 * An interface (incorrectly) marked as non-abstract would
162 * appear on all_types, but not on obj_types:
164 g_assert(type_list_find(obj_types
, qdict_get_str(d
, "name")));
173 int main(int argc
, char **argv
)
175 g_test_init(&argc
, &argv
, NULL
);
177 qtest_add_func("device/introspect/list", test_device_intro_list
);
178 qtest_add_func("device/introspect/none", test_device_intro_none
);
179 qtest_add_func("device/introspect/abstract", test_device_intro_abstract
);
180 qtest_add_func("device/introspect/concrete", test_device_intro_concrete
);
181 qtest_add_func("device/introspect/abstract-interfaces", test_abstract_interfaces
);