tests/qtest/cmsdk-apb-watchdog-test: Test clock changes
[qemu/ar7.git] / tests / qtest / qom-test.c
blobeb34af843b794dbc028cfb9382ed9184f30fb1eb
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 "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)
20 char *child_path;
21 QDict *response, *tuple, *tmp;
22 QList *list;
23 QListEntry *entry;
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 test_properties(qts, child_path, is_child);
46 g_free(child_path);
47 } else {
48 const char *prop = qdict_get_str(tuple, "name");
49 g_test_message("Testing property %s.%s", path, prop);
50 tmp = qtest_qmp(qts,
51 "{ 'execute': 'qom-get',"
52 " 'arguments': { 'path': %s, 'property': %s } }",
53 path, prop);
54 /* qom-get may fail but should not, e.g., segfault. */
55 g_assert(tmp);
56 qobject_unref(tmp);
59 qobject_unref(response);
62 static void test_machine(gconstpointer data)
64 const char *machine = data;
65 QDict *response;
66 QTestState *qts;
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);
76 qtest_quit(qts);
77 g_free((void *)machine);
80 static void add_machine_test_case(const char *mname)
82 char *path;
84 path = g_strdup_printf("qom/%s", mname);
85 qtest_add_data_func(path, g_strdup(mname), test_machine);
86 g_free(path);
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());
95 return g_test_run();