]>
Commit | Line | Data |
---|---|---|
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 AF |
9 | |
10 | #include <glib.h> | |
11 | #include <string.h> | |
91f32b0c SH |
12 | |
13 | #include "libqtest.h" | |
7c41f217 | 14 | #include "qemu/osdep.h" |
5c1904f1 MA |
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 | } | |
7c41f217 | 45 | |
bb6c5e3c | 46 | static void test_machine(gconstpointer data) |
7c41f217 | 47 | { |
7c41f217 AF |
48 | const char *machine = data; |
49 | char *args; | |
bb6c5e3c | 50 | QDict *response; |
7c41f217 | 51 | |
2ad645d2 | 52 | args = g_strdup_printf("-machine %s", machine); |
bb6c5e3c MA |
53 | qtest_start(args); |
54 | response = qmp("{ 'execute': 'quit' }"); | |
55 | g_assert(qdict_haskey(response, "return")); | |
56 | qtest_end(); | |
7c41f217 AF |
57 | g_free(args); |
58 | } | |
59 | ||
5c1904f1 | 60 | static void add_machine_test_cases(void) |
7c41f217 | 61 | { |
5c1904f1 MA |
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); | |
bb6c5e3c | 86 | g_test_add_data_func(path, mname, test_machine); |
5c1904f1 MA |
87 | } |
88 | } | |
89 | qtest_end(); | |
7c41f217 AF |
90 | } |
91 | ||
7c41f217 AF |
92 | int main(int argc, char **argv) |
93 | { | |
7c41f217 AF |
94 | g_test_init(&argc, &argv, NULL); |
95 | ||
5c1904f1 | 96 | add_machine_test_cases(); |
7c41f217 AF |
97 | |
98 | return g_test_run(); | |
99 | } |