4 * Copyright (c) 2022 Red Hat, Inc.
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.
10 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "qapi/qapi-visit-machine.h"
14 #include "qapi/qapi-visit-qom.h"
15 #include "qapi/qapi-visit-ui.h"
16 #include "qapi/qmp/qdict.h"
17 #include "qapi/qmp/qlist.h"
18 #include "qapi/qobject-input-visitor.h"
19 #include "qapi/qmp/qstring.h"
20 #include "qemu/units.h"
22 static QTestState
*qtest_init_with_config(const char *cfgdata
)
25 g_autofree
char *args
= NULL
;
27 g_autofree
char *cfgpath
= NULL
;
31 cfgfd
= g_file_open_tmp("readconfig-test-XXXXXX", &cfgpath
, &error
);
32 g_assert_no_error(error
);
33 g_assert_cmpint(cfgfd
, >=, 0);
35 ret
= qemu_write_full(cfgfd
, cfgdata
, strlen(cfgdata
));
40 g_assert_cmpint(ret
, ==, strlen(cfgdata
));
42 args
= g_strdup_printf("-nodefaults -machine none -readconfig %s", cfgpath
);
44 qts
= qtest_init(args
);
51 static void test_x86_memdev_resp(QObject
*res
)
54 g_autoptr(MemdevList
) memdevs
= NULL
;
58 v
= qobject_input_visitor_new(res
);
59 visit_type_MemdevList(v
, NULL
, &memdevs
, &error_abort
);
62 g_assert(memdevs
->value
);
63 g_assert(!memdevs
->next
);
65 memdev
= memdevs
->value
;
66 g_assert_cmpstr(memdev
->id
, ==, "ram");
67 g_assert_cmpint(memdev
->size
, ==, 200 * MiB
);
72 static void test_x86_memdev(void)
80 qts
= qtest_init_with_config(cfgdata
);
81 /* Test valid command */
82 resp
= qtest_qmp(qts
, "{ 'execute': 'query-memdev' }");
83 test_x86_memdev_resp(qdict_get(resp
, "return"));
91 static void test_spice_resp(QObject
*res
)
94 g_autoptr(SpiceInfo
) spice
= NULL
;
97 v
= qobject_input_visitor_new(res
);
98 visit_type_SpiceInfo(v
, "spice", &spice
, &error_abort
);
101 g_assert(spice
->enabled
);
106 static void test_spice(void)
110 const char *cfgdata
=
115 "disable-ticketing = \"on\"\n";
117 qts
= qtest_init_with_config(cfgdata
);
118 /* Test valid command */
119 resp
= qtest_qmp(qts
, "{ 'execute': 'query-spice' }");
120 test_spice_resp(qdict_get(resp
, "return"));
127 static void test_object_rng_resp(QObject
*res
)
130 g_autoptr(ObjectPropertyInfoList
) objs
= NULL
;
131 ObjectPropertyInfoList
*tmp
;
132 ObjectPropertyInfo
*obj
;
133 bool seen_rng
= false;
136 v
= qobject_input_visitor_new(res
);
137 visit_type_ObjectPropertyInfoList(v
, NULL
, &objs
, &error_abort
);
142 g_assert(tmp
->value
);
145 if (g_str_equal(obj
->name
, "rng0") &&
146 g_str_equal(obj
->type
, "child<rng-builtin>")) {
159 static void test_object_rng(void)
163 const char *cfgdata
=
165 "qom-type = \"rng-builtin\"\n"
168 qts
= qtest_init_with_config(cfgdata
);
169 /* Test valid command */
170 resp
= qtest_qmp(qts
,
171 "{ 'execute': 'qom-list',"
172 " 'arguments': {'path': '/objects' }}");
173 test_object_rng_resp(qdict_get(resp
, "return"));
179 int main(int argc
, char *argv
[])
182 g_test_init(&argc
, &argv
, NULL
);
184 arch
= qtest_get_arch();
186 if (g_str_equal(arch
, "i386") ||
187 g_str_equal(arch
, "x86_64")) {
188 qtest_add_func("readconfig/x86/memdev", test_x86_memdev
);
191 qtest_add_func("readconfig/spice", test_spice
);
194 qtest_add_func("readconfig/object-rng", test_object_rng
);