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.c25
-rw-r--r--test/core/iomgr/endpoint_tests.c26
-rw-r--r--test/core/iomgr/endpoint_tests.h4
-rw-r--r--test/core/iomgr/fd_conservation_posix_test.c4
-rw-r--r--test/core/iomgr/fd_posix_test.c108
-rw-r--r--test/core/iomgr/resolve_address_test.c4
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c2
-rw-r--r--test/core/iomgr/socket_utils_test.c2
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c172
-rw-r--r--test/core/iomgr/tcp_posix_test.c115
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c56
-rw-r--r--test/core/iomgr/time_averaged_stats_test.c2
-rw-r--r--test/core/iomgr/timer_heap_test.c196
-rw-r--r--test/core/iomgr/timer_list_test.c33
-rw-r--r--test/core/iomgr/udp_server_test.c29
-rw-r--r--test/core/iomgr/workqueue_test.c47
16 files changed, 401 insertions, 424 deletions
diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c
index 7e266ebfb9..0df94a878f 100644
--- a/test/core/iomgr/endpoint_pair_test.c
+++ b/test/core/iomgr/endpoint_pair_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,18 +31,17 @@
*
*/
-#include "src/core/iomgr/tcp_posix.h"
-
+#include "src/core/lib/iomgr/endpoint_pair.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
-#include "src/core/iomgr/endpoint_pair.h"
-#include "test/core/util/test_config.h"
#include "test/core/iomgr/endpoint_tests.h"
+#include "test/core/util/test_config.h"
-static grpc_pollset g_pollset;
+static gpr_mu *g_mu;
+static grpc_pollset *g_pollset;
static void clean_up(void) {}
@@ -54,8 +53,8 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair(
f.client_ep = p.client;
f.server_ep = p.server;
- grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, &g_pollset);
- grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, &g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset);
grpc_exec_ctx_finish(&exec_ctx);
return f;
@@ -74,12 +73,14 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_init(&g_pollset);
- grpc_endpoint_tests(configs[0], &g_pollset);
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
+ grpc_endpoint_tests(configs[0], g_pollset, g_mu);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+ gpr_free(g_pollset);
return 0;
}
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 1b6a78da9a..52082c3c6b 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,8 +36,8 @@
#include <sys/types.h>
#include <grpc/support/alloc.h>
-#include <grpc/support/slice.h>
#include <grpc/support/log.h>
+#include <grpc/support/slice.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
#include "test/core/util/test_config.h"
@@ -58,6 +58,7 @@
*/
+static gpr_mu *g_mu;
static grpc_pollset *g_pollset;
size_t count_slices(gpr_slice *slices, size_t nslices, int *current_data) {
@@ -88,7 +89,7 @@ static void end_test(grpc_endpoint_test_config config) { config.clean_up(); }
static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
size_t *num_blocks, uint8_t *current_data) {
size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
- gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices);
+ gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices);
size_t num_bytes_left = num_bytes;
size_t i;
size_t j;
@@ -134,10 +135,10 @@ static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx,
state->incoming.slices, state->incoming.count, &state->current_read_data);
if (state->bytes_read == state->target_bytes || !success) {
gpr_log(GPR_INFO, "Read handler done");
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_lock(g_mu);
state->read_done = 1 + success;
grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_unlock(g_mu);
} else if (success) {
grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming,
&state->done_read);
@@ -163,16 +164,16 @@ static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
gpr_slice_buffer_addn(&state->outgoing, slices, nslices);
grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing,
&state->done_write);
- free(slices);
+ gpr_free(slices);
return;
}
}
gpr_log(GPR_INFO, "Write handler done");
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_lock(g_mu);
state->write_done = 1 + success;
grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_unlock(g_mu);
}
/* Do both reading and writing using the grpc_endpoint API.
@@ -232,14 +233,14 @@ static void read_and_write_test(grpc_endpoint_test_config config,
}
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_lock(g_mu);
while (!state.read_done || !state.write_done) {
- grpc_pollset_worker worker;
+ 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_mu_unlock(GRPC_POLLSET_MU(g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
end_test(config);
@@ -251,9 +252,10 @@ static void read_and_write_test(grpc_endpoint_test_config config,
}
void grpc_endpoint_tests(grpc_endpoint_test_config config,
- grpc_pollset *pollset) {
+ 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);
diff --git a/test/core/iomgr/endpoint_tests.h b/test/core/iomgr/endpoint_tests.h
index 700f854891..586010c863 100644
--- a/test/core/iomgr/endpoint_tests.h
+++ b/test/core/iomgr/endpoint_tests.h
@@ -36,7 +36,7 @@
#include <sys/types.h>
-#include "src/core/iomgr/endpoint.h"
+#include "src/core/lib/iomgr/endpoint.h"
typedef struct grpc_endpoint_test_config grpc_endpoint_test_config;
typedef struct grpc_endpoint_test_fixture grpc_endpoint_test_fixture;
@@ -53,6 +53,6 @@ struct grpc_endpoint_test_config {
};
void grpc_endpoint_tests(grpc_endpoint_test_config config,
- grpc_pollset *pollset);
+ grpc_pollset *pollset, gpr_mu *mu);
#endif /* GRPC_TEST_CORE_IOMGR_ENDPOINT_TESTS_H */
diff --git a/test/core/iomgr/fd_conservation_posix_test.c b/test/core/iomgr/fd_conservation_posix_test.c
index 401bf70a9e..bbb3f46497 100644
--- a/test/core/iomgr/fd_conservation_posix_test.c
+++ b/test/core/iomgr/fd_conservation_posix_test.c
@@ -35,9 +35,9 @@
#include <grpc/support/log.h>
+#include "src/core/lib/iomgr/endpoint_pair.h"
+#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
-#include "src/core/iomgr/endpoint_pair.h"
-#include "src/core/iomgr/iomgr.h"
int main(int argc, char **argv) {
int i;
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 347a86af10..f97f33712e 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/iomgr/fd_posix.h"
+#include "src/core/lib/iomgr/ev_posix.h"
#include <ctype.h>
#include <errno.h>
@@ -49,9 +49,13 @@
#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"
-static grpc_pollset g_pollset;
+static gpr_mu *g_mu;
+static grpc_pollset *g_pollset;
/* buffer size used to send and receive data.
1024 is the minimal value to set TCP send and receive buffer. */
@@ -131,7 +135,7 @@ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */
static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */
bool success) {
session *se = arg;
- int fd = se->em_fd->fd;
+ int fd = grpc_fd_wrapped_fd(se->em_fd);
ssize_t read_once = 0;
ssize_t read_total = 0;
@@ -179,10 +183,10 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */,
grpc_fd_orphan(exec_ctx, sv->em_fd, NULL, NULL, "b");
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
sv->done = 1;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
/* Called when a new TCP connection request arrives in the listening port. */
@@ -201,7 +205,7 @@ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/
return;
}
- fd = accept(listen_em_fd->fd, (struct sockaddr *)&ss, &slen);
+ fd = accept(grpc_fd_wrapped_fd(listen_em_fd), (struct sockaddr *)&ss, &slen);
GPR_ASSERT(fd >= 0);
GPR_ASSERT(fd < FD_SETSIZE);
flags = fcntl(fd, F_GETFL, 0);
@@ -209,7 +213,7 @@ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/
se = gpr_malloc(sizeof(*se));
se->sv = sv;
se->em_fd = grpc_fd_create(fd, "listener");
- grpc_pollset_add_fd(exec_ctx, &g_pollset, se->em_fd);
+ grpc_pollset_add_fd(exec_ctx, g_pollset, se->em_fd);
se->session_read_closure.cb = session_read_cb;
se->session_read_closure.cb_arg = se;
grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure);
@@ -238,7 +242,7 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) {
GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0);
sv->em_fd = grpc_fd_create(fd, "server");
- grpc_pollset_add_fd(exec_ctx, &g_pollset, sv->em_fd);
+ grpc_pollset_add_fd(exec_ctx, g_pollset, sv->em_fd);
/* Register to be interested in reading from listen_fd. */
sv->listen_closure.cb = listen_cb;
sv->listen_closure.cb_arg = sv;
@@ -249,18 +253,18 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) {
/* Wait and shutdown a sever. */
static void server_wait_and_shutdown(server *sv) {
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (!sv->done) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ 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_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
/* ===An upload client to test notify_on_write=== */
@@ -296,20 +300,20 @@ 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);
+ 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) {
client *cl = arg;
- int fd = cl->em_fd->fd;
+ int fd = grpc_fd_wrapped_fd(cl->em_fd);
ssize_t write_once = 0;
if (!success) {
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
client_session_shutdown_cb(exec_ctx, arg, 1);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
return;
}
@@ -319,7 +323,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */
} while (write_once > 0);
if (errno == EAGAIN) {
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) {
cl->write_closure.cb = client_session_write;
cl->write_closure.cb_arg = cl;
@@ -328,7 +332,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */
} else {
client_session_shutdown_cb(exec_ctx, arg, 1);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
} else {
gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno));
abort();
@@ -357,25 +361,25 @@ 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);
+ grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd);
client_session_write(exec_ctx, cl, 1);
}
/* Wait for the signal to shutdown a client. */
static void client_wait_and_shutdown(client *cl) {
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (!cl->done) {
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC));
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
/* Test grpc_fd. Start an upload server and client, upload a stream of
@@ -410,20 +414,20 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx,
void *arg /* fd_change_data */, bool success) {
fd_change_data *fdc = arg;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
fdc->cb_that_ran = first_read_callback;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ 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) {
fd_change_data *fdc = arg;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
fdc->cb_that_ran = second_read_callback;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
/* Test that changing the callback we use for notify_on_read actually works.
@@ -456,7 +460,7 @@ static void test_grpc_fd_change(void) {
GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0);
em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change");
- grpc_pollset_add_fd(&exec_ctx, &g_pollset, em_fd);
+ grpc_pollset_add_fd(&exec_ctx, g_pollset, em_fd);
/* Register the first callback, then make its FD readable */
grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure);
@@ -465,18 +469,18 @@ static void test_grpc_fd_change(void) {
GPR_ASSERT(result == 1);
/* And now wait for it to run. */
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (a.cb_that_ran == NULL) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ 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_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(a.cb_that_ran == first_read_callback);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
/* And drain the socket so we can generate a new read edge */
result = read(sv[0], &data, 1);
@@ -489,19 +493,19 @@ static void test_grpc_fd_change(void) {
result = write(sv[1], &data, 1);
GPR_ASSERT(result == 1);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (b.cb_that_ran == NULL) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ 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_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
/* Except now we verify that second_read_callback ran instead */
GPR_ASSERT(b.cb_that_ran == second_read_callback);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_fd_orphan(&exec_ctx, em_fd, NULL, NULL, "d");
grpc_exec_ctx_finish(&exec_ctx);
@@ -519,12 +523,14 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_iomgr_init();
- grpc_pollset_init(&g_pollset);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
test_grpc_fd();
test_grpc_fd_change();
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
+ gpr_free(g_pollset);
grpc_iomgr_shutdown();
return 0;
}
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 56ce091a88..a66edc9df2 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -31,11 +31,11 @@
*
*/
-#include "src/core/iomgr/resolve_address.h"
-#include "src/core/iomgr/executor.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
+#include "src/core/lib/iomgr/executor.h"
#include "test/core/util/test_config.h"
static gpr_timespec test_deadline(void) {
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index a7b57c1466..a330314443 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/iomgr/sockaddr_utils.h"
+#include "src/core/lib/iomgr/sockaddr_utils.h"
#include <errno.h>
#include <string.h>
diff --git a/test/core/iomgr/socket_utils_test.c b/test/core/iomgr/socket_utils_test.c
index 58c3fbc0ae..85c027a978 100644
--- a/test/core/iomgr/socket_utils_test.c
+++ b/test/core/iomgr/socket_utils_test.c
@@ -32,7 +32,7 @@
*/
#include <grpc/support/port_platform.h>
-#include "src/core/iomgr/socket_utils_posix.h"
+#include "src/core/lib/iomgr/socket_utils_posix.h"
#include <errno.h>
#include <string.h>
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 9725d8a3b6..22dc9366c3 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/iomgr/tcp_client.h"
+#include "src/core/lib/iomgr/tcp_client.h"
#include <errno.h>
#include <netinet/in.h>
@@ -40,15 +40,19 @@
#include <unistd.h>
#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/iomgr/iomgr.h"
-#include "src/core/iomgr/socket_utils_posix.h"
+#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/pollset_set.h"
+#include "src/core/lib/iomgr/socket_utils_posix.h"
+#include "src/core/lib/iomgr/timer.h"
#include "test/core/util/test_config.h"
-static grpc_pollset_set g_pollset_set;
-static grpc_pollset g_pollset;
+static grpc_pollset_set *g_pollset_set;
+static gpr_mu *g_mu;
+static grpc_pollset *g_pollset;
static int g_connections_complete = 0;
static grpc_endpoint *g_connecting = NULL;
@@ -57,10 +61,10 @@ static gpr_timespec test_deadline(void) {
}
static void finish_connection() {
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
g_connections_complete++;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
@@ -98,14 +102,14 @@ void test_succeeds(void) {
GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len));
GPR_ASSERT(0 == listen(svr_fd, 1));
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
connections_complete_before = g_connections_complete;
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
/* connect to it */
GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0);
grpc_closure_init(&done, must_succeed, NULL);
- grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set,
+ grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
(struct sockaddr *)&addr, addr_len,
gpr_inf_future(GPR_CLOCK_REALTIME));
@@ -117,19 +121,21 @@ void test_succeeds(void) {
GPR_ASSERT(r >= 0);
close(r);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (g_connections_complete == connections_complete_before) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ 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_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
+ grpc_exec_ctx_flush(&exec_ctx);
+ gpr_mu_lock(g_mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
+
+ grpc_exec_ctx_finish(&exec_ctx);
}
void test_fails(void) {
@@ -144,118 +150,33 @@ void test_fails(void) {
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
connections_complete_before = g_connections_complete;
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
/* connect to a broken address */
grpc_closure_init(&done, must_fail, NULL);
- grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set,
+ grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
(struct sockaddr *)&addr, addr_len,
gpr_inf_future(GPR_CLOCK_REALTIME));
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
/* wait for the connection callback to finish */
while (g_connections_complete == connections_complete_before) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), test_deadline());
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- }
-
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
-}
-
-void test_times_out(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
- int svr_fd;
-#define NUM_CLIENT_CONNECTS 100
- int client_fd[NUM_CLIENT_CONNECTS];
- int i;
- int r;
- int connections_complete_before;
- gpr_timespec connect_deadline;
- grpc_closure done;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
-
- gpr_log(GPR_DEBUG, "test_times_out");
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
-
- /* create a dummy server */
- svr_fd = socket(AF_INET, SOCK_STREAM, 0);
- GPR_ASSERT(svr_fd >= 0);
- GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len));
- GPR_ASSERT(0 == listen(svr_fd, 1));
- /* Get its address */
- GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0);
-
- /* tie up the listen buffer, which is somewhat arbitrarily sized. */
- for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) {
- client_fd[i] = socket(AF_INET, SOCK_STREAM, 0);
- grpc_set_socket_nonblocking(client_fd[i], 1);
- do {
- r = connect(client_fd[i], (struct sockaddr *)&addr, addr_len);
- } while (r == -1 && errno == EINTR);
- GPR_ASSERT(r < 0);
- GPR_ASSERT(errno == EWOULDBLOCK || errno == EINPROGRESS);
- }
-
- /* connect to dummy server address */
-
- connect_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
-
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- connections_complete_before = g_connections_complete;
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
-
- grpc_closure_init(&done, must_fail, NULL);
- grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set,
- (struct sockaddr *)&addr, addr_len, connect_deadline);
-
- /* Make sure the event doesn't trigger early */
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- for (;;) {
- grpc_pollset_worker worker;
- gpr_timespec now = gpr_now(connect_deadline.clock_type);
- gpr_timespec continue_verifying_time =
- gpr_time_from_seconds(5, GPR_TIMESPAN);
- gpr_timespec grace_time = gpr_time_from_seconds(3, GPR_TIMESPAN);
- gpr_timespec finish_time =
- gpr_time_add(connect_deadline, continue_verifying_time);
- gpr_timespec restart_verifying_time =
- gpr_time_add(connect_deadline, grace_time);
- int is_after_deadline = gpr_time_cmp(now, connect_deadline) > 0;
- if (gpr_time_cmp(now, finish_time) > 0) {
- break;
+ grpc_pollset_worker *worker = NULL;
+ 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_log(GPR_DEBUG, "now=%lld.%09d connect_deadline=%lld.%09d",
- (long long)now.tv_sec, (int)now.tv_nsec,
- (long long)connect_deadline.tv_sec, (int)connect_deadline.tv_nsec);
- if (is_after_deadline && gpr_time_cmp(now, restart_verifying_time) <= 0) {
- /* allow some slack before insisting that things be done */
- } else {
- GPR_ASSERT(g_connections_complete ==
- connections_complete_before + is_after_deadline);
- }
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10));
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
+ grpc_exec_ctx_flush(&exec_ctx);
+ gpr_mu_lock(g_mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- close(svr_fd);
- for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) {
- close(client_fd[i]);
- }
+ gpr_mu_unlock(g_mu);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
@@ -267,18 +188,19 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_set_init(&g_pollset_set);
- grpc_pollset_init(&g_pollset);
- grpc_pollset_set_add_pollset(&exec_ctx, &g_pollset_set, &g_pollset);
+ g_pollset_set = grpc_pollset_set_create();
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
+ grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset);
grpc_exec_ctx_finish(&exec_ctx);
test_succeeds();
gpr_log(GPR_ERROR, "End of first test");
test_fails();
- test_times_out();
- grpc_pollset_set_destroy(&g_pollset_set);
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_pollset_set_destroy(g_pollset_set);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+ gpr_free(g_pollset);
return 0;
}
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index d290c6bc3a..7a98fa0e50 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,13 +31,13 @@
*
*/
-#include "src/core/iomgr/tcp_posix.h"
+#include "src/core/lib/iomgr/tcp_posix.h"
#include <errno.h>
#include <fcntl.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include <unistd.h>
#include <grpc/grpc.h>
@@ -45,10 +45,11 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>
-#include "test/core/util/test_config.h"
#include "test/core/iomgr/endpoint_tests.h"
+#include "test/core/util/test_config.h"
-static grpc_pollset g_pollset;
+static gpr_mu *g_mu;
+static grpc_pollset *g_pollset;
/*
General test notes:
@@ -96,7 +97,7 @@ static ssize_t fill_socket(int fd) {
static size_t fill_socket_partial(int fd, size_t bytes) {
ssize_t write_bytes;
size_t total_bytes = 0;
- unsigned char *buf = malloc(bytes);
+ unsigned char *buf = gpr_malloc(bytes);
unsigned i;
for (i = 0; i < bytes; ++i) {
buf[i] = (uint8_t)(i % 256);
@@ -145,7 +146,7 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) {
GPR_ASSERT(success);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
current_data = state->read_bytes % 256;
read_bytes = count_slices(state->incoming.slices, state->incoming.count,
&current_data);
@@ -153,10 +154,10 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) {
gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes,
state->target_read_bytes);
if (state->read_bytes >= state->target_read_bytes) {
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
} else {
grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
}
@@ -175,7 +176,7 @@ static void read_test(size_t num_bytes, size_t slice_size) {
create_sockets(sv);
ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test");
- grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset);
+ 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);
@@ -188,17 +189,17 @@ static void read_test(size_t num_bytes, size_t slice_size) {
grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
gpr_slice_buffer_destroy(&state.incoming);
grpc_endpoint_destroy(&exec_ctx, ep);
@@ -221,7 +222,7 @@ static void large_read_test(size_t slice_size) {
ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size,
"test");
- grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset);
+ 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);
@@ -234,17 +235,17 @@ static void large_read_test(size_t slice_size) {
grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
gpr_slice_buffer_destroy(&state.incoming);
grpc_endpoint_destroy(&exec_ctx, ep);
@@ -283,15 +284,15 @@ static void write_done(grpc_exec_ctx *exec_ctx,
void *user_data /* write_socket_state */, bool success) {
struct write_socket_state *state = (struct write_socket_state *)user_data;
gpr_log(GPR_INFO, "Write done callback called");
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
gpr_log(GPR_INFO, "Signalling write done");
state->write_done = 1;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
- unsigned char *buf = malloc(read_size);
+ unsigned char *buf = gpr_malloc(read_size);
ssize_t bytes_read;
size_t bytes_left = num_bytes;
int flags;
@@ -303,12 +304,12 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0);
for (;;) {
- grpc_pollset_worker worker;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ 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_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
do {
bytes_read =
@@ -350,7 +351,7 @@ static void write_test(size_t num_bytes, size_t slice_size) {
ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"),
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test");
- grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset);
state.ep = ep;
state.write_done = 0;
@@ -363,19 +364,19 @@ static void write_test(size_t num_bytes, size_t slice_size) {
grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure);
drain_socket_blocking(sv[0], num_bytes, num_bytes);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
for (;;) {
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
if (state.write_done) {
break;
}
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
gpr_slice_buffer_destroy(&outgoing);
grpc_endpoint_destroy(&exec_ctx, ep);
@@ -386,7 +387,7 @@ static void write_test(size_t num_bytes, size_t slice_size) {
void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
int *done = arg;
*done = 1;
- grpc_pollset_kick(&g_pollset, NULL);
+ grpc_pollset_kick(g_pollset, NULL);
}
/* Do a read_test, then release fd and try to read/write again. Verify that
@@ -410,7 +411,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test");
GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0);
- grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset);
+ 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);
@@ -423,27 +424,27 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (state.read_bytes < state.target_read_bytes) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
gpr_slice_buffer_destroy(&state.incoming);
grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
while (!fd_released_done) {
- grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
GPR_ASSERT(fd_released_done == 1);
GPR_ASSERT(fd == sv[1]);
grpc_exec_ctx_finish(&exec_ctx);
@@ -491,8 +492,8 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair(
slice_size, "test");
f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"),
slice_size, "test");
- grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, &g_pollset);
- grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, &g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset);
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset);
grpc_exec_ctx_finish(&exec_ctx);
@@ -512,13 +513,15 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_init(&g_pollset);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
run_tests();
- grpc_endpoint_tests(configs[0], &g_pollset);
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_endpoint_tests(configs[0], g_pollset, g_mu);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+ gpr_free(g_pollset);
return 0;
}
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 272d97bfcb..266d2396af 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,25 +31,29 @@
*
*/
-#include "src/core/iomgr/tcp_server.h"
-#include "src/core/iomgr/iomgr.h"
-#include "src/core/iomgr/sockaddr_utils.h"
+#include "src/core/lib/iomgr/tcp_server.h"
+
+#include <errno.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/iomgr.h"
+#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <unistd.h>
-
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
-static grpc_pollset g_pollset;
+static gpr_mu *g_mu;
+static grpc_pollset *g_pollset;
static int g_nconnects = 0;
typedef struct on_connect_result {
@@ -113,11 +117,11 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
grpc_endpoint_shutdown(exec_ctx, tcp);
grpc_endpoint_destroy(exec_ctx, tcp);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
on_connect_result_set(&g_result, acceptor);
g_nconnects++;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
static void test_no_op(void) {
@@ -174,7 +178,7 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
int clifd = socket(remote->sa_family, SOCK_STREAM, 0);
int nconnects_before;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
nconnects_before = g_nconnects;
on_connect_result_init(&g_result);
GPR_ASSERT(clifd >= 0);
@@ -183,19 +187,19 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
gpr_log(GPR_DEBUG, "wait");
while (g_nconnects == nconnects_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
- grpc_pollset_worker worker;
- grpc_pollset_work(exec_ctx, &g_pollset, &worker,
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
gpr_log(GPR_DEBUG, "wait done");
GPR_ASSERT(g_nconnects == nconnects_before + 1);
close(clifd);
*result = g_result;
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
/* Tests a tcp server with multiple ports. TODO(daniel-j-born): Multiple fds for
@@ -210,7 +214,6 @@ static void test_connect(unsigned n) {
unsigned svr1_fd_count;
int svr1_port;
grpc_tcp_server *s = grpc_tcp_server_create(NULL);
- grpc_pollset *pollsets[1];
unsigned i;
server_weak_ref weak_ref;
server_weak_ref_init(&weak_ref);
@@ -259,8 +262,7 @@ static void test_connect(unsigned n) {
}
}
- pollsets[0] = &g_pollset;
- grpc_tcp_server_start(&exec_ctx, s, pollsets, 1, on_connect, NULL);
+ grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, NULL);
for (i = 0; i < n; i++) {
on_connect_result result;
@@ -312,7 +314,8 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_init(&g_pollset);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
test_no_op();
test_no_op_with_start();
@@ -321,9 +324,10 @@ int main(int argc, char **argv) {
test_connect(1);
test_connect(10);
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+ gpr_free(g_pollset);
return 0;
}
diff --git a/test/core/iomgr/time_averaged_stats_test.c b/test/core/iomgr/time_averaged_stats_test.c
index cb006d152a..72f8559d66 100644
--- a/test/core/iomgr/time_averaged_stats_test.c
+++ b/test/core/iomgr/time_averaged_stats_test.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/iomgr/time_averaged_stats.h"
+#include "src/core/lib/iomgr/time_averaged_stats.h"
#include <math.h>
diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c
index 077a9fd6bd..d1cb0047f2 100644
--- a/test/core/iomgr/timer_heap_test.c
+++ b/test/core/iomgr/timer_heap_test.c
@@ -31,13 +31,15 @@
*
*/
-#include "src/core/iomgr/timer_heap.h"
+#include "src/core/lib/iomgr/timer_heap.h"
#include <stdlib.h>
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
+
#include "test/core/util/test_config.h"
static gpr_timespec random_deadline(void) {
@@ -57,79 +59,6 @@ static grpc_timer *create_test_elements(size_t num_elements) {
return elems;
}
-static int cmp_elem(const void *a, const void *b) {
- int i = *(const int *)a;
- int j = *(const int *)b;
- return i - j;
-}
-
-static size_t *all_top(grpc_timer_heap *pq, size_t *n) {
- size_t *vec = NULL;
- size_t *need_to_check_children;
- size_t num_need_to_check_children = 0;
-
- *n = 0;
- if (pq->timer_count == 0) return vec;
- need_to_check_children =
- gpr_malloc(pq->timer_count * sizeof(*need_to_check_children));
- need_to_check_children[num_need_to_check_children++] = 0;
- vec = gpr_malloc(pq->timer_count * sizeof(*vec));
- while (num_need_to_check_children > 0) {
- size_t ind = need_to_check_children[0];
- size_t leftchild, rightchild;
- num_need_to_check_children--;
- memmove(need_to_check_children, need_to_check_children + 1,
- num_need_to_check_children * sizeof(*need_to_check_children));
- vec[(*n)++] = ind;
- leftchild = 1u + 2u * ind;
- if (leftchild < pq->timer_count) {
- if (gpr_time_cmp(pq->timers[leftchild]->deadline,
- pq->timers[ind]->deadline) >= 0) {
- need_to_check_children[num_need_to_check_children++] = leftchild;
- }
- rightchild = leftchild + 1;
- if (rightchild < pq->timer_count &&
- gpr_time_cmp(pq->timers[rightchild]->deadline,
- pq->timers[ind]->deadline) >= 0) {
- need_to_check_children[num_need_to_check_children++] = rightchild;
- }
- }
- }
-
- gpr_free(need_to_check_children);
-
- return vec;
-}
-
-static void check_pq_top(grpc_timer *elements, grpc_timer_heap *pq,
- uint8_t *inpq, size_t num_elements) {
- gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME);
- size_t *max_deadline_indices =
- gpr_malloc(num_elements * sizeof(*max_deadline_indices));
- size_t *top_elements;
- size_t num_max_deadline_indices = 0;
- size_t num_top_elements;
- size_t i;
- for (i = 0; i < num_elements; ++i) {
- if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) {
- if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) {
- num_max_deadline_indices = 0;
- max_deadline = elements[i].deadline;
- }
- max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index;
- }
- }
- qsort(max_deadline_indices, num_max_deadline_indices,
- sizeof(*max_deadline_indices), cmp_elem);
- top_elements = all_top(pq, &num_top_elements);
- GPR_ASSERT(num_top_elements == num_max_deadline_indices);
- for (i = 0; i < num_top_elements; i++) {
- GPR_ASSERT(max_deadline_indices[i] == top_elements[i]);
- }
- gpr_free(max_deadline_indices);
- gpr_free(top_elements);
-}
-
static int contains(grpc_timer_heap *pq, grpc_timer *el) {
size_t i;
for (i = 0; i < pq->timer_count; i++) {
@@ -145,15 +74,19 @@ static void check_valid(grpc_timer_heap *pq) {
size_t right_child = left_child + 1u;
if (left_child < pq->timer_count) {
GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline,
- pq->timers[left_child]->deadline) >= 0);
+ pq->timers[left_child]->deadline) <= 0);
}
if (right_child < pq->timer_count) {
GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline,
- pq->timers[right_child]->deadline) >= 0);
+ pq->timers[right_child]->deadline) <= 0);
}
}
}
+/*******************************************************************************
+ * test1
+ */
+
static void test1(void) {
grpc_timer_heap pq;
const size_t num_test_elements = 200;
@@ -162,6 +95,8 @@ static void test1(void) {
grpc_timer *test_elements = create_test_elements(num_test_elements);
uint8_t *inpq = gpr_malloc(num_test_elements);
+ gpr_log(GPR_INFO, "test1");
+
grpc_timer_heap_init(&pq);
memset(inpq, 0, num_test_elements);
GPR_ASSERT(grpc_timer_heap_is_empty(&pq));
@@ -172,7 +107,6 @@ static void test1(void) {
check_valid(&pq);
GPR_ASSERT(contains(&pq, &test_elements[i]));
inpq[i] = 1;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
}
for (i = 0; i < num_test_elements; ++i) {
/* Test that check still succeeds even for element that wasn't just
@@ -182,7 +116,7 @@ static void test1(void) {
GPR_ASSERT(pq.timer_count == num_test_elements);
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
+ check_valid(&pq);
for (i = 0; i < num_test_operations; ++i) {
size_t elem_num = (size_t)rand() % num_test_elements;
@@ -193,14 +127,12 @@ static void test1(void) {
grpc_timer_heap_add(&pq, el);
GPR_ASSERT(contains(&pq, el));
inpq[elem_num] = 1;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
check_valid(&pq);
} else {
GPR_ASSERT(contains(&pq, el));
grpc_timer_heap_remove(&pq, el);
GPR_ASSERT(!contains(&pq, el));
inpq[elem_num] = 0;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
check_valid(&pq);
}
}
@@ -210,7 +142,110 @@ static void test1(void) {
gpr_free(inpq);
}
+/*******************************************************************************
+ * test2
+ */
+
+typedef struct {
+ grpc_timer elem;
+ bool inserted;
+} elem_struct;
+
+static elem_struct *search_elems(elem_struct *elems, size_t count,
+ bool inserted) {
+ size_t *search_order = gpr_malloc(count * sizeof(*search_order));
+ for (size_t i = 0; i < count; i++) {
+ search_order[i] = i;
+ }
+ for (size_t i = 0; i < count * 2; i++) {
+ size_t a = (size_t)rand() % count;
+ size_t b = (size_t)rand() % count;
+ GPR_SWAP(size_t, search_order[a], search_order[b]);
+ }
+ elem_struct *out = NULL;
+ for (size_t i = 0; out == NULL && i < count; i++) {
+ if (elems[search_order[i]].inserted == inserted) {
+ out = &elems[search_order[i]];
+ }
+ }
+ gpr_free(search_order);
+ return out;
+}
+
+static void test2(void) {
+ gpr_log(GPR_INFO, "test2");
+
+ grpc_timer_heap pq;
+
+ static const size_t elems_size = 1000;
+ elem_struct *elems = gpr_malloc(elems_size * sizeof(elem_struct));
+ size_t num_inserted = 0;
+
+ grpc_timer_heap_init(&pq);
+ memset(elems, 0, elems_size);
+
+ for (size_t round = 0; round < 10000; round++) {
+ int r = rand() % 1000;
+ if (r <= 550) {
+ /* 55% of the time we try to add something */
+ elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), false);
+ if (el != NULL) {
+ el->elem.deadline = random_deadline();
+ grpc_timer_heap_add(&pq, &el->elem);
+ el->inserted = true;
+ num_inserted++;
+ check_valid(&pq);
+ }
+ } else if (r <= 650) {
+ /* 10% of the time we try to remove something */
+ elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), true);
+ if (el != NULL) {
+ grpc_timer_heap_remove(&pq, &el->elem);
+ el->inserted = false;
+ num_inserted--;
+ check_valid(&pq);
+ }
+ } else {
+ /* the remaining times we pop */
+ if (num_inserted > 0) {
+ grpc_timer *top = grpc_timer_heap_top(&pq);
+ grpc_timer_heap_pop(&pq);
+ for (size_t i = 0; i < elems_size; i++) {
+ if (top == &elems[i].elem) {
+ GPR_ASSERT(elems[i].inserted);
+ elems[i].inserted = false;
+ }
+ }
+ num_inserted--;
+ check_valid(&pq);
+ }
+ }
+
+ if (num_inserted) {
+ gpr_timespec *min_deadline = NULL;
+ for (size_t i = 0; i < elems_size; i++) {
+ if (elems[i].inserted) {
+ if (min_deadline == NULL) {
+ min_deadline = &elems[i].elem.deadline;
+ } else {
+ if (gpr_time_cmp(elems[i].elem.deadline, *min_deadline) < 0) {
+ min_deadline = &elems[i].elem.deadline;
+ }
+ }
+ }
+ }
+ GPR_ASSERT(
+ 0 == gpr_time_cmp(grpc_timer_heap_top(&pq)->deadline, *min_deadline));
+ }
+ }
+
+ grpc_timer_heap_destroy(&pq);
+ gpr_free(elems);
+}
+
static void shrink_test(void) {
+ gpr_log(GPR_INFO, "shrink_test");
+
grpc_timer_heap pq;
size_t i;
size_t expected_size;
@@ -274,6 +309,7 @@ int main(int argc, char **argv) {
for (i = 0; i < 5; i++) {
test1();
+ test2();
shrink_test();
}
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 15de87c5a1..2e0f5c8701 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,11 +31,10 @@
*
*/
-#include "src/core/iomgr/timer.h"
+#include "src/core/lib/iomgr/timer.h"
#include <string.h>
-#include "src/core/iomgr/timer_internal.h"
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
@@ -72,20 +71,18 @@ static void add_test(void) {
}
/* collect timers. Only the first batch should be ready. */
- GPR_ASSERT(10 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 20; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
@@ -93,20 +90,18 @@ static void add_test(void) {
}
/* collect the rest of the timers */
- GPR_ASSERT(10 == grpc_timer_check(
- &exec_ctx, gpr_time_add(start, gpr_time_from_millis(
- 1500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 1600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)),
+ NULL));
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 2e253d8a8a..463d40a46b 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,16 +31,18 @@
*
*/
-#include "src/core/iomgr/udp_server.h"
-#include "src/core/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/udp_server.h"
+#include <grpc/grpc.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 <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
+#include <sys/socket.h>
#include <unistd.h>
#ifdef GRPC_NEED_UDP
@@ -48,6 +50,7 @@
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
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;
@@ -56,14 +59,14 @@ static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
char read_buffer[512];
ssize_t byte_count;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
byte_count = recv(emfd->fd, read_buffer, sizeof(read_buffer), 0);
g_number_of_reads++;
g_number_of_bytes_read += (int)byte_count;
grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
static void test_no_op(void) {
@@ -142,7 +145,7 @@ static void test_receive(int number_of_clients) {
pollsets[0] = &g_pollset;
grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
for (i = 0; i < number_of_clients; i++) {
deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
@@ -155,19 +158,19 @@ static void test_receive(int number_of_clients) {
GPR_ASSERT(5 == write(clifd, "hello", 5));
while (g_number_of_reads == number_of_reads_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1);
close(clifd);
}
GPR_ASSERT(g_number_of_bytes_read == 5 * number_of_clients);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx);
@@ -181,8 +184,8 @@ int main(int argc, char **argv) {
grpc_closure destroyed;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
- grpc_iomgr_init();
- grpc_pollset_init(&g_pollset);
+ grpc_init();
+ grpc_pollset_init(&g_pollset, &g_mu);
test_no_op();
test_no_op_with_start();
diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c
index 500170b542..874e696fc2 100644
--- a/test/core/iomgr/workqueue_test.c
+++ b/test/core/iomgr/workqueue_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,21 +31,23 @@
*
*/
-#include "src/core/iomgr/workqueue.h"
+#include "src/core/lib/iomgr/workqueue.h"
#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
-static grpc_pollset g_pollset;
+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);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
*(int *)p = 1;
- grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_pollset_kick(g_pollset, NULL);
+ gpr_mu_unlock(g_mu);
}
static void test_ref_unref(void) {
@@ -63,17 +65,17 @@ static void test_add_closure(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
grpc_closure_init(&c, must_succeed, &done);
grpc_workqueue_push(wq, &c, 1);
- grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset);
+ grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
GPR_ASSERT(!done);
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(deadline.clock_type), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ 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,18 +89,18 @@ static void test_flush(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
grpc_closure_init(&c, must_succeed, &done);
grpc_exec_ctx_enqueue(&exec_ctx, &c, true, NULL);
grpc_workqueue_flush(&exec_ctx, wq);
- grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset);
+ grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
GPR_ASSERT(!done);
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(deadline.clock_type), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ 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);
@@ -115,15 +117,18 @@ int main(int argc, char **argv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
grpc_init();
- grpc_pollset_init(&g_pollset);
+ g_pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
test_ref_unref();
test_add_closure();
test_flush();
- grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
- grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
+ grpc_closure_init(&destroyed, destroy_pollset, g_pollset);
+ grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
grpc_exec_ctx_finish(&exec_ctx);
grpc_shutdown();
+
+ gpr_free(g_pollset);
return 0;
}