test: add vectored uv_write() ping-pong tests
PR-URL: https://github.com/libuv/libuv/pull/1843 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
e7e8b6fb9b
commit
b36c0945d1
@ -71,8 +71,11 @@ TEST_DECLARE (ipc_closed_handle)
|
||||
#endif
|
||||
TEST_DECLARE (tcp_alloc_cb_fail)
|
||||
TEST_DECLARE (tcp_ping_pong)
|
||||
TEST_DECLARE (tcp_ping_pong_v6)
|
||||
TEST_DECLARE (tcp_ping_pong_vec)
|
||||
TEST_DECLARE (tcp6_ping_pong)
|
||||
TEST_DECLARE (tcp6_ping_pong_vec)
|
||||
TEST_DECLARE (pipe_ping_pong)
|
||||
TEST_DECLARE (pipe_ping_pong_vec)
|
||||
TEST_DECLARE (delayed_accept)
|
||||
TEST_DECLARE (multiple_listen)
|
||||
#ifndef _WIN32
|
||||
@ -499,12 +502,21 @@ TASK_LIST_START
|
||||
TEST_ENTRY (tcp_ping_pong)
|
||||
TEST_HELPER (tcp_ping_pong, tcp4_echo_server)
|
||||
|
||||
TEST_ENTRY (tcp_ping_pong_v6)
|
||||
TEST_HELPER (tcp_ping_pong_v6, tcp6_echo_server)
|
||||
TEST_ENTRY (tcp_ping_pong_vec)
|
||||
TEST_HELPER (tcp_ping_pong_vec, tcp4_echo_server)
|
||||
|
||||
TEST_ENTRY (tcp6_ping_pong)
|
||||
TEST_HELPER (tcp6_ping_pong, tcp6_echo_server)
|
||||
|
||||
TEST_ENTRY (tcp6_ping_pong_vec)
|
||||
TEST_HELPER (tcp6_ping_pong_vec, tcp6_echo_server)
|
||||
|
||||
TEST_ENTRY (pipe_ping_pong)
|
||||
TEST_HELPER (pipe_ping_pong, pipe_echo_server)
|
||||
|
||||
TEST_ENTRY (pipe_ping_pong_vec)
|
||||
TEST_HELPER (pipe_ping_pong_vec, pipe_echo_server)
|
||||
|
||||
TEST_ENTRY (delayed_accept)
|
||||
TEST_ENTRY (multiple_listen)
|
||||
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
#include "uv.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int completed_pingers = 0;
|
||||
|
||||
@ -41,6 +41,7 @@ static int pinger_on_connect_count;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int vectored_writes;
|
||||
int pongs;
|
||||
int state;
|
||||
union {
|
||||
@ -77,15 +78,26 @@ static void pinger_after_write(uv_write_t *req, int status) {
|
||||
|
||||
static void pinger_write_ping(pinger_t* pinger) {
|
||||
uv_write_t *req;
|
||||
uv_buf_t buf;
|
||||
uv_buf_t bufs[sizeof PING - 1];
|
||||
int i, nbufs;
|
||||
|
||||
buf = uv_buf_init(PING, sizeof(PING) - 1);
|
||||
if (!pinger->vectored_writes) {
|
||||
/* Write a single buffer. */
|
||||
nbufs = 1;
|
||||
bufs[0] = uv_buf_init(PING, sizeof PING - 1);
|
||||
} else {
|
||||
/* Write multiple buffers, each with one byte in them. */
|
||||
nbufs = sizeof PING - 1;
|
||||
for (i = 0; i < nbufs; i++) {
|
||||
bufs[i] = uv_buf_init(&PING[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
req = malloc(sizeof(*req));
|
||||
if (uv_write(req,
|
||||
(uv_stream_t*) &pinger->stream.tcp,
|
||||
&buf,
|
||||
1,
|
||||
bufs,
|
||||
nbufs,
|
||||
pinger_after_write)) {
|
||||
FATAL("uv_write failed");
|
||||
}
|
||||
@ -154,7 +166,7 @@ static void pinger_on_connect(uv_connect_t *req, int status) {
|
||||
|
||||
|
||||
/* same ping-pong test, but using IPv6 connection */
|
||||
static void tcp_pinger_v6_new(void) {
|
||||
static void tcp_pinger_v6_new(int vectored_writes) {
|
||||
int r;
|
||||
struct sockaddr_in6 server_addr;
|
||||
pinger_t *pinger;
|
||||
@ -163,6 +175,7 @@ static void tcp_pinger_v6_new(void) {
|
||||
ASSERT(0 ==uv_ip6_addr("::1", TEST_PORT, &server_addr));
|
||||
pinger = malloc(sizeof(*pinger));
|
||||
ASSERT(pinger != NULL);
|
||||
pinger->vectored_writes = vectored_writes;
|
||||
pinger->state = 0;
|
||||
pinger->pongs = 0;
|
||||
|
||||
@ -184,7 +197,7 @@ static void tcp_pinger_v6_new(void) {
|
||||
}
|
||||
|
||||
|
||||
static void tcp_pinger_new(void) {
|
||||
static void tcp_pinger_new(int vectored_writes) {
|
||||
int r;
|
||||
struct sockaddr_in server_addr;
|
||||
pinger_t *pinger;
|
||||
@ -192,6 +205,7 @@ static void tcp_pinger_new(void) {
|
||||
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
|
||||
pinger = malloc(sizeof(*pinger));
|
||||
ASSERT(pinger != NULL);
|
||||
pinger->vectored_writes = vectored_writes;
|
||||
pinger->state = 0;
|
||||
pinger->pongs = 0;
|
||||
|
||||
@ -213,12 +227,13 @@ static void tcp_pinger_new(void) {
|
||||
}
|
||||
|
||||
|
||||
static void pipe_pinger_new(void) {
|
||||
static void pipe_pinger_new(int vectored_writes) {
|
||||
int r;
|
||||
pinger_t *pinger;
|
||||
|
||||
pinger = (pinger_t*)malloc(sizeof(*pinger));
|
||||
ASSERT(pinger != NULL);
|
||||
pinger->vectored_writes = vectored_writes;
|
||||
pinger->state = 0;
|
||||
pinger->pongs = 0;
|
||||
|
||||
@ -237,10 +252,8 @@ static void pipe_pinger_new(void) {
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(tcp_ping_pong) {
|
||||
tcp_pinger_new();
|
||||
static int run_ping_pong_test(void) {
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
ASSERT(completed_pingers == 1);
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
@ -248,26 +261,41 @@ TEST_IMPL(tcp_ping_pong) {
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(tcp_ping_pong_v6) {
|
||||
TEST_IMPL(tcp_ping_pong) {
|
||||
tcp_pinger_new(0);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(tcp_ping_pong_vec) {
|
||||
tcp_pinger_new(1);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(tcp6_ping_pong) {
|
||||
if (!can_ipv6())
|
||||
RETURN_SKIP("IPv6 not supported");
|
||||
tcp_pinger_v6_new(0);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
tcp_pinger_v6_new();
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
ASSERT(completed_pingers == 1);
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
TEST_IMPL(tcp6_ping_pong_vec) {
|
||||
if (!can_ipv6())
|
||||
RETURN_SKIP("IPv6 not supported");
|
||||
tcp_pinger_v6_new(1);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(pipe_ping_pong) {
|
||||
pipe_pinger_new();
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
ASSERT(completed_pingers == 1);
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
pipe_pinger_new(0);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(pipe_ping_pong_vec) {
|
||||
pipe_pinger_new(1);
|
||||
return run_ping_pong_test();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user