1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

test: add a bunch of ASSERT macros

To make the debugging of test issues easier.

The following integer macros are added:

`ASSERT_EQ(a, b)`, `ASSERT_GE(a, b)`, `ASSERT_GT(a, b)`,
`ASSERT_LE(a, b)`, `ASSERT_LT(a, b)` and `ASSERT_NE(a, b)`.

And its corresponding unsigned integer macros:

`ASSERT_UINT64_EQ(a, b)`, `ASSERT_UINT64_GE(a, b)`,
`ASSERT_UINT64_GT(a, b)`, `ASSERT_UINT64_LE(a, b)`,
`ASSERT_UINT64_LT(a, b)` and `ASSERT_UINT64_NE(a, b)`.

Also these macros for `NULL` and pointer checks:

`ASSERT_NULL(a)`, `ASSERT_NOT_NULL(a)`, `ASSERT_PTR_EQ(a, b)` and
`ASSERT_PTR_NE(a, b)`.

And finally these macros for strings and buffers:

`ASSERT_STR_EQ(a, b)`/`ASSERT_STR_NEQ(a, b)` that use the `strcmp()`
call.
`ASSERT_MEM_EQ(a, b)`/`ASSERT_MEM_NEQ(a, b)` and
`ASSERT_MEM_HEX_EQ(a, b)`/`ASSERT_MEM_HEX_NEQ(a, b)` that use the
`memcmp()` call. The former, prints the data in string format and the
latter in hex format.

These macros are used in the following way:
```c
ASSERT_EQ(UV_EINVAL, uv_loop_close(&loop));
```

With a sample output that would be as follows:
```
Assertion failed in test/test-loop-close.c on line 44: `UV_EINVAL == uv_loop_close(&loop)` (-22 == -16)
```

To view multiples examples if their use, the `test-ipc.c` file has been
modified to use these macros.

The `_ISOC99_SOURCE` is defined to support `inttypes.h` in `z/OS`.

PR-URL: https://github.com/libuv/libuv/pull/2739
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
Santiago Gimeno 2020-03-14 21:26:47 +01:00
parent c10431165a
commit 53caf044e3
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE
5 changed files with 281 additions and 159 deletions

View File

@ -227,6 +227,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
list(APPEND uv_defines PATH_MAX=255)
list(APPEND uv_defines _AE_BIMODAL)
list(APPEND uv_defines _ALL_SOURCE)
list(APPEND uv_defines _ISOC99_SOURCE)
list(APPEND uv_defines _LARGE_TIME_API)
list(APPEND uv_defines _OPEN_MSGQ_EXT)
list(APPEND uv_defines _OPEN_SYS_FILE_EXT)

View File

@ -346,7 +346,8 @@ test_run_tests_CFLAGS += -D__EXTENSIONS__ \
endif
if OS390
test_run_tests_CFLAGS += -D_UNIX03_THREADS \
test_run_tests_CFLAGS += -D_ISOC99_SOURCE \
-D_UNIX03_THREADS \
-D_UNIX03_SOURCE \
-D_OPEN_SYS_IF_EXT=1 \
-D_OPEN_SYS_SOCK_IPV6 \

View File

@ -27,6 +27,8 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv/stdint-msvc2008.h"
@ -109,6 +111,118 @@ typedef enum {
} \
} while (0)
#define ASSERT_BASE(expr, a, operator, b, type, conv) \
do { \
if (!(expr)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` " \
"(%"conv" %s %"conv")\n", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b, \
(type)a, \
#operator, \
(type)b); \
abort(); \
} \
} while (0)
#define ASSERT_BASE_LEN(expr, a, operator, b, conv, len) \
do { \
if (!(expr)) { \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` " \
"(%.*"#conv" %s %.*"#conv")\n", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b, \
(int)len, \
a, \
#operator, \
(int)len, \
b); \
abort(); \
} \
} while (0)
#define ASSERT_BASE_HEX(expr, a, operator, b, size) \
do { \
if (!(expr)) { \
int i; \
unsigned char* a_ = (unsigned char*)a; \
unsigned char* b_ = (unsigned char*)b; \
fprintf(stderr, \
"Assertion failed in %s on line %d: `%s %s %s` (", \
__FILE__, \
__LINE__, \
#a, \
#operator, \
#b); \
for (i = 0; i < size; ++i) { \
if (i > 0) fprintf(stderr, ":"); \
fprintf(stderr, "%02X", a_[i]); \
} \
fprintf(stderr, " %s ", #operator); \
for (i = 0; i < size; ++i) { \
if (i > 0) fprintf(stderr, ":"); \
fprintf(stderr, "%02X", b_[i]); \
} \
fprintf(stderr, ")\n"); \
abort(); \
} \
} while (0)
#define ASSERT_INT_BASE(a, operator, b, type, conv) \
ASSERT_BASE(a operator b, a, operator, b, type, conv)
#define ASSERT_EQ(a, b) ASSERT_INT_BASE(a, ==, b, int64_t, PRId64)
#define ASSERT_GE(a, b) ASSERT_INT_BASE(a, >=, b, int64_t, PRId64)
#define ASSERT_GT(a, b) ASSERT_INT_BASE(a, >, b, int64_t, PRId64)
#define ASSERT_LE(a, b) ASSERT_INT_BASE(a, <=, b, int64_t, PRId64)
#define ASSERT_LT(a, b) ASSERT_INT_BASE(a, <, b, int64_t, PRId64)
#define ASSERT_NE(a, b) ASSERT_INT_BASE(a, !=, b, int64_t, PRId64)
#define ASSERT_UINT64_EQ(a, b) ASSERT_INT_BASE(a, ==, b, uint64_t, PRIu64)
#define ASSERT_UINT64_GE(a, b) ASSERT_INT_BASE(a, >=, b, uint64_t, PRIu64)
#define ASSERT_UINT64_GT(a, b) ASSERT_INT_BASE(a, >, b, uint64_t, PRIu64)
#define ASSERT_UINT64_LE(a, b) ASSERT_INT_BASE(a, <=, b, uint64_t, PRIu64)
#define ASSERT_UINT64_LT(a, b) ASSERT_INT_BASE(a, <, b, uint64_t, PRIu64)
#define ASSERT_UINT64_NE(a, b) ASSERT_INT_BASE(a, !=, b, uint64_t, PRIu64)
#define ASSERT_STR_EQ(a, b) \
ASSERT_BASE(strcmp(a, b) == 0, a, ==, b, char*, "s")
#define ASSERT_STR_NE(a, b) \
ASSERT_BASE(strcmp(a, b) != 0, a, !=, b, char*, "s")
#define ASSERT_MEM_EQ(a, b, size) \
ASSERT_BASE_LEN(memcmp(a, b, size) == 0, a, ==, b, s, size)
#define ASSERT_MEM_NE(a, b, size) \
ASSERT_BASE_LEN(memcmp(a, b, size) != 0, a, !=, b, s, size)
#define ASSERT_MEM_HEX_EQ(a, b, size) \
ASSERT_BASE_HEX(memcmp(a, b, size) == 0, a, ==, b, size)
#define ASSERT_MEM_HEX_NE(a, b, size) \
ASSERT_BASE_HEX(memcmp(a, b, size) != 0, a, !=, b, size)
#define ASSERT_NULL(a) \
ASSERT_BASE(a == NULL, a, ==, NULL, void*, "p")
#define ASSERT_NOT_NULL(a) \
ASSERT_BASE(a != NULL, a, !=, NULL, void*, "p")
#define ASSERT_PTR_EQ(a, b) \
ASSERT_BASE((void*)a == (void*)b, a, ==, b, void*, "p")
#define ASSERT_PTR_NE(a, b) \
ASSERT_BASE((void*)a != (void*)b, a, !=, b, void*, "p")
/* This macro cleans up the main loop. This is used to avoid valgrind
* warnings about memory being "leaked" by the main event loop.
*/

View File

@ -79,16 +79,16 @@ static void on_connection(uv_stream_t* server, int status) {
if (!local_conn_accepted) {
/* Accept the connection and close it. Also and close the server. */
ASSERT(status == 0);
ASSERT((uv_stream_t*)&tcp_server == server);
ASSERT_EQ(status, 0);
ASSERT_PTR_EQ(&tcp_server, server);
conn = malloc(sizeof(*conn));
ASSERT(conn);
ASSERT_NOT_NULL(conn);
r = uv_tcp_init(server->loop, conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept(server, (uv_stream_t*)conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_close((uv_handle_t*)conn, close_server_conn_cb);
uv_close((uv_handle_t*)server, NULL);
@ -102,8 +102,8 @@ static void exit_cb(uv_process_t* process,
int term_signal) {
printf("exit_cb\n");
exit_cb_called++;
ASSERT(exit_status == 0);
ASSERT(term_signal == 0);
ASSERT_EQ(exit_status, 0);
ASSERT_EQ(term_signal, 0);
uv_close((uv_handle_t*)process, NULL);
}
@ -134,18 +134,17 @@ static void make_many_connections(void) {
for (i = 0; i < CONN_COUNT; i++) {
conn = malloc(sizeof(*conn));
ASSERT(conn);
ASSERT_NOT_NULL(conn);
r = uv_tcp_init(uv_default_loop(), &conn->conn);
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT_EQ(r, 0);
ASSERT_EQ(0, uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_tcp_connect(&conn->conn_req,
(uv_tcp_t*) &conn->conn,
(const struct sockaddr*) &addr,
connect_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
conn->conn.data = conn;
}
@ -182,36 +181,38 @@ static void on_read(uv_stream_t* handle,
pending = uv_pipe_pending_type(pipe);
if (!tcp_server_listening) {
ASSERT(1 == uv_pipe_pending_count(pipe));
ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
ASSERT_EQ(1, uv_pipe_pending_count(pipe));
ASSERT_GT(nread, 0);
ASSERT_NOT_NULL(buf->base);
ASSERT_NE(pending, UV_UNKNOWN_HANDLE);
read_cb_called++;
/* Accept the pending TCP server, and start listening on it. */
ASSERT(pending == UV_TCP);
ASSERT_EQ(pending, UV_TCP);
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept((uv_stream_t*)pipe, (uv_stream_t*)&tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, on_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
tcp_server_listening = 1;
/* Make sure that the expected data is correctly multiplexed. */
ASSERT(memcmp("hello\n", buf->base, nread) == 0);
ASSERT_MEM_EQ("hello\n", buf->base, nread);
outbuf = uv_buf_init("world\n", 6);
r = uv_write(&write_req, (uv_stream_t*)pipe, &outbuf, 1, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
/* Create a bunch of connections to get both servers to accept. */
make_many_connections();
} else if (memcmp("accepted_connection\n", buf->base, nread) == 0) {
/* Remote server has accepted a connection. Close the channel. */
ASSERT(0 == uv_pipe_pending_count(pipe));
ASSERT(pending == UV_UNKNOWN_HANDLE);
ASSERT_EQ(0, uv_pipe_pending_count(pipe));
ASSERT_EQ(pending, UV_UNKNOWN_HANDLE);
remote_conn_accepted = 1;
uv_close((uv_handle_t*)&channel, NULL);
}
@ -247,37 +248,39 @@ static void on_read_listen_after_bound_twice(uv_stream_t* handle,
fprintf(stderr, "got %d bytes\n", (int)nread);
ASSERT(uv_pipe_pending_count(pipe) > 0);
ASSERT_GT(uv_pipe_pending_count(pipe), 0);
pending = uv_pipe_pending_type(pipe);
ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
ASSERT_GT(nread, 0);
ASSERT_NOT_NULL(buf->base);
ASSERT_NE(pending, UV_UNKNOWN_HANDLE);
read_cb_called++;
if (read_cb_called == 1) {
/* Accept the first TCP server, and start listening on it. */
ASSERT(pending == UV_TCP);
ASSERT_EQ(pending, UV_TCP);
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept((uv_stream_t*)pipe, (uv_stream_t*)&tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, on_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
} else if (read_cb_called == 2) {
/* Accept the second TCP server, and start listening on it. */
ASSERT(pending == UV_TCP);
ASSERT_EQ(pending, UV_TCP);
r = uv_tcp_init(uv_default_loop(), &tcp_server2);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept((uv_stream_t*)pipe, (uv_stream_t*)&tcp_server2);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&tcp_server2, BACKLOG, on_connection);
ASSERT(r == UV_EADDRINUSE);
ASSERT_EQ(r, UV_EADDRINUSE);
uv_close((uv_handle_t*)&tcp_server, NULL);
uv_close((uv_handle_t*)&tcp_server2, NULL);
ASSERT(0 == uv_pipe_pending_count(pipe));
ASSERT_EQ(0, uv_pipe_pending_count(pipe));
uv_close((uv_handle_t*)&channel, NULL);
}
@ -296,12 +299,12 @@ void spawn_helper(uv_pipe_t* channel,
uv_stdio_container_t stdio[3];
r = uv_pipe_init(uv_default_loop(), channel, 1);
ASSERT(r == 0);
ASSERT(channel->ipc);
ASSERT_EQ(r, 0);
ASSERT_NE(channel->ipc, 0);
exepath_size = sizeof(exepath);
r = uv_exepath(exepath, &exepath_size);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
exepath[exepath_size] = '\0';
args[0] = exepath;
@ -323,13 +326,13 @@ void spawn_helper(uv_pipe_t* channel,
stdio[2].data.fd = 2;
r = uv_spawn(uv_default_loop(), process, &options);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
}
static void on_tcp_write(uv_write_t* req, int status) {
ASSERT(status == 0);
ASSERT(req->handle == (uv_stream_t*)&tcp_connection);
ASSERT_EQ(status, 0);
ASSERT_PTR_EQ(req->handle, &tcp_connection);
tcp_write_cb_called++;
}
@ -343,9 +346,9 @@ static void on_read_alloc(uv_handle_t* handle,
static void on_tcp_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nread > 0);
ASSERT(memcmp("hello again\n", buf->base, nread) == 0);
ASSERT(tcp == (uv_stream_t*)&tcp_connection);
ASSERT_GT(nread, 0);
ASSERT_MEM_EQ("hello again\n", buf->base, nread);
ASSERT_PTR_EQ(tcp, &tcp_connection);
free(buf->base);
tcp_read_cb_called++;
@ -382,31 +385,33 @@ static void on_read_connection(uv_stream_t* handle,
fprintf(stderr, "got %d bytes\n", (int)nread);
ASSERT(1 == uv_pipe_pending_count(pipe));
ASSERT_EQ(1, uv_pipe_pending_count(pipe));
pending = uv_pipe_pending_type(pipe);
ASSERT(nread > 0 && buf->base && pending != UV_UNKNOWN_HANDLE);
ASSERT_GT(nread, 0);
ASSERT_NOT_NULL(buf->base);
ASSERT_NE(pending, UV_UNKNOWN_HANDLE);
read_cb_called++;
/* Accept the pending TCP connection */
ASSERT(pending == UV_TCP);
ASSERT_EQ(pending, UV_TCP);
r = uv_tcp_init(uv_default_loop(), &tcp_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept(handle, (uv_stream_t*)&tcp_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
/* Make sure that the expected data is correctly multiplexed. */
ASSERT(memcmp("hello\n", buf->base, nread) == 0);
ASSERT_MEM_EQ("hello\n", buf->base, nread);
/* Write/read to/from the connection */
outbuf = uv_buf_init("world\n", 6);
r = uv_write(&write_req, (uv_stream_t*)&tcp_connection, &outbuf, 1,
on_tcp_write);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_read_start((uv_stream_t*)&tcp_connection, on_read_alloc, on_tcp_read);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
free(buf->base);
}
@ -448,7 +453,7 @@ static int run_ipc_test(const char* helper, uv_read_cb read_cb) {
uv_read_start((uv_stream_t*)&channel, on_alloc, read_cb);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
MAKE_VALGRIND_HAPPY();
return 0;
@ -460,10 +465,10 @@ TEST_IMPL(ipc_listen_before_write) {
RETURN_SKIP(NO_SEND_HANDLE_ON_PIPE);
#endif
int r = run_ipc_test("ipc_helper_listen_before_write", on_read);
ASSERT(local_conn_accepted == 1);
ASSERT(remote_conn_accepted == 1);
ASSERT(read_cb_called == 1);
ASSERT(exit_cb_called == 1);
ASSERT_EQ(local_conn_accepted, 1);
ASSERT_EQ(remote_conn_accepted, 1);
ASSERT_EQ(read_cb_called, 1);
ASSERT_EQ(exit_cb_called, 1);
return r;
}
@ -473,10 +478,10 @@ TEST_IMPL(ipc_listen_after_write) {
RETURN_SKIP(NO_SEND_HANDLE_ON_PIPE);
#endif
int r = run_ipc_test("ipc_helper_listen_after_write", on_read);
ASSERT(local_conn_accepted == 1);
ASSERT(remote_conn_accepted == 1);
ASSERT(read_cb_called == 1);
ASSERT(exit_cb_called == 1);
ASSERT_EQ(local_conn_accepted, 1);
ASSERT_EQ(remote_conn_accepted, 1);
ASSERT_EQ(read_cb_called, 1);
ASSERT_EQ(exit_cb_called, 1);
return r;
}
@ -486,10 +491,10 @@ TEST_IMPL(ipc_tcp_connection) {
RETURN_SKIP(NO_SEND_HANDLE_ON_PIPE);
#endif
int r = run_ipc_test("ipc_helper_tcp_connection", on_read_connection);
ASSERT(read_cb_called == 1);
ASSERT(tcp_write_cb_called == 1);
ASSERT(tcp_read_cb_called == 1);
ASSERT(exit_cb_called == 1);
ASSERT_EQ(read_cb_called, 1);
ASSERT_EQ(tcp_write_cb_called, 1);
ASSERT_EQ(tcp_read_cb_called, 1);
ASSERT_EQ(exit_cb_called, 1);
return r;
}
@ -497,7 +502,7 @@ TEST_IMPL(ipc_tcp_connection) {
TEST_IMPL(ipc_closed_handle) {
int r;
r = run_ipc_test("ipc_helper_closed_handle", on_read_closed_handle);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
return 0;
}
#endif
@ -509,20 +514,20 @@ TEST_IMPL(listen_with_simultaneous_accepts) {
int r;
struct sockaddr_in addr;
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_bind(&server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_simultaneous_accepts(&server, 1);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
ASSERT(r == 0);
ASSERT(server.reqs_pending == 32);
ASSERT_EQ(r, 0);
ASSERT_EQ(server.reqs_pending, 32);
MAKE_VALGRIND_HAPPY();
return 0;
@ -534,20 +539,20 @@ TEST_IMPL(listen_no_simultaneous_accepts) {
int r;
struct sockaddr_in addr;
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_bind(&server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_simultaneous_accepts(&server, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
ASSERT(r == 0);
ASSERT(server.reqs_pending == 1);
ASSERT_EQ(r, 0);
ASSERT_EQ(server.reqs_pending, 1);
MAKE_VALGRIND_HAPPY();
return 0;
@ -558,8 +563,8 @@ TEST_IMPL(ipc_listen_after_bind_twice) {
RETURN_SKIP(NO_SEND_HANDLE_ON_PIPE);
#endif
int r = run_ipc_test("ipc_helper_bind_twice", on_read_listen_after_bound_twice);
ASSERT(read_cb_called == 2);
ASSERT(exit_cb_called == 1);
ASSERT_EQ(read_cb_called, 2);
ASSERT_EQ(exit_cb_called, 1);
return r;
}
#endif
@ -567,7 +572,7 @@ TEST_IMPL(ipc_listen_after_bind_twice) {
TEST_IMPL(ipc_send_zero) {
int r;
r = run_ipc_test("ipc_helper_send_zero", on_read_send_zero);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
return 0;
}
@ -589,7 +594,7 @@ static void conn_notify_write_cb(uv_write_t* req, int status) {
static void tcp_connection_write_cb(uv_write_t* req, int status) {
ASSERT((uv_handle_t*)&conn.conn == (uv_handle_t*)req->handle);
ASSERT_PTR_EQ(&conn.conn, req->handle);
uv_close((uv_handle_t*)req->handle, close_cb);
uv_close((uv_handle_t*)&channel, close_cb);
uv_close((uv_handle_t*)&tcp_server, close_cb);
@ -598,7 +603,7 @@ static void tcp_connection_write_cb(uv_write_t* req, int status) {
static void closed_handle_large_write_cb(uv_write_t* req, int status) {
ASSERT(status == 0);
ASSERT_EQ(status, 0);
ASSERT(closed_handle_data_read = LARGE_SIZE);
if (++write_reqs_completed == ARRAY_SIZE(write_reqs)) {
write_reqs_completed = 0;
@ -609,13 +614,13 @@ static void closed_handle_large_write_cb(uv_write_t* req, int status) {
static void closed_handle_write_cb(uv_write_t* req, int status) {
ASSERT(status == UV_EBADF);
ASSERT_EQ(status, UV_EBADF);
closed_handle_write = 1;
}
static void send_zero_write_cb(uv_write_t* req, int status) {
ASSERT(status == 0);
ASSERT_EQ(status, 0);
send_zero_write++;
}
@ -635,15 +640,15 @@ static void on_tcp_child_process_read(uv_stream_t* tcp,
abort();
}
ASSERT(nread > 0);
ASSERT(memcmp("world\n", buf->base, nread) == 0);
ASSERT_GT(nread, 0);
ASSERT_MEM_EQ("world\n", buf->base, nread);
on_pipe_read_called++;
free(buf->base);
/* Write to the socket */
outbuf = uv_buf_init("hello again\n", 12);
r = uv_write(&conn.tcp_write_req, tcp, &outbuf, 1, tcp_connection_write_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
tcp_conn_read_cb_called++;
}
@ -652,9 +657,9 @@ static void on_tcp_child_process_read(uv_stream_t* tcp,
static void connect_child_process_cb(uv_connect_t* req, int status) {
int r;
ASSERT(status == 0);
ASSERT_EQ(status, 0);
r = uv_read_start(req->handle, on_read_alloc, on_tcp_child_process_read);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
}
@ -667,21 +672,21 @@ static void ipc_on_connection(uv_stream_t* server, int status) {
* Accept the connection and close it. Also let the other
* side know.
*/
ASSERT(status == 0);
ASSERT((uv_stream_t*)&tcp_server == server);
ASSERT_EQ(status, 0);
ASSERT_PTR_EQ(&tcp_server, server);
r = uv_tcp_init(server->loop, &conn.conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept(server, (uv_stream_t*)&conn.conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_close((uv_handle_t*)&conn.conn, close_cb);
buf = uv_buf_init("accepted_connection\n", 20);
r = uv_write2(&conn_notify_req, (uv_stream_t*)&channel, &buf, 1,
NULL, conn_notify_write_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
connection_accepted = 1;
}
@ -693,28 +698,28 @@ static void ipc_on_connection_tcp_conn(uv_stream_t* server, int status) {
uv_buf_t buf;
uv_tcp_t* conn;
ASSERT(status == 0);
ASSERT((uv_stream_t*)&tcp_server == server);
ASSERT_EQ(status, 0);
ASSERT_PTR_EQ(&tcp_server, server);
conn = malloc(sizeof(*conn));
ASSERT(conn);
ASSERT_NOT_NULL(conn);
r = uv_tcp_init(server->loop, conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_accept(server, (uv_stream_t*)conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
/* Send the accepted connection to the other process */
buf = uv_buf_init("hello\n", 6);
r = uv_write2(&conn_notify_req, (uv_stream_t*)&channel, &buf, 1,
(uv_stream_t*)conn, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_read_start((uv_stream_t*) conn,
on_read_alloc,
on_tcp_child_process_read);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_close((uv_handle_t*)conn, close_cb);
}
@ -729,44 +734,44 @@ int ipc_helper(int listen_after_write) {
int r;
uv_buf_t buf;
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_pipe_open(&channel, 0);
ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
ASSERT_EQ(1, uv_is_readable((uv_stream_t*) &channel));
ASSERT_EQ(1, uv_is_writable((uv_stream_t*) &channel));
ASSERT_EQ(0, uv_is_closing((uv_handle_t*) &channel));
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
if (!listen_after_write) {
r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
}
buf = uv_buf_init("hello\n", 6);
r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1,
(uv_stream_t*)&tcp_server, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
if (listen_after_write) {
r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
}
notify_parent_process();
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(connection_accepted == 1);
ASSERT(close_cb_called == 3);
ASSERT_EQ(connection_accepted, 1);
ASSERT_EQ(close_cb_called, 3);
MAKE_VALGRIND_HAPPY();
return 0;
@ -783,43 +788,43 @@ int ipc_helper_tcp_connection(void) {
struct sockaddr_in addr;
r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_pipe_open(&channel, 0);
ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
ASSERT_EQ(1, uv_is_readable((uv_stream_t*) &channel));
ASSERT_EQ(1, uv_is_writable((uv_stream_t*) &channel));
ASSERT_EQ(0, uv_is_closing((uv_handle_t*) &channel));
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_listen((uv_stream_t*)&tcp_server, BACKLOG, ipc_on_connection_tcp_conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
/* Make a connection to the server */
r = uv_tcp_init(uv_default_loop(), &conn.conn);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
r = uv_tcp_connect(&conn.conn_req,
(uv_tcp_t*) &conn.conn,
(const struct sockaddr*) &addr,
connect_child_process_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(tcp_conn_read_cb_called == 1);
ASSERT(tcp_conn_write_cb_called == 1);
ASSERT(close_cb_called == 4);
ASSERT_EQ(tcp_conn_read_cb_called, 1);
ASSERT_EQ(tcp_conn_write_cb_called, 1);
ASSERT_EQ(close_cb_called, 4);
MAKE_VALGRIND_HAPPY();
return 0;
@ -836,7 +841,7 @@ static unsigned int write_until_data_queued() {
&large_buf,
1,
closed_handle_large_write_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
i++;
} while (channel.write_queue_size == 0 &&
i < ARRAY_SIZE(write_reqs));
@ -849,12 +854,12 @@ static void send_handle_and_close() {
struct sockaddr_in addr;
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_write2(&write_req,
(uv_stream_t*)&channel,
@ -862,7 +867,7 @@ static void send_handle_and_close() {
1,
(uv_stream_t*)&tcp_server,
closed_handle_write_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_close((uv_handle_t*)&tcp_server, NULL);
}
@ -874,21 +879,21 @@ int ipc_helper_closed_handle(void) {
large_buf = uv_buf_init(buffer, LARGE_SIZE);
r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_pipe_open(&channel, 0);
ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
ASSERT_EQ(1, uv_is_readable((uv_stream_t*) &channel));
ASSERT_EQ(1, uv_is_writable((uv_stream_t*) &channel));
ASSERT_EQ(0, uv_is_closing((uv_handle_t*) &channel));
if (write_until_data_queued() > 0)
send_handle_and_close();
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(closed_handle_write == 1);
ASSERT_EQ(closed_handle_write, 1);
MAKE_VALGRIND_HAPPY();
return 0;
@ -904,38 +909,38 @@ int ipc_helper_bind_twice(void) {
int r;
uv_buf_t buf;
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
ASSERT_EQ(0, uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));
r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_pipe_open(&channel, 0);
ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
ASSERT_EQ(1, uv_is_readable((uv_stream_t*) &channel));
ASSERT_EQ(1, uv_is_writable((uv_stream_t*) &channel));
ASSERT_EQ(0, uv_is_closing((uv_handle_t*) &channel));
buf = uv_buf_init("hello\n", 6);
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_init(uv_default_loop(), &tcp_server2);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_tcp_bind(&tcp_server2, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_write2(&write_req, (uv_stream_t*)&channel, &buf, 1,
(uv_stream_t*)&tcp_server, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_write2(&write_req2, (uv_stream_t*)&channel, &buf, 1,
(uv_stream_t*)&tcp_server2, NULL);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
MAKE_VALGRIND_HAPPY();
return 0;
@ -948,13 +953,13 @@ int ipc_helper_send_zero(void) {
zero_buf = uv_buf_init(0, 0);
r = uv_pipe_init(uv_default_loop(), &channel, 0);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
uv_pipe_open(&channel, 0);
ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
ASSERT_EQ(1, uv_is_readable((uv_stream_t*) &channel));
ASSERT_EQ(1, uv_is_writable((uv_stream_t*) &channel));
ASSERT_EQ(0, uv_is_closing((uv_handle_t*) &channel));
r = uv_write(&write_req,
(uv_stream_t*)&channel,
@ -962,12 +967,12 @@ int ipc_helper_send_zero(void) {
1,
send_zero_write_cb);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
ASSERT_EQ(r, 0);
ASSERT(send_zero_write == 1);
ASSERT_EQ(send_zero_write, 1);
MAKE_VALGRIND_HAPPY();
return 0;

1
uv.gyp
View File

@ -16,6 +16,7 @@
}],
['OS=="zos"', {
'shared_zos_defines': [
'_ISOC99_SOURCE',
'_UNIX03_THREADS',
'_UNIX03_SOURCE',
'_UNIX03_WITHDRAWN',