aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2017-05-09 15:49:08 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2017-05-09 15:49:14 -0400
commit76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb (patch)
treebcb0e4a8f29bdcfa0f5785a09608bff57a82107c /tests
parent7ed57b66221b5a3e23b3519824637b297dc92090 (diff)
parentdcd3b25d656d346205dc0f2254723fccf0264e45 (diff)
Merge remote-tracking branch 'armbru/tags/pull-qapi-2017-05-04-v3' into staging
QAPI patches for 2017-05-04 # gpg: Signature made Tue 09 May 2017 03:16:12 AM EDT # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * armbru/tags/pull-qapi-2017-05-04-v3: (28 commits) qmp-shell: improve help qmp-shell: don't show version greeting if unavailable qmp-shell: Cope with query-commands error qmp-shell: add -N option to skip negotiate qmp-shell: add persistent command history qobject-input-visitor: Catch misuse of end_struct vs. end_list qapi: Document intended use of @name within alternate visits qobject-input-visitor: Document full_name_nth() qmp: Improve QMP dispatch error messages sockets: Delete unused helper socket_address_crumple() sockets: Limit SocketAddressLegacy to external interfaces sockets: Rename SocketAddressFlat to SocketAddress sockets: Rename SocketAddress to SocketAddressLegacy qapi: New QAPI_CLONE_MEMBERS() sockets: Prepare inet_parse() for flattened SocketAddress sockets: Prepare vsock_parse() for flattened SocketAddress test-qga: Actually test 0xff sync bytes fdc-test: Avoid deprecated 'change' command QemuOpts: Simplify qemu_opts_to_qdict() block: Simplify bdrv_append_temp_snapshot() logic ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/check-qdict.c144
-rw-r--r--tests/check-qlist.c4
-rw-r--r--tests/device-introspect-test.c4
-rw-r--r--tests/fdc-test.c8
-rw-r--r--tests/libqtest.c8
-rw-r--r--tests/test-char.c5
-rw-r--r--tests/test-io-channel-socket.c52
-rw-r--r--tests/test-keyval.c4
-rw-r--r--tests/test-qemu-opts.c4
-rw-r--r--tests/test-qga.c41
-rw-r--r--tests/test-qmp-commands.c30
-rw-r--r--tests/test-qmp-event.c30
-rw-r--r--tests/test-qobject-output-visitor.c6
13 files changed, 185 insertions, 155 deletions
diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 81162ee572..be8d81f07b 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -47,7 +47,7 @@ static void qdict_put_obj_test(void)
qdict = qdict_new();
// key "" will have tdb hash 12345
- qdict_put_obj(qdict, "", QOBJECT(qint_from_int(num)));
+ qdict_put_int(qdict, "", num);
g_assert(qdict_size(qdict) == 1);
ent = QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]);
@@ -66,8 +66,8 @@ static void qdict_destroy_simple_test(void)
QDict *qdict;
qdict = qdict_new();
- qdict_put_obj(qdict, "num", QOBJECT(qint_from_int(0)));
- qdict_put_obj(qdict, "str", QOBJECT(qstring_from_str("foo")));
+ qdict_put_int(qdict, "num", 0);
+ qdict_put_str(qdict, "str", "foo");
QDECREF(qdict);
}
@@ -80,7 +80,7 @@ static void qdict_get_test(void)
const char *key = "test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
obj = qdict_get(tests_dict, key);
g_assert(obj != NULL);
@@ -98,7 +98,7 @@ static void qdict_get_int_test(void)
const char *key = "int";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
ret = qdict_get_int(tests_dict, key);
g_assert(ret == value);
@@ -113,7 +113,7 @@ static void qdict_get_try_int_test(void)
const char *key = "int";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(value));
+ qdict_put_int(tests_dict, key, value);
ret = qdict_get_try_int(tests_dict, key, 0);
g_assert(ret == value);
@@ -128,7 +128,7 @@ static void qdict_get_str_test(void)
const char *str = "string";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str(str));
+ qdict_put_str(tests_dict, key, str);
p = qdict_get_str(tests_dict, key);
g_assert(p != NULL);
@@ -144,7 +144,7 @@ static void qdict_get_try_str_test(void)
const char *str = "string";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str(str));
+ qdict_put_str(tests_dict, key, str);
p = qdict_get_try_str(tests_dict, key);
g_assert(p != NULL);
@@ -188,7 +188,7 @@ static void qdict_haskey_test(void)
const char *key = "test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(0));
+ qdict_put_int(tests_dict, key, 0);
g_assert(qdict_haskey(tests_dict, key) == 1);
QDECREF(tests_dict);
@@ -199,7 +199,7 @@ static void qdict_del_test(void)
const char *key = "key test";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qstring_from_str("foo"));
+ qdict_put_str(tests_dict, key, "foo");
g_assert(qdict_size(tests_dict) == 1);
qdict_del(tests_dict, key);
@@ -226,9 +226,9 @@ static void qdict_iterapi_test(void)
g_assert(qdict_first(tests_dict) == NULL);
- qdict_put(tests_dict, "key1", qint_from_int(1));
- qdict_put(tests_dict, "key2", qint_from_int(2));
- qdict_put(tests_dict, "key3", qint_from_int(3));
+ qdict_put_int(tests_dict, "key1", 1);
+ qdict_put_int(tests_dict, "key2", 2);
+ qdict_put_int(tests_dict, "key3", 3);
count = 0;
for (ent = qdict_first(tests_dict); ent; ent = qdict_next(tests_dict, ent)){
@@ -294,20 +294,20 @@ static void qdict_flatten_test(void)
* }
*/
- qdict_put(dict1, "a", qint_from_int(0));
- qdict_put(dict1, "b", qint_from_int(1));
+ qdict_put_int(dict1, "a", 0);
+ qdict_put_int(dict1, "b", 1);
- qlist_append_obj(list1, QOBJECT(qint_from_int(23)));
- qlist_append_obj(list1, QOBJECT(qint_from_int(66)));
- qlist_append_obj(list1, QOBJECT(dict1));
- qlist_append_obj(list2, QOBJECT(qint_from_int(42)));
- qlist_append_obj(list2, QOBJECT(list1));
+ qlist_append_int(list1, 23);
+ qlist_append_int(list1, 66);
+ qlist_append(list1, dict1);
+ qlist_append_int(list2, 42);
+ qlist_append(list2, list1);
- qdict_put(dict2, "c", qint_from_int(2));
- qdict_put(dict2, "d", qint_from_int(3));
- qdict_put_obj(dict3, "e", QOBJECT(list2));
- qdict_put_obj(dict3, "f", QOBJECT(dict2));
- qdict_put(dict3, "g", qint_from_int(4));
+ qdict_put_int(dict2, "c", 2);
+ qdict_put_int(dict2, "d", 3);
+ qdict_put(dict3, "e", list2);
+ qdict_put(dict3, "f", dict2);
+ qdict_put_int(dict3, "g", 4);
qdict_flatten(dict3);
@@ -369,12 +369,12 @@ static void qdict_array_split_test(void)
* This example is given in the comment of qdict_array_split().
*/
- qdict_put(test_dict, "1.x", qint_from_int(0));
- qdict_put(test_dict, "4.y", qint_from_int(1));
- qdict_put(test_dict, "0.a", qint_from_int(42));
- qdict_put(test_dict, "o.o", qint_from_int(7));
- qdict_put(test_dict, "0.b", qint_from_int(23));
- qdict_put(test_dict, "2", qint_from_int(66));
+ qdict_put_int(test_dict, "1.x", 0);
+ qdict_put_int(test_dict, "4.y", 1);
+ qdict_put_int(test_dict, "0.a", 42);
+ qdict_put_int(test_dict, "o.o", 7);
+ qdict_put_int(test_dict, "0.b", 23);
+ qdict_put_int(test_dict, "2", 66);
qdict_array_split(test_dict, &test_list);
@@ -441,9 +441,9 @@ static void qdict_array_split_test(void)
test_dict = qdict_new();
- qdict_put(test_dict, "0", qint_from_int(42));
- qdict_put(test_dict, "1", qint_from_int(23));
- qdict_put(test_dict, "1.x", qint_from_int(84));
+ qdict_put_int(test_dict, "0", 42);
+ qdict_put_int(test_dict, "1", 23);
+ qdict_put_int(test_dict, "1.x", 84);
qdict_array_split(test_dict, &test_list);
@@ -472,38 +472,38 @@ static void qdict_array_entries_test(void)
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
- qdict_put(dict, "bar", qint_from_int(0));
- qdict_put(dict, "baz.0", qint_from_int(0));
+ qdict_put_int(dict, "bar", 0);
+ qdict_put_int(dict, "baz.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
- qdict_put(dict, "foo.1", qint_from_int(0));
+ qdict_put_int(dict, "foo.1", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
- qdict_put(dict, "foo.0", qint_from_int(0));
+ qdict_put_int(dict, "foo.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2);
- qdict_put(dict, "foo.bar", qint_from_int(0));
+ qdict_put_int(dict, "foo.bar", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_del(dict, "foo.bar");
- qdict_put(dict, "foo.2.a", qint_from_int(0));
- qdict_put(dict, "foo.2.b", qint_from_int(0));
- qdict_put(dict, "foo.2.c", qint_from_int(0));
+ qdict_put_int(dict, "foo.2.a", 0);
+ qdict_put_int(dict, "foo.2.b", 0);
+ qdict_put_int(dict, "foo.2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
QDECREF(dict);
dict = qdict_new();
- qdict_put(dict, "1", qint_from_int(0));
+ qdict_put_int(dict, "1", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
- qdict_put(dict, "0", qint_from_int(0));
+ qdict_put_int(dict, "0", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2);
- qdict_put(dict, "bar", qint_from_int(0));
+ qdict_put_int(dict, "bar", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_del(dict, "bar");
- qdict_put(dict, "2.a", qint_from_int(0));
- qdict_put(dict, "2.b", qint_from_int(0));
- qdict_put(dict, "2.c", qint_from_int(0));
+ qdict_put_int(dict, "2.a", 0);
+ qdict_put_int(dict, "2.b", 0);
+ qdict_put_int(dict, "2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
QDECREF(dict);
@@ -529,7 +529,7 @@ static void qdict_join_test(void)
/* First iteration: Test movement */
/* Second iteration: Test empty source and non-empty destination */
- qdict_put(dict2, "foo", qint_from_int(42));
+ qdict_put_int(dict2, "foo", 42);
for (i = 0; i < 2; i++) {
qdict_join(dict1, dict2, overwrite);
@@ -541,7 +541,7 @@ static void qdict_join_test(void)
}
/* Test non-empty source and destination without conflict */
- qdict_put(dict2, "bar", qint_from_int(23));
+ qdict_put_int(dict2, "bar", 23);
qdict_join(dict1, dict2, overwrite);
@@ -552,14 +552,14 @@ static void qdict_join_test(void)
g_assert(qdict_get_int(dict1, "bar") == 23);
/* Test conflict */
- qdict_put(dict2, "foo", qint_from_int(84));
+ qdict_put_int(dict2, "foo", 84);
qdict_join(dict1, dict2, overwrite);
g_assert(qdict_size(dict1) == 2);
g_assert(qdict_size(dict2) == !overwrite);
- g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
+ g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42));
g_assert(qdict_get_int(dict1, "bar") == 23);
if (!overwrite) {
@@ -594,15 +594,15 @@ static void qdict_crumple_test_recursive(void)
QList *rules;
src = qdict_new();
- qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1"));
- qdict_put(src, "vnc.listen.port", qstring_from_str("5901"));
- qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred"));
- qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow"));
- qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob"));
- qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny"));
- qdict_put(src, "vnc.acl.default", qstring_from_str("deny"));
- qdict_put(src, "vnc.acl..name", qstring_from_str("acl0"));
- qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0"));
+ qdict_put_str(src, "vnc.listen.addr", "127.0.0.1");
+ qdict_put_str(src, "vnc.listen.port", "5901");
+ qdict_put_str(src, "vnc.acl.rules.0.match", "fred");
+ qdict_put_str(src, "vnc.acl.rules.0.policy", "allow");
+ qdict_put_str(src, "vnc.acl.rules.1.match", "bob");
+ qdict_put_str(src, "vnc.acl.rules.1.policy", "deny");
+ qdict_put_str(src, "vnc.acl.default", "deny");
+ qdict_put_str(src, "vnc.acl..name", "acl0");
+ qdict_put_str(src, "vnc.acl.rule..name", "acl0");
dst = qobject_to_qdict(qdict_crumple(src, &error_abort));
g_assert(dst);
@@ -669,8 +669,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* rule.0 can't be both a string and a dict */
- qdict_put(src, "rule.0", qstring_from_str("fred"));
- qdict_put(src, "rule.0.policy", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "fred");
+ qdict_put_str(src, "rule.0.policy", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -680,8 +680,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* rule can't be both a list and a dict */
- qdict_put(src, "rule.0", qstring_from_str("fred"));
- qdict_put(src, "rule.a", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "fred");
+ qdict_put_str(src, "rule.a", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -692,7 +692,7 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* The input should be flat, ie no dicts or lists */
qdict_put(src, "rule.a", qdict_new());
- qdict_put(src, "rule.b", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.b", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -702,8 +702,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* List indexes must not have gaps */
- qdict_put(src, "rule.0", qstring_from_str("deny"));
- qdict_put(src, "rule.3", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "deny");
+ qdict_put_str(src, "rule.3", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -713,8 +713,8 @@ static void qdict_crumple_test_bad_inputs(void)
src = qdict_new();
/* List indexes must be in %zu format */
- qdict_put(src, "rule.0", qstring_from_str("deny"));
- qdict_put(src, "rule.+1", qstring_from_str("allow"));
+ qdict_put_str(src, "rule.0", "deny");
+ qdict_put_str(src, "rule.+1", "allow");
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
@@ -733,8 +733,8 @@ static void qdict_put_exists_test(void)
const char *key = "exists";
QDict *tests_dict = qdict_new();
- qdict_put(tests_dict, key, qint_from_int(1));
- qdict_put(tests_dict, key, qint_from_int(2));
+ qdict_put_int(tests_dict, key, 1);
+ qdict_put_int(tests_dict, key, 2);
value = qdict_get_int(tests_dict, key);
g_assert(value == 2);
diff --git a/tests/check-qlist.c b/tests/check-qlist.c
index e16da5e5c6..4983867c27 100644
--- a/tests/check-qlist.c
+++ b/tests/check-qlist.c
@@ -74,7 +74,7 @@ static void qlist_destroy_test(void)
qlist = qlist_new();
for (i = 0; i < 42; i++)
- qlist_append(qlist, qint_from_int(i));
+ qlist_append_int(qlist, i);
QDECREF(qlist);
}
@@ -103,7 +103,7 @@ static void qlist_iter_test(void)
qlist = qlist_new();
for (i = 0; i < iter_max; i++)
- qlist_append(qlist, qint_from_int(i));
+ qlist_append_int(qlist, i);
iter_called = 0;
qlist_iter(qlist, iter_func, NULL);
diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index c5637cc406..b1abb2ad89 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -32,9 +32,9 @@ static QList *qom_list_types(const char *implements, bool abstract)
QList *ret;
QDict *args = qdict_new();
- qdict_put(args, "abstract", qbool_from_bool(abstract));
+ qdict_put_bool(args, "abstract", abstract);
if (implements) {
- qdict_put(args, "implements", qstring_from_str(implements));
+ qdict_put_str(args, "implements", implements);
}
resp = qmp("{'execute': 'qom-list-types',"
" 'arguments': %p }", args);
diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 738c6b4a5e..325712e0f2 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -298,8 +298,8 @@ static void test_media_insert(void)
/* Insert media in drive. DSKCHK should not be reset until a step pulse
* is sent. */
- qmp_discard_response("{'execute':'change', 'arguments':{"
- " 'device':'floppy0', 'target': %s, 'arg': 'raw' }}",
+ qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments':{"
+ " 'id':'floppy0', 'filename': %s, 'format': 'raw' }}",
test_image);
dir = inb(FLOPPY_BASE + reg_dir);
@@ -330,7 +330,7 @@ static void test_media_change(void)
/* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
* reset the bit. */
qmp_discard_response("{'execute':'eject', 'arguments':{"
- " 'device':'floppy0' }}");
+ " 'id':'floppy0' }}");
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
@@ -564,7 +564,7 @@ int main(int argc, char **argv)
/* Run the tests */
g_test_init(&argc, &argv, NULL);
- qtest_start(NULL);
+ qtest_start("-device floppy,id=floppy0");
qtest_irq_intercept_in(global_qtest, "ioapic");
qtest_add_func("/fdc/cmos", test_cmos);
qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 512c150266..84ecbd2bd8 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -446,6 +446,14 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
va_list ap_copy;
QObject *qobj;
+ /* qobject_from_jsonv() silently eats leading 0xff as invalid
+ * JSON, but we want to test sending them over the wire to force
+ * resyncs */
+ if (*fmt == '\377') {
+ socket_send(fd, fmt, 1);
+ fmt++;
+ }
+
/* Going through qobject ensures we escape strings properly.
* This seemingly unnecessary copy is required in case va_list
* is an array type.
diff --git a/tests/test-char.c b/tests/test-char.c
index 773a1c36ba..124d0c5439 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -291,7 +291,7 @@ static void char_socket_test(void)
Chardev *chr = qemu_chr_new("server", "tcp:127.0.0.1:0,server,nowait");
Chardev *chr_client;
QObject *addr;
- QDict *qdict, *data;
+ QDict *qdict;
const char *port;
SocketIdleData d = { .chr = chr };
CharBackend be;
@@ -306,8 +306,7 @@ static void char_socket_test(void)
addr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort);
qdict = qobject_to_qdict(addr);
- data = qdict_get_qdict(qdict, "data");
- port = qdict_get_str(data, "port");
+ port = qdict_get_str(qdict, "port");
tmp = g_strdup_printf("tcp:127.0.0.1:%s", port);
QDECREF(qdict);
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index c5c131479c..d357cd2a8e 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -125,12 +125,12 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr,
lioc = qio_channel_socket_new();
qio_channel_socket_listen_sync(lioc, listen_addr, &error_abort);
- if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) {
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
qapi_free_SocketAddress(laddr);
}
@@ -186,12 +186,12 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr,
g_assert(!data.err);
- if (listen_addr->type == SOCKET_ADDRESS_KIND_INET) {
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
qapi_free_SocketAddress(laddr);
}
@@ -300,16 +300,14 @@ static void test_io_channel_ipv4(bool async)
SocketAddress *listen_addr = g_new0(SocketAddress, 1);
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Filled in later */
};
@@ -338,16 +336,14 @@ static void test_io_channel_ipv6(bool async)
SocketAddress *listen_addr = g_new0(SocketAddress, 1);
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Filled in later */
};
@@ -378,13 +374,11 @@ static void test_io_channel_unix(bool async)
SocketAddress *connect_addr = g_new0(SocketAddress, 1);
#define TEST_SOCKET "test-io-channel-socket.sock"
- listen_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel(async, listen_addr, connect_addr, true);
@@ -427,13 +421,11 @@ static void test_io_channel_unix_fd_pass(void)
fdsend[1] = testfd;
fdsend[2] = testfd;
- listen_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
diff --git a/tests/test-keyval.c b/tests/test-keyval.c
index ba19560a22..c556b1b117 100644
--- a/tests/test-keyval.c
+++ b/tests/test-keyval.c
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
visit_type_AltNumStr(v, "a", &ans, &error_abort);
g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
g_assert_cmpstr(ans->u.s, ==, "1");
+ qapi_free_AltNumStr(ans);
visit_type_AltNumInt(v, "a", &ani, &err);
error_free_or_abort(&err);
visit_end_struct(v, NULL);
@@ -651,9 +652,12 @@ static void test_keyval_visit_any(void)
g_assert(qlist);
qstr = qobject_to_qstring(qlist_pop(qlist));
g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+ QDECREF(qstr);
qstr = qobject_to_qstring(qlist_pop(qlist));
g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
g_assert(qlist_empty(qlist));
+ QDECREF(qstr);
+ qobject_decref(any);
visit_check_struct(v, &error_abort);
visit_end_struct(v, NULL);
visit_free(v);
diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c
index 0ad74b464f..cc1bb1afdf 100644
--- a/tests/test-qemu-opts.c
+++ b/tests/test-qemu-opts.c
@@ -299,7 +299,7 @@ static void test_qemu_opt_get_size(void)
dict = qdict_new();
g_assert(dict != NULL);
- qdict_put(dict, "size1", qstring_from_str("10"));
+ qdict_put_str(dict, "size1", "10");
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
@@ -309,7 +309,7 @@ static void test_qemu_opt_get_size(void)
g_assert(opt == 10);
/* reset value */
- qdict_put(dict, "size1", qstring_from_str("15"));
+ qdict_put_str(dict, "size1", "15");
qemu_opts_absorb_qdict(opts, dict, &error_abort);
g_assert(error_abort == NULL);
diff --git a/tests/test-qga.c b/tests/test-qga.c
index c780f0079a..c77f241036 100644
--- a/tests/test-qga.c
+++ b/tests/test-qga.c
@@ -146,14 +146,30 @@ static void test_qga_sync_delimited(gconstpointer fix)
QDict *ret;
gchar *cmd;
- cmd = g_strdup_printf("%c{'execute': 'guest-sync-delimited',"
- " 'arguments': {'id': %u } }", 0xff, r);
+ cmd = g_strdup_printf("\xff{'execute': 'guest-sync-delimited',"
+ " 'arguments': {'id': %u } }", r);
qmp_fd_send(fixture->fd, cmd);
g_free(cmd);
- v = read(fixture->fd, &c, 1);
- g_assert_cmpint(v, ==, 1);
- g_assert_cmpint(c, ==, 0xff);
+ /*
+ * Read and ignore garbage until resynchronized.
+ *
+ * Note that the full reset sequence would involve checking the
+ * response of guest-sync-delimited and repeating the loop if
+ * 'id' field of the response does not match the 'id' field of
+ * the request. Testing this fully would require inserting
+ * garbage in the response stream and is left as a future test
+ * to implement.
+ *
+ * TODO: The server shouldn't emit so much garbage (among other
+ * things, it loudly complains about the client's \xff being
+ * invalid JSON, even though it is a documented part of the
+ * handshake.
+ */
+ do {
+ v = read(fixture->fd, &c, 1);
+ g_assert_cmpint(v, ==, 1);
+ } while (c != 0xff);
ret = qmp_fd_receive(fixture->fd);
g_assert_nonnull(ret);
@@ -172,8 +188,19 @@ static void test_qga_sync(gconstpointer fix)
QDict *ret;
gchar *cmd;
- cmd = g_strdup_printf("%c{'execute': 'guest-sync',"
- " 'arguments': {'id': %u } }", 0xff, r);
+ /*
+ * TODO guest-sync is inherently limited: we cannot distinguish
+ * failure caused by reacting to garbage on the wire prior to this
+ * command, from failure of this actual command. Clients are
+ * supposed to be able to send a raw '\xff' byte to at least
+ * re-synchronize the server's parser prior to this command, but
+ * we are not in a position to test that here because (at least
+ * for now) it causes the server to issue an error message about
+ * invalid JSON. Testing of '\xff' handling is done in
+ * guest-sync-delimited instead.
+ */
+ cmd = g_strdup_printf("{'execute': 'guest-sync',"
+ " 'arguments': {'id': %u } }", r);
ret = qmp_fd(fixture->fd, cmd);
g_free(cmd);
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index 0f81a98be2..acdded4d67 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -94,7 +94,7 @@ static void test_dispatch_cmd(void)
QDict *req = qdict_new();
QObject *resp;
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
+ qdict_put_str(req, "execute", "user_def_cmd");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -111,7 +111,7 @@ static void test_dispatch_cmd_failure(void)
QDict *args = qdict_new();
QObject *resp;
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
+ qdict_put_str(req, "execute", "user_def_cmd2");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -122,10 +122,10 @@ static void test_dispatch_cmd_failure(void)
/* check that with extra arguments it throws an error */
req = qdict_new();
- qdict_put(args, "a", qint_from_int(66));
+ qdict_put_int(args, "a", 66);
qdict_put(req, "arguments", args);
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
+ qdict_put_str(req, "execute", "user_def_cmd");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
@@ -164,14 +164,14 @@ static void test_dispatch_cmd_io(void)
QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
QInt *ret3;
- qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42)));
- qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello")));
- qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422)));
- qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2")));
- qdict_put_obj(args, "ud1a", QOBJECT(ud1a));
- qdict_put_obj(args, "ud1b", QOBJECT(ud1b));
- qdict_put_obj(req, "arguments", QOBJECT(args));
- qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
+ qdict_put_int(ud1a, "integer", 42);
+ qdict_put_str(ud1a, "string", "hello");
+ qdict_put_int(ud1b, "integer", 422);
+ qdict_put_str(ud1b, "string", "hello2");
+ qdict_put(args, "ud1a", ud1a);
+ qdict_put(args, "ud1b", ud1b);
+ qdict_put(req, "arguments", args);
+ qdict_put_str(req, "execute", "user_def_cmd2");
ret = qobject_to_qdict(test_qmp_dispatch(req));
@@ -190,9 +190,9 @@ static void test_dispatch_cmd_io(void)
assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4"));
QDECREF(ret);
- qdict_put(args3, "a", qint_from_int(66));
+ qdict_put_int(args3, "a", 66);
qdict_put(req, "arguments", args3);
- qdict_put(req, "execute", qstring_from_str("guest-get-time"));
+ qdict_put_str(req, "execute", "guest-get-time");
ret3 = qobject_to_qint(test_qmp_dispatch(req));
assert(qint_get_int(ret3) == 66);
@@ -244,7 +244,7 @@ static void test_dealloc_partial(void)
Visitor *v;
ud2_dict = qdict_new();
- qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
+ qdict_put_str(ud2_dict, "string0", text);
v = qobject_input_visitor_new(QOBJECT(ud2_dict));
visit_type_UserDefTwo(v, NULL, &ud2, &err);
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index 7bb621b027..4c0f09601d 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -153,7 +153,7 @@ static void test_event_a(TestEventData *data,
{
QDict *d;
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_A"));
+ qdict_put_str(d, "event", "EVENT_A");
qapi_event_send_event_a(&error_abort);
}
@@ -162,7 +162,7 @@ static void test_event_b(TestEventData *data,
{
QDict *d;
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_B"));
+ qdict_put_str(d, "event", "EVENT_B");
qapi_event_send_event_b(&error_abort);
}
@@ -177,16 +177,16 @@ static void test_event_c(TestEventData *data,
b.has_enum1 = false;
d_b = qdict_new();
- qdict_put(d_b, "integer", qint_from_int(2));
- qdict_put(d_b, "string", qstring_from_str("test1"));
+ qdict_put_int(d_b, "integer", 2);
+ qdict_put_str(d_b, "string", "test1");
d_data = qdict_new();
- qdict_put(d_data, "a", qint_from_int(1));
+ qdict_put_int(d_data, "a", 1);
qdict_put(d_data, "b", d_b);
- qdict_put(d_data, "c", qstring_from_str("test2"));
+ qdict_put_str(d_data, "c", "test2");
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_C"));
+ qdict_put_str(d, "event", "EVENT_C");
qdict_put(d, "data", d_data);
qapi_event_send_event_c(true, 1, true, &b, "test2", &error_abort);
@@ -213,22 +213,22 @@ static void test_event_d(TestEventData *data,
a.enum2 = ENUM_ONE_VALUE2;
d_struct1 = qdict_new();
- qdict_put(d_struct1, "integer", qint_from_int(2));
- qdict_put(d_struct1, "string", qstring_from_str("test1"));
- qdict_put(d_struct1, "enum1", qstring_from_str("value1"));
+ qdict_put_int(d_struct1, "integer", 2);
+ qdict_put_str(d_struct1, "string", "test1");
+ qdict_put_str(d_struct1, "enum1", "value1");
d_a = qdict_new();
qdict_put(d_a, "struct1", d_struct1);
- qdict_put(d_a, "string", qstring_from_str("test2"));
- qdict_put(d_a, "enum2", qstring_from_str("value2"));
+ qdict_put_str(d_a, "string", "test2");
+ qdict_put_str(d_a, "enum2", "value2");
d_data = qdict_new();
qdict_put(d_data, "a", d_a);
- qdict_put(d_data, "b", qstring_from_str("test3"));
- qdict_put(d_data, "enum3", qstring_from_str("value3"));
+ qdict_put_str(d_data, "b", "test3");
+ qdict_put_str(d_data, "enum3", "value3");
d = data->expect;
- qdict_put(d, "event", qstring_from_str("EVENT_D"));
+ qdict_put_str(d, "event", "EVENT_D");
qdict_put(d, "data", d_data);
qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE3,
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index c213fceeb3..94b9518e40 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -343,9 +343,9 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
visitor_reset(data);
qdict = qdict_new();
- qdict_put(qdict, "integer", qint_from_int(-42));
- qdict_put(qdict, "boolean", qbool_from_bool(true));
- qdict_put(qdict, "string", qstring_from_str("foo"));
+ qdict_put_int(qdict, "integer", -42);
+ qdict_put_bool(qdict, "boolean", true);
+ qdict_put_str(qdict, "string", "foo");
qobj = QOBJECT(qdict);
visit_type_any(data->ov, NULL, &qobj, &error_abort);
qobject_decref(qobj);