1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <glib.h>
21#include <stdarg.h>
22#include "qemu-common.h"
23#include "qapi/qmp/qstring.h"
24#include "libqtest.h"
25
26const char common_args[] = "-nodefaults -machine none";
27
28static QList *device_type_list(bool abstract)
29{
30 QDict *resp;
31 QList *ret;
32
33 resp = qmp("{'execute': 'qom-list-types',"
34 " 'arguments': {'implements': 'device', 'abstract': %i}}",
35 abstract);
36 g_assert(qdict_haskey(resp, "return"));
37 ret = qdict_get_qlist(resp, "return");
38 QINCREF(ret);
39 QDECREF(resp);
40 return ret;
41}
42
43static void test_one_device(const char *type)
44{
45 QDict *resp;
46 char *help, *qom_tree;
47
48 resp = qmp("{'execute': 'device-list-properties',"
49 " 'arguments': {'typename': %s}}",
50 type);
51 QDECREF(resp);
52
53 help = hmp("device_add \"%s,help\"", type);
54 g_free(help);
55
56
57
58
59
60 qom_tree = hmp("info qom-tree");
61 g_free(qom_tree);
62}
63
64static void test_device_intro_list(void)
65{
66 QList *types;
67 char *help;
68
69 qtest_start(common_args);
70
71 types = device_type_list(true);
72 QDECREF(types);
73
74 help = hmp("device_add help");
75 g_free(help);
76
77 qtest_end();
78}
79
80static void test_device_intro_none(void)
81{
82 qtest_start(common_args);
83 test_one_device("nonexistent");
84 qtest_end();
85}
86
87static void test_device_intro_abstract(void)
88{
89 qtest_start(common_args);
90 test_one_device("device");
91 qtest_end();
92}
93
94static void test_device_intro_concrete(void)
95{
96 QList *types;
97 QListEntry *entry;
98 const char *type;
99
100 qtest_start(common_args);
101 types = device_type_list(false);
102
103 QLIST_FOREACH_ENTRY(types, entry) {
104 type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)),
105 "name");
106 g_assert(type);
107 test_one_device(type);
108 }
109
110 QDECREF(types);
111 qtest_end();
112}
113
114int main(int argc, char **argv)
115{
116 g_test_init(&argc, &argv, NULL);
117
118 qtest_add_func("device/introspect/list", test_device_intro_list);
119 qtest_add_func("device/introspect/none", test_device_intro_none);
120 qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
121 qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
122
123 return g_test_run();
124}
125