]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qtest/qom-test.c
tests/qtest: enable tests for virtio-gpio
[mirror_qemu.git] / tests / qtest / qom-test.c
CommitLineData
7c41f217
AF
1/*
2 * QTest testcase for QOM
3 *
4 * Copyright (c) 2013 SUSE LINUX Products GmbH
5 *
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 */
7c41f217 9
681c28a3 10#include "qemu/osdep.h"
91f32b0c 11
452fcdbc 12#include "qapi/qmp/qdict.h"
47e6b297 13#include "qapi/qmp/qlist.h"
f348b6d1 14#include "qemu/cutils.h"
907b5105 15#include "libqtest.h"
5c1904f1 16
9266ebc9 17static void test_properties(QTestState *qts, const char *path, bool recurse)
dc06cbd2
AF
18{
19 char *child_path;
0d2cd785 20 QDict *response, *tuple, *tmp;
dc06cbd2
AF
21 QList *list;
22 QListEntry *entry;
23
24 g_test_message("Obtaining properties of %s", path);
9266ebc9
TH
25 response = qtest_qmp(qts, "{ 'execute': 'qom-list',"
26 " 'arguments': { 'path': %s } }", path);
dc06cbd2
AF
27 g_assert(response);
28
0380aef3 29 if (!recurse) {
cb3e7f08 30 qobject_unref(response);
0380aef3
CR
31 return;
32 }
33
dc06cbd2 34 g_assert(qdict_haskey(response, "return"));
7dc847eb 35 list = qobject_to(QList, qdict_get(response, "return"));
dc06cbd2 36 QLIST_FOREACH_ENTRY(list, entry) {
7dc847eb 37 tuple = qobject_to(QDict, qlist_entry_obj(entry));
0380aef3
CR
38 bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL);
39 bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL);
40
41 if (is_child || is_link) {
dc06cbd2
AF
42 child_path = g_strdup_printf("%s/%s",
43 path, qdict_get_str(tuple, "name"));
9266ebc9 44 test_properties(qts, child_path, is_child);
dc06cbd2
AF
45 g_free(child_path);
46 } else {
47 const char *prop = qdict_get_str(tuple, "name");
48 g_test_message("Testing property %s.%s", path, prop);
9266ebc9
TH
49 tmp = qtest_qmp(qts,
50 "{ 'execute': 'qom-get',"
51 " 'arguments': { 'path': %s, 'property': %s } }",
52 path, prop);
dc06cbd2 53 /* qom-get may fail but should not, e.g., segfault. */
0d2cd785 54 g_assert(tmp);
cb3e7f08 55 qobject_unref(tmp);
dc06cbd2
AF
56 }
57 }
cb3e7f08 58 qobject_unref(response);
dc06cbd2
AF
59}
60
bb6c5e3c 61static void test_machine(gconstpointer data)
7c41f217 62{
7c41f217 63 const char *machine = data;
bb6c5e3c 64 QDict *response;
9266ebc9 65 QTestState *qts;
7c41f217 66
9266ebc9 67 qts = qtest_initf("-machine %s", machine);
dc06cbd2 68
9266ebc9 69 test_properties(qts, "/machine", true);
dc06cbd2 70
9266ebc9 71 response = qtest_qmp(qts, "{ 'execute': 'quit' }");
bb6c5e3c 72 g_assert(qdict_haskey(response, "return"));
cb3e7f08 73 qobject_unref(response);
dc06cbd2 74
9266ebc9 75 qtest_quit(qts);
0d2cd785 76 g_free((void *)machine);
7c41f217
AF
77}
78
02ef6e87 79static void add_machine_test_case(const char *mname)
7c41f217 80{
9a709f06 81 char *path;
5c1904f1 82
9a709f06
OH
83 path = g_strdup_printf("qom/%s", mname);
84 qtest_add_data_func(path, g_strdup(mname), test_machine);
85 g_free(path);
7c41f217
AF
86}
87
7c41f217
AF
88int main(int argc, char **argv)
89{
7c41f217
AF
90 g_test_init(&argc, &argv, NULL);
91
1f4a0d81 92 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
7c41f217
AF
93
94 return g_test_run();
95}