aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-01-03 19:22:19 +0100
committerMarc-André Lureau <marcandre.lureau@redhat.com>2017-05-04 15:34:42 +0400
commitbb1490486df2ea60c57a1d72c6a779ab1652b429 (patch)
treedd540781bc8d0530db3a32d597409c5a979871ee /tests
parentd47fb5d17c049b7add784c088f327d506097a970 (diff)
downloadqemu-bb1490486df2ea60c57a1d72c6a779ab1652b429.zip
qemu-bb1490486df2ea60c57a1d72c6a779ab1652b429.tar.gz
qemu-bb1490486df2ea60c57a1d72c6a779ab1652b429.tar.bz2
tests: add /char/udp test
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-char.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test-char.c b/tests/test-char.c
index 9971498..19707bf 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -385,6 +385,51 @@ static void char_pipe_test(void)
}
#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);
@@ -529,6 +574,7 @@ int main(int argc, char **argv)
#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();
}