diff options
Diffstat (limited to 'test/core/iomgr')
-rw-r--r-- | test/core/iomgr/endpoint_tests.c | 6 | ||||
-rw-r--r-- | test/core/iomgr/fd_posix_test.c | 11 | ||||
-rw-r--r-- | test/core/iomgr/tcp_posix_test.c | 24 | ||||
-rw-r--r-- | test/core/iomgr/tcp_server_posix_test.c | 1 | ||||
-rw-r--r-- | test/core/iomgr/udp_server_test.c | 39 | ||||
-rw-r--r-- | test/core/iomgr/workqueue_test.c | 13 |
6 files changed, 61 insertions, 33 deletions
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 52082c3c6b..6d15ecf141 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -188,13 +188,15 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_log(GPR_DEBUG, "num_bytes=%d write_size=%d slice_size=%d shutdown=%d", + gpr_log(GPR_DEBUG, "num_bytes=%" PRIuPTR " write_size=%" PRIuPTR + " slice_size=%" PRIuPTR " shutdown=%d", num_bytes, write_size, slice_size, shutdown); if (shutdown) { gpr_log(GPR_INFO, "Start read and write shutdown test"); } else { - gpr_log(GPR_INFO, "Start read and write test with %d bytes, slice size %d", + gpr_log(GPR_INFO, "Start read and write test with %" PRIuPTR + " bytes, slice size %" PRIuPTR, num_bytes, slice_size); } diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index f97f33712e..24ba474680 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -52,6 +52,7 @@ #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/iomgr/socket_utils_posix.h" #include "test/core/util/test_config.h" static gpr_mu *g_mu; @@ -68,17 +69,15 @@ static void create_test_socket(int port, int *socket_fd, struct sockaddr_in *sin) { int fd; int one = 1; - int buf_size = BUF_SIZE; + int buffer_size_bytes = BUF_SIZE; int flags; fd = socket(AF_INET, SOCK_STREAM, 0); setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); /* Reset the size of socket send buffer to the minimal value to facilitate buffer filling up and triggering notify_on_write */ - GPR_ASSERT( - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size)) != -1); - GPR_ASSERT( - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size)) != -1); + GPR_ASSERT(grpc_set_socket_sndbuf(fd, buffer_size_bytes)); + GPR_ASSERT(grpc_set_socket_rcvbuf(fd, buffer_size_bytes)); /* Make fd non-blocking */ flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); @@ -399,7 +398,7 @@ static void test_grpc_fd(void) { client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); - gpr_log(GPR_INFO, "Total read bytes %d", sv.read_bytes_total); + gpr_log(GPR_INFO, "Total read bytes %" PRIdPTR, sv.read_bytes_total); } typedef struct fd_change_data { diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 7a98fa0e50..19ba258303 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -151,7 +151,7 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { read_bytes = count_slices(state->incoming.slices, state->incoming.count, ¤t_data); state->read_bytes += read_bytes; - gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes, + gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { gpr_mu_unlock(g_mu); @@ -170,8 +170,8 @@ static void read_test(size_t num_bytes, size_t slice_size) { gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes, - slice_size); + gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, + num_bytes, slice_size); create_sockets(sv); @@ -179,7 +179,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); - gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); + gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); state.ep = ep; state.read_bytes = 0; @@ -216,7 +216,7 @@ static void large_read_test(size_t slice_size) { gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_log(GPR_INFO, "Start large read test, slice size %d", slice_size); + gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); create_sockets(sv); @@ -225,7 +225,7 @@ static void large_read_test(size_t slice_size) { grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket(sv[0]); - gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); + gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); state.ep = ep; state.read_bytes = 0; @@ -344,8 +344,9 @@ static void write_test(size_t num_bytes, size_t slice_size) { gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_log(GPR_INFO, "Start write test with %d bytes, slice size %d", num_bytes, - slice_size); + gpr_log(GPR_INFO, + "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, + num_bytes, slice_size); create_sockets(sv); @@ -404,8 +405,9 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd_released_done = 0; grpc_closure_init(&fd_released_cb, &on_fd_released, &fd_released_done); - gpr_log(GPR_INFO, "Release fd read_test of size %d, slice size %d", num_bytes, - slice_size); + gpr_log(GPR_INFO, + "Release fd read_test of size %" PRIuPTR ", slice size %" PRIuPTR, + num_bytes, slice_size); create_sockets(sv); @@ -414,7 +416,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); - gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); + gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); state.ep = ep; state.read_bytes = 0; diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 266d2396af..222ae774fc 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -113,6 +113,7 @@ static void server_weak_ref_set(server_weak_ref *weak_ref, } static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, + grpc_pollset *pollset, grpc_tcp_server_acceptor *acceptor) { grpc_endpoint_shutdown(exec_ctx, tcp); grpc_endpoint_destroy(exec_ctx, tcp); diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 5248b613d7..3152fb7a46 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -32,20 +32,22 @@ */ #include "src/core/lib/iomgr/udp_server.h" + +#include <netinet/in.h> +#include <string.h> +#include <sys/socket.h> +#include <unistd.h> + #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> + #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" -#include <netinet/in.h> -#include <string.h> -#include <sys/socket.h> -#include <unistd.h> - #ifdef GRPC_NEED_UDP #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) @@ -54,6 +56,7 @@ static grpc_pollset *g_pollset; static gpr_mu *g_mu; static int g_number_of_reads = 0; static int g_number_of_bytes_read = 0; +static int g_number_of_orphan_calls = 0; static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, grpc_server *server) { @@ -71,6 +74,12 @@ static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, gpr_mu_unlock(g_mu); } +static void on_fd_orphaned(grpc_fd *emfd) { + gpr_log(GPR_INFO, "gRPC FD about to be orphaned: %d", + grpc_fd_wrapped_fd(emfd)); + g_number_of_orphan_calls++; +} + static void test_no_op(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_udp_server *s = grpc_udp_server_create(); @@ -88,6 +97,7 @@ static void test_no_op_with_start(void) { } static void test_no_op_with_port(void) { + g_number_of_orphan_calls = 0; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_udp_server *s = grpc_udp_server_create(); @@ -96,13 +106,17 @@ static void test_no_op_with_port(void) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), - on_read)); + on_read, on_fd_orphaned)); grpc_udp_server_destroy(&exec_ctx, s, NULL); grpc_exec_ctx_finish(&exec_ctx); + + /* The server had a single FD, which should have been orphaned. */ + GPR_ASSERT(g_number_of_orphan_calls == 1); } static void test_no_op_with_port_and_start(void) { + g_number_of_orphan_calls = 0; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_udp_server *s = grpc_udp_server_create(); @@ -111,12 +125,15 @@ static void test_no_op_with_port_and_start(void) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), - on_read)); + on_read, on_fd_orphaned)); grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL); grpc_udp_server_destroy(&exec_ctx, s, NULL); grpc_exec_ctx_finish(&exec_ctx); + + /* The server had a single FD, which should have been orphaned. */ + GPR_ASSERT(g_number_of_orphan_calls == 1); } static void test_receive(int number_of_clients) { @@ -133,11 +150,12 @@ static void test_receive(int number_of_clients) { gpr_log(GPR_INFO, "clients=%d", number_of_clients); g_number_of_bytes_read = 0; + g_number_of_orphan_calls = 0; memset(&addr, 0, sizeof(addr)); addr.ss_family = AF_INET; - GPR_ASSERT( - grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len, on_read)); + GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len, + on_read, on_fd_orphaned)); svrfd = grpc_udp_server_get_fd(s, 0); GPR_ASSERT(svrfd >= 0); @@ -176,6 +194,9 @@ static void test_receive(int number_of_clients) { grpc_udp_server_destroy(&exec_ctx, s, NULL); grpc_exec_ctx_finish(&exec_ctx); + + /* The server had a single FD, which should have been orphaned. */ + GPR_ASSERT(g_number_of_orphan_calls == 1); } static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c index 874e696fc2..953cc35ee6 100644 --- a/test/core/iomgr/workqueue_test.c +++ b/test/core/iomgr/workqueue_test.c @@ -73,8 +73,10 @@ static void test_add_closure(void) { gpr_mu_lock(g_mu); GPR_ASSERT(!done); - grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), - deadline); + while (!done) { + grpc_pollset_work(&exec_ctx, g_pollset, &worker, + gpr_now(deadline.clock_type), deadline); + } gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); @@ -97,9 +99,10 @@ static void test_flush(void) { grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); gpr_mu_lock(g_mu); - GPR_ASSERT(!done); - grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), - deadline); + while (!done) { + grpc_pollset_work(&exec_ctx, g_pollset, &worker, + gpr_now(deadline.clock_type), deadline); + } gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); |