qemu-ga: isa-serial support on Windows
[qemu.git] / tests / qom-test.c
blobb6671fbec3f31522b5369e36e4d614b98437bd82
1 /*
2 * QTest testcase for QOM
4 * Copyright (c) 2013 SUSE LINUX Products GmbH
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 */
10 #include <glib.h>
11 #include <string.h>
13 #include "libqtest.h"
14 #include "qemu/osdep.h"
15 #include "qapi/qmp/types.h"
17 static const char *blacklist_x86[] = {
18 "xenfv", "xenpv", NULL
21 static const struct {
22 const char *arch;
23 const char **machine;
24 } blacklists[] = {
25 { "i386", blacklist_x86 },
26 { "x86_64", blacklist_x86 },
29 static bool is_blacklisted(const char *arch, const char *mach)
31 int i;
32 const char **p;
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;
43 return false;
46 static void test_machine(gconstpointer data)
48 const char *machine = data;
49 char *args;
50 QDict *response;
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);
60 static void add_machine_test_cases(void)
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;
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);
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);
89 qtest_end();
92 int main(int argc, char **argv)
94 g_test_init(&argc, &argv, NULL);
96 add_machine_test_cases();
98 return g_test_run();