libuv 1.47.0.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4615 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
110
deps/libuv/test/test-poll.c
vendored
110
deps/libuv/test/test-poll.c
vendored
@@ -106,9 +106,9 @@ static uv_os_sock_t create_bound_socket (struct sockaddr_in bind_addr) {
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
#ifdef _WIN32
|
||||
ASSERT(sock != INVALID_SOCKET);
|
||||
ASSERT_NE(sock, INVALID_SOCKET);
|
||||
#else
|
||||
ASSERT(sock >= 0);
|
||||
ASSERT_GE(sock, 0);
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -116,12 +116,12 @@ static uv_os_sock_t create_bound_socket (struct sockaddr_in bind_addr) {
|
||||
/* Allow reuse of the port. */
|
||||
int yes = 1;
|
||||
r = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
r = bind(sock, (const struct sockaddr*) &bind_addr, sizeof bind_addr);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
return sock;
|
||||
}
|
||||
@@ -163,12 +163,12 @@ static connection_context_t* create_connection_context(
|
||||
r = uv_poll_init_socket(uv_default_loop(), &context->poll_handle, sock);
|
||||
context->open_handles++;
|
||||
context->poll_handle.data = context;
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
r = uv_timer_init(uv_default_loop(), &context->timer_handle);
|
||||
context->open_handles++;
|
||||
context->timer_handle.data = context;
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
return context;
|
||||
}
|
||||
@@ -179,15 +179,15 @@ static void connection_close_cb(uv_handle_t* handle) {
|
||||
|
||||
if (--context->open_handles == 0) {
|
||||
if (test_mode == DUPLEX || context->is_server_connection) {
|
||||
ASSERT(context->read == TRANSFER_BYTES);
|
||||
ASSERT_EQ(context->read, TRANSFER_BYTES);
|
||||
} else {
|
||||
ASSERT(context->read == 0);
|
||||
ASSERT_OK(context->read);
|
||||
}
|
||||
|
||||
if (test_mode == DUPLEX || !context->is_server_connection) {
|
||||
ASSERT(context->sent == TRANSFER_BYTES);
|
||||
ASSERT_EQ(context->sent, TRANSFER_BYTES);
|
||||
} else {
|
||||
ASSERT(context->sent == 0);
|
||||
ASSERT_OK(context->sent);
|
||||
}
|
||||
|
||||
closed_connections++;
|
||||
@@ -208,7 +208,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
unsigned int new_events;
|
||||
int r;
|
||||
|
||||
ASSERT(status == 0);
|
||||
ASSERT_OK(status);
|
||||
ASSERT(events & context->events);
|
||||
ASSERT(!(events & ~context->events));
|
||||
|
||||
@@ -226,7 +226,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
do
|
||||
r = recv(context->sock, buffer, sizeof buffer, 0);
|
||||
while (r == -1 && errno == EINTR);
|
||||
ASSERT(r >= 0);
|
||||
ASSERT_GE(r, 0);
|
||||
|
||||
if (r > 0) {
|
||||
context->read += r;
|
||||
@@ -306,7 +306,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
static char buffer[103];
|
||||
|
||||
int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
|
||||
ASSERT(send_bytes > 0);
|
||||
ASSERT_GT(send_bytes, 0);
|
||||
|
||||
do
|
||||
r = send(context->sock, buffer, send_bytes, 0);
|
||||
@@ -318,7 +318,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(r > 0);
|
||||
ASSERT_GT(r, 0);
|
||||
context->sent += r;
|
||||
valid_writable_wakeups++;
|
||||
break;
|
||||
@@ -330,7 +330,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
static char buffer[1234];
|
||||
|
||||
int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
|
||||
ASSERT(send_bytes > 0);
|
||||
ASSERT_GT(send_bytes, 0);
|
||||
|
||||
do
|
||||
r = send(context->sock, buffer, send_bytes, 0);
|
||||
@@ -342,18 +342,18 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(r > 0);
|
||||
ASSERT_GT(r, 0);
|
||||
valid_writable_wakeups++;
|
||||
context->sent += r;
|
||||
|
||||
while (context->sent < TRANSFER_BYTES) {
|
||||
send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
|
||||
ASSERT(send_bytes > 0);
|
||||
ASSERT_GT(send_bytes, 0);
|
||||
|
||||
do
|
||||
r = send(context->sock, buffer, send_bytes, 0);
|
||||
while (r == -1 && errno == EINTR);
|
||||
ASSERT(r != 0);
|
||||
ASSERT(r);
|
||||
|
||||
if (r < 0) {
|
||||
ASSERT(got_eagain());
|
||||
@@ -403,7 +403,7 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
#else
|
||||
r = shutdown(context->sock, SHUT_WR);
|
||||
#endif
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
context->sent_fin = 1;
|
||||
new_events &= ~UV_WRITABLE;
|
||||
}
|
||||
@@ -432,9 +432,9 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
|
||||
/* Assert that uv_is_active works correctly for poll handles. */
|
||||
if (context->events != 0) {
|
||||
ASSERT(1 == uv_is_active((uv_handle_t*) handle));
|
||||
ASSERT_EQ(1, uv_is_active((uv_handle_t*) handle));
|
||||
} else {
|
||||
ASSERT(0 == uv_is_active((uv_handle_t*) handle));
|
||||
ASSERT_OK(uv_is_active((uv_handle_t*) handle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ static void delay_timer_cb(uv_timer_t* timer) {
|
||||
int r;
|
||||
|
||||
/* Timer should auto stop. */
|
||||
ASSERT(0 == uv_is_active((uv_handle_t*) timer));
|
||||
ASSERT_OK(uv_is_active((uv_handle_t*) timer));
|
||||
|
||||
/* Add the requested events to the poll mask. */
|
||||
ASSERT(context->delayed_events != 0);
|
||||
@@ -454,7 +454,7 @@ static void delay_timer_cb(uv_timer_t* timer) {
|
||||
r = uv_poll_start(&context->poll_handle,
|
||||
context->events,
|
||||
connection_poll_cb);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -471,7 +471,7 @@ static server_context_t* create_server_context(
|
||||
|
||||
r = uv_poll_init_socket(uv_default_loop(), &context->poll_handle, sock);
|
||||
context->poll_handle.data = context;
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
return context;
|
||||
}
|
||||
@@ -500,9 +500,9 @@ static void server_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
addr_len = sizeof addr;
|
||||
sock = accept(server_context->sock, (struct sockaddr*) &addr, &addr_len);
|
||||
#ifdef _WIN32
|
||||
ASSERT(sock != INVALID_SOCKET);
|
||||
ASSERT_NE(sock, INVALID_SOCKET);
|
||||
#else
|
||||
ASSERT(sock >= 0);
|
||||
ASSERT_GE(sock, 0);
|
||||
#endif
|
||||
|
||||
connection_context = create_connection_context(sock, 1);
|
||||
@@ -510,7 +510,7 @@ static void server_poll_cb(uv_poll_t* handle, int status, int events) {
|
||||
r = uv_poll_start(&connection_context->poll_handle,
|
||||
UV_READABLE | UV_WRITABLE | UV_DISCONNECT,
|
||||
connection_poll_cb);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
if (++server_context->connections == NUM_CLIENTS) {
|
||||
close_socket(server_context->sock);
|
||||
@@ -525,15 +525,15 @@ static void start_server(void) {
|
||||
uv_os_sock_t sock;
|
||||
int r;
|
||||
|
||||
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
|
||||
ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
|
||||
sock = create_bound_socket(addr);
|
||||
context = create_server_context(sock);
|
||||
|
||||
r = listen(sock, 100);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
r = uv_poll_start(&context->poll_handle, UV_READABLE, server_poll_cb);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -544,8 +544,8 @@ static void start_client(void) {
|
||||
struct sockaddr_in addr;
|
||||
int r;
|
||||
|
||||
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
|
||||
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &addr));
|
||||
ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
|
||||
ASSERT_OK(uv_ip4_addr("0.0.0.0", 0, &addr));
|
||||
|
||||
sock = create_bound_socket(addr);
|
||||
context = create_connection_context(sock, 0);
|
||||
@@ -554,7 +554,7 @@ static void start_client(void) {
|
||||
r = uv_poll_start(&context->poll_handle,
|
||||
UV_READABLE | UV_WRITABLE | UV_DISCONNECT,
|
||||
connection_poll_cb);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
r = connect(sock, (struct sockaddr*) &server_addr, sizeof server_addr);
|
||||
ASSERT(r == 0 || got_eagain());
|
||||
@@ -568,7 +568,7 @@ static void start_poll_test(void) {
|
||||
{
|
||||
struct WSAData wsa_data;
|
||||
int r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -578,16 +578,16 @@ static void start_poll_test(void) {
|
||||
start_client();
|
||||
|
||||
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
ASSERT(r == 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
/* Assert that at most five percent of the writable wakeups was spurious. */
|
||||
ASSERT(spurious_writable_wakeups == 0 ||
|
||||
(valid_writable_wakeups + spurious_writable_wakeups) /
|
||||
spurious_writable_wakeups > 20);
|
||||
ASSERT_NE(spurious_writable_wakeups == 0 ||
|
||||
(valid_writable_wakeups + spurious_writable_wakeups) /
|
||||
spurious_writable_wakeups > 20, 0);
|
||||
|
||||
ASSERT(closed_connections == NUM_CLIENTS * 2);
|
||||
ASSERT_EQ(closed_connections, NUM_CLIENTS * 2);
|
||||
#if !defined(__sun) && !defined(_AIX) && !defined(__MVS__)
|
||||
ASSERT(disconnects == NUM_CLIENTS * 2);
|
||||
ASSERT_EQ(disconnects, NUM_CLIENTS * 2);
|
||||
#endif
|
||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||
}
|
||||
@@ -642,9 +642,9 @@ TEST_IMPL(poll_bad_fdtype) {
|
||||
#else
|
||||
fd = open(".", O_RDONLY);
|
||||
#endif
|
||||
ASSERT(fd != -1);
|
||||
ASSERT(0 != uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT(0 == close(fd));
|
||||
ASSERT_NE(fd, -1);
|
||||
ASSERT_NE(0, uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT_OK(close(fd));
|
||||
#endif
|
||||
|
||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||
@@ -658,15 +658,15 @@ TEST_IMPL(poll_nested_epoll) {
|
||||
int fd;
|
||||
|
||||
fd = epoll_create(1);
|
||||
ASSERT(fd != -1);
|
||||
ASSERT_NE(fd, -1);
|
||||
|
||||
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT(0 == uv_poll_start(&poll_handle, UV_READABLE, (uv_poll_cb) abort));
|
||||
ASSERT(0 != uv_run(uv_default_loop(), UV_RUN_NOWAIT));
|
||||
ASSERT_OK(uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT_OK(uv_poll_start(&poll_handle, UV_READABLE, (uv_poll_cb) abort));
|
||||
ASSERT_NE(0, uv_run(uv_default_loop(), UV_RUN_NOWAIT));
|
||||
|
||||
uv_close((uv_handle_t*) &poll_handle, NULL);
|
||||
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||
ASSERT(0 == close(fd));
|
||||
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||
ASSERT_OK(close(fd));
|
||||
|
||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||
return 0;
|
||||
@@ -680,15 +680,15 @@ TEST_IMPL(poll_nested_kqueue) {
|
||||
int fd;
|
||||
|
||||
fd = kqueue();
|
||||
ASSERT(fd != -1);
|
||||
ASSERT_NE(fd, -1);
|
||||
|
||||
ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT(0 == uv_poll_start(&poll_handle, UV_READABLE, (uv_poll_cb) abort));
|
||||
ASSERT(0 != uv_run(uv_default_loop(), UV_RUN_NOWAIT));
|
||||
ASSERT_OK(uv_poll_init(uv_default_loop(), &poll_handle, fd));
|
||||
ASSERT_OK(uv_poll_start(&poll_handle, UV_READABLE, (uv_poll_cb) abort));
|
||||
ASSERT_NE(0, uv_run(uv_default_loop(), UV_RUN_NOWAIT));
|
||||
|
||||
uv_close((uv_handle_t*) &poll_handle, NULL);
|
||||
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||
ASSERT(0 == close(fd));
|
||||
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
|
||||
ASSERT_OK(close(fd));
|
||||
|
||||
MAKE_VALGRIND_HAPPY(uv_default_loop());
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user