aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/iomgr')
-rw-r--r--test/core/iomgr/combiner_test.cc15
-rw-r--r--test/core/iomgr/error_test.cc1
-rw-r--r--test/core/iomgr/ev_epollsig_linux_test.cc16
-rw-r--r--test/core/iomgr/resolve_address_posix_test.cc11
-rw-r--r--test/core/iomgr/wakeup_fd_cv_test.cc162
5 files changed, 110 insertions, 95 deletions
diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc
index 8426b3d233..e4f4783e58 100644
--- a/test/core/iomgr/combiner_test.cc
+++ b/test/core/iomgr/combiner_test.cc
@@ -18,12 +18,14 @@
#include "src/core/lib/iomgr/combiner.h"
+#include <new>
+
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
static void test_no_op(void) {
@@ -97,21 +99,20 @@ static void test_execute_many(void) {
gpr_log(GPR_DEBUG, "test_execute_many");
grpc_combiner* lock = grpc_combiner_create();
- gpr_thd_id thds[100];
+ grpc_core::Thread thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
- gpr_thd_options options = gpr_thd_options_default();
- gpr_thd_options_set_joinable(&options);
ta[i].ctr = 0;
ta[i].lock = lock;
gpr_event_init(&ta[i].done);
- GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_execute_many", execute_many_loop,
- &ta[i], &options));
+ new (&thds[i])
+ grpc_core::Thread("grpc_execute_many", execute_many_loop, &ta[i]);
+ thds[i].Start();
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
GPR_ASSERT(gpr_event_wait(&ta[i].done,
gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr);
- gpr_thd_join(thds[i]);
+ thds[i].Join();
}
grpc_core::ExecCtx exec_ctx;
GRPC_COMBINER_UNREF(lock, "test_execute_many");
diff --git a/test/core/iomgr/error_test.cc b/test/core/iomgr/error_test.cc
index f6292b72a9..a1628a1f71 100644
--- a/test/core/iomgr/error_test.cc
+++ b/test/core/iomgr/error_test.cc
@@ -24,7 +24,6 @@
#include <string.h>
-#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
static void test_set_get_int() {
diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc
index 02d11271ec..4ec6fc8b0d 100644
--- a/test/core/iomgr/ev_epollsig_linux_test.cc
+++ b/test/core/iomgr/ev_epollsig_linux_test.cc
@@ -25,13 +25,14 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <new>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
@@ -259,11 +260,10 @@ static void test_threading(void) {
shared.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(shared.pollset, &shared.mu);
- gpr_thd_id thds[10];
- for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
- gpr_thd_options opt = gpr_thd_options_default();
- gpr_thd_options_set_joinable(&opt);
- gpr_thd_new(&thds[i], "test_thread", test_threading_loop, &shared, &opt);
+ grpc_core::Thread thds[10];
+ for (auto& th : thds) {
+ new (&th) grpc_core::Thread("test_thread", test_threading_loop, &shared);
+ th.Start();
}
grpc_wakeup_fd fd;
GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&fd)));
@@ -280,8 +280,8 @@ static void test_threading(void) {
}
GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first",
grpc_wakeup_fd_wakeup(shared.wakeup_fd)));
- for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th : thds) {
+ th.Join();
}
fd.read_fd = 0;
grpc_wakeup_fd_destroy(&fd);
diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc
index 341579f178..895ede24c7 100644
--- a/test/core/iomgr/resolve_address_posix_test.cc
+++ b/test/core/iomgr/resolve_address_posix_test.cc
@@ -20,6 +20,7 @@
#include <string.h>
#include <sys/un.h>
+#include <new>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
@@ -27,8 +28,8 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
@@ -38,6 +39,7 @@ static gpr_timespec test_deadline(void) {
}
typedef struct args_struct {
+ grpc_core::Thread thd;
gpr_event ev;
grpc_resolved_addresses* addrs;
gpr_atm done_atm;
@@ -59,6 +61,9 @@ void args_init(args_struct* args) {
void args_finish(args_struct* args) {
GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline()));
+ args->thd.Join();
+ // Don't need to explicitly destruct args->thd since
+ // args is actually going to be destructed, not just freed
grpc_resolved_addresses_destroy(args->addrs);
grpc_pollset_set_del_pollset(args->pollset_set, args->pollset);
grpc_pollset_set_destroy(args->pollset_set);
@@ -101,8 +106,8 @@ static void actually_poll(void* argsp) {
static void poll_pollset_until_request_done(args_struct* args) {
gpr_atm_rel_store(&args->done_atm, 0);
- gpr_thd_id id;
- gpr_thd_new(&id, "grpc_poll_pollset", actually_poll, args, nullptr);
+ new (&args->thd) grpc_core::Thread("grpc_poll_pollset", actually_poll, args);
+ args->thd.Start();
}
static void must_succeed(void* argsp, grpc_error* err) {
diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc
index 68dcb50aa6..9bd7c6e47e 100644
--- a/test/core/iomgr/wakeup_fd_cv_test.cc
+++ b/test/core/iomgr/wakeup_fd_cv_test.cc
@@ -26,7 +26,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/gpr/env.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr_posix.h"
@@ -103,8 +103,6 @@ void test_poll_cv_trigger(void) {
grpc_wakeup_fd cvfd1, cvfd2, cvfd3;
struct pollfd pfds[6];
poll_args pargs;
- gpr_thd_id t_id;
- gpr_thd_options opt;
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd1) == GRPC_ERROR_NONE);
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd2) == GRPC_ERROR_NONE);
@@ -135,79 +133,91 @@ void test_poll_cv_trigger(void) {
pargs.timeout = 1000;
pargs.result = -2;
- opt = gpr_thd_options_default();
- gpr_thd_options_set_joinable(&opt);
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt);
-
- // Wakeup wakeup_fd not listening for events
- GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE);
- gpr_thd_join(t_id);
- GPR_ASSERT(pargs.result == 0);
- GPR_ASSERT(pfds[0].revents == 0);
- GPR_ASSERT(pfds[1].revents == 0);
- GPR_ASSERT(pfds[2].revents == 0);
- GPR_ASSERT(pfds[3].revents == 0);
- GPR_ASSERT(pfds[4].revents == 0);
- GPR_ASSERT(pfds[5].revents == 0);
-
- // Pollin on socket fd
- pargs.timeout = -1;
- pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt);
- trigger_socket_event();
- gpr_thd_join(t_id);
- GPR_ASSERT(pargs.result == 1);
- GPR_ASSERT(pfds[0].revents == 0);
- GPR_ASSERT(pfds[1].revents == 0);
- GPR_ASSERT(pfds[2].revents == POLLIN);
- GPR_ASSERT(pfds[3].revents == 0);
- GPR_ASSERT(pfds[4].revents == 0);
- GPR_ASSERT(pfds[5].revents == 0);
-
- // Pollin on wakeup fd
- reset_socket_event();
- pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt);
- GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE);
- gpr_thd_join(t_id);
-
- GPR_ASSERT(pargs.result == 1);
- GPR_ASSERT(pfds[0].revents == 0);
- GPR_ASSERT(pfds[1].revents == POLLIN);
- GPR_ASSERT(pfds[2].revents == 0);
- GPR_ASSERT(pfds[3].revents == 0);
- GPR_ASSERT(pfds[4].revents == 0);
- GPR_ASSERT(pfds[5].revents == 0);
-
- // Pollin on wakeupfd before poll()
- pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt);
- gpr_thd_join(t_id);
-
- GPR_ASSERT(pargs.result == 1);
- GPR_ASSERT(pfds[0].revents == 0);
- GPR_ASSERT(pfds[1].revents == POLLIN);
- GPR_ASSERT(pfds[2].revents == 0);
- GPR_ASSERT(pfds[3].revents == 0);
- GPR_ASSERT(pfds[4].revents == 0);
- GPR_ASSERT(pfds[5].revents == 0);
-
- // No Events
- pargs.result = -2;
- pargs.timeout = 1000;
- reset_socket_event();
- GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd1) == GRPC_ERROR_NONE);
- GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd2) == GRPC_ERROR_NONE);
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt);
- gpr_thd_join(t_id);
-
- GPR_ASSERT(pargs.result == 0);
- GPR_ASSERT(pfds[0].revents == 0);
- GPR_ASSERT(pfds[1].revents == 0);
- GPR_ASSERT(pfds[2].revents == 0);
- GPR_ASSERT(pfds[3].revents == 0);
- GPR_ASSERT(pfds[4].revents == 0);
- GPR_ASSERT(pfds[5].revents == 0);
+ {
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ // Wakeup wakeup_fd not listening for events
+ GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE);
+ thd.Join();
+ GPR_ASSERT(pargs.result == 0);
+ GPR_ASSERT(pfds[0].revents == 0);
+ GPR_ASSERT(pfds[1].revents == 0);
+ GPR_ASSERT(pfds[2].revents == 0);
+ GPR_ASSERT(pfds[3].revents == 0);
+ GPR_ASSERT(pfds[4].revents == 0);
+ GPR_ASSERT(pfds[5].revents == 0);
+ }
+
+ {
+ // Pollin on socket fd
+ pargs.timeout = -1;
+ pargs.result = -2;
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ trigger_socket_event();
+ thd.Join();
+ GPR_ASSERT(pargs.result == 1);
+ GPR_ASSERT(pfds[0].revents == 0);
+ GPR_ASSERT(pfds[1].revents == 0);
+ GPR_ASSERT(pfds[2].revents == POLLIN);
+ GPR_ASSERT(pfds[3].revents == 0);
+ GPR_ASSERT(pfds[4].revents == 0);
+ GPR_ASSERT(pfds[5].revents == 0);
+ }
+
+ {
+ // Pollin on wakeup fd
+ reset_socket_event();
+ pargs.result = -2;
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE);
+ thd.Join();
+
+ GPR_ASSERT(pargs.result == 1);
+ GPR_ASSERT(pfds[0].revents == 0);
+ GPR_ASSERT(pfds[1].revents == POLLIN);
+ GPR_ASSERT(pfds[2].revents == 0);
+ GPR_ASSERT(pfds[3].revents == 0);
+ GPR_ASSERT(pfds[4].revents == 0);
+ GPR_ASSERT(pfds[5].revents == 0);
+ }
+
+ {
+ // Pollin on wakeupfd before poll()
+ pargs.result = -2;
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ thd.Join();
+
+ GPR_ASSERT(pargs.result == 1);
+ GPR_ASSERT(pfds[0].revents == 0);
+ GPR_ASSERT(pfds[1].revents == POLLIN);
+ GPR_ASSERT(pfds[2].revents == 0);
+ GPR_ASSERT(pfds[3].revents == 0);
+ GPR_ASSERT(pfds[4].revents == 0);
+ GPR_ASSERT(pfds[5].revents == 0);
+ }
+
+ {
+ // No Events
+ pargs.result = -2;
+ pargs.timeout = 1000;
+ reset_socket_event();
+ GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd1) == GRPC_ERROR_NONE);
+ GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd2) == GRPC_ERROR_NONE);
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ thd.Join();
+
+ GPR_ASSERT(pargs.result == 0);
+ GPR_ASSERT(pfds[0].revents == 0);
+ GPR_ASSERT(pfds[1].revents == 0);
+ GPR_ASSERT(pfds[2].revents == 0);
+ GPR_ASSERT(pfds[3].revents == 0);
+ GPR_ASSERT(pfds[4].revents == 0);
+ GPR_ASSERT(pfds[5].revents == 0);
+ }
}
int main(int argc, char** argv) {