]> git.proxmox.com Git - mirror_qemu.git/blame - tests/device-introspect-test.c
megasas: fix guest-triggered memory leak
[mirror_qemu.git] / tests / device-introspect-test.c
CommitLineData
2d1abb85
MA
1/*
2 * Device introspection test cases
3 *
4 * Copyright (c) 2015 Red Hat Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *
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.
11 */
12
13/*
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.
18 */
19
681c28a3 20#include "qemu/osdep.h"
2d1abb85
MA
21#include "qemu-common.h"
22#include "qapi/qmp/qstring.h"
23#include "libqtest.h"
24
25const char common_args[] = "-nodefaults -machine none";
26
27static QList *device_type_list(bool abstract)
28{
29 QDict *resp;
30 QList *ret;
31
32 resp = qmp("{'execute': 'qom-list-types',"
33 " 'arguments': {'implements': 'device', 'abstract': %i}}",
34 abstract);
35 g_assert(qdict_haskey(resp, "return"));
36 ret = qdict_get_qlist(resp, "return");
37 QINCREF(ret);
38 QDECREF(resp);
39 return ret;
40}
41
42static void test_one_device(const char *type)
43{
44 QDict *resp;
45 char *help, *qom_tree;
46
edb1523d
MA
47 resp = qmp("{'execute': 'device-list-properties',"
48 " 'arguments': {'typename': %s}}",
49 type);
50 QDECREF(resp);
2d1abb85
MA
51
52 help = hmp("device_add \"%s,help\"", type);
53 g_free(help);
54
55 /*
56 * Some devices leave dangling pointers in QOM behind.
57 * "info qom-tree" has a good chance at crashing then
58 */
59 qom_tree = hmp("info qom-tree");
60 g_free(qom_tree);
61}
62
63static void test_device_intro_list(void)
64{
65 QList *types;
66 char *help;
67
68 qtest_start(common_args);
69
70 types = device_type_list(true);
71 QDECREF(types);
72
73 help = hmp("device_add help");
74 g_free(help);
75
76 qtest_end();
77}
78
79static void test_device_intro_none(void)
80{
81 qtest_start(common_args);
82 test_one_device("nonexistent");
83 qtest_end();
84}
85
86static void test_device_intro_abstract(void)
87{
88 qtest_start(common_args);
89 test_one_device("device");
90 qtest_end();
91}
92
2d1abb85
MA
93static void test_device_intro_concrete(void)
94{
95 QList *types;
96 QListEntry *entry;
97 const char *type;
98
99 qtest_start(common_args);
100 types = device_type_list(false);
101
102 QLIST_FOREACH_ENTRY(types, entry) {
103 type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)),
104 "name");
105 g_assert(type);
2d1abb85
MA
106 test_one_device(type);
107 }
108
109 QDECREF(types);
110 qtest_end();
111}
112
113int main(int argc, char **argv)
114{
115 g_test_init(&argc, &argv, NULL);
116
117 qtest_add_func("device/introspect/list", test_device_intro_list);
118 qtest_add_func("device/introspect/none", test_device_intro_none);
119 qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
120 qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
121
122 return g_test_run();
123}