]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qom-test.c
Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-next-050719-3' into...
[mirror_qemu.git] / tests / 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
dc06cbd2 12#include "qemu-common.h"
452fcdbc 13#include "qapi/qmp/qdict.h"
47e6b297 14#include "qapi/qmp/qlist.h"
f348b6d1 15#include "qemu/cutils.h"
91f32b0c 16#include "libqtest.h"
5c1904f1
MA
17
18static const char *blacklist_x86[] = {
19 "xenfv", "xenpv", NULL
20};
21
22static const struct {
23 const char *arch;
24 const char **machine;
25} blacklists[] = {
26 { "i386", blacklist_x86 },
27 { "x86_64", blacklist_x86 },
28};
29
30static bool is_blacklisted(const char *arch, const char *mach)
31{
32 int i;
33 const char **p;
34
35 for (i = 0; i < ARRAY_SIZE(blacklists); i++) {
36 if (!strcmp(blacklists[i].arch, arch)) {
37 for (p = blacklists[i].machine; *p; p++) {
38 if (!strcmp(*p, mach)) {
39 return true;
40 }
41 }
42 }
43 }
44 return false;
45}
7c41f217 46
9266ebc9 47static void test_properties(QTestState *qts, const char *path, bool recurse)
dc06cbd2
AF
48{
49 char *child_path;
0d2cd785 50 QDict *response, *tuple, *tmp;
dc06cbd2
AF
51 QList *list;
52 QListEntry *entry;
53
54 g_test_message("Obtaining properties of %s", path);
9266ebc9
TH
55 response = qtest_qmp(qts, "{ 'execute': 'qom-list',"
56 " 'arguments': { 'path': %s } }", path);
dc06cbd2
AF
57 g_assert(response);
58
0380aef3 59 if (!recurse) {
cb3e7f08 60 qobject_unref(response);
0380aef3
CR
61 return;
62 }
63
dc06cbd2 64 g_assert(qdict_haskey(response, "return"));
7dc847eb 65 list = qobject_to(QList, qdict_get(response, "return"));
dc06cbd2 66 QLIST_FOREACH_ENTRY(list, entry) {
7dc847eb 67 tuple = qobject_to(QDict, qlist_entry_obj(entry));
0380aef3
CR
68 bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL);
69 bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL);
70
71 if (is_child || is_link) {
dc06cbd2
AF
72 child_path = g_strdup_printf("%s/%s",
73 path, qdict_get_str(tuple, "name"));
9266ebc9 74 test_properties(qts, child_path, is_child);
dc06cbd2
AF
75 g_free(child_path);
76 } else {
77 const char *prop = qdict_get_str(tuple, "name");
78 g_test_message("Testing property %s.%s", path, prop);
9266ebc9
TH
79 tmp = qtest_qmp(qts,
80 "{ 'execute': 'qom-get',"
81 " 'arguments': { 'path': %s, 'property': %s } }",
82 path, prop);
dc06cbd2 83 /* qom-get may fail but should not, e.g., segfault. */
0d2cd785 84 g_assert(tmp);
cb3e7f08 85 qobject_unref(tmp);
dc06cbd2
AF
86 }
87 }
cb3e7f08 88 qobject_unref(response);
dc06cbd2
AF
89}
90
bb6c5e3c 91static void test_machine(gconstpointer data)
7c41f217 92{
7c41f217 93 const char *machine = data;
bb6c5e3c 94 QDict *response;
9266ebc9 95 QTestState *qts;
7c41f217 96
9266ebc9 97 qts = qtest_initf("-machine %s", machine);
dc06cbd2 98
9266ebc9 99 test_properties(qts, "/machine", true);
dc06cbd2 100
9266ebc9 101 response = qtest_qmp(qts, "{ 'execute': 'quit' }");
bb6c5e3c 102 g_assert(qdict_haskey(response, "return"));
cb3e7f08 103 qobject_unref(response);
dc06cbd2 104
9266ebc9 105 qtest_quit(qts);
0d2cd785 106 g_free((void *)machine);
7c41f217
AF
107}
108
02ef6e87 109static void add_machine_test_case(const char *mname)
7c41f217 110{
5c1904f1 111 const char *arch = qtest_get_arch();
5c1904f1 112
02ef6e87
TH
113 if (!is_blacklisted(arch, mname)) {
114 char *path = g_strdup_printf("qom/%s", mname);
115 qtest_add_data_func(path, g_strdup(mname), test_machine);
116 g_free(path);
5c1904f1 117 }
7c41f217
AF
118}
119
7c41f217
AF
120int main(int argc, char **argv)
121{
7c41f217
AF
122 g_test_init(&argc, &argv, NULL);
123
1f4a0d81 124 qtest_cb_for_every_machine(add_machine_test_case, g_test_quick());
7c41f217
AF
125
126 return g_test_run();
127}