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