aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@gmail.com>2017-11-29 16:25:10 -0800
committerGravatar Dave MacLachlan <dmaclach@gmail.com>2017-11-29 16:25:10 -0800
commitaf5c54de9cdf3a8ac27aa428571d98a93f32cc1f (patch)
tree5ba4015c5d815aa9652efe44e95d6afd9b430090 /test/core
parentc99a3ca415fcf5581f9c365e4dc3004e858fc76a (diff)
Add thread naming support on platforms that support it.
As a client of grpc I want to be aware of which threads are being created by grpc, and giving them recognizable names makes it significantly easier to diagnose what is going on in my programs. This provides thread names for macOS and Linux. Adding support for other platforms should be easy for platform specialists.
Diffstat (limited to 'test/core')
-rw-r--r--test/core/bad_client/bad_client.cc2
-rw-r--r--test/core/end2end/bad_server_response_test.cc2
-rw-r--r--test/core/end2end/fixtures/http_proxy_fixture.cc3
-rw-r--r--test/core/end2end/fixtures/proxy.cc3
-rw-r--r--test/core/end2end/tests/connectivity.cc3
-rw-r--r--test/core/handshake/client_ssl.cc3
-rw-r--r--test/core/handshake/server_ssl_common.cc3
-rw-r--r--test/core/iomgr/combiner_test.cc3
-rw-r--r--test/core/iomgr/resolve_address_posix_test.cc2
-rw-r--r--test/core/iomgr/wakeup_fd_cv_test.cc10
-rw-r--r--test/core/support/arena_test.cc3
-rw-r--r--test/core/support/cpu_test.cc2
-rw-r--r--test/core/support/mpscq_test.cc9
-rw-r--r--test/core/support/spinlock_test.cc3
-rw-r--r--test/core/support/sync_test.cc4
-rw-r--r--test/core/support/thd_test.cc5
-rw-r--r--test/core/support/tls_test.cc2
-rw-r--r--test/core/surface/completion_queue_threading_test.cc5
-rw-r--r--test/core/surface/concurrent_connectivity_test.cc16
-rw-r--r--test/core/surface/sequential_connectivity_test.cc3
20 files changed, 52 insertions, 34 deletions
diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc
index c19b7bdf40..99e61b0c5f 100644
--- a/test/core/bad_client/bad_client.cc
+++ b/test/core/bad_client/bad_client.cc
@@ -128,7 +128,7 @@ void grpc_run_bad_client_test(
GPR_ASSERT(grpc_server_has_open_connections(a.server));
/* Start validator */
- gpr_thd_new(&id, thd_func, &a, nullptr);
+ gpr_thd_new(&id, "gpr_bad_client", thd_func, &a, nullptr);
grpc_slice_buffer_init(&outgoing);
grpc_slice_buffer_add(&outgoing, slice);
diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc
index b0c6ae926e..566fd12915 100644
--- a/test/core/end2end/bad_server_response_test.cc
+++ b/test/core/end2end/bad_server_response_test.cc
@@ -262,7 +262,7 @@ static void poll_server_until_read_done(test_tcp_server* server,
poll_args* pa = (poll_args*)gpr_malloc(sizeof(*pa));
pa->server = server;
pa->signal_when_done = signal_when_done;
- gpr_thd_new(&id, actually_poll_server, pa, nullptr);
+ gpr_thd_new(&id, "gpr_poll_server", actually_poll_server, pa, nullptr);
}
static void run_test(const char* response_payload,
diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc
index ac0c953a79..25d8983503 100644
--- a/test/core/end2end/fixtures/http_proxy_fixture.cc
+++ b/test/core/end2end/fixtures/http_proxy_fixture.cc
@@ -529,7 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
// Start proxy thread.
gpr_thd_options opt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&opt);
- GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt));
+ GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_http_proxy", thread_main, proxy,
+ &opt));
return proxy;
}
diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc
index 2fab62b721..6bbb1f4d1d 100644
--- a/test/core/end2end/fixtures/proxy.cc
+++ b/test/core/end2end/fixtures/proxy.cc
@@ -98,7 +98,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
grpc_call_details_init(&proxy->new_call_details);
gpr_thd_options_set_joinable(&opt);
- GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt));
+ GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_end2end_proxy", thread_main, proxy,
+ &opt));
request_call(proxy);
diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc
index 2ea4ca81f5..6477dcdd69 100644
--- a/test/core/end2end/tests/connectivity.cc
+++ b/test/core/end2end/tests/connectivity.cc
@@ -68,7 +68,8 @@ static void test_connectivity(grpc_end2end_test_config config) {
ce.cq = f.cq;
gpr_event_init(&ce.started);
gpr_thd_options_set_joinable(&thdopt);
- GPR_ASSERT(gpr_thd_new(&thdid, child_thread, &ce, &thdopt));
+ GPR_ASSERT(gpr_thd_new(&thdid, "gpr_connectivity", child_thread, &ce,
+ &thdopt));
gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC));
diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc
index 2b149a73b3..21147ef445 100644
--- a/test/core/handshake/client_ssl.cc
+++ b/test/core/handshake/client_ssl.cc
@@ -231,7 +231,8 @@ static bool client_ssl_test(char* server_alpn_preferred) {
gpr_thd_id thdid;
gpr_thd_options_set_joinable(&thdopt);
server_args args = {server_socket, server_alpn_preferred};
- GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &args, &thdopt));
+ GPR_ASSERT(gpr_thd_new(&thdid, "gpr_client_ssl_test", server_thread, &args,
+ &thdopt));
// Load key pair and establish client SSL credentials.
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc
index 599b2814e0..9b06d31ab2 100644
--- a/test/core/handshake/server_ssl_common.cc
+++ b/test/core/handshake/server_ssl_common.cc
@@ -137,7 +137,8 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len,
gpr_thd_options thdopt = gpr_thd_options_default();
gpr_thd_id thdid;
gpr_thd_options_set_joinable(&thdopt);
- GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &port, &thdopt));
+ GPR_ASSERT(gpr_thd_new(&thdid, "gpr_ssl_test", server_thread, &port,
+ &thdopt));
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc
index 146a6bd553..8c97d8a6ef 100644
--- a/test/core/iomgr/combiner_test.cc
+++ b/test/core/iomgr/combiner_test.cc
@@ -112,7 +112,8 @@ static void test_execute_many(void) {
ta[i].ctr = 0;
ta[i].lock = lock;
gpr_event_init(&ta[i].done);
- GPR_ASSERT(gpr_thd_new(&thds[i], execute_many_loop, &ta[i], &options));
+ GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_execute_many", execute_many_loop,
+ &ta[i], &options));
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
GPR_ASSERT(gpr_event_wait(&ta[i].done,
diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc
index 1a5eb9ace1..ea70dab89e 100644
--- a/test/core/iomgr/resolve_address_posix_test.cc
+++ b/test/core/iomgr/resolve_address_posix_test.cc
@@ -104,7 +104,7 @@ 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, actually_poll, args, nullptr);
+ gpr_thd_new(&id, "gpr_poll_pollset", actually_poll, args, nullptr);
}
static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp,
diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc
index dc1d77a0ab..9d761712e7 100644
--- a/test/core/iomgr/wakeup_fd_cv_test.cc
+++ b/test/core/iomgr/wakeup_fd_cv_test.cc
@@ -138,7 +138,7 @@ void test_poll_cv_trigger(void) {
opt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&opt);
- gpr_thd_new(&t_id, &background_poll, &pargs, &opt);
+ gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt);
// Wakeup wakeup_fd not listening for events
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE);
@@ -154,7 +154,7 @@ void test_poll_cv_trigger(void) {
// Pollin on socket fd
pargs.timeout = -1;
pargs.result = -2;
- gpr_thd_new(&t_id, &background_poll, &pargs, &opt);
+ gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt);
trigger_socket_event();
gpr_thd_join(t_id);
GPR_ASSERT(pargs.result == 1);
@@ -168,7 +168,7 @@ void test_poll_cv_trigger(void) {
// Pollin on wakeup fd
reset_socket_event();
pargs.result = -2;
- gpr_thd_new(&t_id, &background_poll, &pargs, &opt);
+ gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt);
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE);
gpr_thd_join(t_id);
@@ -182,7 +182,7 @@ void test_poll_cv_trigger(void) {
// Pollin on wakeupfd before poll()
pargs.result = -2;
- gpr_thd_new(&t_id, &background_poll, &pargs, &opt);
+ gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt);
gpr_thd_join(t_id);
GPR_ASSERT(pargs.result == 1);
@@ -199,7 +199,7 @@ void test_poll_cv_trigger(void) {
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, &background_poll, &pargs, &opt);
+ gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt);
gpr_thd_join(t_id);
GPR_ASSERT(pargs.result == 0);
diff --git a/test/core/support/arena_test.cc b/test/core/support/arena_test.cc
index 244d860639..4e11652318 100644
--- a/test/core/support/arena_test.cc
+++ b/test/core/support/arena_test.cc
@@ -100,7 +100,8 @@ static void concurrent_test(void) {
for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) {
gpr_thd_options opt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&opt);
- gpr_thd_new(&thds[i], concurrent_test_body, &args, &opt);
+ gpr_thd_new(&thds[i], "gpr_concurrent_test", concurrent_test_body, &args,
+ &opt);
}
gpr_event_set(&args.ev_start, (void*)1);
diff --git a/test/core/support/cpu_test.cc b/test/core/support/cpu_test.cc
index 1783ec3c60..db94b8f1c4 100644
--- a/test/core/support/cpu_test.cc
+++ b/test/core/support/cpu_test.cc
@@ -110,7 +110,7 @@ static void cpu_test(void) {
gpr_cv_init(&ct.done_cv);
ct.is_done = 0;
for (i = 0; i < ct.ncores * 3; i++) {
- GPR_ASSERT(gpr_thd_new(&thd, &worker_thread, &ct, nullptr));
+ GPR_ASSERT(gpr_thd_new(&thd, "gpr_cpu_test", &worker_thread, &ct, nullptr));
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
diff --git a/test/core/support/mpscq_test.cc b/test/core/support/mpscq_test.cc
index 50ff8174f6..026b045b0f 100644
--- a/test/core/support/mpscq_test.cc
+++ b/test/core/support/mpscq_test.cc
@@ -85,7 +85,8 @@ static void test_mt(void) {
ta[i].ctr = 0;
ta[i].q = &q;
ta[i].start = &start;
- GPR_ASSERT(gpr_thd_new(&thds[i], test_thread, &ta[i], &options));
+ GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_test_md", test_thread, &ta[i],
+ &options));
}
size_t num_done = 0;
size_t spins = 0;
@@ -156,7 +157,8 @@ static void test_mt_multipop(void) {
ta[i].ctr = 0;
ta[i].q = &q;
ta[i].start = &start;
- GPR_ASSERT(gpr_thd_new(&thds[i], test_thread, &ta[i], &options));
+ GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_multipop_test", test_thread, &ta[i],
+ &options));
}
pull_args pa;
pa.ta = ta;
@@ -169,7 +171,8 @@ static void test_mt_multipop(void) {
for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
gpr_thd_options options = gpr_thd_options_default();
gpr_thd_options_set_joinable(&options);
- GPR_ASSERT(gpr_thd_new(&pull_thds[i], pull_thread, &pa, &options));
+ GPR_ASSERT(gpr_thd_new(&pull_thds[i], "gpr_multipop_pull", pull_thread, &pa,
+ &options));
}
gpr_event_set(&start, (void*)1);
for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
diff --git a/test/core/support/spinlock_test.cc b/test/core/support/spinlock_test.cc
index 3639802cd7..1658c5c5f1 100644
--- a/test/core/support/spinlock_test.cc
+++ b/test/core/support/spinlock_test.cc
@@ -67,7 +67,8 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) {
for (i = 0; i != m->thread_count; i++) {
gpr_thd_options opt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&opt);
- GPR_ASSERT(gpr_thd_new(&m->threads[i], body, m, &opt));
+ GPR_ASSERT(gpr_thd_new(&m->threads[i], "gpr_create_threads", body, m,
+ &opt));
}
}
diff --git a/test/core/support/sync_test.cc b/test/core/support/sync_test.cc
index 86e78ce0b5..de53742dd8 100644
--- a/test/core/support/sync_test.cc
+++ b/test/core/support/sync_test.cc
@@ -189,7 +189,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) {
gpr_thd_id id;
int i;
for (i = 0; i != m->threads; i++) {
- GPR_ASSERT(gpr_thd_new(&id, body, m, nullptr));
+ GPR_ASSERT(gpr_thd_new(&id, "gpr_create_threads", body, m, nullptr));
}
}
@@ -244,7 +244,7 @@ static void test(const char* name, void (*body)(void* m),
m = test_new(10, iterations, incr_step);
if (extra != nullptr) {
gpr_thd_id id;
- GPR_ASSERT(gpr_thd_new(&id, extra, m, nullptr));
+ GPR_ASSERT(gpr_thd_new(&id, name, extra, m, nullptr));
m->done++; /* one more thread to wait for */
}
test_create_threads(m, body);
diff --git a/test/core/support/thd_test.cc b/test/core/support/thd_test.cc
index 34befd80d1..50702c4ae7 100644
--- a/test/core/support/thd_test.cc
+++ b/test/core/support/thd_test.cc
@@ -74,7 +74,7 @@ static void test(void) {
t.n = NUM_THREADS;
t.is_done = 0;
for (i = 0; i < NUM_THREADS; i++) {
- GPR_ASSERT(gpr_thd_new(&thd, &thd_body, &t, nullptr));
+ GPR_ASSERT(gpr_thd_new(&thd, "gpr_thread_test", &thd_body, &t, nullptr));
}
gpr_mu_lock(&t.mu);
while (!t.is_done) {
@@ -84,7 +84,8 @@ static void test(void) {
GPR_ASSERT(t.n == 0);
gpr_thd_options_set_joinable(&options);
for (i = 0; i < NUM_THREADS; i++) {
- GPR_ASSERT(gpr_thd_new(&thds[i], &thd_body_joinable, nullptr, &options));
+ GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_thread_test_joinable",
+ &thd_body_joinable, nullptr, &options));
}
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(thds[i]);
diff --git a/test/core/support/tls_test.cc b/test/core/support/tls_test.cc
index 0f64d2ee7c..2a560a4df3 100644
--- a/test/core/support/tls_test.cc
+++ b/test/core/support/tls_test.cc
@@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
gpr_thd_options_set_joinable(&opt);
for (i = 0; i < NUM_THREADS; i++) {
- gpr_thd_new(&threads[i], thd_body, nullptr, &opt);
+ gpr_thd_new(&threads[i], "gpr_tls_test", thd_body, nullptr, &opt);
}
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(threads[i]);
diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc
index af54e00c4a..17e185d236 100644
--- a/test/core/surface/completion_queue_threading_test.cc
+++ b/test/core/surface/completion_queue_threading_test.cc
@@ -96,7 +96,8 @@ static void test_too_many_plucks(void) {
}
thread_states[i].cc = cc;
thread_states[i].tag = tags[i];
- gpr_thd_new(thread_ids + i, pluck_one, thread_states + i, &thread_options);
+ gpr_thd_new(thread_ids + i, "gpr_test_pluck", pluck_one, thread_states + i,
+ &thread_options);
}
/* wait until all other threads are plucking */
@@ -233,7 +234,7 @@ static void test_threading(size_t producers, size_t consumers) {
options[i].events_triggered = 0;
options[i].cc = cc;
options[i].id = optid++;
- GPR_ASSERT(gpr_thd_new(&id,
+ GPR_ASSERT(gpr_thd_new(&id, i < producers ? "gpr_producer" : "gpr_consumer",
i < producers ? producer_thread : consumer_thread,
options + i, nullptr));
gpr_event_wait(&options[i].on_started, ten_seconds_time());
diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc
index 8fa15ab331..50bea0aee1 100644
--- a/test/core/surface/concurrent_connectivity_test.cc
+++ b/test/core/surface/concurrent_connectivity_test.cc
@@ -180,7 +180,8 @@ int run_concurrent_connectivity_test() {
/* First round, no server */
gpr_log(GPR_DEBUG, "Wave 1");
for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], create_loop_destroy, localhost, &options);
+ gpr_thd_new(&threads[i], "gpr_wave_1", create_loop_destroy, localhost,
+ &options);
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
@@ -196,10 +197,11 @@ int run_concurrent_connectivity_test() {
args.cq = grpc_completion_queue_create_for_next(nullptr);
grpc_server_register_completion_queue(args.server, args.cq, nullptr);
grpc_server_start(args.server);
- gpr_thd_new(&server, server_thread, &args, &options);
+ gpr_thd_new(&server, "gpr_wave_2_server", server_thread, &args, &options);
for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], create_loop_destroy, args.addr, &options);
+ gpr_thd_new(&threads[i], "gpr_wave_2", create_loop_destroy, args.addr,
+ &options);
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
@@ -216,11 +218,12 @@ int run_concurrent_connectivity_test() {
args.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(args.pollset, &args.mu);
gpr_event_init(&args.ready);
- gpr_thd_new(&server, bad_server_thread, &args, &options);
+ gpr_thd_new(&server, "gpr_wave_3_server", bad_server_thread, &args, &options);
gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC));
for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], create_loop_destroy, args.addr, &options);
+ gpr_thd_new(&threads[i], "gpr_wave_3", create_loop_destroy, args.addr,
+ &options);
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
@@ -278,7 +281,8 @@ int run_concurrent_watches_with_short_timeouts_test() {
gpr_thd_options_set_joinable(&options);
for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], watches_with_short_timeouts, localhost, &options);
+ gpr_thd_new(&threads[i], "gpr_watches_with_short_timeouts",
+ watches_with_short_timeouts, localhost, &options);
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc
index 015db92cb0..82225f7a89 100644
--- a/test/core/surface/sequential_connectivity_test.cc
+++ b/test/core/surface/sequential_connectivity_test.cc
@@ -70,7 +70,8 @@ static void run_test(const test_fixture* fixture) {
gpr_thd_id server_thread;
gpr_thd_options thdopt = gpr_thd_options_default();
gpr_thd_options_set_joinable(&thdopt);
- gpr_thd_new(&server_thread, server_thread_func, &sta, &thdopt);
+ gpr_thd_new(&server_thread, "gpr_server_thread", server_thread_func, &sta,
+ &thdopt);
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
grpc_channel* channels[NUM_CONNECTIONS];