]> Git Repo - qemu.git/blob - tests/qom-test.c
tests/qapi-schema: Cover union types with base
[qemu.git] / tests / qom-test.c
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  */
9
10 #include <glib.h>
11 #include <string.h>
12
13 #include "libqtest.h"
14 #include "qemu/osdep.h"
15 #include "qapi/qmp/types.h"
16
17 static const char *blacklist_x86[] = {
18     "xenfv", "xenpv", NULL
19 };
20
21 static const struct {
22     const char *arch;
23     const char **machine;
24 } blacklists[] = {
25     { "i386", blacklist_x86 },
26     { "x86_64", blacklist_x86 },
27 };
28
29 static 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 }
45
46 static void test_machine(gconstpointer data)
47 {
48     const char *machine = data;
49     char *args;
50     QDict *response;
51
52     args = g_strdup_printf("-machine %s", machine);
53     qtest_start(args);
54     response = qmp("{ 'execute': 'quit' }");
55     g_assert(qdict_haskey(response, "return"));
56     qtest_end();
57     g_free(args);
58 }
59
60 static void add_machine_test_cases(void)
61 {
62     const char *arch = qtest_get_arch();
63     QDict *response, *minfo;
64     QList *list;
65     const QListEntry *p;
66     QObject *qobj;
67     QString *qstr;
68     const char *mname, *path;
69
70     qtest_start("-machine none");
71     response = qmp("{ 'execute': 'query-machines' }");
72     g_assert(response);
73     list = qdict_get_qlist(response, "return");
74     g_assert(list);
75
76     for (p = qlist_first(list); p; p = qlist_next(p)) {
77         minfo = qobject_to_qdict(qlist_entry_obj(p));
78         g_assert(minfo);
79         qobj = qdict_get(minfo, "name");
80         g_assert(qobj);
81         qstr = qobject_to_qstring(qobj);
82         g_assert(qstr);
83         mname = qstring_get_str(qstr);
84         if (!is_blacklisted(arch, mname)) {
85             path = g_strdup_printf("/%s/qom/%s", arch, mname);
86             g_test_add_data_func(path, mname, test_machine);
87         }
88     }
89     qtest_end();
90 }
91
92 int main(int argc, char **argv)
93 {
94     g_test_init(&argc, &argv, NULL);
95
96     add_machine_test_cases();
97
98     return g_test_run();
99 }
This page took 0.029358 seconds and 4 git commands to generate.