aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/iomgr')
-rw-r--r--test/core/iomgr/endpoint_pair_test.c3
-rw-r--r--test/core/iomgr/endpoint_tests.c106
-rw-r--r--test/core/iomgr/ev_epoll_linux_test.c244
-rw-r--r--test/core/iomgr/fd_posix_test.c78
-rw-r--r--test/core/iomgr/load_file_test.c175
-rw-r--r--test/core/iomgr/resolve_address_test.c99
-rw-r--r--test/core/iomgr/socket_utils_test.c24
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c27
-rw-r--r--test/core/iomgr/tcp_posix_test.c83
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c51
-rw-r--r--test/core/iomgr/timer_list_test.c4
-rw-r--r--test/core/iomgr/udp_server_test.c39
-rw-r--r--test/core/iomgr/workqueue_test.c42
13 files changed, 791 insertions, 184 deletions
diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c
index 0df94a878f..99b86b6213 100644
--- a/test/core/iomgr/endpoint_pair_test.c
+++ b/test/core/iomgr/endpoint_pair_test.c
@@ -64,7 +64,8 @@ static grpc_endpoint_test_config configs[] = {
{"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up},
};
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 52082c3c6b..b79c22e42a 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -33,6 +33,7 @@
#include "test/core/iomgr/endpoint_tests.h"
+#include <stdbool.h>
#include <sys/types.h>
#include <grpc/support/alloc.h>
@@ -128,30 +129,30 @@ struct read_and_write_test_state {
};
static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx,
- void *data, bool success) {
+ void *data, grpc_error *error) {
struct read_and_write_test_state *state = data;
state->bytes_read += count_slices(
state->incoming.slices, state->incoming.count, &state->current_read_data);
- if (state->bytes_read == state->target_bytes || !success) {
+ if (state->bytes_read == state->target_bytes || error != GRPC_ERROR_NONE) {
gpr_log(GPR_INFO, "Read handler done");
gpr_mu_lock(g_mu);
- state->read_done = 1 + success;
- grpc_pollset_kick(g_pollset, NULL);
+ state->read_done = 1 + (error == GRPC_ERROR_NONE);
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL));
gpr_mu_unlock(g_mu);
- } else if (success) {
+ } else if (error == GRPC_ERROR_NONE) {
grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming,
&state->done_read);
}
}
static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
- void *data, bool success) {
+ void *data, grpc_error *error) {
struct read_and_write_test_state *state = data;
gpr_slice *slices = NULL;
size_t nslices;
- if (success) {
+ if (error == GRPC_ERROR_NONE) {
state->bytes_written += state->current_write_size;
if (state->target_bytes - state->bytes_written <
state->current_write_size) {
@@ -171,8 +172,8 @@ static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
gpr_log(GPR_INFO, "Write handler done");
gpr_mu_lock(g_mu);
- state->write_done = 1 + success;
- grpc_pollset_kick(g_pollset, NULL);
+ state->write_done = 1 + (error == GRPC_ERROR_NONE);
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL));
gpr_mu_unlock(g_mu);
}
@@ -182,19 +183,21 @@ static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
*/
static void read_and_write_test(grpc_endpoint_test_config config,
size_t num_bytes, size_t write_size,
- size_t slice_size, int shutdown) {
+ size_t slice_size, bool shutdown) {
struct read_and_write_test_state state;
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);
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);
}
@@ -219,8 +222,8 @@ static void read_and_write_test(grpc_endpoint_test_config config,
for the first iteration as for later iterations. It does the right thing
even when bytes_written is unsigned. */
state.bytes_written -= state.current_write_size;
- read_and_write_test_write_handler(&exec_ctx, &state, 1);
- grpc_exec_ctx_finish(&exec_ctx);
+ read_and_write_test_write_handler(&exec_ctx, &state, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming,
&state.done_read);
@@ -231,17 +234,19 @@ static void read_and_write_test(grpc_endpoint_test_config config,
gpr_log(GPR_DEBUG, "shutdown write");
grpc_endpoint_shutdown(&exec_ctx, state.write_ep);
}
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
while (!state.read_done || !state.write_done) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0);
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
}
gpr_mu_unlock(g_mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
end_test(config);
gpr_slice_buffer_destroy(&state.outgoing);
@@ -251,16 +256,73 @@ static void read_and_write_test(grpc_endpoint_test_config config,
grpc_exec_ctx_finish(&exec_ctx);
}
+static void inc_on_failure(grpc_exec_ctx *exec_ctx, void *arg,
+ grpc_error *error) {
+ *(int *)arg += (error != GRPC_ERROR_NONE);
+}
+
+static void wait_for_fail_count(grpc_exec_ctx *exec_ctx, int *fail_count,
+ int want_fail_count) {
+ grpc_exec_ctx_flush(exec_ctx);
+ for (int i = 0; i < 5 && *fail_count < want_fail_count; i++) {
+ grpc_pollset_worker *worker = NULL;
+ gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
+ gpr_timespec deadline =
+ gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN));
+ gpr_mu_lock(g_mu);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(exec_ctx, g_pollset, &worker, now, deadline)));
+ gpr_mu_unlock(g_mu);
+ grpc_exec_ctx_flush(exec_ctx);
+ }
+ GPR_ASSERT(*fail_count == want_fail_count);
+}
+
+static void multiple_shutdown_test(grpc_endpoint_test_config config) {
+ grpc_endpoint_test_fixture f =
+ begin_test(config, "multiple_shutdown_test", 128);
+ int fail_count = 0;
+
+ gpr_slice_buffer slice_buffer;
+ gpr_slice_buffer_init(&slice_buffer);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset);
+ grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer,
+ grpc_closure_create(inc_on_failure, &fail_count));
+ wait_for_fail_count(&exec_ctx, &fail_count, 0);
+ grpc_endpoint_shutdown(&exec_ctx, f.client_ep);
+ wait_for_fail_count(&exec_ctx, &fail_count, 1);
+ grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer,
+ grpc_closure_create(inc_on_failure, &fail_count));
+ wait_for_fail_count(&exec_ctx, &fail_count, 2);
+ gpr_slice_buffer_add(&slice_buffer, gpr_slice_from_copied_string("a"));
+ grpc_endpoint_write(&exec_ctx, f.client_ep, &slice_buffer,
+ grpc_closure_create(inc_on_failure, &fail_count));
+ wait_for_fail_count(&exec_ctx, &fail_count, 3);
+ grpc_endpoint_shutdown(&exec_ctx, f.client_ep);
+ wait_for_fail_count(&exec_ctx, &fail_count, 3);
+
+ gpr_slice_buffer_destroy(&slice_buffer);
+
+ grpc_endpoint_destroy(&exec_ctx, f.client_ep);
+ grpc_endpoint_destroy(&exec_ctx, f.server_ep);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
void grpc_endpoint_tests(grpc_endpoint_test_config config,
grpc_pollset *pollset, gpr_mu *mu) {
size_t i;
g_pollset = pollset;
g_mu = mu;
- read_and_write_test(config, 10000000, 100000, 8192, 0);
- read_and_write_test(config, 1000000, 100000, 1, 0);
- read_and_write_test(config, 100000000, 100000, 1, 1);
+ multiple_shutdown_test(config);
+ read_and_write_test(config, 10000000, 100000, 8192, false);
+ read_and_write_test(config, 1000000, 100000, 1, false);
+ read_and_write_test(config, 100000000, 100000, 1, true);
for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
- read_and_write_test(config, 40320, i, i, 0);
+ read_and_write_test(config, 40320, i, i, false);
}
g_pollset = NULL;
+ g_mu = NULL;
}
diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c
new file mode 100644
index 0000000000..2547dc9871
--- /dev/null
+++ b/test/core/iomgr/ev_epoll_linux_test.c
@@ -0,0 +1,244 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include <grpc/support/port_platform.h>
+
+/* This test only relevant on linux systems where epoll() is available */
+#ifdef GPR_LINUX_EPOLL
+#include "src/core/lib/iomgr/ev_epoll_linux.h"
+#include "src/core/lib/iomgr/ev_posix.h"
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "src/core/lib/iomgr/iomgr.h"
+#include "test/core/util/test_config.h"
+
+typedef struct test_pollset {
+ grpc_pollset *pollset;
+ gpr_mu *mu;
+} test_pollset;
+
+typedef struct test_fd {
+ int inner_fd;
+ grpc_fd *fd;
+} test_fd;
+
+/* num_fds should be an even number */
+static void test_fd_init(test_fd *tfds, int *fds, int num_fds) {
+ int i;
+ for (i = 0; i < num_fds; i++) {
+ tfds[i].inner_fd = fds[i];
+ tfds[i].fd = grpc_fd_create(fds[i], "test_fd");
+ }
+}
+
+static void test_fd_cleanup(grpc_exec_ctx *exec_ctx, test_fd *tfds,
+ int num_fds) {
+ int release_fd;
+ int i;
+
+ for (i = 0; i < num_fds; i++) {
+ grpc_fd_shutdown(exec_ctx, tfds[i].fd);
+ grpc_exec_ctx_flush(exec_ctx);
+
+ grpc_fd_orphan(exec_ctx, tfds[i].fd, NULL, &release_fd, "test_fd_cleanup");
+ grpc_exec_ctx_flush(exec_ctx);
+
+ GPR_ASSERT(release_fd == tfds[i].inner_fd);
+ close(tfds[i].inner_fd);
+ }
+}
+
+static void test_pollset_init(test_pollset *pollsets, int num_pollsets) {
+ int i;
+ for (i = 0; i < num_pollsets; i++) {
+ pollsets[i].pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(pollsets[i].pollset, &pollsets[i].mu);
+ }
+}
+
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
+ grpc_pollset_destroy(p);
+}
+
+static void test_pollset_cleanup(grpc_exec_ctx *exec_ctx,
+ test_pollset *pollsets, int num_pollsets) {
+ grpc_closure destroyed;
+ int i;
+
+ for (i = 0; i < num_pollsets; i++) {
+ grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].pollset);
+ grpc_pollset_shutdown(exec_ctx, pollsets[i].pollset, &destroyed);
+
+ grpc_exec_ctx_flush(exec_ctx);
+ gpr_free(pollsets[i].pollset);
+ }
+}
+
+#define NUM_FDS 8
+#define NUM_POLLSETS 4
+/*
+ * Cases to test:
+ * case 1) Polling islands of both fd and pollset are NULL
+ * case 2) Polling island of fd is NULL but that of pollset is not-NULL
+ * case 3) Polling island of fd is not-NULL but that of pollset is NULL
+ * case 4) Polling islands of both fd and pollset are not-NULL and:
+ * case 4.1) Polling islands of fd and pollset are equal
+ * case 4.2) Polling islands of fd and pollset are NOT-equal (This results
+ * in a merge)
+ * */
+static void test_add_fd_to_pollset() {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ test_fd tfds[NUM_FDS];
+ int fds[NUM_FDS];
+ test_pollset pollsets[NUM_POLLSETS];
+ void *expected_pi = NULL;
+ int i;
+ int r;
+
+ /* Create some dummy file descriptors. Currently using pipe file descriptors
+ * for this test but we could use any other type of file descriptors. Also,
+ * since pipe() used in this test creates two fds in each call, NUM_FDS should
+ * be an even number */
+ for (i = 0; i < NUM_FDS; i = i + 2) {
+ r = pipe(fds + i);
+ if (r != 0) {
+ gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno,
+ strerror(errno));
+ return;
+ }
+ }
+
+ test_fd_init(tfds, fds, NUM_FDS);
+ test_pollset_init(pollsets, NUM_POLLSETS);
+
+ /*Step 1.
+ * Create three polling islands (This will exercise test case 1 and 2) with
+ * the following configuration:
+ * polling island 0 = { fds:0,1,2, pollsets:0}
+ * polling island 1 = { fds:3,4, pollsets:1}
+ * polling island 2 = { fds:5,6,7 pollsets:2}
+ *
+ *Step 2.
+ * Add pollset 3 to polling island 0 (by adding fds 0 and 1 to pollset 3)
+ * (This will exercise test cases 3 and 4.1). The configuration becomes:
+ * polling island 0 = { fds:0,1,2, pollsets:0,3} <<< pollset 3 added here
+ * polling island 1 = { fds:3,4, pollsets:1}
+ * polling island 2 = { fds:5,6,7 pollsets:2}
+ *
+ *Step 3.
+ * Merge polling islands 0 and 1 by adding fd 0 to pollset 1 (This will
+ * exercise test case 4.2). The configuration becomes:
+ * polling island (merged) = {fds: 0,1,2,3,4, pollsets: 0,1,3}
+ * polling island 2 = {fds: 5,6,7 pollsets: 2}
+ *
+ *Step 4.
+ * Finally do one more merge by adding fd 3 to pollset 2.
+ * polling island (merged) = {fds: 0,1,2,3,4,5,6,7, pollsets: 0,1,2,3}
+ */
+
+ /* == Step 1 == */
+ for (i = 0; i <= 2; i++) {
+ grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[i].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+ }
+
+ for (i = 3; i <= 4; i++) {
+ grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[i].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+ }
+
+ for (i = 5; i <= 7; i++) {
+ grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[i].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+ }
+
+ /* == Step 2 == */
+ for (i = 0; i <= 1; i++) {
+ grpc_pollset_add_fd(&exec_ctx, pollsets[3].pollset, tfds[i].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+ }
+
+ /* == Step 3 == */
+ grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[0].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+
+ /* == Step 4 == */
+ grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[3].fd);
+ grpc_exec_ctx_flush(&exec_ctx);
+
+ /* All polling islands are merged at this point */
+
+ /* Compare Fd:0's polling island with that of all other Fds */
+ expected_pi = grpc_fd_get_polling_island(tfds[0].fd);
+ for (i = 1; i < NUM_FDS; i++) {
+ GPR_ASSERT(grpc_are_polling_islands_equal(
+ expected_pi, grpc_fd_get_polling_island(tfds[i].fd)));
+ }
+
+ /* Compare Fd:0's polling island with that of all other pollsets */
+ for (i = 0; i < NUM_POLLSETS; i++) {
+ GPR_ASSERT(grpc_are_polling_islands_equal(
+ expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset)));
+ }
+
+ test_fd_cleanup(&exec_ctx, tfds, NUM_FDS);
+ test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+int main(int argc, char **argv) {
+ const char *poll_strategy = NULL;
+ grpc_test_init(argc, argv);
+ grpc_iomgr_init();
+
+ poll_strategy = grpc_get_poll_strategy_name();
+ if (poll_strategy != NULL && strcmp(poll_strategy, "epoll") == 0) {
+ test_add_fd_to_pollset();
+ } else {
+ gpr_log(GPR_INFO,
+ "Skipping the test. The test is only relevant for 'epoll' "
+ "strategy. and the current strategy is: '%s'",
+ poll_strategy);
+ }
+ grpc_iomgr_shutdown();
+ return 0;
+}
+#else /* defined(GPR_LINUX_EPOLL) */
+int main(int argc, char **argv) { return 0; }
+#endif /* !defined(GPR_LINUX_EPOLL) */
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index f97f33712e..62dc24d85a 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) == GRPC_ERROR_NONE);
+ GPR_ASSERT(grpc_set_socket_rcvbuf(fd, buffer_size_bytes) == GRPC_ERROR_NONE);
/* Make fd non-blocking */
flags = fcntl(fd, F_GETFL, 0);
GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0);
@@ -133,14 +132,14 @@ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */
/* Called when data become readable in a session. */
static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */
- bool success) {
+ grpc_error *error) {
session *se = arg;
int fd = grpc_fd_wrapped_fd(se->em_fd);
ssize_t read_once = 0;
ssize_t read_total = 0;
- if (!success) {
+ if (error != GRPC_ERROR_NONE) {
session_shutdown_cb(exec_ctx, arg, 1);
return;
}
@@ -185,13 +184,14 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */,
gpr_mu_lock(g_mu);
sv->done = 1;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
/* Called when a new TCP connection request arrives in the listening port. */
static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/
- bool success) {
+ grpc_error *error) {
server *sv = arg;
int fd;
int flags;
@@ -200,7 +200,7 @@ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/
socklen_t slen = sizeof(ss);
grpc_fd *listen_em_fd = sv->em_fd;
- if (!success) {
+ if (error != GRPC_ERROR_NONE) {
listen_shutdown_cb(exec_ctx, arg, 1);
return;
}
@@ -257,9 +257,11 @@ static void server_wait_and_shutdown(server *sv) {
while (!sv->done) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -300,17 +302,18 @@ static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx,
client *cl = arg;
grpc_fd_orphan(exec_ctx, cl->em_fd, NULL, NULL, "c");
cl->done = 1;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
}
/* Write as much as possible, then register notify_on_write. */
static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */
- bool success) {
+ grpc_error *error) {
client *cl = arg;
int fd = grpc_fd_wrapped_fd(cl->em_fd);
ssize_t write_once = 0;
- if (!success) {
+ if (error != GRPC_ERROR_NONE) {
gpr_mu_lock(g_mu);
client_session_shutdown_cb(exec_ctx, arg, 1);
gpr_mu_unlock(g_mu);
@@ -363,7 +366,7 @@ static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) {
cl->em_fd = grpc_fd_create(fd, "client");
grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd);
- client_session_write(exec_ctx, cl, 1);
+ client_session_write(exec_ctx, cl, GRPC_ERROR_NONE);
}
/* Wait for the signal to shutdown a client. */
@@ -372,9 +375,11 @@ static void client_wait_and_shutdown(client *cl) {
while (!cl->done) {
grpc_pollset_worker *worker = NULL;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -399,7 +404,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 {
@@ -411,22 +416,26 @@ void init_change_data(fd_change_data *fdc) { fdc->cb_that_ran = NULL; }
void destroy_change_data(fd_change_data *fdc) {}
static void first_read_callback(grpc_exec_ctx *exec_ctx,
- void *arg /* fd_change_data */, bool success) {
+ void *arg /* fd_change_data */,
+ grpc_error *error) {
fd_change_data *fdc = arg;
gpr_mu_lock(g_mu);
fdc->cb_that_ran = first_read_callback;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
static void second_read_callback(grpc_exec_ctx *exec_ctx,
- void *arg /* fd_change_data */, bool success) {
+ void *arg /* fd_change_data */,
+ grpc_error *error) {
fd_change_data *fdc = arg;
gpr_mu_lock(g_mu);
fdc->cb_that_ran = second_read_callback;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -472,9 +481,11 @@ static void test_grpc_fd_change(void) {
gpr_mu_lock(g_mu);
while (a.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -496,9 +507,11 @@ static void test_grpc_fd_change(void) {
gpr_mu_lock(g_mu);
while (b.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -514,7 +527,8 @@ static void test_grpc_fd_change(void) {
close(sv[1]);
}
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}
diff --git a/test/core/iomgr/load_file_test.c b/test/core/iomgr/load_file_test.c
new file mode 100644
index 0000000000..f70295a81c
--- /dev/null
+++ b/test/core/iomgr/load_file_test.c
@@ -0,0 +1,175 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/slice.h>
+
+#include "src/core/lib/iomgr/load_file.h"
+#include "src/core/lib/support/string.h"
+#include "src/core/lib/support/tmpfile.h"
+#include "test/core/util/test_config.h"
+
+#define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x)
+
+static const char prefix[] = "file_test";
+
+static void test_load_empty_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ gpr_slice slice_with_null_term;
+ grpc_error *error;
+ char *tmp_name;
+
+ LOG_TEST_NAME("test_load_empty_file");
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ fclose(tmp);
+
+ error = grpc_load_file(tmp_name, 0, &slice);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0);
+
+ error = grpc_load_file(tmp_name, 1, &slice_with_null_term);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice_with_null_term) == 1);
+ GPR_ASSERT(GPR_SLICE_START_PTR(slice_with_null_term)[0] == 0);
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+ gpr_slice_unref(slice_with_null_term);
+}
+
+static void test_load_failure(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ grpc_error *error;
+ char *tmp_name;
+
+ LOG_TEST_NAME("test_load_failure");
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ fclose(tmp);
+ remove(tmp_name);
+
+ error = grpc_load_file(tmp_name, 0, &slice);
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
+ GRPC_ERROR_UNREF(error);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+}
+
+static void test_load_small_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ gpr_slice slice_with_null_term;
+ grpc_error *error;
+ char *tmp_name;
+ const char *blah = "blah";
+
+ LOG_TEST_NAME("test_load_small_file");
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah));
+ fclose(tmp);
+
+ error = grpc_load_file(tmp_name, 0, &slice);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == strlen(blah));
+ GPR_ASSERT(!memcmp(GPR_SLICE_START_PTR(slice), blah, strlen(blah)));
+
+ error = grpc_load_file(tmp_name, 1, &slice_with_null_term);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice_with_null_term) == (strlen(blah) + 1));
+ GPR_ASSERT(strcmp((const char *)GPR_SLICE_START_PTR(slice_with_null_term),
+ blah) == 0);
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+ gpr_slice_unref(slice_with_null_term);
+}
+
+static void test_load_big_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ grpc_error *error;
+ char *tmp_name;
+ static const size_t buffer_size = 124631;
+ unsigned char *buffer = gpr_malloc(buffer_size);
+ unsigned char *current;
+ size_t i;
+
+ LOG_TEST_NAME("test_load_big_file");
+
+ memset(buffer, 42, buffer_size);
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp != NULL);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(fwrite(buffer, 1, buffer_size, tmp) == buffer_size);
+ fclose(tmp);
+
+ error = grpc_load_file(tmp_name, 0, &slice);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == buffer_size);
+ current = GPR_SLICE_START_PTR(slice);
+ for (i = 0; i < buffer_size; i++) {
+ GPR_ASSERT(current[i] == 42);
+ }
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+ gpr_free(buffer);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ test_load_empty_file();
+ test_load_failure();
+ test_load_small_file();
+ test_load_big_file();
+ return 0;
+}
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index c3ede1801d..4417d96043 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -42,54 +42,74 @@ static gpr_timespec test_deadline(void) {
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100);
}
-static void must_succeed(grpc_exec_ctx *exec_ctx, void *evp,
- grpc_resolved_addresses *p) {
- GPR_ASSERT(p);
- GPR_ASSERT(p->naddrs >= 1);
- grpc_resolved_addresses_destroy(p);
- gpr_event_set(evp, (void *)1);
+typedef struct args_struct {
+ gpr_event ev;
+ grpc_resolved_addresses *addrs;
+} args_struct;
+
+void args_init(args_struct *args) {
+ gpr_event_init(&args->ev);
+ args->addrs = NULL;
+}
+
+void args_finish(args_struct *args) {
+ GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline()));
+ grpc_resolved_addresses_destroy(args->addrs);
+}
+
+static void must_succeed(grpc_exec_ctx *exec_ctx, void *argsp,
+ grpc_error *err) {
+ args_struct *args = argsp;
+ GPR_ASSERT(err == GRPC_ERROR_NONE);
+ GPR_ASSERT(args->addrs != NULL);
+ GPR_ASSERT(args->addrs->naddrs > 0);
+ gpr_event_set(&args->ev, (void *)1);
}
-static void must_fail(grpc_exec_ctx *exec_ctx, void *evp,
- grpc_resolved_addresses *p) {
- GPR_ASSERT(!p);
- gpr_event_set(evp, (void *)1);
+static void must_fail(grpc_exec_ctx *exec_ctx, void *argsp, grpc_error *err) {
+ args_struct *args = argsp;
+ GPR_ASSERT(err != GRPC_ERROR_NONE);
+ gpr_event_set(&args->ev, (void *)1);
}
static void test_localhost(void) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, "localhost:1", NULL, must_succeed, &ev);
+ grpc_resolve_address(&exec_ctx, "localhost:1", NULL,
+ grpc_closure_create(must_succeed, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
static void test_default_port(void) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, "localhost", "1", must_succeed, &ev);
+ grpc_resolve_address(&exec_ctx, "localhost", "1",
+ grpc_closure_create(must_succeed, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
static void test_missing_default_port(void) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, "localhost", NULL, must_fail, &ev);
+ grpc_resolve_address(&exec_ctx, "localhost", NULL,
+ grpc_closure_create(must_fail, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
static void test_ipv6_with_port(void) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, "[2001:db8::1]:1", NULL, must_succeed, &ev);
+ grpc_resolve_address(&exec_ctx, "[2001:db8::1]:1", NULL,
+ grpc_closure_create(must_succeed, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
static void test_ipv6_without_port(void) {
@@ -98,12 +118,13 @@ static void test_ipv6_without_port(void) {
};
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, kCases[i], "80", must_succeed, &ev);
+ grpc_resolve_address(&exec_ctx, kCases[i], "80",
+ grpc_closure_create(must_succeed, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
}
@@ -113,12 +134,13 @@ static void test_invalid_ip_addresses(void) {
};
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, kCases[i], NULL, must_fail, &ev);
+ grpc_resolve_address(&exec_ctx, kCases[i], NULL,
+ grpc_closure_create(must_fail, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
}
@@ -128,12 +150,13 @@ static void test_unparseable_hostports(void) {
};
unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
- gpr_event ev;
- gpr_event_init(&ev);
+ args_struct args;
+ args_init(&args);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_resolve_address(&exec_ctx, kCases[i], "1", must_fail, &ev);
+ grpc_resolve_address(&exec_ctx, kCases[i], "1",
+ grpc_closure_create(must_fail, &args), &args.addrs);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(gpr_event_wait(&ev, test_deadline()));
+ args_finish(&args);
}
}
diff --git a/test/core/iomgr/socket_utils_test.c b/test/core/iomgr/socket_utils_test.c
index 85c027a978..297531c44d 100644
--- a/test/core/iomgr/socket_utils_test.c
+++ b/test/core/iomgr/socket_utils_test.c
@@ -47,14 +47,22 @@ int main(int argc, char **argv) {
sock = socket(PF_INET, SOCK_STREAM, 0);
GPR_ASSERT(sock > 0);
- GPR_ASSERT(grpc_set_socket_nonblocking(sock, 1));
- GPR_ASSERT(grpc_set_socket_nonblocking(sock, 0));
- GPR_ASSERT(grpc_set_socket_cloexec(sock, 1));
- GPR_ASSERT(grpc_set_socket_cloexec(sock, 0));
- GPR_ASSERT(grpc_set_socket_reuse_addr(sock, 1));
- GPR_ASSERT(grpc_set_socket_reuse_addr(sock, 0));
- GPR_ASSERT(grpc_set_socket_low_latency(sock, 1));
- GPR_ASSERT(grpc_set_socket_low_latency(sock, 0));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_nonblocking",
+ grpc_set_socket_nonblocking(sock, 1)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_nonblocking",
+ grpc_set_socket_nonblocking(sock, 0)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_cloexec",
+ grpc_set_socket_cloexec(sock, 1)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_cloexec",
+ grpc_set_socket_cloexec(sock, 0)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_reuse_addr",
+ grpc_set_socket_reuse_addr(sock, 1)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_reuse_addr",
+ grpc_set_socket_reuse_addr(sock, 0)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_low_latency",
+ grpc_set_socket_low_latency(sock, 1)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("set_socket_low_latency",
+ grpc_set_socket_low_latency(sock, 0)));
close(sock);
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 22dc9366c3..d0c1047423 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -63,22 +63,24 @@ static gpr_timespec test_deadline(void) {
static void finish_connection() {
gpr_mu_lock(g_mu);
g_connections_complete++;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
-static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
+static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
+ grpc_error *error) {
GPR_ASSERT(g_connecting != NULL);
- GPR_ASSERT(success);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
grpc_endpoint_shutdown(exec_ctx, g_connecting);
grpc_endpoint_destroy(exec_ctx, g_connecting);
g_connecting = NULL;
finish_connection();
}
-static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
+static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
GPR_ASSERT(g_connecting == NULL);
- GPR_ASSERT(!success);
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
finish_connection();
}
@@ -125,9 +127,11 @@ void test_succeeds(void) {
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -168,7 +172,9 @@ void test_fails(void) {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
gpr_timespec polling_deadline = test_deadline();
if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
- grpc_pollset_work(&exec_ctx, g_pollset, &worker, now, polling_deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, now,
+ polling_deadline)));
}
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -179,7 +185,8 @@ void test_fails(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index 7a98fa0e50..42614567ca 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -139,19 +139,20 @@ static size_t count_slices(gpr_slice *slices, size_t nslices,
return num_bytes;
}
-static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) {
+static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data,
+ grpc_error *error) {
struct read_socket_state *state = (struct read_socket_state *)user_data;
size_t read_bytes;
int current_data;
- GPR_ASSERT(success);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
gpr_mu_lock(g_mu);
current_data = state->read_bytes % 256;
read_bytes = count_slices(state->incoming.slices, state->incoming.count,
&current_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 +171,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 +180,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;
@@ -192,8 +193,10 @@ static void read_test(size_t num_bytes, size_t slice_size) {
gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -216,7 +219,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 +228,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;
@@ -238,8 +241,10 @@ static void large_read_test(size_t slice_size) {
gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -281,13 +286,15 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
}
static void write_done(grpc_exec_ctx *exec_ctx,
- void *user_data /* write_socket_state */, bool success) {
+ void *user_data /* write_socket_state */,
+ grpc_error *error) {
struct write_socket_state *state = (struct write_socket_state *)user_data;
gpr_log(GPR_INFO, "Write done callback called");
gpr_mu_lock(g_mu);
gpr_log(GPR_INFO, "Signalling write done");
state->write_done = 1;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -306,9 +313,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
for (;;) {
grpc_pollset_worker *worker = NULL;
gpr_mu_lock(g_mu);
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
do {
@@ -344,8 +353,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);
@@ -370,8 +380,10 @@ static void write_test(size_t num_bytes, size_t slice_size) {
if (state.write_done) {
break;
}
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -384,10 +396,11 @@ static void write_test(size_t num_bytes, size_t slice_size) {
grpc_exec_ctx_finish(&exec_ctx);
}
-void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
+void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *errors) {
int *done = arg;
*done = 1;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
}
/* Do a read_test, then release fd and try to read/write again. Verify that
@@ -404,8 +417,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 +428,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;
@@ -427,8 +441,10 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -441,8 +457,10 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
gpr_mu_lock(g_mu);
while (!fd_released_done) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
}
gpr_mu_unlock(g_mu);
GPR_ASSERT(fd_released_done == 1);
@@ -504,7 +522,8 @@ static grpc_endpoint_test_config configs[] = {
{"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up},
};
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}
@@ -515,8 +534,8 @@ int main(int argc, char **argv) {
grpc_init();
g_pollset = gpr_malloc(grpc_pollset_size());
grpc_pollset_init(g_pollset, &g_mu);
- run_tests();
grpc_endpoint_tests(configs[0], g_pollset, g_mu);
+ run_tests();
grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 266d2396af..6e2d1d0fc9 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -90,7 +90,7 @@ static void on_connect_result_set(on_connect_result *result,
}
static void server_weak_ref_shutdown(grpc_exec_ctx *exec_ctx, void *arg,
- bool success) {
+ grpc_error *error) {
server_weak_ref *weak_ref = arg;
weak_ref->server = NULL;
}
@@ -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);
@@ -120,20 +121,23 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
gpr_mu_lock(g_mu);
on_connect_result_set(&g_result, acceptor);
g_nconnects++;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
static void test_no_op(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
grpc_tcp_server_unref(&exec_ctx, s);
grpc_exec_ctx_finish(&exec_ctx);
}
static void test_no_op_with_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
LOG_TEST("test_no_op_with_start");
grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL);
grpc_tcp_server_unref(&exec_ctx, s);
@@ -143,13 +147,16 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
struct sockaddr_in addr;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
LOG_TEST("test_no_op_with_port");
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- GPR_ASSERT(
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr)) > 0);
+ int port;
+ GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
+ &port) == GRPC_ERROR_NONE &&
+ port > 0);
grpc_tcp_server_unref(&exec_ctx, s);
grpc_exec_ctx_finish(&exec_ctx);
@@ -158,13 +165,16 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
struct sockaddr_in addr;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
LOG_TEST("test_no_op_with_port_and_start");
+ int port;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- GPR_ASSERT(
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr)) > 0);
+ GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
+ &port) == GRPC_ERROR_NONE &&
+ port > 0);
grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL);
@@ -188,8 +198,10 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
while (g_nconnects == nconnects_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(exec_ctx, g_pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(exec_ctx);
gpr_mu_lock(g_mu);
@@ -213,7 +225,8 @@ static void test_connect(unsigned n) {
int svr_port;
unsigned svr1_fd_count;
int svr1_port;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
unsigned i;
server_weak_ref weak_ref;
server_weak_ref_init(&weak_ref);
@@ -222,14 +235,17 @@ static void test_connect(unsigned n) {
memset(&addr, 0, sizeof(addr));
memset(&addr1, 0, sizeof(addr1));
addr.ss_family = addr1.ss_family = AF_INET;
- svr_port = grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len);
+ GPR_ASSERT(GRPC_ERROR_NONE ==
+ grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
+ &svr_port));
GPR_ASSERT(svr_port > 0);
/* Cannot use wildcard (port==0), because add_port() will try to reuse the
same port as a previous add_port(). */
svr1_port = grpc_pick_unused_port_or_die();
grpc_sockaddr_set_port((struct sockaddr *)&addr1, svr1_port);
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr1, addr_len) ==
- svr1_port);
+ GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr1, addr_len,
+ &svr_port) == GRPC_ERROR_NONE &&
+ svr_port == svr1_port);
/* Bad port_index. */
GPR_ASSERT(grpc_tcp_server_port_fd_count(s, 2) == 0);
@@ -305,7 +321,8 @@ static void test_connect(unsigned n) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 2e0f5c8701..be8988ab75 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -42,8 +42,8 @@
static int cb_called[MAX_CB][2];
-static void cb(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
- cb_called[(intptr_t)arg][success]++;
+static void cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
+ cb_called[(intptr_t)arg][error == GRPC_ERROR_NONE]++;
}
static void add_test(void) {
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..76ecfae74b 100644
--- a/test/core/iomgr/workqueue_test.c
+++ b/test/core/iomgr/workqueue_test.c
@@ -42,17 +42,20 @@
static gpr_mu *g_mu;
static grpc_pollset *g_pollset;
-static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, bool success) {
- GPR_ASSERT(success == 1);
+static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, grpc_error *error) {
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
gpr_mu_lock(g_mu);
*(int *)p = 1;
- grpc_pollset_kick(g_pollset, NULL);
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
static void test_ref_unref(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
+ grpc_workqueue *wq;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_workqueue_create",
+ grpc_workqueue_create(&exec_ctx, &wq)));
GRPC_WORKQUEUE_REF(wq, "test");
GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "test");
GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy");
@@ -63,18 +66,24 @@ static void test_add_closure(void) {
grpc_closure c;
int done = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
+ grpc_workqueue *wq;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_workqueue_create",
+ grpc_workqueue_create(&exec_ctx, &wq)));
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
grpc_pollset_worker *worker = NULL;
grpc_closure_init(&c, must_succeed, &done);
- grpc_workqueue_push(wq, &c, 1);
+ grpc_workqueue_enqueue(&exec_ctx, wq, &c, GRPC_ERROR_NONE);
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) {
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ 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);
@@ -87,19 +96,25 @@ static void test_flush(void) {
grpc_closure c;
int done = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
+ grpc_workqueue *wq;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_workqueue_create",
+ grpc_workqueue_create(&exec_ctx, &wq)));
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
grpc_pollset_worker *worker = NULL;
grpc_closure_init(&c, must_succeed, &done);
- grpc_exec_ctx_enqueue(&exec_ctx, &c, true, NULL);
+ grpc_exec_ctx_sched(&exec_ctx, &c, GRPC_ERROR_NONE, NULL);
grpc_workqueue_flush(&exec_ctx, wq);
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) {
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ 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);
@@ -108,7 +123,8 @@ static void test_flush(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
+static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
+ grpc_error *error) {
grpc_pollset_destroy(p);
}