qemu-log: remove -d ioport
[qemu/ar7.git] / tests / device-introspect-test.c
blob11d5fea3e2b646c5655e213d4cbe5d6b289c020f
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 <glib.h>
21 #include <stdarg.h>
22 #include "qemu-common.h"
23 #include "qapi/qmp/qstring.h"
24 #include "libqtest.h"
26 const char common_args[] = "-nodefaults -machine none";
28 static QList *device_type_list(bool abstract)
30 QDict *resp;
31 QList *ret;
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;
43 static void test_one_device(const char *type)
45 QDict *resp;
46 char *help, *qom_tree;
48 resp = qmp("{'execute': 'device-list-properties',"
49 " 'arguments': {'typename': %s}}",
50 type);
51 QDECREF(resp);
53 help = hmp("device_add \"%s,help\"", type);
54 g_free(help);
57 * Some devices leave dangling pointers in QOM behind.
58 * "info qom-tree" has a good chance at crashing then
60 qom_tree = hmp("info qom-tree");
61 g_free(qom_tree);
64 static void test_device_intro_list(void)
66 QList *types;
67 char *help;
69 qtest_start(common_args);
71 types = device_type_list(true);
72 QDECREF(types);
74 help = hmp("device_add help");
75 g_free(help);
77 qtest_end();
80 static void test_device_intro_none(void)
82 qtest_start(common_args);
83 test_one_device("nonexistent");
84 qtest_end();
87 static void test_device_intro_abstract(void)
89 qtest_start(common_args);
90 test_one_device("device");
91 qtest_end();
94 static void test_device_intro_concrete(void)
96 QList *types;
97 QListEntry *entry;
98 const char *type;
100 qtest_start(common_args);
101 types = device_type_list(false);
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);
110 QDECREF(types);
111 qtest_end();
114 int main(int argc, char **argv)
116 g_test_init(&argc, &argv, NULL);
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);
123 return g_test_run();