diff options
author | ncteisen <ncteisen@gmail.com> | 2018-03-02 22:09:52 -0800 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2018-03-02 22:09:52 -0800 |
commit | 94dad67f4386ca1d46d96fd255cf4a9df5c087b2 (patch) | |
tree | 43e29b584e7d8c062d91eee5d0fc50639c1643e4 /test | |
parent | c1284576f81efc4b2d9c33c4337d8c9fbafc29de (diff) | |
parent | 6eae794c9f8f305a51274a79400124093ddc9354 (diff) |
Merge branch 'master' of https://github.com/grpc/grpc into channel-tracing
Diffstat (limited to 'test')
64 files changed, 408 insertions, 414 deletions
diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 6055ccbf4b..c03ebcf409 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -29,7 +29,7 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/gpr/murmur_hash.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/completion_queue.h" @@ -220,11 +220,12 @@ void grpc_run_bad_client_test( /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); - gpr_thd_id id; gpr_event_init(&a.done_thd); a.validator = server_validator; /* Start validator */ - gpr_thd_new(&id, "grpc_bad_client", thd_func, &a, nullptr); + + grpc_core::Thread server_validator_thd("grpc_bad_client", thd_func, &a); + server_validator_thd.Start(); for (int i = 0; i < num_args; i++) { grpc_run_client_side_validator(&args[i], i == (num_args - 1) ? flags : 0, &sfd, client_cq); @@ -234,6 +235,7 @@ void grpc_run_bad_client_test( /* Shutdown. */ shutdown_client(&sfd.client); + server_validator_thd.Join(); shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); grpc_server_shutdown_and_notify(a.server, shutdown_cq, nullptr); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 1af168e1f9..3d133cfc18 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -31,7 +31,8 @@ #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/memory.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" @@ -253,15 +254,17 @@ static void actually_poll_server(void* arg) { gpr_free(pa); } -static void poll_server_until_read_done(test_tcp_server* server, - gpr_event* signal_when_done) { +static grpc_core::Thread* poll_server_until_read_done( + test_tcp_server* server, gpr_event* signal_when_done) { gpr_atm_rel_store(&state.done_atm, 0); state.write_done = 0; - gpr_thd_id id; poll_args* pa = static_cast<poll_args*>(gpr_malloc(sizeof(*pa))); pa->server = server; pa->signal_when_done = signal_when_done; - gpr_thd_new(&id, "grpc_poll_server", actually_poll_server, pa, nullptr); + auto* th = grpc_core::New<grpc_core::Thread>("grpc_poll_server", + actually_poll_server, pa); + th->Start(); + return th; } static void run_test(const char* response_payload, @@ -281,9 +284,11 @@ static void run_test(const char* response_payload, state.response_payload_length = response_payload_length; /* poll server until sending out the response */ - poll_server_until_read_done(&test_server, &ev); + grpc_core::UniquePtr<grpc_core::Thread> thdptr( + poll_server_until_read_done(&test_server, &ev)); start_rpc(server_port, expected_status, expected_detail); gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); + thdptr->Join(); /* clean up */ grpc_endpoint_shutdown(state.tcp, diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index 27b897ce5a..b3b4171a72 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -30,7 +30,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index b4ec78d710..565c96cf93 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -30,7 +30,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_full+pipe.cc b/test/core/end2end/fixtures/h2_full+pipe.cc index e97d078d9c..ed173c1afb 100644 --- a/test/core/end2end/fixtures/h2_full+pipe.cc +++ b/test/core/end2end/fixtures/h2_full+pipe.cc @@ -34,7 +34,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" diff --git a/test/core/end2end/fixtures/h2_full+trace.cc b/test/core/end2end/fixtures/h2_full+trace.cc index 12aa69bb17..afb86ea899 100644 --- a/test/core/end2end/fixtures/h2_full+trace.cc +++ b/test/core/end2end/fixtures/h2_full+trace.cc @@ -35,7 +35,6 @@ #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index c6b358dcc5..bd9ddff5b5 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -31,7 +31,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_full.cc b/test/core/end2end/fixtures/h2_full.cc index 32e3e55128..ca61ec8eff 100644 --- a/test/core/end2end/fixtures/h2_full.cc +++ b/test/core/end2end/fixtures/h2_full.cc @@ -29,7 +29,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_http_proxy.cc b/test/core/end2end/fixtures/h2_http_proxy.cc index b990d7a763..90d0627860 100644 --- a/test/core/end2end/fixtures/h2_http_proxy.cc +++ b/test/core/end2end/fixtures/h2_http_proxy.cc @@ -31,7 +31,6 @@ #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/fixtures/http_proxy_fixture.h" diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 6adc0c154e..ec9eedbd34 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -31,7 +31,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/h2_proxy.cc b/test/core/end2end/fixtures/h2_proxy.cc index 28a6eeeb78..c97188fbb2 100644 --- a/test/core/end2end/fixtures/h2_proxy.cc +++ b/test/core/end2end/fixtures/h2_proxy.cc @@ -29,7 +29,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/fixtures/proxy.h" diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 5dd5c2ad67..d539ddae8f 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -36,7 +36,6 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/surface/channel.h" diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 52a7b95c3a..75f64024cd 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -30,7 +30,6 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/surface/channel.h" diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 0d3cb34724..929631917d 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -30,7 +30,6 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/surface/channel.h" diff --git a/test/core/end2end/fixtures/h2_uds.cc b/test/core/end2end/fixtures/h2_uds.cc index a97b14f1d6..1b081f9ea3 100644 --- a/test/core/end2end/fixtures/h2_uds.cc +++ b/test/core/end2end/fixtures/h2_uds.cc @@ -33,7 +33,6 @@ #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 18e8310251..58353376f3 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -33,7 +33,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/http/parser.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/combiner.h" @@ -53,7 +53,7 @@ struct grpc_end2end_http_proxy { char* proxy_name; - gpr_thd_id thd; + grpc_core::Thread thd; grpc_tcp_server* server; grpc_channel_args* channel_args; gpr_mu* mu; @@ -550,10 +550,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); // Start proxy thread. - gpr_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - GPR_ASSERT( - gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); + proxy->thd = grpc_core::Thread("grpc_http_proxy", thread_main, proxy); + proxy->thd.Start(); return proxy; } @@ -566,7 +564,7 @@ static void destroy_pollset(void* arg, grpc_error* error) { void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. grpc_core::ExecCtx exec_ctx; - gpr_thd_join(proxy->thd); + proxy->thd.Join(); grpc_tcp_server_shutdown_listeners(proxy->server); grpc_tcp_server_unref(proxy->server); gpr_free(proxy->proxy_name); diff --git a/test/core/end2end/fixtures/inproc.cc b/test/core/end2end/fixtures/inproc.cc index 4ddcc78495..d47de42540 100644 --- a/test/core/end2end/fixtures/inproc.cc +++ b/test/core/end2end/fixtures/inproc.cc @@ -29,7 +29,6 @@ #include "src/core/ext/transport/inproc/inproc_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index bc3b0ca35c..042c858b4c 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -25,12 +25,12 @@ #include <grpc/support/sync.h> #include "src/core/lib/gpr/host_port.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/port.h" struct grpc_end2end_proxy { - gpr_thd_id thd; + grpc_core::Thread thd; char* proxy_port; char* server_port; grpc_completion_queue* cq; @@ -76,7 +76,6 @@ static void request_call(grpc_end2end_proxy* proxy); grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_channel_args* client_args, grpc_channel_args* server_args) { - gpr_thd_options opt = gpr_thd_options_default(); int proxy_port = grpc_pick_unused_port_or_die(); int server_port = grpc_pick_unused_port_or_die(); @@ -98,9 +97,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_server_start(proxy->server); grpc_call_details_init(&proxy->new_call_details); - gpr_thd_options_set_joinable(&opt); - GPR_ASSERT( - gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, &opt)); + proxy->thd = grpc_core::Thread("grpc_end2end_proxy", thread_main, proxy); + proxy->thd.Start(); request_call(proxy); @@ -123,7 +121,7 @@ static void shutdown_complete(void* arg, int success) { void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) { grpc_server_shutdown_and_notify(proxy->server, proxy->cq, new_closure(shutdown_complete, proxy)); - gpr_thd_join(proxy->thd); + proxy->thd.Join(); gpr_free(proxy->proxy_port); gpr_free(proxy->server_port); grpc_server_destroy(proxy->server); diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc index 9fff3bfb7d..f305ea5703 100644 --- a/test/core/end2end/tests/bad_ping.cc +++ b/test/core/end2end/tests/bad_ping.cc @@ -25,7 +25,6 @@ #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 "test/core/end2end/cq_verifier.h" diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index a517ffa686..caa4265aa2 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -22,7 +22,7 @@ #include <grpc/support/sync.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } @@ -50,8 +50,6 @@ static void test_connectivity(grpc_end2end_test_config config) { grpc_connectivity_state state; cq_verifier* cqv = cq_verifier_create(f.cq); child_events ce; - gpr_thd_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; grpc_channel_args client_args; grpc_arg arg_array[1]; @@ -67,9 +65,8 @@ static void test_connectivity(grpc_end2end_test_config config) { ce.channel = f.client; ce.cq = f.cq; gpr_event_init(&ce.started); - gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT( - gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce, &thdopt)); + grpc_core::Thread thd("grpc_connectivity", child_thread, &ce); + thd.Start(); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); @@ -86,7 +83,7 @@ static void test_connectivity(grpc_end2end_test_config config) { f.client, GRPC_CHANNEL_IDLE, gpr_now(GPR_CLOCK_MONOTONIC), f.cq, tag(1)); /* eventually the child thread completion should trigger */ - gpr_thd_join(thdid); + thd.Join(); /* check that we're still in idle, and start connecting */ GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) == diff --git a/test/core/end2end/tests/ping.cc b/test/core/end2end/tests/ping.cc index 8fce295f90..f523cbb0c7 100644 --- a/test/core/end2end/tests/ping.cc +++ b/test/core/end2end/tests/ping.cc @@ -22,7 +22,6 @@ #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 "test/core/end2end/cq_verifier.h" diff --git a/test/core/gpr/BUILD b/test/core/gpr/BUILD index 4032664b59..5308ea0934 100644 --- a/test/core/gpr/BUILD +++ b/test/core/gpr/BUILD @@ -129,16 +129,6 @@ grpc_cc_test( ) grpc_cc_test( - name = "thd_test", - srcs = ["thd_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//test/core/util:gpr_test_util", - ], -) - -grpc_cc_test( name = "time_test", srcs = ["time_test.cc"], language = "C++", diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc index 9eaf57b631..111414ea3e 100644 --- a/test/core/gpr/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -18,16 +18,17 @@ #include "src/core/lib/gpr/arena.h" +#include <inttypes.h> +#include <string.h> + #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include <inttypes.h> -#include <string.h> #include "src/core/lib/gpr/string.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_noop(void) { gpr_arena_destroy(gpr_arena_create(1)); } @@ -97,19 +98,18 @@ static void concurrent_test(void) { gpr_event_init(&args.ev_start); args.arena = gpr_arena_create(1024); - gpr_thd_id thds[CONCURRENT_TEST_THREADS]; + grpc_core::Thread thds[CONCURRENT_TEST_THREADS]; 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], "grpc_concurrent_test", concurrent_test_body, &args, - &opt); + thds[i] = + grpc_core::Thread("grpc_concurrent_test", concurrent_test_body, &args); + thds[i].Start(); } gpr_event_set(&args.ev_start, (void*)1); - for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) { - gpr_thd_join(thds[i]); + for (auto& th : thds) { + th.Join(); } gpr_arena_destroy(args.arena); diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc index 9f2c3f1923..1052d40b42 100644 --- a/test/core/gpr/cpu_test.cc +++ b/test/core/gpr/cpu_test.cc @@ -21,15 +21,17 @@ gpr_cpu_current_cpu() */ -#include <grpc/support/alloc.h> #include <grpc/support/cpu.h> + +#include <stdio.h> +#include <string.h> + +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> -#include <stdio.h> -#include <string.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" /* Test structure is essentially: @@ -101,7 +103,6 @@ static void cpu_test(void) { uint32_t i; int cores_seen = 0; struct cpu_test ct; - gpr_thd_id thd; ct.ncores = gpr_cpu_num_cores(); GPR_ASSERT(ct.ncores > 0); ct.nthreads = static_cast<int>(ct.ncores) * 3; @@ -110,15 +111,24 @@ static void cpu_test(void) { gpr_mu_init(&ct.mu); gpr_cv_init(&ct.done_cv); ct.is_done = 0; - for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT( - gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, nullptr)); + + uint32_t nthreads = ct.ncores * 3; + grpc_core::Thread* thd = + static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*thd) * nthreads)); + + for (i = 0; i < nthreads; i++) { + thd[i] = grpc_core::Thread("grpc_cpu_test", &worker_thread, &ct); + thd[i].Start(); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&ct.mu); + for (i = 0; i < nthreads; i++) { + thd[i].Join(); + } + gpr_free(thd); fprintf(stderr, "Saw cores ["); fflush(stderr); for (i = 0; i < ct.ncores; i++) { diff --git a/test/core/gpr/mpscq_test.cc b/test/core/gpr/mpscq_test.cc index 96813466c9..8c0873941f 100644 --- a/test/core/gpr/mpscq_test.cc +++ b/test/core/gpr/mpscq_test.cc @@ -24,8 +24,8 @@ #include <grpc/support/log.h> #include <grpc/support/sync.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" typedef struct test_node { @@ -76,18 +76,16 @@ static void test_mt(void) { gpr_log(GPR_DEBUG, "test_mt"); gpr_event start; gpr_event_init(&start); - gpr_thd_id thds[100]; + grpc_core::Thread thds[100]; thd_args ta[GPR_ARRAY_SIZE(thds)]; gpr_mpscq q; gpr_mpscq_init(&q); 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].q = &q; ta[i].start = &start; - GPR_ASSERT( - gpr_thd_new(&thds[i], "grpc_mt_test", test_thread, &ta[i], &options)); + thds[i] = grpc_core::Thread("grpc_mt_test", test_thread, &ta[i]); + thds[i].Start(); } size_t num_done = 0; size_t spins = 0; @@ -104,8 +102,8 @@ static void test_mt(void) { gpr_free(tn); } gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, spins); - for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_join(thds[i]); + for (auto& th : thds) { + th.Join(); } gpr_mpscq_destroy(&q); } @@ -147,19 +145,17 @@ static void test_mt_multipop(void) { gpr_log(GPR_DEBUG, "test_mt_multipop"); gpr_event start; gpr_event_init(&start); - gpr_thd_id thds[100]; - gpr_thd_id pull_thds[100]; + grpc_core::Thread thds[50]; + grpc_core::Thread pull_thds[50]; thd_args ta[GPR_ARRAY_SIZE(thds)]; gpr_mpscq q; gpr_mpscq_init(&q); 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].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_multipop_test", test_thread, &ta[i], - &options)); + thds[i] = grpc_core::Thread("grpc_multipop_test", test_thread, &ta[i]); + thds[i].Start(); } pull_args pa; pa.ta = ta; @@ -170,18 +166,16 @@ static void test_mt_multipop(void) { pa.start = &start; gpr_mu_init(&pa.mu); 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], "grpc_multipop_pull", pull_thread, - &pa, &options)); + pull_thds[i] = grpc_core::Thread("grpc_multipop_pull", pull_thread, &pa); + pull_thds[i].Start(); } gpr_event_set(&start, (void*)1); - for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) { - gpr_thd_join(pull_thds[i]); + for (auto& pth : pull_thds) { + pth.Join(); } gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, pa.spins); - for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_join(thds[i]); + for (auto& th : thds) { + th.Join(); } gpr_mpscq_destroy(&q); } diff --git a/test/core/gpr/spinlock_test.cc b/test/core/gpr/spinlock_test.cc index 9f182bc154..0ee72edb15 100644 --- a/test/core/gpr/spinlock_test.cc +++ b/test/core/gpr/spinlock_test.cc @@ -16,24 +16,26 @@ * */ -/* Test of gpr synchronization support. */ +/* Test of gpr spin-lock support. */ #include "src/core/lib/gpr/spinlock.h" + +#include <stdio.h> +#include <stdlib.h> + #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> -#include <stdio.h> -#include <stdlib.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" /* ------------------------------------------------- */ /* Tests for gpr_spinlock. */ struct test { int thread_count; /* number of threads */ - gpr_thd_id* threads; + grpc_core::Thread* threads; int64_t iterations; /* number of iterations per thread */ int64_t counter; @@ -46,7 +48,7 @@ struct test { static struct test* test_new(int threads, int64_t iterations, int incr_step) { struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m))); m->thread_count = threads; - m->threads = static_cast<gpr_thd_id*>( + m->threads = static_cast<grpc_core::Thread*>( gpr_malloc(sizeof(*m->threads) * static_cast<size_t>(threads))); m->iterations = iterations; m->counter = 0; @@ -66,10 +68,8 @@ static void test_destroy(struct test* m) { static void test_create_threads(struct test* m, void (*body)(void* arg)) { int i; 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], "grpc_create_threads", body, m, &opt)); + m->threads[i] = grpc_core::Thread("grpc_create_threads", body, m); + m->threads[i].Start(); } } @@ -77,7 +77,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { static void test_wait(struct test* m) { int i; for (i = 0; i != m->thread_count; i++) { - gpr_thd_join(m->threads[i]); + m->threads[i].Join(); } } diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc index bafd91020b..24b4562819 100644 --- a/test/core/gpr/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -18,14 +18,16 @@ /* Test of gpr synchronization support. */ -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/time.h> + #include <stdio.h> #include <stdlib.h> -#include "src/core/lib/gpr/thd.h" +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> + +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" /* ==================Example use of interface=================== @@ -133,7 +135,8 @@ int queue_remove(queue* q, int* head, gpr_timespec abs_deadline) { /* ------------------------------------------------- */ /* Tests for gpr_mu and gpr_cv, and the queue example. */ struct test { - int threads; /* number of threads */ + int nthreads; /* number of threads */ + grpc_core::Thread* threads; int64_t iterations; /* number of iterations per thread */ int64_t counter; @@ -157,13 +160,15 @@ struct test { }; /* Return pointer to a new struct test. */ -static struct test* test_new(int threads, int64_t iterations, int incr_step) { +static struct test* test_new(int nthreads, int64_t iterations, int incr_step) { struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m))); - m->threads = threads; + m->nthreads = nthreads; + m->threads = static_cast<grpc_core::Thread*>( + gpr_malloc(sizeof(*m->threads) * nthreads)); m->iterations = iterations; m->counter = 0; m->thread_count = 0; - m->done = threads; + m->done = nthreads; m->incr_step = incr_step; gpr_mu_init(&m->mu); gpr_cv_init(&m->cv); @@ -171,7 +176,7 @@ static struct test* test_new(int threads, int64_t iterations, int incr_step) { queue_init(&m->q); gpr_stats_init(&m->stats_counter, 0); gpr_ref_init(&m->refcount, 0); - gpr_ref_init(&m->thread_refcount, threads); + gpr_ref_init(&m->thread_refcount, nthreads); gpr_event_init(&m->event); return m; } @@ -182,15 +187,16 @@ static void test_destroy(struct test* m) { gpr_cv_destroy(&m->cv); gpr_cv_destroy(&m->done_cv); queue_destroy(&m->q); + gpr_free(m->threads); gpr_free(m); } -/* Create m->threads threads, each running (*body)(m) */ +/* Create m->nthreads threads, each running (*body)(m) */ 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, "grpc_create_threads", body, m, nullptr)); + for (i = 0; i != m->nthreads; i++) { + m->threads[i] = grpc_core::Thread("grpc_create_threads", body, m); + m->threads[i].Start(); } } @@ -201,9 +207,12 @@ static void test_wait(struct test* m) { gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&m->mu); + for (int i = 0; i != m->nthreads; i++) { + m->threads[i].Join(); + } } -/* Get an integer thread id in the raneg 0..threads-1 */ +/* Get an integer thread id in the raneg 0..nthreads-1 */ static int thread_id(struct test* m) { int id; gpr_mu_lock(&m->mu); @@ -245,16 +254,20 @@ static void test(const char* name, void (*body)(void* m), fprintf(stderr, " %ld", static_cast<long>(iterations)); fflush(stderr); m = test_new(10, iterations, incr_step); + grpc_core::Thread extra_thd; if (extra != nullptr) { - gpr_thd_id id; - GPR_ASSERT(gpr_thd_new(&id, name, extra, m, nullptr)); + extra_thd = grpc_core::Thread(name, extra, m); + extra_thd.Start(); m->done++; /* one more thread to wait for */ } test_create_threads(m, body); test_wait(m); - if (m->counter != m->threads * m->iterations * m->incr_step) { + if (extra != nullptr) { + extra_thd.Join(); + } + if (m->counter != m->nthreads * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", - static_cast<long>(m->counter), m->threads, + static_cast<long>(m->counter), m->nthreads, static_cast<long>(m->iterations)); fflush(stderr); GPR_ASSERT(0); @@ -296,7 +309,7 @@ static void inctry(void* v /*=m*/) { mark_thread_done(m); } -/* Increment counter only when (m->counter%m->threads)==m->thread_id; then mark +/* Increment counter only when (m->counter%m->nthreads)==m->thread_id; then mark thread as done. */ static void inc_by_turns(void* v /*=m*/) { struct test* m = static_cast<struct test*>(v); @@ -304,7 +317,7 @@ static void inc_by_turns(void* v /*=m*/) { int id = thread_id(m); for (i = 0; i != m->iterations; i++) { gpr_mu_lock(&m->mu); - while ((m->counter % m->threads) != id) { + while ((m->counter % m->nthreads) != id) { gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } m->counter++; @@ -369,12 +382,12 @@ static void many_producers(void* v /*=m*/) { mark_thread_done(m); } -/* Consume elements from m->q until m->threads*m->iterations are seen, +/* Consume elements from m->q until m->nthreads*m->iterations are seen, wait an extra second to confirm that no more elements are arriving, then mark thread as done. */ static void consumer(void* v /*=m*/) { struct test* m = static_cast<struct test*>(v); - int64_t n = m->iterations * m->threads; + int64_t n = m->iterations * m->nthreads; int64_t i; int value; for (i = 0; i != n; i++) { @@ -424,11 +437,11 @@ static void refinc(void* v /*=m*/) { } /* Wait until m->event is set to (void *)1, then decrement m->refcount by 1 - (m->threads * m->iterations * m->incr_step) times, and ensure that the last + (m->nthreads * m->iterations * m->incr_step) times, and ensure that the last decrement caused the counter to reach zero, then mark thread as done. */ static void refcheck(void* v /*=m*/) { struct test* m = static_cast<struct test*>(v); - int64_t n = m->iterations * m->threads * m->incr_step; + int64_t n = m->iterations * m->nthreads * m->incr_step; int64_t i; GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future(GPR_CLOCK_REALTIME)) == (void*)1); diff --git a/test/core/gpr/time_test.cc b/test/core/gpr/time_test.cc index e6bcc1247d..c80aac649d 100644 --- a/test/core/gpr/time_test.cc +++ b/test/core/gpr/time_test.cc @@ -26,7 +26,6 @@ #include <stdlib.h> #include <string.h> -#include "src/core/lib/gpr/thd.h" #include "test/core/util/test_config.h" static void to_fp(void* arg, const char* buf, size_t len) { diff --git a/test/core/gpr/tls_test.cc b/test/core/gpr/tls_test.cc index 1e4534dc5a..0502fc7ef4 100644 --- a/test/core/gpr/tls_test.cc +++ b/test/core/gpr/tls_test.cc @@ -18,13 +18,15 @@ /* Test of gpr thread local storage support. */ -#include <grpc/support/log.h> -#include <grpc/support/sync.h> +#include "src/core/lib/gpr/tls.h" + #include <stdio.h> #include <stdlib.h> -#include "src/core/lib/gpr/thd.h" -#include "src/core/lib/gpr/tls.h" +#include <grpc/support/log.h> +#include <grpc/support/sync.h> + +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" #define NUM_THREADS 100 @@ -46,21 +48,18 @@ static void thd_body(void* arg) { /* ------------------------------------------------- */ int main(int argc, char* argv[]) { - gpr_thd_options opt = gpr_thd_options_default(); - int i; - gpr_thd_id threads[NUM_THREADS]; + grpc_core::Thread threads[NUM_THREADS]; grpc_test_init(argc, argv); gpr_tls_init(&test_var); - gpr_thd_options_set_joinable(&opt); - - for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_new(&threads[i], "grpc_tls_test", thd_body, nullptr, &opt); + for (auto& th : threads) { + th = grpc_core::Thread("grpc_tls_test", thd_body, nullptr); + th.Start(); } - for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_join(threads[i]); + for (auto& th : threads) { + th.Join(); } gpr_tls_destroy(&test_var); diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 1c11e0bdb5..a8a5739552 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -24,7 +24,6 @@ grpc_cc_test( language = "C++", deps = [ "//:gpr", - "//:gpr++_base", "//test/core/util:gpr_test_util", ], ) @@ -37,7 +36,7 @@ grpc_cc_test( ], language = "C++", deps = [ - "//:gpr++_base", + "//:gpr_base", "//test/core/util:gpr_test_util", ], ) @@ -58,39 +57,49 @@ grpc_cc_test( grpc_cc_test( name = "orphanable_test", srcs = ["orphanable_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:orphanable", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "ref_counted_test", srcs = ["ref_counted_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:ref_counted", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "ref_counted_ptr_test", srcs = ["ref_counted_ptr_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:ref_counted", "//:ref_counted_ptr", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", +) + +grpc_cc_test( + name = "thd_test", + srcs = ["thd_test.cc"], + language = "C++", + deps = [ + "//:gpr", + "//test/core/util:gpr_test_util", ], ) diff --git a/test/core/gprpp/manual_constructor_test.cc b/test/core/gprpp/manual_constructor_test.cc index 74777fe11c..af162ae8e8 100644 --- a/test/core/gprpp/manual_constructor_test.cc +++ b/test/core/gprpp/manual_constructor_test.cc @@ -26,7 +26,6 @@ #include <stdlib.h> #include <cstring> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gprpp/abstract.h" #include "test/core/util/test_config.h" diff --git a/test/core/gpr/thd_test.cc b/test/core/gprpp/thd_test.cc index 18bbaae6c9..82dd681049 100644 --- a/test/core/gpr/thd_test.cc +++ b/test/core/gprpp/thd_test.cc @@ -18,17 +18,18 @@ /* Test of gpr thread support. */ -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" + +#include <stdio.h> +#include <stdlib.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> -#include <stdio.h> -#include <stdlib.h> #include "test/core/util/test_config.h" -#define NUM_THREADS 300 +#define NUM_THREADS 100 struct test { gpr_mu mu; @@ -38,7 +39,7 @@ struct test { }; /* A Thread body. Decrement t->n, and if is becomes zero, set t->done. */ -static void thd_body(void* v) { +static void thd_body1(void* v) { struct test* t = static_cast<struct test*>(v); gpr_mu_lock(&t->mu); t->n--; @@ -49,48 +50,42 @@ static void thd_body(void* v) { gpr_mu_unlock(&t->mu); } -static void thd_body_joinable(void* v) {} - -/* Test thread options work as expected */ -static void test_options(void) { - gpr_thd_options options = gpr_thd_options_default(); - GPR_ASSERT(!gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(gpr_thd_options_is_detached(&options)); - gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(!gpr_thd_options_is_detached(&options)); - gpr_thd_options_set_detached(&options); - GPR_ASSERT(!gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(gpr_thd_options_is_detached(&options)); -} - -/* Test that we can create a number of threads and wait for them. */ -static void test(void) { - int i; - gpr_thd_id thd; - gpr_thd_id thds[NUM_THREADS]; +/* Test that we can create a number of threads, wait for them, and join them. */ +static void test1(void) { + grpc_core::Thread thds[NUM_THREADS]; struct test t; - gpr_thd_options options = gpr_thd_options_default(); gpr_mu_init(&t.mu); gpr_cv_init(&t.done_cv); t.n = NUM_THREADS; t.is_done = 0; - for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thd, "grpc_thread_test", &thd_body, &t, nullptr)); + for (auto& th : thds) { + th = grpc_core::Thread("grpc_thread_body1_test", &thd_body1, &t); + th.Start(); } gpr_mu_lock(&t.mu); while (!t.is_done) { gpr_cv_wait(&t.done_cv, &t.mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&t.mu); + for (auto& th : thds) { + th.Join(); + } 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], "grpc_joinable_thread_test", - &thd_body_joinable, nullptr, &options)); +} + +static void thd_body2(void* v) {} + +/* Test that we can create a number of threads and join them. */ +static void test2(void) { + grpc_core::Thread thds[NUM_THREADS]; + for (auto& th : thds) { + bool ok; + th = grpc_core::Thread("grpc_thread_body2_test", &thd_body2, nullptr, &ok); + GPR_ASSERT(ok); + th.Start(); } - for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_join(thds[i]); + for (auto& th : thds) { + th.Join(); } } @@ -98,7 +93,7 @@ static void test(void) { int main(int argc, char* argv[]) { grpc_test_init(argc, argv); - test_options(); - test(); + test1(); + test2(); return 0; } diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index fe2ab251e3..8ac763ac4b 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -35,7 +35,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -230,12 +230,11 @@ static bool client_ssl_test(char* server_alpn_preferred) { GPR_ASSERT(server_socket > 0 && port > 0); // Launch the TLS server thread. - gpr_thd_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; - gpr_thd_options_set_joinable(&thdopt); server_args args = {server_socket, server_alpn_preferred}; - GPR_ASSERT(gpr_thd_new(&thdid, "grpc_client_ssl_test", server_thread, &args, - &thdopt)); + bool ok; + grpc_core::Thread thd("grpc_client_ssl_test", server_thread, &args, &ok); + GPR_ASSERT(ok); + thd.Start(); // Load key pair and establish client SSL credentials. grpc_ssl_pem_key_cert_pair pem_key_cert_pair; @@ -303,7 +302,7 @@ static bool client_ssl_test(char* server_alpn_preferred) { grpc_slice_unref(key_slice); grpc_slice_unref(ca_slice); - gpr_thd_join(thdid); + thd.Join(); grpc_shutdown(); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 80000ca8d3..9788320e0d 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -30,7 +30,6 @@ #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/handshake/server_ssl.cc b/test/core/handshake/server_ssl.cc index f0465c8e3e..8fa5f7fb35 100644 --- a/test/core/handshake/server_ssl.cc +++ b/test/core/handshake/server_ssl.cc @@ -30,7 +30,6 @@ #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index d202a7cfd6..41b2829d8b 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -32,7 +32,7 @@ #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -138,11 +138,10 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, gpr_event_init(&client_handshake_complete); // Launch the gRPC server thread. - gpr_thd_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; - gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT( - gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port, &thdopt)); + bool ok; + grpc_core::Thread thd("grpc_ssl_test", server_thread, &port, &ok); + GPR_ASSERT(ok); + thd.Start(); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); @@ -235,7 +234,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, EVP_cleanup(); close(sock); - gpr_thd_join(thdid); + thd.Join(); grpc_shutdown(); diff --git a/test/core/handshake/server_ssl_common.h b/test/core/handshake/server_ssl_common.h index f726a1cd3a..32bc6f9897 100644 --- a/test/core/handshake/server_ssl_common.h +++ b/test/core/handshake/server_ssl_common.h @@ -26,7 +26,6 @@ #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 8426b3d233..cf2c7db846 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -22,8 +22,8 @@ #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 +97,19 @@ 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)); + 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..c3ba6d7c14 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -30,8 +30,8 @@ #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 +259,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) { + 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 +279,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..79b2b50e70 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -27,8 +27,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 +38,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 +60,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 +105,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); + 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) { diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 33716b9d4a..a983b1876d 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -38,8 +38,8 @@ #include <grpc/support/log.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/error.h" #include "src/core/lib/iomgr/socket_utils_posix.h" #include "test/core/util/cmdline.h" @@ -575,7 +575,6 @@ int create_socket(const char* socket_type, fd_pair* client_fds, static int run_benchmark(const char* socket_type, thread_args* client_args, thread_args* server_args) { - gpr_thd_id tid; int rv = 0; rv = create_socket(socket_type, &client_args->fds, &server_args->fds); @@ -586,8 +585,11 @@ static int run_benchmark(const char* socket_type, thread_args* client_args, gpr_log(GPR_INFO, "Starting test %s %s %zu", client_args->strategy_name, socket_type, client_args->msg_size); - gpr_thd_new(&tid, "server_thread", server_thread_wrap, server_args, nullptr); + grpc_core::Thread server("server_thread", server_thread_wrap, server_args); + server.Start(); client_thread(client_args); + server.Join(); + return 0; } diff --git a/test/core/statistics/rpc_stats_test.cc b/test/core/statistics/rpc_stats_test.cc index ff48075365..a2a648e2ad 100644 --- a/test/core/statistics/rpc_stats_test.cc +++ b/test/core/statistics/rpc_stats_test.cc @@ -27,7 +27,6 @@ #include "src/core/ext/census/census_interface.h" #include "src/core/ext/census/census_rpc_stats.h" #include "src/core/ext/census/census_tracing.h" -#include "src/core/lib/gpr/thd.h" #include "test/core/util/test_config.h" /* Ensure all possible state transitions are called without causing problem */ diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index 861ed5d1a8..cff05caec1 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -26,7 +26,7 @@ #include <grpc/support/time.h> #include "src/core/lib/compression/message_compress.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "test/core/util/test_config.h" diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 81319f4df4..9c8d8d8395 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/log.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/iomgr.h" #include "test/core/util/test_config.h" @@ -78,16 +78,14 @@ static void test_too_many_plucks(void) { grpc_completion_queue* cc; void* tags[GRPC_MAX_COMPLETION_QUEUE_PLUCKERS]; grpc_cq_completion completions[GPR_ARRAY_SIZE(tags)]; - gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; + grpc_core::Thread threads[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; - gpr_thd_options thread_options = gpr_thd_options_default(); grpc_core::ExecCtx exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); cc = grpc_completion_queue_create_for_pluck(nullptr); - gpr_thd_options_set_joinable(&thread_options); for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { tags[i] = create_test_tag(); @@ -96,8 +94,9 @@ static void test_too_many_plucks(void) { } thread_states[i].cc = cc; thread_states[i].tag = tags[i]; - gpr_thd_new(thread_ids + i, "grpc_pluck_test", pluck_one, thread_states + i, - &thread_options); + threads[i] = + grpc_core::Thread("grpc_pluck_test", pluck_one, thread_states + i); + threads[i].Start(); } /* wait until all other threads are plucking */ @@ -113,8 +112,8 @@ static void test_too_many_plucks(void) { nullptr, &completions[i]); } - for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { - gpr_thd_join(thread_ids[i]); + for (auto& th : threads) { + th.Join(); } shutdown_and_destroy(cc); @@ -220,8 +219,9 @@ static void test_threading(size_t producers, size_t consumers) { "test_threading", producers, consumers); /* start all threads: they will wait for phase1 */ + grpc_core::Thread* threads = reinterpret_cast<grpc_core::Thread*>( + gpr_malloc(sizeof(*threads) * (producers + consumers))); for (i = 0; i < producers + consumers; i++) { - gpr_thd_id id; gpr_event_init(&options[i].on_started); gpr_event_init(&options[i].on_phase1_done); gpr_event_init(&options[i].on_finished); @@ -230,10 +230,13 @@ 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, - i < producers ? "grpc_producer" : "grpc_consumer", - i < producers ? producer_thread : consumer_thread, - options + i, nullptr)); + + bool ok; + threads[i] = grpc_core::Thread( + i < producers ? "grpc_producer" : "grpc_consumer", + i < producers ? producer_thread : consumer_thread, options + i, &ok); + GPR_ASSERT(ok); + threads[i].Start(); gpr_event_wait(&options[i].on_started, ten_seconds_time()); } @@ -266,6 +269,11 @@ static void test_threading(size_t producers, size_t consumers) { /* destroy the completion channel */ grpc_completion_queue_destroy(cc); + for (i = 0; i < producers + consumers; i++) { + threads[i].Join(); + } + gpr_free(threads); + /* verify that everything was produced and consumed */ for (i = 0; i < producers + consumers; i++) { if (i < producers) { diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 95af4abd48..c1298b6636 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -30,7 +30,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/resolve_address.h" @@ -172,73 +172,77 @@ int run_concurrent_connectivity_test() { grpc_init(); - gpr_thd_id threads[NUM_THREADS]; - gpr_thd_id server; - - char* localhost = gpr_strdup("localhost:54321"); - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - /* First round, no server */ - gpr_log(GPR_DEBUG, "Wave 1"); - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_wave_1", create_loop_destroy, localhost, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); + { + gpr_log(GPR_DEBUG, "Wave 1"); + char* localhost = gpr_strdup("localhost:54321"); + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + th = grpc_core::Thread("grpc_wave_1", create_loop_destroy, localhost); + th.Start(); + } + for (auto& th : threads) { + th.Join(); + } + gpr_free(localhost); } - gpr_free(localhost); - /* Second round, actual grpc server */ - gpr_log(GPR_DEBUG, "Wave 2"); - int port = grpc_pick_unused_port_or_die(); - gpr_asprintf(&args.addr, "localhost:%d", port); - args.server = grpc_server_create(nullptr, nullptr); - grpc_server_add_insecure_http2_port(args.server, args.addr); - 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, "grpc_wave_2_server", server_thread, &args, &options); - - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_wave_2", create_loop_destroy, args.addr, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); - } - grpc_server_shutdown_and_notify(args.server, args.cq, tag(0xd1e)); - - gpr_thd_join(server); - grpc_server_destroy(args.server); - grpc_completion_queue_destroy(args.cq); - gpr_free(args.addr); - - /* Third round, bogus tcp server */ - gpr_log(GPR_DEBUG, "Wave 3"); - 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, "grpc_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], "grpc_wave_3", create_loop_destroy, args.addr, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); + { + /* Second round, actual grpc server */ + gpr_log(GPR_DEBUG, "Wave 2"); + int port = grpc_pick_unused_port_or_die(); + gpr_asprintf(&args.addr, "localhost:%d", port); + args.server = grpc_server_create(nullptr, nullptr); + grpc_server_add_insecure_http2_port(args.server, args.addr); + args.cq = grpc_completion_queue_create_for_next(nullptr); + grpc_server_register_completion_queue(args.server, args.cq, nullptr); + grpc_server_start(args.server); + grpc_core::Thread server2("grpc_wave_2_server", server_thread, &args); + server2.Start(); + + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + th = grpc_core::Thread("grpc_wave_2", create_loop_destroy, args.addr); + th.Start(); + } + for (auto& th : threads) { + th.Join(); + } + grpc_server_shutdown_and_notify(args.server, args.cq, tag(0xd1e)); + + server2.Join(); + grpc_server_destroy(args.server); + grpc_completion_queue_destroy(args.cq); + gpr_free(args.addr); } - gpr_atm_rel_store(&args.stop, 1); - gpr_thd_join(server); { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_shutdown( - args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, - grpc_schedule_on_exec_ctx)); + /* Third round, bogus tcp server */ + gpr_log(GPR_DEBUG, "Wave 3"); + args.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(args.pollset, &args.mu); + gpr_event_init(&args.ready); + grpc_core::Thread server3("grpc_wave_3_server", bad_server_thread, &args); + server3.Start(); + gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC)); + + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + th = grpc_core::Thread("grpc_wave_3", create_loop_destroy, args.addr); + th.Start(); + } + for (auto& th : threads) { + th.Join(); + } + + gpr_atm_rel_store(&args.stop, 1); + server3.Join(); + { + grpc_core::ExecCtx exec_ctx; + grpc_pollset_shutdown( + args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, + grpc_schedule_on_exec_ctx)); + } } grpc_shutdown(); @@ -278,18 +282,17 @@ void watches_with_short_timeouts(void* addr) { int run_concurrent_watches_with_short_timeouts_test() { grpc_init(); - gpr_thd_id threads[NUM_THREADS]; + grpc_core::Thread threads[NUM_THREADS]; char* localhost = gpr_strdup("localhost:54321"); - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts, - localhost, &options); + for (auto& th : threads) { + th = grpc_core::Thread("grpc_short_watches", watches_with_short_timeouts, + localhost); + th.Start(); } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); + for (auto& th : threads) { + th.Join(); } gpr_free(localhost); diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index 49d28ad1c7..467deeeaec 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -23,7 +23,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 428d17ff1b..9aba4c499e 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -23,7 +23,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" @@ -67,10 +67,8 @@ static void run_test(const test_fixture* fixture) { grpc_server_start(server); server_thread_args sta = {server, server_cq}; - gpr_thd_id server_thread; - gpr_thd_options thdopt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&thdopt); - gpr_thd_new(&server_thread, "grpc_server", server_thread_func, &sta, &thdopt); + grpc_core::Thread server_thread("grpc_server", server_thread_func, &sta); + server_thread.Start(); grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channels[NUM_CONNECTIONS]; @@ -95,7 +93,7 @@ static void run_test(const test_fixture* fixture) { } grpc_server_shutdown_and_notify(server, server_cq, nullptr); - gpr_thd_join(server_thread); + server_thread.Join(); grpc_completion_queue_shutdown(server_cq); grpc_completion_queue_shutdown(cq); diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 7af6431c66..8ea83f7088 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -24,7 +24,6 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/security/transport/tsi_error.h" #include "test/core/tsi/transport_security_test_lib.h" diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index 1d2dcae94b..ee6958dfcf 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -35,8 +35,8 @@ #include <grpc/support/time.h> #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/sockaddr.h" #include "test/core/util/port.h" diff --git a/test/cpp/cocoapods/generic/generic.mm b/test/cpp/cocoapods/generic/generic.mm index 5ca34f195c..26f09b0af0 100644 --- a/test/cpp/cocoapods/generic/generic.mm +++ b/test/cpp/cocoapods/generic/generic.mm @@ -32,7 +32,7 @@ #include <grpc/grpc.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index df706a2237..d3620584a9 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -33,7 +33,6 @@ #include <grpc/support/time.h> #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/tls.h" #include "src/core/lib/iomgr/port.h" #include "src/proto/grpc/health/v1/health.grpc.pb.h" diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index c28ffea79c..6bde6641b7 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -26,7 +26,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 16600d12b0..96a855c30e 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -38,7 +38,6 @@ #include "src/core/ext/filters/client_channel/subchannel_index.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 38fdde990f..1e2cdb8b62 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -35,7 +35,6 @@ #include <grpc/support/time.h> #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index ae6c6c7d11..20804bc19e 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -33,7 +33,6 @@ #include <grpc/grpc.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/cpp/common/channel_filter.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 86a41fc585..42b15a06e9 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -31,7 +31,6 @@ #include <grpc/grpc.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index ce06ac83e9..33f485be93 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -34,7 +34,6 @@ #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index fe530432ea..e3976a4838 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -29,7 +29,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo_mock.grpc.pb.h" diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index 574d357bef..108dcd29e7 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -26,7 +26,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" diff --git a/test/cpp/end2end/server_early_return_test.cc b/test/cpp/end2end/server_early_return_test.cc index 38f9b6755c..a0349fdc4c 100644 --- a/test/cpp/end2end/server_early_return_test.cc +++ b/test/cpp/end2end/server_early_return_test.cc @@ -29,7 +29,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index 2c8928151a..4dc1d1f1d9 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -33,7 +33,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 0842d8e64a..828beefea3 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -28,7 +28,6 @@ #include <grpc/grpc.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/surface/api_trace.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" |