diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.include | 4 | ||||
-rw-r--r-- | tests/check-qjson.c | 5 | ||||
-rw-r--r-- | tests/test-io-channel-socket.c | 86 | ||||
-rw-r--r-- | tests/test-qmp-event.c | 6 |
4 files changed, 84 insertions, 17 deletions
diff --git a/tests/Makefile.include b/tests/Makefile.include index f5e6eb5152..19b4c0a696 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -529,7 +529,7 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tests test-util-obj-y = libqemuutil.a test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ - tests/test-qapi-events.o tests/test-qapi-introspect.o \ + tests/test-qapi-introspect.o \ $(test-qom-obj-y) benchmark-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y) test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y) @@ -621,7 +621,7 @@ tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/tests/qapi-schema/doc-good.jso tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) -tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) +tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) tests/test-qapi-events.o tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index d876a7a96e..fa2afccb0a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -176,6 +176,11 @@ static void utf8_string(void) "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5", "\\u03BA\\u1F79\\u03C3\\u03BC\\u03B5", }, + /* '%' character when not interpolating */ + { + "100%", + "100%", + }, /* 2 Boundary condition test cases */ /* 2.1 First possible sequence of a certain length */ /* diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index 0597213f93..c253ae30f5 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -49,6 +49,7 @@ static void test_io_channel_set_socket_bufs(QIOChannel *src, static void test_io_channel_setup_sync(SocketAddress *listen_addr, SocketAddress *connect_addr, + QIOChannel **srv, QIOChannel **src, QIOChannel **dst) { @@ -78,7 +79,7 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr, test_io_channel_set_socket_bufs(*src, *dst); - object_unref(OBJECT(lioc)); + *srv = QIO_CHANNEL(lioc); } @@ -99,6 +100,7 @@ static void test_io_channel_complete(QIOTask *task, static void test_io_channel_setup_async(SocketAddress *listen_addr, SocketAddress *connect_addr, + QIOChannel **srv, QIOChannel **src, QIOChannel **dst) { @@ -146,21 +148,34 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, qio_channel_set_delay(*src, false); test_io_channel_set_socket_bufs(*src, *dst); - object_unref(OBJECT(lioc)); + *srv = QIO_CHANNEL(lioc); g_main_loop_unref(data.loop); } +static void test_io_channel_socket_path_exists(SocketAddress *addr, + bool expectExists) +{ + if (addr->type != SOCKET_ADDRESS_TYPE_UNIX) { + return; + } + + g_assert(g_file_test(addr->u.q_unix.path, + G_FILE_TEST_EXISTS) == expectExists); +} + + static void test_io_channel(bool async, SocketAddress *listen_addr, SocketAddress *connect_addr, bool passFD) { - QIOChannel *src, *dst; + QIOChannel *src, *dst, *srv; QIOChannelTest *test; if (async) { - test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst); + test_io_channel_setup_async(listen_addr, connect_addr, + &srv, &src, &dst); g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); @@ -169,14 +184,25 @@ static void test_io_channel(bool async, g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); + test_io_channel_socket_path_exists(listen_addr, true); + test = qio_channel_test_new(); qio_channel_test_run_threads(test, true, src, dst); qio_channel_test_validate(test); + test_io_channel_socket_path_exists(listen_addr, true); + + /* unref without close, to ensure finalize() cleans up */ + object_unref(OBJECT(src)); object_unref(OBJECT(dst)); + test_io_channel_socket_path_exists(listen_addr, true); - test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst); + object_unref(OBJECT(srv)); + test_io_channel_socket_path_exists(listen_addr, false); + + test_io_channel_setup_async(listen_addr, connect_addr, + &srv, &src, &dst); g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); @@ -189,10 +215,24 @@ static void test_io_channel(bool async, qio_channel_test_run_threads(test, false, src, dst); qio_channel_test_validate(test); + /* close before unref, to ensure finalize copes with already closed */ + + qio_channel_close(src, &error_abort); + qio_channel_close(dst, &error_abort); + test_io_channel_socket_path_exists(listen_addr, true); + object_unref(OBJECT(src)); object_unref(OBJECT(dst)); + test_io_channel_socket_path_exists(listen_addr, true); + + qio_channel_close(srv, &error_abort); + test_io_channel_socket_path_exists(listen_addr, false); + + object_unref(OBJECT(srv)); + test_io_channel_socket_path_exists(listen_addr, false); } else { - test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst); + test_io_channel_setup_sync(listen_addr, connect_addr, + &srv, &src, &dst); g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); @@ -201,14 +241,25 @@ static void test_io_channel(bool async, g_assert(qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_SHUTDOWN)); g_assert(qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_SHUTDOWN)); + test_io_channel_socket_path_exists(listen_addr, true); + test = qio_channel_test_new(); qio_channel_test_run_threads(test, true, src, dst); qio_channel_test_validate(test); + test_io_channel_socket_path_exists(listen_addr, true); + + /* unref without close, to ensure finalize() cleans up */ + object_unref(OBJECT(src)); object_unref(OBJECT(dst)); + test_io_channel_socket_path_exists(listen_addr, true); + + object_unref(OBJECT(srv)); + test_io_channel_socket_path_exists(listen_addr, false); - test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst); + test_io_channel_setup_sync(listen_addr, connect_addr, + &srv, &src, &dst); g_assert(!passFD || qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS)); @@ -221,8 +272,23 @@ static void test_io_channel(bool async, qio_channel_test_run_threads(test, false, src, dst); qio_channel_test_validate(test); + test_io_channel_socket_path_exists(listen_addr, true); + + /* close before unref, to ensure finalize copes with already closed */ + + qio_channel_close(src, &error_abort); + qio_channel_close(dst, &error_abort); + test_io_channel_socket_path_exists(listen_addr, true); + object_unref(OBJECT(src)); object_unref(OBJECT(dst)); + test_io_channel_socket_path_exists(listen_addr, true); + + qio_channel_close(srv, &error_abort); + test_io_channel_socket_path_exists(listen_addr, false); + + object_unref(OBJECT(srv)); + test_io_channel_socket_path_exists(listen_addr, false); } } @@ -316,7 +382,6 @@ static void test_io_channel_unix(bool async) qapi_free_SocketAddress(listen_addr); qapi_free_SocketAddress(connect_addr); - g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) == FALSE); } @@ -335,7 +400,7 @@ static void test_io_channel_unix_fd_pass(void) { SocketAddress *listen_addr = g_new0(SocketAddress, 1); SocketAddress *connect_addr = g_new0(SocketAddress, 1); - QIOChannel *src, *dst; + QIOChannel *src, *dst, *srv; int testfd; int fdsend[3]; int *fdrecv = NULL; @@ -359,7 +424,7 @@ static void test_io_channel_unix_fd_pass(void) 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); + test_io_channel_setup_sync(listen_addr, connect_addr, &srv, &src, &dst); memcpy(bufsend, "Hello World", G_N_ELEMENTS(bufsend)); @@ -412,6 +477,7 @@ static void test_io_channel_unix_fd_pass(void) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); + object_unref(OBJECT(srv)); qapi_free_SocketAddress(listen_addr); qapi_free_SocketAddress(connect_addr); unlink(TEST_SOCKET); diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 9cddd72adb..bf900f14f4 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -93,9 +93,7 @@ static bool qdict_cmp_simple(QDict *a, QDict *b) return d.result; } -/* This function is hooked as final emit function, which can verify the - correctness. */ -static void event_test_emit(test_QAPIEvent event, QDict *d) +void test_qapi_event_emit(test_QAPIEvent event, QDict *d) { QDict *t; int64_t s, ms; @@ -241,8 +239,6 @@ static void test_event_d(TestEventData *data, int main(int argc, char **argv) { - qmp_event_set_func_emit(event_test_emit); - g_test_init(&argc, &argv, NULL); event_test_add("/event/event_a", test_event_a); |