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.
10 #include "qemu/osdep.h"
12 #include "qemu-common.h"
13 #include "qapi/qmp/qdict.h"
14 #include "qapi/qmp/qlist.h"
15 #include "qemu/cutils.h"
16 #include "libqos/libqtest.h"
18 static void test_properties(QTestState
*qts
, const char *path
, bool recurse
)
21 QDict
*response
, *tuple
, *tmp
;
25 g_test_message("Obtaining properties of %s", path
);
26 response
= qtest_qmp(qts
, "{ 'execute': 'qom-list',"
27 " 'arguments': { 'path': %s } }", path
);
31 qobject_unref(response
);
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 test_properties(qts
, child_path
, is_child
);
48 const char *prop
= qdict_get_str(tuple
, "name");
49 g_test_message("Testing property %s.%s", path
, prop
);
51 "{ 'execute': 'qom-get',"
52 " 'arguments': { 'path': %s, 'property': %s } }",
54 /* qom-get may fail but should not, e.g., segfault. */
59 qobject_unref(response
);
62 static void test_machine(gconstpointer data
)
64 const char *machine
= data
;
68 qts
= qtest_initf("-machine %s", machine
);
70 test_properties(qts
, "/machine", true);
72 response
= qtest_qmp(qts
, "{ 'execute': 'quit' }");
73 g_assert(qdict_haskey(response
, "return"));
74 qobject_unref(response
);
77 g_free((void *)machine
);
80 static void add_machine_test_case(const char *mname
)
84 path
= g_strdup_printf("qom/%s", mname
);
85 qtest_add_data_func(path
, g_strdup(mname
), test_machine
);
89 int main(int argc
, char **argv
)
91 g_test_init(&argc
, &argv
, NULL
);
93 qtest_cb_for_every_machine(add_machine_test_case
, g_test_quick());