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
22 #include "qemu-common.h"
23 #include "qapi/qmp/qstring.h"
26 const char common_args
[] = "-nodefaults -machine none";
28 static QList
*device_type_list(bool abstract
)
33 resp
= qmp("{'execute': 'qom-list-types',"
34 " 'arguments': {'implements': 'device', 'abstract': %i}}",
36 g_assert(qdict_haskey(resp
, "return"));
37 ret
= qdict_get_qlist(resp
, "return");
43 static void test_one_device(const char *type
)
46 char *help
, *qom_tree
;
49 * Skip this part for the abstract device test case, because
50 * device-list-properties crashes for such devices.
51 * FIXME fix it not to crash
53 if (strcmp(type
, "device")) {
54 resp
= qmp("{'execute': 'device-list-properties',"
55 " 'arguments': {'typename': %s}}",
60 help
= hmp("device_add \"%s,help\"", type
);
64 * Some devices leave dangling pointers in QOM behind.
65 * "info qom-tree" has a good chance at crashing then
67 qom_tree
= hmp("info qom-tree");
71 static void test_device_intro_list(void)
76 qtest_start(common_args
);
78 types
= device_type_list(true);
81 help
= hmp("device_add help");
87 static void test_device_intro_none(void)
89 qtest_start(common_args
);
90 test_one_device("nonexistent");
94 static void test_device_intro_abstract(void)
96 qtest_start(common_args
);
97 test_one_device("device");
101 static bool blacklisted(const char *type
)
103 static const char *blacklist
[] = {
104 /* hang in object_unref(): */
105 "realview_pci", "versatile_pci",
106 /* create a CPU, thus use after free (see below): */
107 "allwinner-a10", "digic", "fsl,imx25", "fsl,imx31", "xlnx,zynqmp",
109 size_t len
= strlen(type
);
112 if (len
>= 4 && !strcmp(type
+ len
- 4, "-cpu")) {
113 /* use after free: cpu_exec_init() saves CPUState in cpus */
117 for (i
= 0; i
< ARRAY_SIZE(blacklist
); i
++) {
118 if (!strcmp(blacklist
[i
], type
)) {
125 static void test_device_intro_concrete(void)
131 qtest_start(common_args
);
132 types
= device_type_list(false);
134 QLIST_FOREACH_ENTRY(types
, entry
) {
135 type
= qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry
)),
138 if (blacklisted(type
)) {
139 continue; /* FIXME broken device, skip */
141 test_one_device(type
);
148 int main(int argc
, char **argv
)
150 g_test_init(&argc
, &argv
, NULL
);
152 qtest_add_func("device/introspect/list", test_device_intro_list
);
153 qtest_add_func("device/introspect/none", test_device_intro_none
);
154 qtest_add_func("device/introspect/abstract", test_device_intro_abstract
);
155 qtest_add_func("device/introspect/concrete", test_device_intro_concrete
);