diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/acpi-utils.h | 10 | ||||
-rw-r--r-- | tests/bios-tables-test.c | 23 | ||||
-rw-r--r-- | tests/check-qdict.c | 144 | ||||
-rw-r--r-- | tests/check-qlist.c | 4 | ||||
-rw-r--r-- | tests/device-introspect-test.c | 4 | ||||
-rw-r--r-- | tests/fdc-test.c | 8 | ||||
-rw-r--r-- | tests/libqtest.c | 8 | ||||
-rw-r--r-- | tests/test-char.c | 365 | ||||
-rw-r--r-- | tests/test-crypto-block.c | 6 | ||||
-rw-r--r-- | tests/test-io-channel-socket.c | 52 | ||||
-rw-r--r-- | tests/test-keyval.c | 4 | ||||
-rw-r--r-- | tests/test-qemu-opts.c | 4 | ||||
-rw-r--r-- | tests/test-qga.c | 41 | ||||
-rw-r--r-- | tests/test-qmp-commands.c | 30 | ||||
-rw-r--r-- | tests/test-qmp-event.c | 30 | ||||
-rw-r--r-- | tests/test-qobject-output-visitor.c | 6 | ||||
-rw-r--r-- | tests/vhost-user-test.c | 2 |
17 files changed, 575 insertions, 166 deletions
diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index 348e4d7931..f8d87236c6 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -87,6 +87,16 @@ typedef struct { g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ } while (0) +#define ACPI_READ_GENERIC_ADDRESS(field, addr) \ + do { \ + ACPI_READ_FIELD((field).space_id, addr); \ + ACPI_READ_FIELD((field).bit_width, addr); \ + ACPI_READ_FIELD((field).bit_offset, addr); \ + ACPI_READ_FIELD((field).access_width, addr); \ + ACPI_READ_FIELD((field).address, addr); \ + } while (0); + + uint8_t acpi_calc_checksum(const uint8_t *data, int len); uint32_t acpi_find_rsdp_address(void); void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table); diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 88dbf97853..9c96a67053 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -29,7 +29,7 @@ typedef struct { uint32_t rsdp_addr; AcpiRsdpDescriptor rsdp_table; AcpiRsdtDescriptorRev1 rsdt_table; - AcpiFadtDescriptorRev1 fadt_table; + AcpiFadtDescriptorRev3 fadt_table; AcpiFacsDescriptorRev1 facs_table; uint32_t *rsdt_tables_addr; int rsdt_tables_nr; @@ -126,7 +126,7 @@ static void test_acpi_rsdt_table(test_data *data) static void test_acpi_fadt_table(test_data *data) { - AcpiFadtDescriptorRev1 *fadt_table = &data->fadt_table; + AcpiFadtDescriptorRev3 *fadt_table = &data->fadt_table; uint32_t addr; /* FADT table comes first */ @@ -168,10 +168,23 @@ static void test_acpi_fadt_table(test_data *data) ACPI_READ_FIELD(fadt_table->day_alrm, addr); ACPI_READ_FIELD(fadt_table->mon_alrm, addr); ACPI_READ_FIELD(fadt_table->century, addr); - ACPI_READ_FIELD(fadt_table->reserved4, addr); - ACPI_READ_FIELD(fadt_table->reserved4a, addr); - ACPI_READ_FIELD(fadt_table->reserved4b, addr); + ACPI_READ_FIELD(fadt_table->boot_flags, addr); + ACPI_READ_FIELD(fadt_table->reserved, addr); ACPI_READ_FIELD(fadt_table->flags, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->reset_register, addr); + ACPI_READ_FIELD(fadt_table->reset_value, addr); + ACPI_READ_FIELD(fadt_table->arm_boot_flags, addr); + ACPI_READ_FIELD(fadt_table->minor_revision, addr); + ACPI_READ_FIELD(fadt_table->Xfacs, addr); + ACPI_READ_FIELD(fadt_table->Xdsdt, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_event_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_event_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1a_control_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm1b_control_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm2_control_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xpm_timer_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe0_block, addr); + ACPI_READ_GENERIC_ADDRESS(fadt_table->xgpe1_block, addr); ACPI_ASSERT_CMP(fadt_table->signature, "FACP"); g_assert(!acpi_calc_checksum((uint8_t *)fadt_table, fadt_table->length)); 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 da69f110e4..124d0c5439 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -1,18 +1,35 @@ #include "qemu/osdep.h" +#include <glib/gstdio.h> #include "qemu-common.h" #include "qemu/config-file.h" +#include "qemu/sockets.h" #include "sysemu/char.h" #include "sysemu/sysemu.h" #include "qapi/error.h" +#include "qom/qom-qobject.h" #include "qmp-commands.h" +static bool quit; + typedef struct FeHandler { int read_count; int last_event; char read_buf[128]; } FeHandler; +static void main_loop(void) +{ + bool nonblocking; + int last_io = 0; + + quit = false; + do { + nonblocking = last_io > 0; + last_io = main_loop_wait(nonblocking); + } while (!quit); +} + static int fe_can_read(void *opaque) { FeHandler *h = opaque; @@ -28,6 +45,7 @@ static void fe_read(void *opaque, const uint8_t *buf, int size) memcpy(h->read_buf + h->read_count, buf, size); h->read_count += size; + quit = true; } static void fe_event(void *opaque, int event) @@ -35,9 +53,36 @@ static void fe_event(void *opaque, int event) FeHandler *h = opaque; h->last_event = event; + quit = true; } #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS +#ifdef _WIN32 +static void char_console_test_subprocess(void) +{ + QemuOpts *opts; + Chardev *chr; + + opts = qemu_opts_create(qemu_find_opts("chardev"), "console-label", + 1, &error_abort); + qemu_opt_set(opts, "backend", "console", &error_abort); + + chr = qemu_chr_new_from_opts(opts, NULL); + g_assert_nonnull(chr); + + qemu_chr_write_all(chr, (const uint8_t *)"CONSOLE", 7); + + qemu_opts_del(opts); + object_unparent(OBJECT(chr)); +} + +static void char_console_test(void) +{ + g_test_trap_subprocess("/char/console/subprocess", 0, 0); + g_test_trap_assert_passed(); + g_test_trap_assert_stdout("CONSOLE"); +} +#endif static void char_stdio_test_subprocess(void) { Chardev *chr; @@ -53,7 +98,7 @@ static void char_stdio_test_subprocess(void) g_assert_cmpint(ret, ==, 4); qemu_chr_fe_deinit(&be); - qemu_chr_delete(chr); + object_unparent(OBJECT(chr)); } static void char_stdio_test(void) @@ -64,7 +109,6 @@ static void char_stdio_test(void) } #endif - static void char_ringbuf_test(void) { QemuOpts *opts; @@ -103,7 +147,17 @@ static void char_ringbuf_test(void) g_free(data); qemu_chr_fe_deinit(&be); - qemu_chr_delete(chr); + object_unparent(OBJECT(chr)); + + /* check alias */ + opts = qemu_opts_create(qemu_find_opts("chardev"), "memory-label", + 1, &error_abort); + qemu_opt_set(opts, "backend", "memory", &error_abort); + qemu_opt_set(opts, "size", "2", &error_abort); + chr = qemu_chr_new_from_opts(opts, NULL); + g_assert_nonnull(chr); + object_unparent(OBJECT(chr)); + qemu_opts_del(opts); } static void char_mux_test(void) @@ -179,7 +233,295 @@ static void char_mux_test(void) qemu_chr_fe_deinit(&chr_be1); qemu_chr_fe_deinit(&chr_be2); - qemu_chr_delete(chr); + object_unparent(OBJECT(chr)); +} + +typedef struct SocketIdleData { + GMainLoop *loop; + Chardev *chr; + bool conn_expected; + CharBackend *be; + CharBackend *client_be; +} SocketIdleData; + +static gboolean char_socket_test_idle(gpointer user_data) +{ + SocketIdleData *data = user_data; + + if (object_property_get_bool(OBJECT(data->chr), "connected", NULL) + == data->conn_expected) { + quit = true; + return FALSE; + } + + return TRUE; +} + +static void socket_read(void *opaque, const uint8_t *buf, int size) +{ + SocketIdleData *data = opaque; + + g_assert_cmpint(size, ==, 1); + g_assert_cmpint(*buf, ==, 'Z'); + + size = qemu_chr_fe_write(data->be, (const uint8_t *)"hello", 5); + g_assert_cmpint(size, ==, 5); +} + +static int socket_can_read(void *opaque) +{ + return 10; +} + +static void socket_read_hello(void *opaque, const uint8_t *buf, int size) +{ + g_assert_cmpint(size, ==, 5); + g_assert(strncmp((char *)buf, "hello", 5) == 0); + + quit = true; +} + +static int socket_can_read_hello(void *opaque) +{ + return 10; +} + +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; + const char *port; + SocketIdleData d = { .chr = chr }; + CharBackend be; + CharBackend client_be; + char *tmp; + + d.be = &be; + d.client_be = &be; + + g_assert_nonnull(chr); + g_assert(!object_property_get_bool(OBJECT(chr), "connected", &error_abort)); + + addr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort); + qdict = qobject_to_qdict(addr); + port = qdict_get_str(qdict, "port"); + tmp = g_strdup_printf("tcp:127.0.0.1:%s", port); + QDECREF(qdict); + + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, socket_can_read, socket_read, + NULL, &d, NULL, true); + + chr_client = qemu_chr_new("client", tmp); + qemu_chr_fe_init(&client_be, chr_client, &error_abort); + qemu_chr_fe_set_handlers(&client_be, socket_can_read_hello, + socket_read_hello, + NULL, &d, NULL, true); + g_free(tmp); + + d.conn_expected = true; + guint id = g_idle_add(char_socket_test_idle, &d); + g_source_set_name_by_id(id, "test-idle"); + g_assert_cmpint(id, >, 0); + main_loop(); + + g_assert(object_property_get_bool(OBJECT(chr), "connected", &error_abort)); + g_assert(object_property_get_bool(OBJECT(chr_client), + "connected", &error_abort)); + + qemu_chr_write_all(chr_client, (const uint8_t *)"Z", 1); + main_loop(); + + object_unparent(OBJECT(chr_client)); + + d.conn_expected = false; + g_idle_add(char_socket_test_idle, &d); + main_loop(); + + object_unparent(OBJECT(chr)); +} + +#ifndef _WIN32 +static void char_pipe_test(void) +{ + gchar *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL); + gchar *tmp, *in, *out, *pipe = g_build_filename(tmp_path, "pipe", NULL); + Chardev *chr; + CharBackend be; + int ret, fd; + char buf[10]; + FeHandler fe = { 0, }; + + in = g_strdup_printf("%s.in", pipe); + if (mkfifo(in, 0600) < 0) { + abort(); + } + out = g_strdup_printf("%s.out", pipe); + if (mkfifo(out, 0600) < 0) { + abort(); + } + + tmp = g_strdup_printf("pipe:%s", pipe); + chr = qemu_chr_new("pipe", tmp); + g_assert_nonnull(chr); + g_free(tmp); + + qemu_chr_fe_init(&be, chr, &error_abort); + + ret = qemu_chr_fe_write(&be, (void *)"pipe-out", 9); + g_assert_cmpint(ret, ==, 9); + + fd = open(out, O_RDWR); + ret = read(fd, buf, sizeof(buf)); + g_assert_cmpint(ret, ==, 9); + g_assert_cmpstr(buf, ==, "pipe-out"); + close(fd); + + fd = open(in, O_WRONLY); + ret = write(fd, "pipe-in", 8); + g_assert_cmpint(ret, ==, 8); + close(fd); + + qemu_chr_fe_set_handlers(&be, + fe_can_read, + fe_read, + fe_event, + &fe, + NULL, true); + + main_loop(); + + g_assert_cmpint(fe.read_count, ==, 8); + g_assert_cmpstr(fe.read_buf, ==, "pipe-in"); + + qemu_chr_fe_deinit(&be); + object_unparent(OBJECT(chr)); + + g_assert(g_unlink(in) == 0); + g_assert(g_unlink(out) == 0); + g_assert(g_rmdir(tmp_path) == 0); + g_free(in); + g_free(out); + g_free(tmp_path); + g_free(pipe); +} +#endif + +static void char_udp_test(void) +{ + struct sockaddr_in addr = { 0, }, other; + SocketIdleData d = { 0, }; + Chardev *chr; + CharBackend be; + socklen_t alen = sizeof(addr); + int ret, sock = qemu_socket(PF_INET, SOCK_DGRAM, 0); + char buf[10]; + char *tmp; + + g_assert_cmpint(sock, >, 0); + addr.sin_family = AF_INET ; + addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.sin_port = 0; + ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + g_assert_cmpint(ret, ==, 0); + ret = getsockname(sock, (struct sockaddr *)&addr, &alen); + g_assert_cmpint(ret, ==, 0); + + tmp = g_strdup_printf("udp:127.0.0.1:%d", + ntohs(addr.sin_port)); + chr = qemu_chr_new("client", tmp); + g_assert_nonnull(chr); + + d.chr = chr; + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, socket_can_read_hello, socket_read_hello, + NULL, &d, NULL, true); + ret = qemu_chr_write_all(chr, (uint8_t *)"hello", 5); + g_assert_cmpint(ret, ==, 5); + + alen = sizeof(addr); + ret = recvfrom(sock, buf, sizeof(buf), 0, + (struct sockaddr *)&other, &alen); + g_assert_cmpint(ret, ==, 5); + ret = sendto(sock, buf, 5, 0, (struct sockaddr *)&other, alen); + g_assert_cmpint(ret, ==, 5); + + main_loop(); + + close(sock); + g_free(tmp); +} + +static void char_file_test(void) +{ + char *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL); + char *out = g_build_filename(tmp_path, "out", NULL); + char *contents = NULL; + ChardevFile file = { .out = out }; + ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE, + .u.file.data = &file }; + Chardev *chr; + gsize length; + int ret; + + chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, + &error_abort); + ret = qemu_chr_write_all(chr, (uint8_t *)"hello!", 6); + g_assert_cmpint(ret, ==, 6); + object_unref(OBJECT(chr)); + + ret = g_file_get_contents(out, &contents, &length, NULL); + g_assert(ret == TRUE); + g_assert_cmpint(length, ==, 6); + g_assert(strncmp(contents, "hello!", 6) == 0); + g_free(contents); + +#ifndef _WIN32 + { + CharBackend be; + FeHandler fe = { 0, }; + char *fifo = g_build_filename(tmp_path, "fifo", NULL); + int fd; + + if (mkfifo(fifo, 0600) < 0) { + abort(); + } + + fd = open(fifo, O_RDWR); + ret = write(fd, "fifo-in", 8); + g_assert_cmpint(ret, ==, 8); + + file.in = fifo; + file.has_in = true; + chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, + &error_abort); + + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, + fe_can_read, + fe_read, + fe_event, + &fe, NULL, true); + + main_loop(); + + close(fd); + + g_assert_cmpint(fe.read_count, ==, 8); + g_assert_cmpstr(fe.read_buf, ==, "fifo-in"); + qemu_chr_fe_deinit(&be); + object_unref(OBJECT(chr)); + g_unlink(fifo); + g_free(fifo); + } +#endif + + g_unlink(out); + g_rmdir(tmp_path); + g_free(tmp_path); + g_free(out); } static void char_null_test(void) @@ -222,7 +564,7 @@ static void char_null_test(void) g_assert_cmpint(ret, ==, 4); qemu_chr_fe_deinit(&be); - qemu_chr_delete(chr); + object_unparent(OBJECT(chr)); } static void char_invalid_test(void) @@ -235,6 +577,9 @@ static void char_invalid_test(void) int main(int argc, char **argv) { + qemu_init_main_loop(&error_abort); + socket_init(); + g_test_init(&argc, &argv, NULL); module_call_init(MODULE_INIT_QOM); @@ -245,9 +590,19 @@ int main(int argc, char **argv) g_test_add_func("/char/ringbuf", char_ringbuf_test); g_test_add_func("/char/mux", char_mux_test); #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS +#ifdef _WIN32 + g_test_add_func("/char/console/subprocess", char_console_test_subprocess); + g_test_add_func("/char/console", char_console_test); +#endif g_test_add_func("/char/stdio/subprocess", char_stdio_test_subprocess); g_test_add_func("/char/stdio", char_stdio_test); #endif +#ifndef _WIN32 + g_test_add_func("/char/pipe", char_pipe_test); +#endif + g_test_add_func("/char/file", char_file_test); + g_test_add_func("/char/socket", char_socket_test); + g_test_add_func("/char/udp", char_udp_test); return g_test_run(); } diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c index 85e6603d59..95c4bd5da3 100644 --- a/tests/test-crypto-block.c +++ b/tests/test-crypto-block.c @@ -187,10 +187,10 @@ static struct QCryptoBlockTestData { static ssize_t test_block_read_func(QCryptoBlock *block, - void *opaque, size_t offset, uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { Buffer *header = opaque; @@ -204,8 +204,8 @@ static ssize_t test_block_read_func(QCryptoBlock *block, static ssize_t test_block_init_func(QCryptoBlock *block, - void *opaque, size_t headerlen, + void *opaque, Error **errp) { Buffer *header = opaque; @@ -219,10 +219,10 @@ static ssize_t test_block_init_func(QCryptoBlock *block, static ssize_t test_block_write_func(QCryptoBlock *block, - void *opaque, size_t offset, const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { Buffer *header = opaque; 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); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index a61896c32d..9095af267e 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -491,7 +491,7 @@ static gboolean _test_server_free(TestServer *server) Chardev *chr = qemu_chr_fe_get_driver(&server->chr); qemu_chr_fe_deinit(&server->chr); - qemu_chr_delete(chr); + object_unparent(OBJECT(chr)); for (i = 0; i < server->fds_num; i++) { close(server->fds[i]); |