KVM: remove support for kernel-irqchip=off
[qemu.git] / tests / qtest / qom-test.c
blob13510bc3496199b00e5ea0c13835fb082804b137
1 /*
2 * QTest testcase for QOM
4 * Copyright (c) 2013 SUSE LINUX Products GmbH
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
12 #include "qapi/qmp/qdict.h"
13 #include "qapi/qmp/qlist.h"
14 #include "qemu/cutils.h"
15 #include "libqtest.h"
17 static void test_properties(QTestState *qts, const char *path, bool recurse)
19 char *child_path;
20 QDict *response, *tuple, *tmp;
21 QList *list;
22 QListEntry *entry;
23 GSList *children = NULL, *links = NULL;
25 g_test_message("Obtaining properties of %s", path);
26 response = qtest_qmp(qts, "{ 'execute': 'qom-list',"
27 " 'arguments': { 'path': %s } }", path);
28 g_assert(response);
30 if (!recurse) {
31 qobject_unref(response);
32 return;
35 g_assert(qdict_haskey(response, "return"));
36 list = qobject_to(QList, qdict_get(response, "return"));
37 QLIST_FOREACH_ENTRY(list, entry) {
38 tuple = qobject_to(QDict, qlist_entry_obj(entry));
39 bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL);
40 bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL);
42 if (is_child || is_link) {
43 child_path = g_strdup_printf("%s/%s",
44 path, qdict_get_str(tuple, "name"));
45 if (is_child) {
46 children = g_slist_prepend(children, child_path);
47 } else {
48 links = g_slist_prepend(links, child_path);
50 } else {
51 const char *prop = qdict_get_str(tuple, "name");
52 g_test_message("-> %s", prop);
53 tmp = qtest_qmp(qts,
54 "{ 'execute': 'qom-get',"
55 " 'arguments': { 'path': %s, 'property': %s } }",
56 path, prop);
57 /* qom-get may fail but should not, e.g., segfault. */
58 g_assert(tmp);
59 qobject_unref(tmp);
63 while (links) {
64 test_properties(qts, links->data, false);
65 g_free(links->data);
66 links = g_slist_delete_link(links, links);
68 while (children) {
69 test_properties(qts, children->data, true);
70 g_free(children->data);
71 children = g_slist_delete_link(children, children);
74 qobject_unref(response);
77 static void test_machine(gconstpointer data)
79 const char *machine = data;
80 QDict *response;
81 QTestState *qts;
83 qts = qtest_initf("-machine %s", machine);
85 test_properties(qts, "/machine", true);
87 response = qtest_qmp(qts, "{ 'execute': 'quit' }");
88 g_assert(qdict_haskey(response, "return"));
89 qobject_unref(response);
91 qtest_quit(qts);
92 g_free((void *)machine);
95 static void add_machine_test_case(const char *mname)
97 char *path;
99 path = g_strdup_printf("qom/%s", mname);
100 qtest_add_data_func(path, g_strdup(mname), test_machine);
101 g_free(path);
104 int main(int argc, char **argv)
106 g_test_init(&argc, &argv, NULL);
108 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
110 return g_test_run();