diff options
Diffstat (limited to 'test/core')
145 files changed, 2851 insertions, 3266 deletions
diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index ef2de8d638..d3115fe1dd 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/backoff/backoff.h" +#include <grpc/grpc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> @@ -32,23 +33,24 @@ static void test_constant_backoff(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + next_deadlines = grpc_backoff_step(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); - exec_ctx.now = next_deadlines.current_deadline; + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(&exec_ctx); } static void test_min_connect(void) { @@ -60,17 +62,16 @@ static void test_min_connect(void) { const grpc_millis max_backoff = 1000; grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, min_connect_timeout, max_backoff); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next = grpc_backoff_begin(&exec_ctx, &backoff); + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next = grpc_backoff_begin(&backoff); // Because the min_connect_timeout > initial_backoff, current_deadline is used // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == min_connect_timeout); // ... while, if the current attempt fails, the next one will happen after // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_exec_ctx_now(&exec_ctx) == + GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == initial_backoff); - grpc_exec_ctx_finish(&exec_ctx); } static void test_no_jitter_backoff(void) { @@ -84,49 +85,47 @@ static void test_no_jitter_backoff(void) { min_connect_timeout, max_backoff); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - exec_ctx.now = 0; - exec_ctx.now_is_valid = true; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); + grpc_core::ExecCtx exec_ctx; + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); GPR_ASSERT(next_deadlines.current_deadline == next_deadlines.next_attempt_start_time); GPR_ASSERT(next_deadlines.current_deadline == 2); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 6); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 14); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 30); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 62); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 126); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 254); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 510); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 1022); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. GPR_ASSERT(next_deadlines.current_deadline == 1535); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2048); - exec_ctx.now = next_deadlines.current_deadline; - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_deadlines = grpc_backoff_step(&backoff); GPR_ASSERT(next_deadlines.current_deadline == 2561); - grpc_exec_ctx_finish(&exec_ctx); } static void test_jitter_backoff(void) { @@ -142,12 +141,13 @@ static void test_jitter_backoff(void) { backoff.rng_state = 0; // force consistent PRNG - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&exec_ctx, &backoff); - GPR_ASSERT(next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx exec_ctx; + grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); + GPR_ASSERT(next_deadlines.current_deadline - + grpc_core::ExecCtx::Get()->Now() == initial_backoff); GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_exec_ctx_now(&exec_ctx) == + grpc_core::ExecCtx::Get()->Now() == initial_backoff); grpc_millis expected_next_lower_bound = @@ -156,11 +156,11 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 + jitter)); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&exec_ctx, &backoff); + next_deadlines = grpc_backoff_step(&backoff); // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_exec_ctx_now(&exec_ctx); + next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); GPR_ASSERT(timeout_millis >= expected_next_lower_bound); GPR_ASSERT(timeout_millis <= expected_next_upper_bound); current_backoff = GPR_MIN( @@ -169,13 +169,13 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - exec_ctx.now = next_deadlines.current_deadline; + grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); gpr_time_init(); test_constant_backoff(); @@ -183,5 +183,6 @@ int main(int argc, char** argv) { test_no_jitter_backoff(); test_jitter_backoff(); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 0a7b1c7571..4c1642aa5d 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -50,20 +50,19 @@ static void thd_func(void* arg) { gpr_event_set(&a->done_thd, (void*)1); } -static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void done_write(void* arg, grpc_error* error) { thd_args* a = (thd_args*)arg; gpr_event_set(&a->done_write, (void*)1); } static void server_setup_transport(void* ts, grpc_transport* transport) { thd_args* a = (thd_args*)ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_server_setup_transport(&exec_ctx, a->server, transport, nullptr, + grpc_core::ExecCtx exec_ctx; + grpc_server_setup_transport(a->server, transport, nullptr, grpc_server_get_channel_args(a->server)); - grpc_exec_ctx_finish(&exec_ctx); } -static void read_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void read_done(void* arg, grpc_error* error) { gpr_event* read_done = (gpr_event*)arg; gpr_event_set(read_done, (void*)1); } @@ -81,7 +80,7 @@ void grpc_run_bad_client_test( grpc_slice_from_copied_buffer(client_payload, client_payload_length); grpc_slice_buffer outgoing; grpc_closure done_write_closure; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_completion_queue* shutdown_cq; if (client_payload_length < 4 * 1024) { @@ -115,21 +114,19 @@ void grpc_run_bad_client_test( GRPC_BAD_CLIENT_REGISTERED_HOST, GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); grpc_server_start(a.server); - transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, sfd.server, false); + transport = grpc_create_chttp2_transport(nullptr, sfd.server, false); server_setup_transport(&a, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); /* Bind everything into the same pollset */ - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.client, grpc_cq_pollset(a.cq)); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.server, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq)); /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); /* Start validator */ - gpr_thd_new(&id, thd_func, &a, nullptr); + gpr_thd_new(&id, "grpc_bad_client", thd_func, &a, nullptr); grpc_slice_buffer_init(&outgoing); grpc_slice_buffer_add(&outgoing, slice); @@ -137,8 +134,8 @@ void grpc_run_bad_client_test( grpc_schedule_on_exec_ctx); /* Write data */ - grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure); + grpc_core::ExecCtx::Get()->Flush(); /* Await completion, unless the request is large and write may not finish * before the peer shuts down. */ @@ -149,10 +146,9 @@ void grpc_run_bad_client_test( if (flags & GRPC_BAD_CLIENT_DISCONNECT) { grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); + sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); + grpc_endpoint_destroy(sfd.client); + grpc_core::ExecCtx::Get()->Flush(); sfd.client = nullptr; } @@ -171,9 +167,8 @@ void grpc_run_bad_client_test( grpc_closure read_done_closure; GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, sfd.client, &incoming, - &read_done_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_read(sfd.client, &incoming, &read_done_closure); + grpc_core::ExecCtx::Get()->Flush(); do { GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); GPR_ASSERT( @@ -186,14 +181,13 @@ void grpc_run_bad_client_test( "client validator failed; trying additional read " "in case we didn't get all the data"); } - grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); + grpc_slice_buffer_destroy_internal(&incoming); } // Shutdown. grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); + sfd.client, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + grpc_endpoint_destroy(sfd.client); + grpc_core::ExecCtx::Get()->Flush(); } GPR_ASSERT( @@ -207,8 +201,7 @@ void grpc_run_bad_client_test( grpc_completion_queue_destroy(shutdown_cq); grpc_server_destroy(a.server); grpc_completion_queue_destroy(a.cq); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); + grpc_slice_buffer_destroy_internal(&outgoing); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } diff --git a/test/core/bad_client/tests/badreq.cc b/test/core/bad_client/tests/badreq.cc index c30244e0cd..eeaf4c9974 100644 --- a/test/core/bad_client/tests/badreq.cc +++ b/test/core/bad_client/tests/badreq.cc @@ -20,6 +20,8 @@ #include <string.h> +#include <grpc/grpc.h> + #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -38,6 +40,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* invalid content type */ GRPC_RUN_BAD_CLIENT_TEST( @@ -126,5 +129,6 @@ int main(int argc, char** argv) { "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/connection_prefix.cc b/test/core/bad_client/tests/connection_prefix.cc index 47252f9f10..4aab234d3e 100644 --- a/test/core/bad_client/tests/connection_prefix.cc +++ b/test/core/bad_client/tests/connection_prefix.cc @@ -30,6 +30,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "X", 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PX", 0); @@ -57,5 +58,7 @@ int main(int argc, char** argv) { 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", 0); + + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc index bbc5611991..f56c4d71dd 100644 --- a/test/core/bad_client/tests/head_of_line_blocking.cc +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -20,6 +20,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/lib/surface/server.h" @@ -109,6 +110,7 @@ static void addbuf(const void* data, size_t len) { int main(int argc, char** argv) { int i; grpc_test_init(argc, argv); + grpc_init(); #define NUM_FRAMES 10 #define FRAME_SIZE 1000 @@ -131,6 +133,7 @@ int main(int argc, char** argv) { } grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, 0); gpr_free(g_buffer); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/headers.cc b/test/core/bad_client/tests/headers.cc index 50bb72c493..2aa1b280ce 100644 --- a/test/core/bad_client/tests/headers.cc +++ b/test/core/bad_client/tests/headers.cc @@ -34,6 +34,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* partial http2 header prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -335,5 +336,6 @@ int main(int argc, char** argv) { "15 seconds", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/initial_settings_frame.cc b/test/core/bad_client/tests/initial_settings_frame.cc index edc52f503e..0220000ece 100644 --- a/test/core/bad_client/tests/initial_settings_frame.cc +++ b/test/core/bad_client/tests/initial_settings_frame.cc @@ -33,6 +33,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* various partial prefixes */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", @@ -106,5 +107,6 @@ int main(int argc, char** argv) { PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc index 6613c94b41..c2dc9c66af 100644 --- a/test/core/bad_client/tests/server_registered_method.cc +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -77,6 +77,7 @@ static void verifier_fails(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* body generated with * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ @@ -123,5 +124,6 @@ int main(int argc, char** argv) { "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", 0); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc index 9f4a03e69b..c80fc5cb4a 100644 --- a/test/core/bad_client/tests/simple_request.cc +++ b/test/core/bad_client/tests/simple_request.cc @@ -20,6 +20,8 @@ #include <string.h> +#include <grpc/grpc.h> + #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -122,6 +124,7 @@ static void failure_verifier(grpc_server* server, grpc_completion_queue* cq, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* basic request: check that things are working */ GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR, 0); @@ -164,5 +167,6 @@ int main(int argc, char** argv) { GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, nullptr, PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/unknown_frame.cc b/test/core/bad_client/tests/unknown_frame.cc index d962a4244d..b1b618a43f 100644 --- a/test/core/bad_client/tests/unknown_frame.cc +++ b/test/core/bad_client/tests/unknown_frame.cc @@ -33,6 +33,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq, } int main(int argc, char** argv) { + grpc_init(); grpc_test_init(argc, argv); /* test adding prioritization data */ @@ -40,5 +41,6 @@ int main(int argc, char** argv) { PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", GRPC_BAD_CLIENT_DISCONNECT); + grpc_shutdown(); return 0; } diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc index f4bd81828b..ed8279c951 100644 --- a/test/core/bad_client/tests/window_overflow.cc +++ b/test/core/bad_client/tests/window_overflow.cc @@ -20,6 +20,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/lib/surface/server.h" @@ -72,6 +73,7 @@ int main(int argc, char** argv) { #define SEND_SIZE (6 * 1024 * 1024) #define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) grpc_test_init(argc, argv); + grpc_init(); addbuf(PFX_STR, sizeof(PFX_STR) - 1); for (i = 0; i < NUM_FRAMES; i++) { @@ -93,6 +95,7 @@ int main(int argc, char** argv) { grpc_run_bad_client_test(verifier, nullptr, g_buffer, g_count, GRPC_BAD_CLIENT_LARGE_REQUEST); gpr_free(g_buffer); + grpc_shutdown(); return 0; } diff --git a/test/core/channel/channel_args_test.cc b/test/core/channel/channel_args_test.cc index e8b3334185..4a8195e984 100644 --- a/test/core/channel/channel_args_test.cc +++ b/test/core/channel/channel_args_test.cc @@ -26,7 +26,7 @@ #include "test/core/util/test_config.h" static void test_create(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_arg arg_int; grpc_arg arg_string; @@ -55,12 +55,11 @@ static void test_create(void) { GPR_ASSERT(strcmp(ch_args->args[1].value.string, arg_string.value.string) == 0); - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_set_compression_algorithm(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* ch_args; ch_args = @@ -70,12 +69,11 @@ static void test_set_compression_algorithm(void) { GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER); - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_compression_algorithm_states(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; unsigned states_bitset; size_t i; @@ -91,10 +89,10 @@ static void test_compression_algorithm_states(void) { /* disable gzip and deflate */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args, GRPC_COMPRESS_GZIP, 0); + &ch_args, GRPC_COMPRESS_GZIP, 0); GPR_ASSERT(ch_args == ch_args_wo_gzip); ch_args_wo_gzip_deflate = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); + &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -109,7 +107,7 @@ static void test_compression_algorithm_states(void) { /* re-enabled gzip only */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); + &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( @@ -122,8 +120,7 @@ static void test_compression_algorithm_states(void) { } } - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(ch_args); } static void test_set_socket_mutator(void) { @@ -137,9 +134,8 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ch_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ch_args); } } diff --git a/test/core/channel/channel_stack_builder_test.cc b/test/core/channel/channel_stack_builder_test.cc index a67f0efafe..ef6db81b0b 100644 --- a/test/core/channel/channel_stack_builder_test.cc +++ b/test/core/channel/channel_stack_builder_test.cc @@ -29,34 +29,30 @@ #include "src/core/lib/surface/channel_init.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* call_init_func(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_destroy_func(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_func(grpc_call_element* elem, grpc_transport_stream_op_batch* op) {} -static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op) { +static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); } bool g_replacement_fn_called = false; @@ -106,8 +102,7 @@ const grpc_channel_filter original_filter = { grpc_channel_next_get_info, "filter_name"}; -static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool add_replacement_filter(grpc_channel_stack_builder* builder, void* arg) { const grpc_channel_filter* filter = static_cast<const grpc_channel_filter*>(arg); @@ -118,8 +113,7 @@ static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, builder, filter, set_arg_once_fn, &g_replacement_fn_called); } -static bool add_original_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool add_original_filter(grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter*)arg, set_arg_once_fn, diff --git a/test/core/channel/channel_stack_test.cc b/test/core/channel/channel_stack_test.cc index 988ea9bac9..ef43facd6e 100644 --- a/test/core/channel/channel_stack_test.cc +++ b/test/core/channel/channel_stack_test.cc @@ -27,8 +27,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" -static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* channel_init_func(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->channel_args->num_args == 1); GPR_ASSERT(args->channel_args->args[0].type == GRPC_ARG_INTEGER); @@ -40,42 +39,37 @@ static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* call_init_func(grpc_call_element* elem, const grpc_call_element_args* args) { ++*(int*)(elem->channel_data); *(int*)(elem->call_data) = 0; return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void channel_destroy_func(grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_destroy_func(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { ++*(int*)(elem->channel_data); } -static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void call_func(grpc_call_element* elem, grpc_transport_stream_op_batch* op) { ++*(int*)(elem->call_data); } -static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, - grpc_transport_op* op) { +static void channel_func(grpc_channel_element* elem, grpc_transport_op* op) { ++*(int*)(elem->channel_data); } -static void free_channel(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - grpc_channel_stack_destroy(exec_ctx, static_cast<grpc_channel_stack*>(arg)); +static void free_channel(void* arg, grpc_error* error) { + grpc_channel_stack_destroy(static_cast<grpc_channel_stack*>(arg)); gpr_free(arg); } -static void free_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - grpc_call_stack_destroy(exec_ctx, static_cast<grpc_call_stack*>(arg), nullptr, - nullptr); +static void free_call(void* arg, grpc_error* error) { + grpc_call_stack_destroy(static_cast<grpc_call_stack*>(arg), nullptr, nullptr); gpr_free(arg); } @@ -101,7 +95,7 @@ static void test_create_channel_stack(void) { grpc_channel_args chan_args; int* channel_data; int* call_data; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; @@ -113,8 +107,8 @@ static void test_create_channel_stack(void) { channel_stack = static_cast<grpc_channel_stack*>( gpr_malloc(grpc_channel_stack_size(&filters, 1))); - grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, - 1, &chan_args, nullptr, "test", channel_stack); + grpc_channel_stack_init(1, free_channel, channel_stack, &filters, 1, + &chan_args, nullptr, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_data = (int*)channel_elem->channel_data; @@ -132,8 +126,8 @@ static void test_create_channel_stack(void) { nullptr, /* arena */ nullptr /* call_combiner */ }; - grpc_error* error = grpc_call_stack_init(&exec_ctx, channel_stack, 1, - free_call, call_stack, &args); + grpc_error* error = + grpc_call_stack_init(channel_stack, 1, free_call, call_stack, &args); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); @@ -143,14 +137,13 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); - GRPC_CALL_STACK_UNREF(&exec_ctx, call_stack, "done"); - grpc_exec_ctx_flush(&exec_ctx); + GRPC_CALL_STACK_UNREF(call_stack, "done"); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(*channel_data == 2); - GRPC_CHANNEL_STACK_UNREF(&exec_ctx, channel_stack, "done"); + GRPC_CHANNEL_STACK_UNREF(channel_stack, "done"); - grpc_slice_unref_internal(&exec_ctx, path); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(path); } int main(int argc, char** argv) { diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index e0cffa39a8..3495f603e4 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -125,12 +125,10 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_stack_builder_set_transport(builder, &fake_transport); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_stack_builder_set_channel_arguments(&exec_ctx, builder, - channel_args); + grpc_core::ExecCtx exec_ctx; + grpc_channel_stack_builder_set_channel_arguments(builder, channel_args); GPR_ASSERT(grpc_channel_init_create_stack( - &exec_ctx, builder, (grpc_channel_stack_type)channel_stack_type)); - grpc_exec_ctx_finish(&exec_ctx); + builder, (grpc_channel_stack_type)channel_stack_type)); } // build up our expectation list @@ -212,10 +210,9 @@ static int check_stack(const char* file, int line, const char* transport_name, gpr_free(expect); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_stack_builder_destroy(&exec_ctx, builder); - grpc_channel_args_destroy(&exec_ctx, channel_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_stack_builder_destroy(builder); + grpc_channel_args_destroy(channel_args); } return result; diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 5f8d3b84cc..847ea0066b 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,9 +651,8 @@ static void test_get_channel_info() { grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); channel = grpc_insecure_channel_create("ipv4:127.0.0.1:1234", args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); @@ -959,7 +958,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; @@ -969,9 +968,9 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_tracer_set_enabled("round_robin", 1); - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist", - nullptr) == nullptr); - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, nullptr, nullptr) == nullptr); + GPR_ASSERT(grpc_lb_policy_create("this-lb-policy-does-not-exist", nullptr) == + nullptr); + GPR_ASSERT(grpc_lb_policy_create(nullptr, nullptr) == nullptr); spec = test_spec_create(NUM_ITERS, NUM_SERVERS); /* everything is fine, all servers stay up the whole time and life's peachy @@ -1025,7 +1024,6 @@ int main(int argc, char** argv) { test_ping(); test_get_channel_info(); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 94f76da920..6d56961d84 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -24,6 +24,7 @@ #include <sys/un.h> #endif +#include <grpc/grpc.h> #include <grpc/support/log.h> #include "src/core/lib/iomgr/exec_ctx.h" @@ -33,8 +34,8 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); @@ -43,7 +44,6 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname)); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } #else /* GRPC_HAVE_UNIX_SOCKET */ @@ -54,8 +54,8 @@ static void test_grpc_parse_unix(const char* uri_text, const char* pathname) {} static void test_grpc_parse_ipv4(const char* uri_text, const char* host, unsigned short port) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -68,13 +68,12 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, GPR_ASSERT(ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } static void test_grpc_parse_ipv6(const char* uri_text, const char* host, unsigned short port, uint32_t scope_id) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; @@ -88,14 +87,16 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_grpc_parse_unix("unix:/path/name", "/path/name"); test_grpc_parse_ipv4("ipv4:192.0.2.1:12345", "192.0.2.1", 12345); test_grpc_parse_ipv6("ipv6:[2001:db8::1]:12345", "2001:db8::1", 12345, 0); test_grpc_parse_ipv6("ipv6:[2001:db8::1%252]:12345", "2001:db8::1", 12345, 2); + + grpc_shutdown(); } diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index dcf315eba5..18a795fbcb 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,8 +35,7 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -55,13 +54,13 @@ static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", addr)); @@ -76,27 +75,26 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); return nullptr; } -static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, - const char* name) { +static grpc_resolver* create_resolver(const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(exec_ctx, name, 0); + grpc_uri* uri = grpc_uri_parse(name, 0); GPR_ASSERT(uri); grpc_resolver_args args; memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); + grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { +static void on_done(void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -107,9 +105,8 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_timer_check(&exec_ctx, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_timer_check(nullptr); } return false; } @@ -120,16 +117,14 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, - void* arg, +static void call_resolver_next_now_lock_taken(void* arg, grpc_error* error_unused) { next_args* a = static_cast<next_args*>(arg); - grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast<next_args*>(gpr_malloc(sizeof(*a))); @@ -137,7 +132,6 @@ static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, a->result = result; a->on_complete = on_complete; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a, grpc_combiner_scheduler(resolver->combiner)), GRPC_ERROR_NONE); @@ -153,30 +147,31 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resolver* resolver = create_resolver(&exec_ctx, "dns:test"); - gpr_event ev1; - gpr_event_init(&ev1); - call_resolver_next_after_locking( - &exec_ctx, resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(5, &ev1)); - GPR_ASSERT(result == nullptr); - - gpr_event ev2; - gpr_event_init(&ev2); - call_resolver_next_after_locking( - &exec_ctx, resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(30, &ev2)); - GPR_ASSERT(result != nullptr); - - grpc_channel_args_destroy(&exec_ctx, result); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_resolver* resolver = create_resolver("dns:test"); + gpr_event ev1; + gpr_event_init(&ev1); + call_resolver_next_after_locking( + resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(wait_loop(5, &ev1)); + GPR_ASSERT(result == nullptr); + + gpr_event ev2; + gpr_event_init(&ev2); + call_resolver_next_after_locking( + resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(wait_loop(30, &ev2)); + GPR_ASSERT(result != nullptr); + + grpc_channel_args_destroy(result); + GRPC_RESOLVER_UNREF(resolver, "test"); + GRPC_COMBINER_UNREF(g_combiner, "test"); + } grpc_shutdown(); gpr_mu_destroy(&g_mu); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 4c040caeb9..80667908ef 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,8 +28,8 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -38,16 +38,15 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver != nullptr); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -56,10 +55,9 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -82,9 +80,8 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index d5538e9621..d85cbb1d03 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -33,7 +33,7 @@ #include "test/core/util/test_config.h" static grpc_resolver* build_fake_resolver( - grpc_exec_ctx* exec_ctx, grpc_combiner* combiner, + grpc_combiner* combiner, grpc_fake_resolver_response_generator* response_generator) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("fake"); grpc_arg generator_arg = @@ -44,7 +44,7 @@ static grpc_resolver* build_fake_resolver( args.args = &channel_args; args.combiner = combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); + grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_unref(factory); return resolver; } @@ -55,7 +55,7 @@ typedef struct on_resolution_arg { gpr_event ev; } on_resolution_arg; -void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +void on_resolution_cb(void* arg, grpc_error* error) { on_resolution_arg* res = static_cast<on_resolution_arg*>(arg); // We only check the addresses channel arg because that's the only one // explicitly set by the test via @@ -66,24 +66,23 @@ void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_lb_addresses_find_channel_arg(res->expected_resolver_result); GPR_ASSERT( grpc_lb_addresses_cmp(actual_lb_addresses, expected_lb_addresses) == 0); - grpc_channel_args_destroy(exec_ctx, res->resolver_result); - grpc_channel_args_destroy(exec_ctx, res->expected_resolver_result); + grpc_channel_args_destroy(res->resolver_result); + grpc_channel_args_destroy(res->expected_resolver_result); gpr_event_set(&res->ev, (void*)1); } static void test_fake_resolver() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = grpc_fake_resolver_response_generator_create(); - grpc_resolver* resolver = - build_fake_resolver(&exec_ctx, combiner, response_generator); + grpc_resolver* resolver = build_fake_resolver(combiner, response_generator); GPR_ASSERT(resolver != nullptr); // Setup expectations. - grpc_uri* uris[] = {grpc_uri_parse(&exec_ctx, "ipv4:10.2.1.1:1234", true), - grpc_uri_parse(&exec_ctx, "ipv4:127.0.0.1:4321", true)}; + grpc_uri* uris[] = {grpc_uri_parse("ipv4:10.2.1.1:1234", true), + grpc_uri_parse("ipv4:127.0.0.1:4321", true)}; const char* balancer_names[] = {"name1", "name2"}; const bool is_balancer[] = {true, false}; grpc_lb_addresses* addresses = grpc_lb_addresses_create(3, nullptr); @@ -96,7 +95,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* results = grpc_channel_args_copy_and_add(nullptr, &addresses_arg, 1); - grpc_lb_addresses_destroy(&exec_ctx, addresses); + grpc_lb_addresses_destroy(addresses); on_resolution_arg on_res_arg; memset(&on_res_arg, 0, sizeof(on_res_arg)); on_res_arg.expected_resolver_result = results; @@ -106,17 +105,16 @@ static void test_fake_resolver() { // Set resolver results and trigger first resolution. on_resolution_cb // performs the checks. - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator, results); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_fake_resolver_response_generator_set_response(response_generator, + results); + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Setup update. - grpc_uri* uris_update[] = { - grpc_uri_parse(&exec_ctx, "ipv4:192.168.1.0:31416", true)}; + grpc_uri* uris_update[] = {grpc_uri_parse("ipv4:192.168.1.0:31416", true)}; const char* balancer_names_update[] = {"name3"}; const bool is_balancer_update[] = {false}; grpc_lb_addresses* addresses_update = grpc_lb_addresses_create(1, nullptr); @@ -131,7 +129,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses_update); grpc_channel_args* results_update = grpc_channel_args_copy_and_add(nullptr, &addresses_update_arg, 1); - grpc_lb_addresses_destroy(&exec_ctx, addresses_update); + grpc_lb_addresses_destroy(addresses_update); // Setup expectations for the update. on_resolution_arg on_res_arg_update; @@ -142,27 +140,27 @@ static void test_fake_resolver() { grpc_combiner_scheduler(combiner)); // Set updated resolver results and trigger a second resolution. - grpc_fake_resolver_response_generator_set_response( - &exec_ctx, response_generator, results_update); - grpc_resolver_next_locked(&exec_ctx, resolver, - &on_res_arg_update.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_fake_resolver_response_generator_set_response(response_generator, + results_update); + grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, + on_resolution); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Requesting a new resolution without re-senting the response shouldn't // trigger the resolution callback. memset(&on_res_arg, 0, sizeof(on_res_arg)); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, combiner, "test_fake_resolver"); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_fake_resolver"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); + GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); + grpc_fake_resolver_response_generator_unref(response_generator); } diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index dfa2d12b5e..4d16a77924 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -35,14 +35,14 @@ typedef struct on_resolution_arg { grpc_channel_args* resolver_result; } on_resolution_arg; -void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +void on_resolution_cb(void* arg, grpc_error* error) { on_resolution_arg* res = static_cast<on_resolution_arg*>(arg); - grpc_channel_args_destroy(exec_ctx, res->resolver_result); + grpc_channel_args_destroy(res->resolver_result); } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -51,7 +51,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver != nullptr); on_resolution_arg on_res_arg; @@ -60,16 +60,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_closure* on_resolution = GRPC_CLOSURE_CREATE( on_resolution_cb, &on_res_arg, grpc_schedule_on_exec_ctx); - grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); + grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -78,10 +78,9 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); + resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -112,9 +111,8 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(g_combiner, "test"); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index ba31793ff3..ee38453166 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -20,6 +20,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/ext/filters/client_channel/uri_parser.h" @@ -33,12 +34,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { memcpy(s, data, size); s[size] = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* x; - if ((x = grpc_uri_parse(&exec_ctx, s, 1))) { - grpc_uri_destroy(x); + grpc_init(); + + { + grpc_core::ExecCtx exec_ctx; + grpc_uri* x; + if ((x = grpc_uri_parse(s, 1))) { + grpc_uri_destroy(x); + } + + gpr_free(s); } - grpc_exec_ctx_finish(&exec_ctx); - gpr_free(s); + + grpc_shutdown(); return 0; } diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 30183f9f57..254bfddfb3 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -20,6 +20,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/log.h> #include "src/core/lib/iomgr/exec_ctx.h" @@ -28,29 +29,28 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_core::ExecCtx exec_ctx; + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); GPR_ASSERT(0 == strcmp(authority, uri->authority)); GPR_ASSERT(0 == strcmp(path, uri->path)); GPR_ASSERT(0 == strcmp(query, uri->query)); GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } static void test_fails(const char* uri_text) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(nullptr == grpc_uri_parse(&exec_ctx, uri_text, 0)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(nullptr == grpc_uri_parse(uri_text, 0)); } static void test_query_parts() { { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -77,14 +77,14 @@ static void test_query_parts() { GPR_ASSERT(nullptr == grpc_uri_get_query_arg(uri, "")); GPR_ASSERT(0 == strcmp("frag", uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } { /* test the current behavior of multiple query part values */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -96,14 +96,13 @@ static void test_query_parts() { GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); - grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } { /* empty query */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; const char* uri_text = "http://foo/path"; - grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); + grpc_uri* uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -114,13 +113,14 @@ static void test_query_parts() { GPR_ASSERT(nullptr == uri->query_parts); GPR_ASSERT(nullptr == uri->query_parts_values); GPR_ASSERT(0 == strcmp("", uri->fragment)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", @@ -148,5 +148,6 @@ int main(int argc, char** argv) { test_fails("http://foo?bar#lol#"); test_query_parts(); + grpc_shutdown(); return 0; } diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index 2f1d8bc8eb..9e811e9af1 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -39,7 +39,7 @@ static void test_algorithm_mesh(void) { grpc_compression_algorithm parsed; grpc_slice mdstr; grpc_mdelem mdelem; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); GPR_ASSERT(grpc_compression_algorithm_parse( @@ -51,9 +51,8 @@ static void test_algorithm_mesh(void) { mdelem = grpc_compression_encoding_mdelem(parsed); GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); - grpc_slice_unref_internal(&exec_ctx, mdstr); - GRPC_MDELEM_UNREF(&exec_ctx, mdelem); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(mdstr); + GRPC_MDELEM_UNREF(mdelem); } /* test failure */ @@ -62,7 +61,7 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); @@ -83,8 +82,7 @@ static void test_algorithm_failure(void) { grpc_compression_algorithm_slice(static_cast<grpc_compression_algorithm>( static_cast<int>(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)), grpc_empty_slice())); - grpc_slice_unref_internal(&exec_ctx, mdstr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(mdstr); } int main(int argc, char** argv) { diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 676415ba9d..6ca07b70c4 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -70,10 +70,8 @@ static void assert_passthrough(grpc_slice value, grpc_split_slices_to_buffer(uncompressed_split_mode, &value, 1, &input); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_compressed = - grpc_msg_compress(&exec_ctx, algorithm, &input, &compressed_raw); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); } GPR_ASSERT(input.count > 0); @@ -92,11 +90,9 @@ static void assert_passthrough(grpc_slice value, grpc_split_slice_buffer(compressed_split_mode, &compressed_raw, &compressed); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(grpc_msg_decompress( - &exec_ctx, was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); } final = grpc_slice_merge(output.slices, output.count); @@ -156,11 +152,11 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_compress( - &exec_ctx, static_cast<grpc_compression_algorithm>(i), - &input, &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == + grpc_msg_compress(static_cast<grpc_compression_algorithm>(i), + &input, &output)); + GPR_ASSERT(1 == output.count); } @@ -180,9 +176,9 @@ static void test_bad_decompression_data_crc(void) { grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* compress it */ - grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_GZIP, &input, &corrupted); + grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ GPR_ASSERT(corrupted.count > 1); GPR_ASSERT(GRPC_SLICE_LENGTH(corrupted.slices[1]) > 8); @@ -190,9 +186,7 @@ static void test_bad_decompression_data_crc(void) { memcpy(GRPC_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4); /* try (and fail) to decompress the corrupted compresed buffer */ - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_GZIP, &corrupted, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&corrupted); @@ -211,10 +205,8 @@ static void test_bad_decompression_data_trailing_garbage(void) { "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -230,10 +222,8 @@ static void test_bad_decompression_data_stream(void) { grpc_slice_from_copied_buffer("\x78\xda\xff\xff", 4)); /* try (and fail) to decompress the invalid compresed buffer */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -249,17 +239,15 @@ static void test_bad_compression_algorithm(void) { grpc_slice_buffer_add( &input, grpc_slice_from_copied_string("Never gonna give you up")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_compressed = grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, - &input, &output); + grpc_core::ExecCtx exec_ctx; + was_compressed = + grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_compressed); - was_compressed = grpc_msg_compress(&exec_ctx, - static_cast<grpc_compression_algorithm>( + was_compressed = grpc_msg_compress(static_cast<grpc_compression_algorithm>( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_compressed); - grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); @@ -275,18 +263,16 @@ static void test_bad_decompression_algorithm(void) { grpc_slice_buffer_add(&input, grpc_slice_from_copied_string( "I'm not really compressed but it doesn't matter")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_decompressed = grpc_msg_decompress( - &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); + grpc_core::ExecCtx exec_ctx; + was_decompressed = + grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); was_decompressed = - grpc_msg_decompress(&exec_ctx, - static_cast<grpc_compression_algorithm>( + grpc_msg_decompress(static_cast<grpc_compression_algorithm>( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); GPR_ASSERT(0 == was_decompressed); - grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 5fae61f8f6..e60e54b2fd 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -49,9 +49,8 @@ TEST(StatsTest, IncCounters) { for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_COUNTER(&exec_ctx, (grpc_stats_counters)i); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_STATS_INC_COUNTER((grpc_stats_counters)i); EXPECT_EQ(snapshot.delta().counters[i], 1); } @@ -60,9 +59,8 @@ TEST(StatsTest, IncCounters) { TEST(StatsTest, IncSpecificCounter) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_STATS_INC_SYSCALL_POLL(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_STATS_INC_SYSCALL_POLL(); EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); } @@ -94,9 +92,8 @@ TEST_P(HistogramTest, IncHistogram) { for (auto j : test_values) { Snapshot snapshot; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_stats_inc_histogram[kHistogram](j); auto delta = snapshot.delta(); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index b0c6ae926e..93809ac37a 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -91,22 +91,22 @@ static grpc_closure on_write; static void* tag(intptr_t t) { return (void*)t; } -static void done_write(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void done_write(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); gpr_atm_rel_store(&state.done_atm, 1); } -static void handle_write(grpc_exec_ctx* exec_ctx) { +static void handle_write() { grpc_slice slice = grpc_slice_from_copied_buffer( state.response_payload, state.response_payload_length); grpc_slice_buffer_reset_and_unref(&state.outgoing_buffer); grpc_slice_buffer_add(&state.outgoing_buffer, slice); - grpc_endpoint_write(exec_ctx, state.tcp, &state.outgoing_buffer, &on_write); + grpc_endpoint_write(state.tcp, &state.outgoing_buffer, &on_write); } -static void handle_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void handle_read(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); state.incoming_data_length += state.temp_incoming_buffer.length; @@ -123,14 +123,13 @@ static void handle_read(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD); if (state.incoming_data_length >= SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD) { - handle_write(exec_ctx); + handle_write(); } else { - grpc_endpoint_read(exec_ctx, state.tcp, &state.temp_incoming_buffer, - &on_read); + grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read); } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -141,8 +140,8 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, grpc_slice_buffer_init(&state.outgoing_buffer); state.tcp = tcp; state.incoming_data_length = 0; - grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); - grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); + grpc_endpoint_add_to_pollset(tcp, server->pollset); + grpc_endpoint_read(tcp, &state.temp_incoming_buffer, &on_read); } static gpr_timespec n_sec_deadline(int seconds) { @@ -217,10 +216,10 @@ static void start_rpc(int target_port, grpc_status_code expected_status, cq_verifier_destroy(cqv); } -static void cleanup_rpc(grpc_exec_ctx* exec_ctx) { +static void cleanup_rpc() { grpc_event ev; - grpc_slice_buffer_destroy_internal(exec_ctx, &state.temp_incoming_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &state.outgoing_buffer); + grpc_slice_buffer_destroy_internal(&state.temp_incoming_buffer); + grpc_slice_buffer_destroy_internal(&state.outgoing_buffer); grpc_call_unref(state.call); grpc_completion_queue_shutdown(state.cq); do { @@ -262,7 +261,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, "grpc_poll_server", actually_poll_server, pa, nullptr); } static void run_test(const char* response_payload, @@ -270,7 +269,7 @@ static void run_test(const char* response_payload, grpc_status_code expected_status, const char* expected_detail) { test_tcp_server test_server; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_event ev; grpc_init(); @@ -287,11 +286,11 @@ static void run_test(const char* response_payload, gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); /* clean up */ - grpc_endpoint_shutdown(&exec_ctx, state.tcp, + grpc_endpoint_shutdown(state.tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(&exec_ctx, state.tcp); - cleanup_rpc(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_destroy(state.tcp); + cleanup_rpc(); + grpc_core::ExecCtx::Get()->Flush(); test_tcp_server_destroy(&test_server); grpc_shutdown(); @@ -299,6 +298,7 @@ static void run_test(const char* response_payload, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); /* status defined in hpack static table */ run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_CANCELLED, @@ -337,5 +337,6 @@ int main(int argc, char** argv) { run_test(HTTP1_RESP, sizeof(HTTP1_RESP) - 1, GRPC_STATUS_UNAVAILABLE, HTTP1_DETAIL_MSG); + grpc_shutdown(); return 0; } diff --git a/test/core/end2end/connection_refused_test.cc b/test/core/end2end/connection_refused_test.cc index f3f2dda91d..ca6d17e7c8 100644 --- a/test/core/end2end/connection_refused_test.cc +++ b/test/core/end2end/connection_refused_test.cc @@ -133,9 +133,8 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_metadata_array_destroy(&trailing_metadata_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (args != nullptr) grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (args != nullptr) grpc_channel_args_destroy(args); } grpc_shutdown(); diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index fed8ead5c8..75c80aa1ff 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -75,9 +75,8 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); } } @@ -92,9 +91,8 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index ea8990fd0a..5b9181586c 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -66,9 +66,8 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast<fullstack_compression_fixture_data*>(f->fixture_data); if (ffd->client_args_compression != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->client_args_compression); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( client_args, GRPC_COMPRESS_GZIP); @@ -81,9 +80,8 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, fullstack_compression_fixture_data* ffd = static_cast<fullstack_compression_fixture_data*>(f->fixture_data); if (ffd->server_args_compression != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( server_args, GRPC_COMPRESS_GZIP); @@ -97,14 +95,13 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, } void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; fullstack_compression_fixture_data* ffd = static_cast<fullstack_compression_fixture_data*>(f->fixture_data); - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); + grpc_channel_args_destroy(ffd->client_args_compression); + grpc_channel_args_destroy(ffd->server_args_compression); gpr_free(ffd->localaddr); gpr_free(ffd); - grpc_exec_ctx_finish(&exec_ctx); } /* All test configurations */ diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index 97f4b71bf0..9157ab04d0 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -68,20 +68,18 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data); GPR_ASSERT(!f->client); f->client = grpc_insecure_channel_create_from_fd( "fixture_client", sfd->fd_pair[0], client_args); GPR_ASSERT(f->client); - - grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data); GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); @@ -90,8 +88,6 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_server_start(f->server); grpc_server_add_insecure_channel_from_fd(f->server, nullptr, sfd->fd_pair[1]); - - grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index 71a497d796..237841d185 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -72,7 +72,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; @@ -90,8 +90,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); - grpc_channel_args_destroy(&exec_ctx, server_args_new); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(server_args_new); } void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 7486b6af78..fda5f4b052 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -78,9 +78,8 @@ void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); diff --git a/test/core/end2end/fixtures/h2_oauth2.cc b/test/core/end2end/fixtures/h2_oauth2.cc index 1642cb0db9..5fed4434de 100644 --- a/test/core/end2end/fixtures/h2_oauth2.cc +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -143,11 +143,11 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr); grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - &exec_ctx, "authorization", oauth2_md, true /* is_async */); + "authorization", oauth2_md, true /* is_async */); grpc_channel_credentials* ssl_oauth2_creds = grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, nullptr); @@ -158,10 +158,9 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds); - grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_channel_args_destroy(new_client_args); grpc_channel_credentials_release(ssl_creds); grpc_call_credentials_release(oauth2_creds); - grpc_exec_ctx_finish(&exec_ctx); } static int fail_server_auth_check(grpc_channel_args* server_args) { diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 9319c401dc..9807e929af 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -50,12 +50,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -63,13 +62,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -90,34 +87,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { @@ -133,7 +126,6 @@ static grpc_end2end_test_config configs[] = { int main(int argc, char** argv) { size_t i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* force tracing on, with a value to force many code paths in trace.c to be taken */ @@ -147,7 +139,6 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); grpc_init(); - grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 03566aada2..b68279fd71 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -44,12 +44,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -57,13 +56,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -84,34 +81,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 9adba00204..350be138ca 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -44,12 +44,11 @@ static void server_setup_transport(void* ts, grpc_transport* transport) { grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, nullptr, + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -57,13 +56,11 @@ typedef struct { grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx* exec_ctx, void* ts, - grpc_transport* transport) { +static void client_setup_transport(void* ts, grpc_transport* transport) { sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( @@ -95,34 +92,30 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, true); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); grpc_transport* transport; GPR_ASSERT(!f->server); f->server = grpc_server_create(server_args, nullptr); grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, false); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index 3d7e2e327e..9a0680c40e 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -110,9 +110,8 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index f8d5a699e4..5ddbdefc8c 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -66,9 +66,8 @@ static grpc_channel* create_proxy_client(const char* target, grpc_secure_channel_create(ssl_creds, target, new_client_args, nullptr); grpc_channel_credentials_release(ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } return channel; } @@ -148,9 +147,8 @@ static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 0cec27bad7..137f7c9fa3 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -116,24 +116,21 @@ static void proxy_connection_ref(proxy_connection* conn, const char* reason) { } // Helper function to destroy the proxy connection. -static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, const char* reason) { +static void proxy_connection_unref(proxy_connection* conn, const char* reason) { if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); - grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); + grpc_endpoint_destroy(conn->client_endpoint); if (conn->server_endpoint != nullptr) { - grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); + grpc_endpoint_destroy(conn->server_endpoint); } - grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->client_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->server_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); + grpc_pollset_set_destroy(conn->pollset_set); + grpc_slice_buffer_destroy_internal(&conn->client_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); gpr_unref(&conn->proxy->users); @@ -150,8 +147,7 @@ enum failure_type { }; // Helper function to shut down the proxy connection. -static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, +static void proxy_connection_failed(proxy_connection* conn, failure_type failure, const char* prefix, grpc_error* error) { gpr_log(GPR_INFO, "%s: %s", prefix, grpc_error_string(error)); @@ -175,28 +171,25 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, } // If we decided to shut down either one and have not yet done so, do so. if (shutdown_client && !conn->client_shutdown) { - grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint, - GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(conn->client_endpoint, GRPC_ERROR_REF(error)); conn->client_shutdown = true; } if (shutdown_server && !conn->server_shutdown && (conn->server_endpoint != nullptr)) { - grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, - GRPC_ERROR_REF(error)); + grpc_endpoint_shutdown(conn->server_endpoint, GRPC_ERROR_REF(error)); conn->server_shutdown = true; } // Unref the connection. - proxy_connection_unref(exec_ctx, conn, "conn_failed"); + proxy_connection_unref(conn, "conn_failed"); GRPC_ERROR_UNREF(error); } // Callback for writing proxy data to the client. -static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, CLIENT_WRITE_FAILED, + proxy_connection_failed(conn, CLIENT_WRITE_FAILED, "HTTP proxy client write", GRPC_ERROR_REF(error)); return; } @@ -208,22 +201,20 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer, &conn->client_write_buffer); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "write_done"); + proxy_connection_unref(conn, "write_done"); } } // Callback for writing proxy data to the backend server. -static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->server_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SERVER_WRITE_FAILED, + proxy_connection_failed(conn, SERVER_WRITE_FAILED, "HTTP proxy server write", GRPC_ERROR_REF(error)); return; } @@ -235,23 +226,21 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer, &conn->server_write_buffer); conn->server_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "server_write"); + proxy_connection_unref(conn, "server_write"); } } // Callback for reading data from the client, which will be proxied to // the backend server. -static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, CLIENT_READ_FAILED, - "HTTP proxy client read", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, CLIENT_READ_FAILED, "HTTP proxy client read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., server_write_buffer is @@ -268,23 +257,21 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->server_write_buffer); proxy_connection_ref(conn, "client_read"); conn->server_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); } // Callback for reading data from the backend server, which will be // proxied to the client. -static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SERVER_READ_FAILED, - "HTTP proxy server read", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SERVER_READ_FAILED, "HTTP proxy server read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., client_write_buffer is @@ -301,23 +288,21 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->client_write_buffer); proxy_connection_ref(conn, "server_read"); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to write the HTTP response for the CONNECT request. -static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_write_response_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy write response", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy write response", + GRPC_ERROR_REF(error)); return; } // Clear write buffer. @@ -327,17 +312,16 @@ static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, // for the other one. proxy_connection_ref(conn, "client_read"); proxy_connection_ref(conn, "server_read"); - proxy_connection_unref(exec_ctx, conn, "write_response"); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + proxy_connection_unref(conn, "write_response"); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to connect to the backend server specified by the HTTP // CONNECT request. -static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_connect_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { // TODO(roth): Technically, in this case, we should handle the error @@ -345,8 +329,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, // connection failed. However, for the purposes of this test code, // it's fine to pretend this is a client-side error, which will // cause the client connection to be dropped. - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy server connect", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy server connect", + GRPC_ERROR_REF(error)); return; } // We've established a connection, so send back a 200 response code to @@ -356,8 +340,7 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n"); grpc_slice_buffer_add(&conn->client_write_buffer, slice); conn->client_is_writing = true; - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_write_response_done); } @@ -366,8 +349,7 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, * Basic <base64_encoded_expected_cred> * Returns true if it matches, false otherwise */ -static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, - char* proxy_auth_header_val, +static bool proxy_auth_header_matches(char* proxy_auth_header_val, char* expected_cred) { GPR_ASSERT(proxy_auth_header_val != nullptr); GPR_ASSERT(expected_cred != nullptr); @@ -375,11 +357,10 @@ static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, return false; } proxy_auth_header_val += 6; - grpc_slice decoded_slice = - grpc_base64_decode(exec_ctx, proxy_auth_header_val, 0); + grpc_slice decoded_slice = grpc_base64_decode(proxy_auth_header_val, 0); const bool header_matches = grpc_slice_str_cmp(decoded_slice, expected_cred) == 0; - grpc_slice_unref_internal(exec_ctx, decoded_slice); + grpc_slice_unref_internal(decoded_slice); return header_matches; } @@ -389,14 +370,13 @@ static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, // the client indicating that the request failed. However, for the purposes // of this test code, it's fine to pretend this is a client-side error, // which will cause the client connection to be dropped. -static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_read_request_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); return; } // Read request and feed it to the parser. @@ -405,8 +385,7 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, error = grpc_http_parser_parse( &conn->http_parser, conn->client_read_buffer.slices[i], nullptr); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy request parse", + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy request parse", GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; @@ -416,8 +395,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_reset_and_unref(&conn->client_read_buffer); // If we're not done reading the request, read more data. if (conn->http_parser.state != GRPC_HTTP_BODY) { - grpc_endpoint_read(exec_ctx, conn->client_endpoint, - &conn->client_read_buffer, &conn->on_read_request_done); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + &conn->on_read_request_done); return; } // Make sure we got a CONNECT request. @@ -427,8 +406,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, conn->http_request.method); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -440,16 +419,15 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, for (size_t i = 0; i < conn->http_request.hdr_count; i++) { if (strcmp(conn->http_request.hdrs[i].key, "Proxy-Authorization") == 0) { client_authenticated = proxy_auth_header_matches( - exec_ctx, conn->http_request.hdrs[i].value, - proxy_auth_arg->value.string); + conn->http_request.hdrs[i].value, proxy_auth_arg->value.string); break; } } if (!client_authenticated) { const char* msg = "HTTP Connect could not verify authentication"; error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(msg); - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy read request", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -459,8 +437,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, error = grpc_blocking_resolve_address(conn->http_request.path, "80", &resolved_addresses); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, SETUP_FAILED, - "HTTP proxy DNS lookup", GRPC_ERROR_REF(error)); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy DNS lookup", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -468,15 +446,15 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, // Connect to requested address. // The connection callback inherits our reference to conn. const grpc_millis deadline = - grpc_exec_ctx_now(exec_ctx) + 10 * GPR_MS_PER_SEC; - grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done, - &conn->server_endpoint, conn->pollset_set, nullptr, + grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; + grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, + conn->pollset_set, nullptr, &resolved_addresses->addrs[0], deadline); grpc_resolved_addresses_destroy(resolved_addresses); } -static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint, grpc_pollset* accepting_pollset, +static void on_accept(void* arg, grpc_endpoint* endpoint, + grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; @@ -487,8 +465,8 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); - grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); + grpc_pollset_set_add_pollset(conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(endpoint, conn->pollset_set); GRPC_CLOSURE_INIT(&conn->on_read_request_done, on_read_request_done, conn, grpc_combiner_scheduler(conn->proxy->combiner)); GRPC_CLOSURE_INIT(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -513,7 +491,7 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_init(&conn->server_write_buffer); grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST, &conn->http_request); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_read_request_done); } @@ -523,24 +501,23 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; do { gpr_ref(&proxy->users); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(proxy->mu); GRPC_LOG_IF_ERROR( "grpc_pollset_work", - grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC)); + grpc_pollset_work(proxy->pollset, &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } while (!gpr_unref(&proxy->users)); - grpc_exec_ctx_finish(&exec_ctx); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -552,8 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name); // Create TCP server. proxy->channel_args = grpc_channel_args_copy(args); - grpc_error* error = grpc_tcp_server_create( - &exec_ctx, nullptr, proxy->channel_args, &proxy->server); + grpc_error* error = + grpc_tcp_server_create(nullptr, proxy->channel_args, &proxy->server); GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; @@ -568,37 +545,35 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start server. proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(proxy->pollset, &proxy->mu); - grpc_tcp_server_start(&exec_ctx, proxy->server, &proxy->pollset, 1, on_accept, - proxy); - grpc_exec_ctx_finish(&exec_ctx); + 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, thread_main, proxy, &opt)); + GPR_ASSERT( + gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); return proxy; } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_pollset(void* arg, grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_thd_join(proxy->thd); - grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); - grpc_tcp_server_unref(&exec_ctx, proxy->server); + grpc_tcp_server_shutdown_listeners(proxy->server); + grpc_tcp_server_unref(proxy->server); gpr_free(proxy->proxy_name); - grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); - grpc_pollset_shutdown(&exec_ctx, proxy->pollset, + grpc_channel_args_destroy(proxy->channel_args); + grpc_pollset_shutdown(proxy->pollset, GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset, grpc_schedule_on_exec_ctx)); - GRPC_COMBINER_UNREF(&exec_ctx, proxy->combiner, "test"); + GRPC_COMBINER_UNREF(proxy->combiner, "test"); gpr_free(proxy); - grpc_exec_ctx_finish(&exec_ctx); } const char* grpc_end2end_http_proxy_get_proxy_name( diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index 2fab62b721..b1698c804c 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, "grpc_end2end_proxy", thread_main, proxy, &opt)); request_call(proxy); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 75117218e4..967a6d560f 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -376,8 +376,7 @@ typedef struct addr_req { grpc_lb_addresses** lb_addrs; } addr_req; -static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void finish_resolve(void* arg, grpc_error* error) { addr_req* r = static_cast<addr_req*>(arg); if (error == GRPC_ERROR_NONE && 0 == strcmp(r->addr, "server")) { @@ -395,9 +394,9 @@ static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, nullptr); *r->lb_addrs = lb_addrs; } - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_NONE); } else { - GRPC_CLOSURE_SCHED(exec_ctx, r->on_done, + GRPC_CLOSURE_SCHED(r->on_done, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Resolution failed", &error, 1)); } @@ -406,8 +405,7 @@ static void finish_resolve(grpc_exec_ctx* exec_ctx, void* arg, gpr_free(r); } -void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses) { @@ -417,22 +415,24 @@ void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, r->addrs = addresses; r->lb_addrs = nullptr; grpc_timer_init( - exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } -grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, - char** service_config_json) { +grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, + const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, + bool check_grpclb, + char** service_config_json) { addr_req* r = static_cast<addr_req*>(gpr_malloc(sizeof(*r))); r->addr = gpr_strdup(addr); r->on_done = on_done; r->addrs = nullptr; r->lb_addrs = lb_addrs; grpc_timer_init( - exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &r->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); return nullptr; } @@ -442,12 +442,12 @@ grpc_ares_request* my_dns_lookup_ares( // defined in tcp_client_posix.c extern void (*grpc_tcp_client_connect_impl)( - grpc_exec_ctx* exec_ctx, grpc_closure* closure, grpc_endpoint** ep, + grpc_closure* closure, grpc_endpoint** ep, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* addr, grpc_millis deadline); -static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_endpoint** ep, gpr_timespec deadline); +static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, + gpr_timespec deadline); typedef struct { grpc_timer timer; @@ -456,11 +456,11 @@ typedef struct { gpr_timespec deadline; } future_connect; -static void do_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void do_connect(void* arg, grpc_error* error) { future_connect* fc = static_cast<future_connect*>(arg); if (error != GRPC_ERROR_NONE) { *fc->ep = nullptr; - GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_REF(error)); + GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_REF(error)); } else if (g_server != nullptr) { grpc_endpoint* client; grpc_endpoint* server; @@ -468,25 +468,23 @@ static void do_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { *fc->ep = client; grpc_transport* transport = - grpc_create_chttp2_transport(exec_ctx, nullptr, server, false); - grpc_server_setup_transport(exec_ctx, g_server, transport, nullptr, - nullptr); - grpc_chttp2_transport_start_reading(exec_ctx, transport, nullptr, nullptr); + grpc_create_chttp2_transport(nullptr, server, false); + grpc_server_setup_transport(g_server, transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - GRPC_CLOSURE_SCHED(exec_ctx, fc->closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(fc->closure, GRPC_ERROR_NONE); } else { - sched_connect(exec_ctx, fc->closure, fc->ep, fc->deadline); + sched_connect(fc->closure, fc->ep, fc->deadline); } gpr_free(fc); } -static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, - grpc_endpoint** ep, gpr_timespec deadline) { +static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, + gpr_timespec deadline) { if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) { *ep = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, closure, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connect deadline exceeded")); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Connect deadline exceeded")); return; } @@ -495,17 +493,16 @@ static void sched_connect(grpc_exec_ctx* exec_ctx, grpc_closure* closure, fc->ep = ep; fc->deadline = deadline; grpc_timer_init( - exec_ctx, &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx), + &fc->timer, GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(), GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx)); } -static void my_tcp_client_connect(grpc_exec_ctx* exec_ctx, - grpc_closure* closure, grpc_endpoint** ep, +static void my_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, const grpc_resolved_address* addr, grpc_millis deadline) { - sched_connect(exec_ctx, closure, ep, + sched_connect(closure, ep, grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); } @@ -751,9 +748,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_init(); grpc_timer_manager_set_threading(false); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); } grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; @@ -846,9 +842,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_channel = grpc_insecure_channel_create(target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } gpr_free(target_uri); gpr_free(target); @@ -874,9 +869,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { g_server = grpc_server_create(args, nullptr); GPR_ASSERT(g_server != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } grpc_server_register_completion_queue(g_server, cq, nullptr); grpc_server_start(g_server); @@ -1205,9 +1199,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_secure_channel_create(creds, target_uri, args, nullptr); GPR_ASSERT(g_channel != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } gpr_free(target_uri); gpr_free(target); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index 5871f0f43e..c17d581d8b 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -43,112 +43,114 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("client_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_transport* transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, true); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); - - grpc_channel* channel = grpc_channel_create( - &exec_ctx, "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_slice host = grpc_slice_from_static_string("localhost"); - grpc_call* call = grpc_channel_create_call( - channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - - grpc_metadata_array initial_metadata_recv; - grpc_metadata_array_init(&initial_metadata_recv); - grpc_byte_buffer* response_payload_recv = nullptr; - grpc_metadata_array trailing_metadata_recv; - grpc_metadata_array_init(&trailing_metadata_recv); - grpc_status_code status; - grpc_slice details = grpc_empty_slice(); - - grpc_op ops[6]; - memset(ops, 0, sizeof(ops)); - grpc_op* op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &response_payload_recv; - op->flags = 0; - op->reserved = nullptr; - op++; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; - op->data.recv_status_on_client.status = &status; - op->data.recv_status_on_client.status_details = &details; - op->flags = 0; - op->reserved = nullptr; - op++; - grpc_call_error error = - grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); - int requested_calls = 1; - GPR_ASSERT(GRPC_CALL_OK == error); - - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); - - grpc_event ev; - while (1) { - grpc_exec_ctx_flush(&exec_ctx); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - requested_calls--; - break; + { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("client_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_transport* transport = + grpc_create_chttp2_transport(nullptr, mock_endpoint, true); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); + + grpc_channel* channel = grpc_channel_create( + "test-target", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, transport); + grpc_slice host = grpc_slice_from_static_string("localhost"); + grpc_call* call = grpc_channel_create_call( + channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); + + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array_init(&initial_metadata_recv); + grpc_byte_buffer* response_payload_recv = nullptr; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_status_code status; + grpc_slice details = grpc_empty_slice(); + + grpc_op ops[6]; + memset(ops, 0, sizeof(ops)); + grpc_op* op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &initial_metadata_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->flags = 0; + op->reserved = nullptr; + op++; + grpc_call_error error = + grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr); + int requested_calls = 1; + GPR_ASSERT(GRPC_CALL_OK == error); + + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); + + grpc_event ev; + while (1) { + grpc_core::ExecCtx::Get()->Flush(); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + requested_calls--; + break; + } } - } -done: - if (requested_calls) { - grpc_call_cancel(call, nullptr); - } - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i < requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); - } - grpc_call_unref(call); - grpc_completion_queue_destroy(cq); - grpc_metadata_array_destroy(&initial_metadata_recv); - grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); - grpc_channel_destroy(channel); - if (response_payload_recv != nullptr) { - grpc_byte_buffer_destroy(response_payload_recv); + done: + if (requested_calls) { + grpc_call_cancel(call, nullptr); + } + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i < requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + } + grpc_call_unref(call); + grpc_completion_queue_destroy(cq); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_slice_unref(details); + grpc_channel_destroy(channel); + if (response_payload_recv != nullptr) { + grpc_byte_buffer_destroy(response_payload_recv); + } } grpc_shutdown(); if (leak_check) { diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index 67caf4e720..61c55e0afd 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -41,81 +41,82 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_executor_set_threading(&exec_ctx, false); + { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); - grpc_server* server = grpc_server_create(nullptr, nullptr); - grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); - grpc_server_register_completion_queue(server, cq, nullptr); - // TODO(ctiller): add registered methods (one for POST, one for PUT) - // void *registered_method = - // grpc_server_register_method(server, "/reg", NULL, 0); - grpc_server_start(server); - grpc_transport* transport = - grpc_create_chttp2_transport(&exec_ctx, nullptr, mock_endpoint, false); - grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, nullptr); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr, nullptr); + grpc_server* server = grpc_server_create(nullptr, nullptr); + grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); + grpc_server_register_completion_queue(server, cq, nullptr); + // TODO(ctiller): add registered methods (one for POST, one for PUT) + // void *registered_method = + // grpc_server_register_method(server, "/reg", NULL, 0); + grpc_server_start(server); + grpc_transport* transport = + grpc_create_chttp2_transport(nullptr, mock_endpoint, false); + grpc_server_setup_transport(server, transport, nullptr, nullptr); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); - grpc_call* call1 = nullptr; - grpc_call_details call_details1; - grpc_metadata_array request_metadata1; - grpc_call_details_init(&call_details1); - grpc_metadata_array_init(&request_metadata1); - int requested_calls = 0; + grpc_call* call1 = nullptr; + grpc_call_details call_details1; + grpc_metadata_array request_metadata1; + grpc_call_details_init(&call_details1); + grpc_metadata_array_init(&request_metadata1); + int requested_calls = 0; - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(server, &call1, &call_details1, - &request_metadata1, cq, cq, tag(1))); - requested_calls++; + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(server, &call1, &call_details1, + &request_metadata1, cq, cq, tag(1))); + requested_calls++; - grpc_event ev; - while (1) { - grpc_exec_ctx_flush(&exec_ctx); - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - switch (ev.type) { - case GRPC_QUEUE_TIMEOUT: - goto done; - case GRPC_QUEUE_SHUTDOWN: - break; - case GRPC_OP_COMPLETE: - switch (detag(ev.tag)) { - case 1: - requested_calls--; - // TODO(ctiller): keep reading that call! - break; - } + grpc_event ev; + while (1) { + grpc_core::ExecCtx::Get()->Flush(); + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + switch (ev.type) { + case GRPC_QUEUE_TIMEOUT: + goto done; + case GRPC_QUEUE_SHUTDOWN: + break; + case GRPC_OP_COMPLETE: + switch (detag(ev.tag)) { + case 1: + requested_calls--; + // TODO(ctiller): keep reading that call! + break; + } + } } - } -done: - if (call1 != nullptr) grpc_call_unref(call1); - grpc_call_details_destroy(&call_details1); - grpc_metadata_array_destroy(&request_metadata1); - grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); - grpc_server_cancel_all_calls(server); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - } - grpc_completion_queue_shutdown(cq); - for (int i = 0; i <= requested_calls; i++) { - ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), - nullptr); - GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + done: + if (call1 != nullptr) grpc_call_unref(call1); + grpc_call_details_destroy(&call_details1); + grpc_metadata_array_destroy(&request_metadata1); + grpc_server_shutdown_and_notify(server, cq, tag(0xdead)); + grpc_server_cancel_all_calls(server); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + } + grpc_completion_queue_shutdown(cq); + for (int i = 0; i <= requested_calls; i++) { + ev = grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), + nullptr); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + } + grpc_server_destroy(server); + grpc_completion_queue_destroy(cq); } - grpc_server_destroy(server); - grpc_completion_queue_destroy(cq); grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 2d0db967c3..94cfbdda7e 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -39,16 +39,15 @@ static void* tag(intptr_t i) { return (void*)i; } static gpr_mu g_mu; static int g_resolve_port = -1; -static void (*iomgr_resolve_address)(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void (*iomgr_resolve_address)(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addresses); static grpc_ares_request* (*iomgr_dns_lookup_ares)( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** addresses, bool check_grpclb, char** service_config_json); static void set_resolve_port(int port) { @@ -57,14 +56,13 @@ static void set_resolve_port(int port) { gpr_mu_unlock(&g_mu); } -static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { if (0 != strcmp(addr, "test")) { - iomgr_resolve_address(exec_ctx, addr, default_port, interested_parties, - on_done, addrs); + iomgr_resolve_address(addr, default_port, interested_parties, on_done, + addrs); return; } @@ -86,16 +84,16 @@ static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - grpc_exec_ctx* exec_ctx, const char* dns_server, const char* addr, - const char* default_port, grpc_pollset_set* interested_parties, - grpc_closure* on_done, grpc_lb_addresses** lb_addrs, bool check_grpclb, + const char* dns_server, const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_lb_addresses** lb_addrs, bool check_grpclb, char** service_config_json) { if (0 != strcmp(addr, "test")) { - return iomgr_dns_lookup_ares(exec_ctx, dns_server, addr, default_port, + return iomgr_dns_lookup_ares(dns_server, addr, default_port, interested_parties, on_done, lb_addrs, check_grpclb, service_config_json); } @@ -117,7 +115,7 @@ static grpc_ares_request* my_dns_lookup_ares( gpr_free(sa); gpr_mu_unlock(&g_mu); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); return nullptr; } diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index 9a98c07158..d50d1f4d81 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -181,9 +181,8 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ { \ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; \ - grpc_channel_args_destroy(&exec_ctx, new_client_args); \ - grpc_exec_ctx_finish(&exec_ctx); \ + grpc_core::ExecCtx exec_ctx; \ + grpc_channel_args_destroy(new_client_args); \ } \ } diff --git a/test/core/end2end/tests/cancel_after_accept.cc b/test/core/end2end/tests/cancel_after_accept.cc index 83439d71d2..f59caf7e35 100644 --- a/test/core/end2end/tests/cancel_after_accept.cc +++ b/test/core/end2end/tests/cancel_after_accept.cc @@ -245,9 +245,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/cancel_after_round_trip.cc b/test/core/end2end/tests/cancel_after_round_trip.cc index ddcec67de5..b10b93978d 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.cc +++ b/test/core/end2end/tests/cancel_after_round_trip.cc @@ -278,9 +278,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_unref(s); if (args != nullptr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(args); } cq_verifier_destroy(cqv); diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index a8ea0ff2e0..944edc7a70 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -129,10 +129,9 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(&exec_ctx); + &server_args, algorithm_to_disable, false); } f = begin_test(config, test_name, client_args, server_args); @@ -257,10 +256,9 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); @@ -539,10 +537,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index 2ea4ca81f5..da65080bc0 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, "grpc_connectivity", child_thread, &ce, &thdopt)); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); diff --git a/test/core/end2end/tests/filter_call_init_fails.cc b/test/core/end2end/tests/filter_call_init_fails.cc index 6eed68a2f9..8f46f0bb91 100644 --- a/test/core/end2end/tests/filter_call_init_fails.cc +++ b/test/core/end2end/tests/filter_call_init_fails.cc @@ -399,26 +399,23 @@ static void test_client_subchannel_filter(grpc_end2end_test_config config) { * Test filter - always fails to initialize a call */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("access denied"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED); } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { grpc_call_next_op, @@ -437,8 +434,7 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_server_channel_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_server_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -457,8 +453,7 @@ static bool maybe_add_server_channel_filter(grpc_exec_ctx* exec_ctx, } } -static bool maybe_add_client_channel_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, +static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_channel_filter) { // Want to add the filter as close to the end as possible, to make @@ -478,7 +473,7 @@ static bool maybe_add_client_channel_filter(grpc_exec_ctx* exec_ctx, } static bool maybe_add_client_subchannel_filter( - grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_stack_builder* builder, void* arg) { if (g_enable_client_subchannel_filter) { // Want to add the filter as close to the end as possible, to make // sure that all of the filters work well together. However, we diff --git a/test/core/end2end/tests/filter_causes_close.cc b/test/core/end2end/tests/filter_causes_close.cc index 793f590686..ec8f9dbe00 100644 --- a/test/core/end2end/tests/filter_causes_close.cc +++ b/test/core/end2end/tests/filter_causes_close.cc @@ -197,12 +197,11 @@ typedef struct { uint8_t unused; } channel_data; -static void recv_im_ready(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void recv_im_ready(void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; GRPC_CLOSURE_RUN( - exec_ctx, calld->recv_im_ready, + calld->recv_im_ready, grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failure that's not preventable.", &error, 1), GRPC_ERROR_INT_GRPC_STATUS, @@ -210,8 +209,7 @@ static void recv_im_ready(grpc_exec_ctx* exec_ctx, void* arg, } static void start_transport_stream_op_batch( - grpc_exec_ctx* exec_ctx, grpc_call_element* elem, - grpc_transport_stream_op_batch* op) { + grpc_call_element* elem, grpc_transport_stream_op_batch* op) { call_data* calld = (call_data*)elem->call_data; if (op->recv_initial_metadata) { calld->recv_im_ready = @@ -219,27 +217,24 @@ static void start_transport_stream_op_batch( op->payload->recv_initial_metadata.recv_initial_metadata_ready = GRPC_CLOSURE_CREATE(recv_im_ready, elem, grpc_schedule_on_exec_ctx); } - grpc_call_next_op(exec_ctx, elem, op); + grpc_call_next_op(elem, op); } -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, +static void destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) {} -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_filter = { start_transport_stream_op_batch, @@ -258,8 +253,7 @@ static const grpc_channel_filter test_filter = { * Registration */ -static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { if (g_enable_filter) { return grpc_channel_stack_builder_prepend_filter(builder, &test_filter, nullptr, nullptr); diff --git a/test/core/end2end/tests/filter_latency.cc b/test/core/end2end/tests/filter_latency.cc index c4d96ebfe2..845cbc01cf 100644 --- a/test/core/end2end/tests/filter_latency.cc +++ b/test/core/end2end/tests/filter_latency.cc @@ -247,14 +247,12 @@ static void test_request(grpc_end2end_test_config config) { * Test latency filter */ -static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static grpc_error* init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void client_destroy_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void client_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -262,8 +260,7 @@ static void client_destroy_call_elem(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&g_mu); } -static void server_destroy_call_elem(grpc_exec_ctx* exec_ctx, - grpc_call_element* elem, +static void server_destroy_call_elem(grpc_call_element* elem, const grpc_call_final_info* final_info, grpc_closure* ignored) { gpr_mu_lock(&g_mu); @@ -271,14 +268,12 @@ static void server_destroy_call_elem(grpc_exec_ctx* exec_ctx, gpr_mu_unlock(&g_mu); } -static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem, +static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, - grpc_channel_element* elem) {} +static void destroy_channel_elem(grpc_channel_element* elem) {} static const grpc_channel_filter test_client_filter = { grpc_call_next_op, @@ -310,8 +305,7 @@ static const grpc_channel_filter test_server_filter = { * Registration */ -static bool maybe_add_filter(grpc_exec_ctx* exec_ctx, - grpc_channel_stack_builder* builder, void* arg) { +static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { grpc_channel_filter* filter = (grpc_channel_filter*)arg; if (g_enable_filter) { // Want to add the filter as close to the end as possible, to make diff --git a/test/core/end2end/tests/load_reporting_hook.cc b/test/core/end2end/tests/load_reporting_hook.cc index faabec34cb..e056bd547b 100644 --- a/test/core/end2end/tests/load_reporting_hook.cc +++ b/test/core/end2end/tests/load_reporting_hook.cc @@ -300,9 +300,8 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { &trailing_lr_metadata); end_test(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, lr_server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(lr_server_args); } config.tear_down_data(&f); } diff --git a/test/core/end2end/tests/max_message_length.cc b/test/core/end2end/tests/max_message_length.cc index f1ac27fa7c..e581f1fc20 100644 --- a/test/core/end2end/tests/max_message_length.cc +++ b/test/core/end2end/tests/max_message_length.cc @@ -173,12 +173,9 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, f = begin_test(config, "test_max_request_message_length", client_args, server_args); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (client_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, client_args); - if (server_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (client_args != nullptr) grpc_channel_args_destroy(client_args); + if (server_args != nullptr) grpc_channel_args_destroy(server_args); } cqv = cq_verifier_create(f.cq); @@ -366,12 +363,9 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, f = begin_test(config, "test_max_response_message_length", client_args, server_args); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (client_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, client_args); - if (server_args != nullptr) - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + if (client_args != nullptr) grpc_channel_args_destroy(client_args); + if (server_args != nullptr) grpc_channel_args_destroy(server_args); } cqv = cq_verifier_create(f.cq); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index d73346468a..ec3050ad45 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -129,10 +129,9 @@ static void request_for_disabled_algorithm( server_args = grpc_channel_args_set_stream_compression_algorithm( nullptr, GRPC_STREAM_COMPRESS_NONE); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_stream_compression_algorithm_set_state( - &exec_ctx, &server_args, algorithm_to_disable, false); - grpc_exec_ctx_finish(&exec_ctx); + &server_args, algorithm_to_disable, false); } f = begin_test(config, test_name, client_args, server_args); @@ -258,10 +257,9 @@ static void request_for_disabled_algorithm( grpc_byte_buffer_destroy(request_payload_recv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); @@ -547,10 +545,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 924961ea55..b95e6528cd 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -277,10 +277,9 @@ static void test_invoke_request_response_with_payload( end_test(&f); config.tear_down_data(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } } diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index d3b526f04e..2a8799ee67 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -275,10 +275,9 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, end_test(&f); config.tear_down_data(&f); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } } diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index bc4d5079d8..d4decce0aa 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -142,15 +142,14 @@ static void request_with_payload_template( nullptr, default_server_channel_compression_algorithm); if (user_agent_override) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* client_args_old = client_args; grpc_arg arg; arg.key = const_cast<char*>(GRPC_ARG_PRIMARY_USER_AGENT_STRING); arg.type = GRPC_ARG_STRING; arg.value.string = user_agent_override; client_args = grpc_channel_args_copy_and_add(client_args_old, &arg, 1); - grpc_channel_args_destroy(&exec_ctx, client_args_old); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(client_args_old); } f = begin_test(config, test_name, client_args, server_args); @@ -351,10 +350,9 @@ static void request_with_payload_template( cq_verifier_destroy(cqv); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); } end_test(&f); diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 2b149a73b3..2302e3da2f 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, "grpc_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/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 2810082837..599e0e16e2 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -49,41 +49,37 @@ * to the security_handshaker). This test is meant to protect code relying on * this functionality that lives outside of this repo. */ -static void readahead_handshaker_destroy(grpc_exec_ctx* ctx, - grpc_handshaker* handshaker) { +static void readahead_handshaker_destroy(grpc_handshaker* handshaker) { gpr_free(handshaker); } -static void readahead_handshaker_shutdown(grpc_exec_ctx* ctx, - grpc_handshaker* handshaker, +static void readahead_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* error) {} static void readahead_handshaker_do_handshake( - grpc_exec_ctx* ctx, grpc_handshaker* handshaker, - grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, - grpc_handshaker_args* args) { - grpc_endpoint_read(ctx, args->endpoint, args->read_buffer, on_handshake_done); + grpc_handshaker* handshaker, grpc_tcp_server_acceptor* acceptor, + grpc_closure* on_handshake_done, grpc_handshaker_args* args) { + grpc_endpoint_read(args->endpoint, args->read_buffer, on_handshake_done); } const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_destroy, readahead_handshaker_shutdown, readahead_handshaker_do_handshake}; -static grpc_handshaker* readahead_handshaker_create(grpc_exec_ctx* ctx) { +static grpc_handshaker* readahead_handshaker_create() { grpc_handshaker* h = (grpc_handshaker*)gpr_zalloc(sizeof(grpc_handshaker)); grpc_handshaker_init(&readahead_handshaker_vtable, h); return h; } static void readahead_handshaker_factory_add_handshakers( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* hf, - const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { - grpc_handshake_manager_add(handshake_mgr, - readahead_handshaker_create(exec_ctx)); + grpc_handshaker_factory* hf, const grpc_channel_args* args, + grpc_handshake_manager* handshake_mgr) { + grpc_handshake_manager_add(handshake_mgr, readahead_handshaker_create()); } static void readahead_handshaker_factory_destroy( - grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) {} + grpc_handshaker_factory* handshaker_factory) {} static const grpc_handshaker_factory_vtable readahead_handshaker_factory_vtable = { diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 599b2814e0..0bf453a204 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, "grpc_ssl_test", server_thread, &port, &thdopt)); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); diff --git a/test/core/http/format_request_test.cc b/test/core/http/format_request_test.cc index 684738a997..353e138b2a 100644 --- a/test/core/http/format_request_test.cc +++ b/test/core/http/format_request_test.cc @@ -139,11 +139,13 @@ static void test_format_post_request_content_type_override(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_format_get_request(); test_format_post_request(); test_format_post_request_no_body(); test_format_post_request_content_type_override(); + grpc_shutdown(); return 0; } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index 81e9374819..259e3aa463 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_finish(void* arg, grpc_error* error) { const char* expect = "<html><head><title>Hello world!</title></head>" "<body><p>This is a test</p></body></html>"; @@ -53,15 +53,14 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), - nullptr))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -78,19 +77,18 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -101,7 +99,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -118,20 +116,18 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, - n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -139,69 +135,69 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { - grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( - static_cast<grpc_polling_entity*>(p))); +static void destroy_pops(void* p, grpc_error* error) { + grpc_pollset_destroy( + grpc_polling_entity_pollset(static_cast<grpc_polling_entity*>(p))); } int main(int argc, char** argv) { - grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; - char* me = argv[0]; - char* lslash = strrchr(me, '/'); - char* args[4]; - int port = grpc_pick_unused_port_or_die(); - int arg_shift = 0; - /* figure out where we are */ - char* root; - if (lslash) { - root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1))); - memcpy(root, me, (size_t)(lslash - me)); - root[lslash - me] = 0; - } else { - root = gpr_strdup("."); - } - - GPR_ASSERT(argc <= 2); - if (argc == 2) { - args[0] = gpr_strdup(argv[1]); - } else { - arg_shift = 1; - gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); - gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); - } - - /* start the server */ - args[1 + arg_shift] = const_cast<char*>("--port"); - gpr_asprintf(&args[2 + arg_shift], "%d", port); - server = gpr_subprocess_create(3 + arg_shift, (const char**)args); - GPR_ASSERT(server); - gpr_free(args[0]); - if (arg_shift) gpr_free(args[1]); - gpr_free(args[2 + arg_shift]); - gpr_free(root); - - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(5, GPR_TIMESPAN))); - grpc_test_init(argc, argv); grpc_init(); - grpc_httpcli_context_init(&g_context); - grpc_pollset* pollset = - static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollset, &g_mu); - g_pops = grpc_polling_entity_create_from_pollset(pollset); - - test_get(port); - test_post(port); - - grpc_httpcli_context_destroy(&exec_ctx, &g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_closure destroyed; + grpc_core::ExecCtx exec_ctx; + char* me = argv[0]; + char* lslash = strrchr(me, '/'); + char* args[4]; + int port = grpc_pick_unused_port_or_die(); + int arg_shift = 0; + /* figure out where we are */ + char* root; + if (lslash) { + root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1))); + memcpy(root, me, (size_t)(lslash - me)); + root[lslash - me] = 0; + } else { + root = gpr_strdup("."); + } + + GPR_ASSERT(argc <= 2); + if (argc == 2) { + args[0] = gpr_strdup(argv[1]); + } else { + arg_shift = 1; + gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); + gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); + } + + /* start the server */ + args[1 + arg_shift] = const_cast<char*>("--port"); + gpr_asprintf(&args[2 + arg_shift], "%d", port); + server = gpr_subprocess_create(3 + arg_shift, (const char**)args); + GPR_ASSERT(server); + gpr_free(args[0]); + if (arg_shift) gpr_free(args[1]); + gpr_free(args[2 + arg_shift]); + gpr_free(root); + + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); + + grpc_httpcli_context_init(&g_context); + grpc_pollset* pollset = + static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(pollset, &g_mu); + g_pops = grpc_polling_entity_create_from_pollset(pollset); + + test_get(port); + test_post(port); + + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index da8405c049..adf69f1b16 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -40,7 +40,7 @@ static grpc_millis n_seconds_time(int seconds) { grpc_timeout_seconds_to_deadline(seconds)); } -static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void on_finish(void* arg, grpc_error* error) { const char* expect = "<html><head><title>Hello world!</title></head>" "<body><p>This is a test</p></body></html>"; @@ -53,15 +53,14 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { g_done = 1; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), - nullptr))); + grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), nullptr))); gpr_mu_unlock(g_mu); } static void test_get(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_get"); @@ -79,19 +78,18 @@ static void test_get(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_get"); grpc_httpcli_get( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -102,7 +100,7 @@ static void test_get(int port) { static void test_post(int port) { grpc_httpcli_request req; char* host; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; g_done = 0; gpr_log(GPR_INFO, "test_post"); @@ -120,20 +118,18 @@ static void test_post(int port) { memset(&response, 0, sizeof(response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("test_post"); grpc_httpcli_post( - &exec_ctx, &g_context, &g_pops, resource_quota, &req, "hello", 5, - n_seconds_time(15), + &g_context, &g_pops, resource_quota, &req, "hello", 5, n_seconds_time(15), GRPC_CLOSURE_CREATE(on_finish, &response, grpc_schedule_on_exec_ctx), &response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); gpr_mu_lock(g_mu); while (!g_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &worker, n_seconds_time(1)))); + "pollset_work", grpc_pollset_work(grpc_polling_entity_pollset(&g_pops), + &worker, n_seconds_time(1)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -141,14 +137,13 @@ static void test_post(int port) { grpc_http_response_destroy(&response); } -static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) { - grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset( - static_cast<grpc_polling_entity*>(p))); +static void destroy_pops(void* p, grpc_error* error) { + grpc_pollset_destroy( + grpc_polling_entity_pollset(static_cast<grpc_polling_entity*>(p))); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_subprocess* server; char* me = argv[0]; char* lslash = strrchr(me, '/'); @@ -199,12 +194,13 @@ int main(int argc, char** argv) { test_get(port); test_post(port); - grpc_httpcli_context_destroy(&exec_ctx, &g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&g_pops), - &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/parser_test.cc b/test/core/http/parser_test.cc index 0b60e369b7..18f19856bd 100644 --- a/test/core/http/parser_test.cc +++ b/test/core/http/parser_test.cc @@ -21,6 +21,7 @@ #include <stdarg.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> @@ -217,6 +218,7 @@ int main(int argc, char** argv) { char *tmp1, *tmp2; grpc_test_init(argc, argv); + grpc_init(); for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) { test_succeeds(split_modes[i], @@ -300,5 +302,6 @@ int main(int argc, char** argv) { gpr_free(tmp2); } + grpc_shutdown(); return 0; } diff --git a/test/core/http/request_fuzzer.cc b/test/core/http/request_fuzzer.cc index 368ac1b49d..9798cfb33c 100644 --- a/test/core/http/request_fuzzer.cc +++ b/test/core/http/request_fuzzer.cc @@ -20,6 +20,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/lib/http/parser.h" @@ -30,6 +31,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_request request; + grpc_init(); memset(&request, 0, sizeof(request)); grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -38,5 +40,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_request_destroy(&request); + grpc_shutdown(); return 0; } diff --git a/test/core/http/response_fuzzer.cc b/test/core/http/response_fuzzer.cc index 2a793fddd4..fc0904b1db 100644 --- a/test/core/http/response_fuzzer.cc +++ b/test/core/http/response_fuzzer.cc @@ -19,6 +19,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/lib/http/parser.h" @@ -29,6 +30,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_http_parser parser; grpc_http_response response; + grpc_init(); memset(&response, 0, sizeof(response)); grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); @@ -37,5 +39,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(slice); grpc_http_parser_destroy(&parser); grpc_http_response_destroy(&response); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 146a6bd553..891008c774 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -28,13 +28,11 @@ static void test_no_op(void) { gpr_log(GPR_DEBUG, "test_no_op"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, grpc_combiner_create(), "test_no_op"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(grpc_combiner_create(), "test_no_op"); } -static void set_event_to_true(grpc_exec_ctx* exec_ctx, void* value, - grpc_error* error) { +static void set_event_to_true(void* value, grpc_error* error) { gpr_event_set(static_cast<gpr_event*>(value), (void*)1); } @@ -44,16 +42,14 @@ static void test_execute_one(void) { grpc_combiner* lock = grpc_combiner_create(); gpr_event done; gpr_event_init(&done); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE(set_event_to_true, &done, + grpc_core::ExecCtx exec_ctx; + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &done, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_one"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(lock, "test_execute_one"); } typedef struct { @@ -67,7 +63,7 @@ typedef struct { size_t value; } ex_args; -static void check_one(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void check_one(void* a, grpc_error* error) { ex_args* args = static_cast<ex_args*>(a); GPR_ASSERT(*args->ctr == args->value - 1); *args->ctr = args->value; @@ -76,28 +72,25 @@ static void check_one(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { static void execute_many_loop(void* a) { thd_args* args = static_cast<thd_args*>(a); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; size_t n = 1; for (size_t i = 0; i < 10; i++) { for (size_t j = 0; j < 10000; j++) { ex_args* c = static_cast<ex_args*>(gpr_malloc(sizeof(*c))); c->ctr = &args->ctr; c->value = n++; - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE( + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE( check_one, c, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } // sleep for a little bit, to test a combiner draining and another thread // picking it up gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); } - GRPC_CLOSURE_SCHED(&exec_ctx, - GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(set_event_to_true, &args->done, grpc_combiner_scheduler(args->lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); } static void test_execute_many(void) { @@ -112,27 +105,26 @@ 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], "grpc_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, gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr); gpr_thd_join(thds[i]); } - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_many"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_COMBINER_UNREF(lock, "test_execute_many"); } static gpr_event got_in_finally; -static void in_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void in_finally(void* arg, grpc_error* error) { gpr_event_set(&got_in_finally, (void*)1); } -static void add_finally(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { - GRPC_CLOSURE_SCHED(exec_ctx, - GRPC_CLOSURE_CREATE(in_finally, arg, +static void add_finally(void* arg, grpc_error* error) { + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(in_finally, arg, grpc_combiner_finally_scheduler( static_cast<grpc_combiner*>(arg))), GRPC_ERROR_NONE); @@ -142,17 +134,15 @@ static void test_execute_finally(void) { gpr_log(GPR_DEBUG, "test_execute_finally"); grpc_combiner* lock = grpc_combiner_create(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_event_init(&got_in_finally); GRPC_CLOSURE_SCHED( - &exec_ctx, GRPC_CLOSURE_CREATE(add_finally, lock, grpc_combiner_scheduler(lock)), GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&got_in_finally, grpc_timeout_seconds_to_deadline(5)) != nullptr); - GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_finally"); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_COMBINER_UNREF(lock, "test_execute_finally"); } int main(int argc, char** argv) { diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 30a0cb5924..90dd40d9c4 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -32,7 +32,7 @@ static void clean_up(void) {} static grpc_endpoint_test_fixture create_fixture_endpoint_pair( size_t slice_size) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_endpoint_test_fixture f; grpc_arg a[1]; a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE); @@ -43,9 +43,8 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( f.client_ep = p.client; f.server_ep = p.server; - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); return f; } @@ -54,23 +53,23 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 026e34105d..8ccae52067 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -115,8 +115,7 @@ struct read_and_write_test_state { grpc_closure done_write; }; -static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx, - void* data, grpc_error* error) { +static void read_and_write_test_read_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; @@ -126,17 +125,14 @@ static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx, gpr_log(GPR_INFO, "Read handler done"); gpr_mu_lock(g_mu); state->read_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); gpr_mu_unlock(g_mu); } else if (error == GRPC_ERROR_NONE) { - grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, - &state->done_read); + grpc_endpoint_read(state->read_ep, &state->incoming, &state->done_read); } } -static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, - void* data, grpc_error* error) { +static void read_and_write_test_write_handler(void* data, grpc_error* error) { struct read_and_write_test_state* state = (struct read_and_write_test_state*)data; grpc_slice* slices = nullptr; @@ -153,7 +149,7 @@ static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, &state->current_write_data); grpc_slice_buffer_reset_and_unref(&state->outgoing); grpc_slice_buffer_addn(&state->outgoing, slices, nslices); - grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing, + grpc_endpoint_write(state->write_ep, &state->outgoing, &state->done_write); gpr_free(slices); return; @@ -163,8 +159,7 @@ static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx, gpr_log(GPR_INFO, "Write handler done"); gpr_mu_lock(g_mu); state->write_done = 1 + (error == GRPC_ERROR_NONE); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr)); gpr_mu_unlock(g_mu); } @@ -178,7 +173,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, struct read_and_write_test_state state; grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, @@ -217,66 +212,57 @@ static void read_and_write_test(grpc_endpoint_test_config config, for the first iteration as for later iterations. It does the right thing even when bytes_written is unsigned. */ state.bytes_written -= state.current_write_size; - read_and_write_test_write_handler(&exec_ctx, &state, GRPC_ERROR_NONE); - grpc_exec_ctx_flush(&exec_ctx); + read_and_write_test_write_handler(&state, GRPC_ERROR_NONE); + grpc_core::ExecCtx::Get()->Flush(); - grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming, - &state.done_read); + grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read); if (shutdown) { gpr_log(GPR_DEBUG, "shutdown read"); grpc_endpoint_shutdown( - &exec_ctx, state.read_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + state.read_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); gpr_log(GPR_DEBUG, "shutdown write"); grpc_endpoint_shutdown( - &exec_ctx, state.write_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = nullptr; - GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline); + GPR_ASSERT(grpc_core::ExecCtx::Get()->Now() < deadline); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); end_test(config); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.outgoing); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, state.read_ep); - grpc_endpoint_destroy(&exec_ctx, state.write_ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.outgoing); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(state.read_ep); + grpc_endpoint_destroy(state.write_ep); } -static void inc_on_failure(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void inc_on_failure(void* arg, grpc_error* error) { gpr_mu_lock(g_mu); *(int*)arg += (error != GRPC_ERROR_NONE); - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void wait_for_fail_count(grpc_exec_ctx* exec_ctx, int* fail_count, - int want_fail_count) { - grpc_exec_ctx_flush(exec_ctx); +static void wait_for_fail_count(int* fail_count, int want_fail_count) { + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); - while (grpc_exec_ctx_now(exec_ctx) < deadline && + while (grpc_core::ExecCtx::Get()->Now() < deadline && *fail_count < want_fail_count) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(*fail_count == want_fail_count); @@ -291,33 +277,32 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) { grpc_slice_buffer slice_buffer; grpc_slice_buffer_init(&slice_buffer); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 0); - grpc_endpoint_shutdown(&exec_ctx, f.client_ep, + wait_for_fail_count(&fail_count, 0); + grpc_endpoint_shutdown(f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&exec_ctx, &fail_count, 1); - grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer, + wait_for_fail_count(&fail_count, 1); + grpc_endpoint_read(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 2); + wait_for_fail_count(&fail_count, 2); grpc_slice_buffer_add(&slice_buffer, grpc_slice_from_copied_string("a")); - grpc_endpoint_write(&exec_ctx, f.client_ep, &slice_buffer, + grpc_endpoint_write(f.client_ep, &slice_buffer, GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count, grpc_schedule_on_exec_ctx)); - wait_for_fail_count(&exec_ctx, &fail_count, 3); - grpc_endpoint_shutdown(&exec_ctx, f.client_ep, + wait_for_fail_count(&fail_count, 3); + grpc_endpoint_shutdown(f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - wait_for_fail_count(&exec_ctx, &fail_count, 3); + wait_for_fail_count(&fail_count, 3); - grpc_slice_buffer_destroy_internal(&exec_ctx, &slice_buffer); + grpc_slice_buffer_destroy_internal(&slice_buffer); - grpc_endpoint_destroy(&exec_ctx, f.client_ep); - grpc_endpoint_destroy(&exec_ctx, f.server_ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_destroy(f.client_ep); + grpc_endpoint_destroy(f.server_ep); } void grpc_endpoint_tests(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index ac8b2f43d1..e767e01f21 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -70,19 +70,18 @@ static void test_fd_init(test_fd* tfds, int* fds, int num_fds) { } } -static void test_fd_cleanup(grpc_exec_ctx* exec_ctx, test_fd* tfds, - int num_fds) { +static void test_fd_cleanup(test_fd* tfds, int num_fds) { int release_fd; int i; for (i = 0; i < num_fds; i++) { - grpc_fd_shutdown(exec_ctx, tfds[i].fd, + grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup")); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, - false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(exec_ctx); + grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, + "test_fd_cleanup"); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(release_fd == tfds[i].inner_fd); close(tfds[i].inner_fd); @@ -98,22 +97,20 @@ static void test_pollset_init(test_pollset* pollsets, int num_pollsets) { } } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } -static void test_pollset_cleanup(grpc_exec_ctx* exec_ctx, - test_pollset* pollsets, int num_pollsets) { +static void test_pollset_cleanup(test_pollset* pollsets, int num_pollsets) { grpc_closure destroyed; int i; for (i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, pollsets[i].pollset, &destroyed); + grpc_pollset_shutdown(pollsets[i].pollset, &destroyed); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].pollset); } } @@ -133,7 +130,7 @@ static void test_pollset_cleanup(grpc_exec_ctx* exec_ctx, #define NUM_POLLSETS 4 static void test_add_fd_to_pollset() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; test_fd tfds[NUM_FDS]; int fds[NUM_FDS]; test_pollset pollsets[NUM_POLLSETS]; @@ -170,33 +167,33 @@ static void test_add_fd_to_pollset() { /* == Step 1 == */ for (i = 0; i <= 2; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[0].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 3; i <= 4; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[1].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } for (i = 5; i <= 7; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[2].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 2 == */ for (i = 0; i <= 1; i++) { - grpc_pollset_add_fd(&exec_ctx, pollsets[3].pollset, tfds[i].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[3].pollset, tfds[i].fd); + grpc_core::ExecCtx::Get()->Flush(); } /* == Step 3 == */ - grpc_pollset_add_fd(&exec_ctx, pollsets[1].pollset, tfds[0].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[1].pollset, tfds[0].fd); + grpc_core::ExecCtx::Get()->Flush(); /* == Step 4 == */ - grpc_pollset_add_fd(&exec_ctx, pollsets[2].pollset, tfds[3].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_pollset_add_fd(pollsets[2].pollset, tfds[3].fd); + grpc_core::ExecCtx::Get()->Flush(); /* All polling islands are merged at this point */ @@ -213,9 +210,8 @@ static void test_add_fd_to_pollset() { expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); } - test_fd_cleanup(&exec_ctx, tfds, NUM_FDS); - test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS); - grpc_exec_ctx_finish(&exec_ctx); + test_fd_cleanup(tfds, NUM_FDS); + test_pollset_cleanup(pollsets, NUM_POLLSETS); } #undef NUM_FDS @@ -235,26 +231,24 @@ static __thread int thread_wakeups = 0; static void test_threading_loop(void* arg) { threading_shared* shared = static_cast<threading_shared*>(arg); while (thread_wakeups < 1000000) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; gpr_mu_lock(shared->mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, shared->pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(shared->pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(shared->mu); - grpc_exec_ctx_finish(&exec_ctx); } } -static void test_threading_wakeup(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void test_threading_wakeup(void* arg, grpc_error* error) { threading_shared* shared = static_cast<threading_shared*>(arg); ++shared->wakeups; ++thread_wakeups; if (error == GRPC_ERROR_NONE) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "consume_wakeup", grpc_wakeup_fd_consume_wakeup(shared->wakeup_fd))); - grpc_fd_notify_on_read(exec_ctx, shared->wakeup_desc, &shared->on_wakeup); + grpc_fd_notify_on_read(shared->wakeup_desc, &shared->on_wakeup); GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_next", grpc_wakeup_fd_wakeup(shared->wakeup_fd))); } @@ -269,7 +263,7 @@ static void test_threading(void) { 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_threading_loop, &shared, &opt); + gpr_thd_new(&thds[i], "test_thread", test_threading_loop, &shared, &opt); } grpc_wakeup_fd fd; GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&fd))); @@ -277,13 +271,12 @@ static void test_threading(void) { shared.wakeup_desc = grpc_fd_create(fd.read_fd, "wakeup"); shared.wakeups = 0; { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_add_fd(&exec_ctx, shared.pollset, shared.wakeup_desc); + grpc_core::ExecCtx exec_ctx; + grpc_pollset_add_fd(shared.pollset, shared.wakeup_desc); grpc_fd_notify_on_read( - &exec_ctx, shared.wakeup_desc, + shared.wakeup_desc, GRPC_CLOSURE_INIT(&shared.on_wakeup, test_threading_wakeup, &shared, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", grpc_wakeup_fd_wakeup(shared.wakeup_fd))); @@ -293,14 +286,13 @@ static void test_threading(void) { fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_fd_shutdown(&exec_ctx, shared.wakeup_desc, GRPC_ERROR_CANCELLED); - grpc_fd_orphan(&exec_ctx, shared.wakeup_desc, nullptr, nullptr, + grpc_core::ExecCtx exec_ctx; + grpc_fd_shutdown(shared.wakeup_desc, GRPC_ERROR_CANCELLED); + grpc_fd_orphan(shared.wakeup_desc, nullptr, nullptr, false /* already_closed */, "done"); - grpc_pollset_shutdown(&exec_ctx, shared.pollset, + grpc_pollset_shutdown(shared.pollset, GRPC_CLOSURE_CREATE(destroy_pollset, shared.pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } gpr_free(shared.pollset); } @@ -309,20 +301,21 @@ int main(int argc, char** argv) { const char* poll_strategy = nullptr; grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - poll_strategy = grpc_get_poll_strategy_name(); - if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { - test_add_fd_to_pollset(); - test_threading(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epollsig' " - "strategy. and the current strategy is: '%s'", - poll_strategy); + { + grpc_core::ExecCtx exec_ctx; + + poll_strategy = grpc_get_poll_strategy_name(); + if (poll_strategy != nullptr && strcmp(poll_strategy, "epollsig") == 0) { + test_add_fd_to_pollset(); + test_threading(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epollsig' " + "strategy. and the current strategy is: '%s'", + poll_strategy); + } } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index f46430c611..aaa14010f8 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -31,26 +31,27 @@ int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - /* set max # of file descriptors to a low value, and - verify we can create and destroy many more than this number - of descriptors */ - rlim.rlim_cur = rlim.rlim_max = 10; - GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("fd_conservation_posix_test"); - - for (i = 0; i < 100; i++) { - p = grpc_iomgr_create_endpoint_pair("test", nullptr); - grpc_endpoint_destroy(&exec_ctx, p.client); - grpc_endpoint_destroy(&exec_ctx, p.server); - grpc_exec_ctx_flush(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + + /* set max # of file descriptors to a low value, and + verify we can create and destroy many more than this number + of descriptors */ + rlim.rlim_cur = rlim.rlim_max = 10; + GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("fd_conservation_posix_test"); + + for (i = 0; i < 100; i++) { + p = grpc_iomgr_create_endpoint_pair("test", NULL); + grpc_endpoint_destroy(p.client); + grpc_endpoint_destroy(p.server); + grpc_core::ExecCtx::Get()->Flush(); + } + + grpc_resource_quota_unref(resource_quota); } - grpc_resource_quota_unref(resource_quota); - - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index a03d841ecd..cf75517538 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -111,20 +111,19 @@ typedef struct { /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ -static void session_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ +static void session_shutdown_cb(void* arg, /*session */ bool success) { session* se = static_cast<session*>(arg); server* sv = se->sv; - grpc_fd_orphan(exec_ctx, se->em_fd, nullptr, nullptr, - false /* already_closed */, "a"); + grpc_fd_orphan(se->em_fd, nullptr, nullptr, false /* already_closed */, "a"); gpr_free(se); /* Start to shutdown listen fd. */ - grpc_fd_shutdown(exec_ctx, sv->em_fd, + grpc_fd_shutdown(sv->em_fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("session_shutdown_cb")); } /* Called when data become readable in a session. */ -static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ +static void session_read_cb(void* arg, /*session */ grpc_error* error) { session* se = static_cast<session*>(arg); int fd = grpc_fd_wrapped_fd(se->em_fd); @@ -133,7 +132,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ ssize_t read_total = 0; if (error != GRPC_ERROR_NONE) { - session_shutdown_cb(exec_ctx, arg, 1); + session_shutdown_cb(arg, 1); return; } @@ -148,7 +147,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ It is possible to read nothing due to spurious edge event or data has been drained, In such a case, read() returns -1 and set errno to EAGAIN. */ if (read_once == 0) { - session_shutdown_cb(exec_ctx, arg, 1); + session_shutdown_cb(arg, 1); } else if (read_once == -1) { if (errno == EAGAIN) { /* An edge triggered event is cached in the kernel until next poll. @@ -159,7 +158,7 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ TODO(chenw): in multi-threaded version, callback and polling can be run in different threads. polling may catch a persist read edge event before notify_on_read is called. */ - grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); } else { gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); abort(); @@ -169,22 +168,20 @@ static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ /* Called when the listen FD can be safely shutdown. Close listen FD and signal that server can be shutdown. */ -static void listen_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg /*server */, - int success) { +static void listen_shutdown_cb(void* arg /*server */, int success) { server* sv = static_cast<server*>(arg); - grpc_fd_orphan(exec_ctx, sv->em_fd, nullptr, nullptr, - false /* already_closed */, "b"); + grpc_fd_orphan(sv->em_fd, nullptr, nullptr, false /* already_closed */, "b"); gpr_mu_lock(g_mu); sv->done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } /* Called when a new TCP connection request arrives in the listening port. */ -static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ +static void listen_cb(void* arg, /*=sv_arg*/ grpc_error* error) { server* sv = static_cast<server*>(arg); int fd; @@ -195,7 +192,7 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ grpc_fd* listen_em_fd = sv->em_fd; if (error != GRPC_ERROR_NONE) { - listen_shutdown_cb(exec_ctx, arg, 1); + listen_shutdown_cb(arg, 1); return; } @@ -207,12 +204,12 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ se = static_cast<session*>(gpr_malloc(sizeof(*se))); se->sv = sv; se->em_fd = grpc_fd_create(fd, "listener"); - grpc_pollset_add_fd(exec_ctx, g_pollset, se->em_fd); + grpc_pollset_add_fd(g_pollset, se->em_fd); GRPC_CLOSURE_INIT(&se->session_read_closure, session_read_cb, se, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); - grpc_fd_notify_on_read(exec_ctx, listen_em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(listen_em_fd, &sv->listen_closure); } /* Max number of connections pending to be accepted by listen(). */ @@ -222,7 +219,7 @@ static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ listen_cb() is registered to be interested in reading from listen_fd. When connection request arrives, listen_cb() is called to accept the connection request. */ -static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { +static int server_start(server* sv) { int port = 0; int fd; struct sockaddr_in sin; @@ -236,11 +233,11 @@ static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); sv->em_fd = grpc_fd_create(fd, "server"); - grpc_pollset_add_fd(exec_ctx, g_pollset, sv->em_fd); + grpc_pollset_add_fd(g_pollset, sv->em_fd); /* Register to be interested in reading from listen_fd. */ GRPC_CLOSURE_INIT(&sv->listen_closure, listen_cb, sv, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, sv->em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(sv->em_fd, &sv->listen_closure); return port; } @@ -249,13 +246,13 @@ static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -289,18 +286,16 @@ static void client_init(client* cl) { } /* Called when a client upload session is ready to shutdown. */ -static void client_session_shutdown_cb(grpc_exec_ctx* exec_ctx, - void* arg /*client */, int success) { +static void client_session_shutdown_cb(void* arg /*client */, int success) { client* cl = static_cast<client*>(arg); - grpc_fd_orphan(exec_ctx, cl->em_fd, nullptr, nullptr, - false /* already_closed */, "c"); + grpc_fd_orphan(cl->em_fd, nullptr, nullptr, false /* already_closed */, "c"); cl->done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); } /* Write as much as possible, then register notify_on_write. */ -static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ +static void client_session_write(void* arg, /*client */ grpc_error* error) { client* cl = static_cast<client*>(arg); int fd = grpc_fd_wrapped_fd(cl->em_fd); @@ -308,7 +303,7 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ if (error != GRPC_ERROR_NONE) { gpr_mu_lock(g_mu); - client_session_shutdown_cb(exec_ctx, arg, 1); + client_session_shutdown_cb(arg, 1); gpr_mu_unlock(g_mu); return; } @@ -323,10 +318,10 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { GRPC_CLOSURE_INIT(&cl->write_closure, client_session_write, cl, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_write(exec_ctx, cl->em_fd, &cl->write_closure); + grpc_fd_notify_on_write(cl->em_fd, &cl->write_closure); cl->client_write_cnt++; } else { - client_session_shutdown_cb(exec_ctx, arg, 1); + client_session_shutdown_cb(arg, 1); } gpr_mu_unlock(g_mu); } else { @@ -336,7 +331,7 @@ static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ } /* Start a client to send a stream of bytes. */ -static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { +static void client_start(client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); @@ -357,9 +352,9 @@ static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { } cl->em_fd = grpc_fd_create(fd, "client"); - grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd); + grpc_pollset_add_fd(g_pollset, cl->em_fd); - client_session_write(exec_ctx, cl, GRPC_ERROR_NONE); + client_session_write(cl, GRPC_ERROR_NONE); } /* Wait for the signal to shutdown a client. */ @@ -367,12 +362,12 @@ static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { grpc_pollset_worker* worker = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); @@ -385,13 +380,13 @@ static void test_grpc_fd(void) { server sv; client cl; int port; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; server_init(&sv); - port = server_start(&exec_ctx, &sv); + port = server_start(&sv); client_init(&cl); - client_start(&exec_ctx, &cl, port); - grpc_exec_ctx_finish(&exec_ctx); + client_start(&cl, port); + client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); @@ -406,27 +401,25 @@ void init_change_data(fd_change_data* fdc) { fdc->cb_that_ran = nullptr; } void destroy_change_data(fd_change_data* fdc) {} -static void first_read_callback(grpc_exec_ctx* exec_ctx, - void* arg /* fd_change_data */, +static void first_read_callback(void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast<fd_change_data*>(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void second_read_callback(grpc_exec_ctx* exec_ctx, - void* arg /* fd_change_data */, +static void second_read_callback(void* arg /* fd_change_data */, grpc_error* error) { fd_change_data* fdc = static_cast<fd_change_data*>(arg); gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -443,7 +436,7 @@ static void test_grpc_fd_change(void) { ssize_t result; grpc_closure first_closure; grpc_closure second_closure; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&first_closure, first_read_callback, &a, grpc_schedule_on_exec_ctx); @@ -460,10 +453,10 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change"); - grpc_pollset_add_fd(&exec_ctx, g_pollset, em_fd); + grpc_pollset_add_fd(g_pollset, em_fd); /* Register the first callback, then make its FD readable */ - grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure); + grpc_fd_notify_on_read(em_fd, &first_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -473,10 +466,10 @@ static void test_grpc_fd_change(void) { while (a.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); @@ -488,7 +481,7 @@ static void test_grpc_fd_change(void) { /* Now register a second callback with distinct change data, and do the same thing again. */ - grpc_fd_notify_on_read(&exec_ctx, em_fd, &second_closure); + grpc_fd_notify_on_read(em_fd, &second_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -497,44 +490,43 @@ static void test_grpc_fd_change(void) { while (b.cb_that_ran == nullptr) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - GRPC_MILLIS_INF_FUTURE))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); gpr_mu_unlock(g_mu); - grpc_fd_orphan(&exec_ctx, em_fd, nullptr, nullptr, false /* already_closed */, - "d"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_fd_orphan(em_fd, nullptr, nullptr, false /* already_closed */, "d"); + destroy_change_data(&a); destroy_change_data(&b); close(sv[1]); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - test_grpc_fd(); - test_grpc_fd_change(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_flush(&exec_ctx); - gpr_free(g_pollset); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + test_grpc_fd(); + test_grpc_fd_change(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(g_pollset); + } grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/load_file_test.cc b/test/core/iomgr/load_file_test.cc index 9f360badcc..797d0ef1a4 100644 --- a/test/core/iomgr/load_file_test.cc +++ b/test/core/iomgr/load_file_test.cc @@ -19,6 +19,7 @@ #include <stdio.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/slice.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -152,9 +153,11 @@ static void test_load_big_file(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_load_empty_file(); test_load_failure(); test_load_small_file(); test_load_big_file(); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index 719eab91fe..f27079134b 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -47,11 +47,10 @@ void init_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { } } -void cleanup_test_pollset_sets(grpc_exec_ctx* exec_ctx, - test_pollset_set* pollset_sets, +void cleanup_test_pollset_sets(test_pollset_set* pollset_sets, const int num_pss) { for (int i = 0; i < num_pss; i++) { - grpc_pollset_set_destroy(exec_ctx, pollset_sets[i].pss); + grpc_pollset_set_destroy(pollset_sets[i].pss); pollset_sets[i].pss = nullptr; } } @@ -73,21 +72,19 @@ static void init_test_pollsets(test_pollset* pollsets, const int num_pollsets) { } } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } -static void cleanup_test_pollsets(grpc_exec_ctx* exec_ctx, - test_pollset* pollsets, +static void cleanup_test_pollsets(test_pollset* pollsets, const int num_pollsets) { grpc_closure destroyed; for (int i = 0; i < num_pollsets; i++) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, pollsets[i].ps, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); + grpc_pollset_shutdown(pollsets[i].ps, &destroyed); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(pollsets[i].ps); pollsets[i].ps = nullptr; } @@ -105,45 +102,43 @@ typedef struct test_fd { grpc_closure on_readable; /* Closure to call when this fd is readable */ } test_fd; -void on_readable(grpc_exec_ctx* exec_ctx, void* tfd, grpc_error* error) { +void on_readable(void* tfd, grpc_error* error) { ((test_fd*)tfd)->is_on_readable_called = true; } -static void reset_test_fd(grpc_exec_ctx* exec_ctx, test_fd* tfd) { +static void reset_test_fd(test_fd* tfd) { tfd->is_on_readable_called = false; GRPC_CLOSURE_INIT(&tfd->on_readable, on_readable, tfd, grpc_schedule_on_exec_ctx); - grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); + grpc_fd_notify_on_read(tfd->fd, &tfd->on_readable); } -static void init_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void init_test_fds(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), "test_fd"); - reset_test_fd(exec_ctx, &tfds[i]); + reset_test_fd(&tfds[i]); } } -static void cleanup_test_fds(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void cleanup_test_fds(test_fd* tfds, const int num_fds) { int release_fd; for (int i = 0; i < num_fds; i++) { - grpc_fd_shutdown(exec_ctx, tfds[i].fd, + grpc_fd_shutdown(tfds[i].fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup")); - grpc_exec_ctx_flush(exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also * calls close() on the underlying fd. In our case, we are using * grpc_wakeup_fd and we would like to destroy it ourselves (by calling * grpc_wakeup_fd_destroy). To prevent grpc_fd from calling close() on the * underlying fd, call it with a non-NULL 'release_fd' parameter */ - grpc_fd_orphan(exec_ctx, tfds[i].fd, nullptr, &release_fd, - false /* already_closed */, "test_fd_cleanup"); - grpc_exec_ctx_flush(exec_ctx); + grpc_fd_orphan(tfds[i].fd, nullptr, &release_fd, false /* already_closed */, + "test_fd_cleanup"); + grpc_core::ExecCtx::Get()->Flush(); grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); } @@ -155,8 +150,7 @@ static void make_test_fds_readable(test_fd* tfds, const int num_fds) { } } -static void verify_readable_and_reset(grpc_exec_ctx* exec_ctx, test_fd* tfds, - const int num_fds) { +static void verify_readable_and_reset(test_fd* tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { /* Verify that the on_readable callback was called */ GPR_ASSERT(tfds[i].is_on_readable_called); @@ -164,7 +158,7 @@ static void verify_readable_and_reset(grpc_exec_ctx* exec_ctx, test_fd* tfds, /* Reset the tfd[i] structure */ GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_consume_wakeup(&tfds[i].wakeup_fd)); - reset_test_fd(exec_ctx, &tfds[i]); + reset_test_fd(&tfds[i]); } } @@ -205,7 +199,7 @@ static void pollset_set_test_basic() { * | * +---> FD9 (Added after PS2 is added to PSS0) */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -216,34 +210,33 @@ static void pollset_set_test_basic() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the pollset_set/pollset/fd tree (see diagram above) */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[2].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[3].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[4].fd); + grpc_pollset_add_fd(pollsets[0].ps, tfds[2].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[3].fd); + grpc_pollset_add_fd(pollsets[2].ps, tfds[4].fd); - grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); + grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); + grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(pollset_sets[0].pss, pollsets[2].ps); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[6].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[7].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[8].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[9].fd); + grpc_pollset_add_fd(pollsets[0].ps, tfds[7].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[8].fd); + grpc_pollset_add_fd(pollsets[2].ps, tfds[9].fd); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); /* Test that if any FD in the above structure is readable, it is observable by * doing grpc_pollset_work on any pollset @@ -263,34 +256,32 @@ static void pollset_set_test_basic() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, deadline)); + grpc_pollset_work(pollsets[i].ps, &worker, deadline)); gpr_mu_unlock(pollsets[i].mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); } /* Test tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); - grpc_exec_ctx_flush(&exec_ctx); - - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); - - grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); - cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[6].fd); + grpc_core::ExecCtx::Get()->Flush(); + + grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_del_pollset(pollset_sets[0].pss, pollsets[2].ps); + + grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(pollsets, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); } /* Same FD added multiple times to the pollset_set tree */ @@ -310,7 +301,7 @@ void pollset_set_test_dup_fds() { * | +--> FD2 * +---> FD1 */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -321,21 +312,20 @@ void pollset_set_test_dup_fds() { const int num_ps = 1; const int num_pss = GPR_ARRAY_SIZE(pollset_sets); - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(&pollset, num_ps); init_test_pollset_sets(pollset_sets, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_add_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_add_fd(pollset_sets[1].pss, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[2].fd); + grpc_pollset_add_fd(pollset.ps, tfds[1].fd); + grpc_pollset_add_fd(pollset.ps, tfds[2].fd); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); + grpc_pollset_set_add_pollset(pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_add_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); /* Test. Make all FDs readable and make sure that can be observed by doing a * grpc_pollset_work on the pollset 'PS' */ @@ -345,27 +335,25 @@ void pollset_set_test_dup_fds() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollset.ps, &worker, deadline)); + grpc_pollset_work(pollset.ps, &worker, deadline)); gpr_mu_unlock(pollset.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); - grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); - - grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); - grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, - pollset_sets[1].pss); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, &pollset, num_ps); - cleanup_test_pollset_sets(&exec_ctx, pollset_sets, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_del_fd(pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_set_del_pollset(pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_del_pollset_set(pollset_sets[0].pss, pollset_sets[1].pss); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(&pollset, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); } /* Pollset_set with an empty pollset */ @@ -383,7 +371,7 @@ void pollset_set_test_empty_pollset() { * | * +---> FD2 */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_pollset_worker* worker; grpc_millis deadline; @@ -394,17 +382,17 @@ void pollset_set_test_empty_pollset() { const int num_ps = GPR_ARRAY_SIZE(pollsets); const int num_pss = 1; - init_test_fds(&exec_ctx, tfds, num_fds); + init_test_fds(tfds, num_fds); init_test_pollsets(pollsets, num_ps); init_test_pollset_sets(&pollset_set, num_pss); /* Construct the structure */ - grpc_pollset_set_add_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[1].fd); - grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[2].fd); + grpc_pollset_set_add_fd(pollset_set.pss, tfds[0].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[1].fd); + grpc_pollset_add_fd(pollsets[1].ps, tfds[2].fd); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(pollset_set.pss, pollsets[1].ps); /* Test. Make all FDs readable and make sure that can be observed by doing * grpc_pollset_work on the empty pollset 'PS0' */ @@ -414,45 +402,44 @@ void pollset_set_test_empty_pollset() { deadline = grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(2)); GPR_ASSERT(GRPC_ERROR_NONE == - grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, deadline)); + grpc_pollset_work(pollsets[0].ps, &worker, deadline)); gpr_mu_unlock(pollsets[0].mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); - verify_readable_and_reset(&exec_ctx, tfds, num_fds); - grpc_exec_ctx_flush(&exec_ctx); + verify_readable_and_reset(tfds, num_fds); + grpc_core::ExecCtx::Get()->Flush(); /* Tear down */ - grpc_pollset_set_del_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); - grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); - grpc_exec_ctx_flush(&exec_ctx); - - cleanup_test_fds(&exec_ctx, tfds, num_fds); - cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); - cleanup_test_pollset_sets(&exec_ctx, &pollset_set, num_pss); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_set_del_fd(pollset_set.pss, tfds[0].fd); + grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(pollset_set.pss, pollsets[1].ps); + grpc_core::ExecCtx::Get()->Flush(); + + cleanup_test_fds(tfds, num_fds); + cleanup_test_pollsets(pollsets, num_ps); + cleanup_test_pollset_sets(&pollset_set, num_pss); } int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - const char* poll_strategy = grpc_get_poll_strategy_name(); - - if (poll_strategy != nullptr && - (strcmp(poll_strategy, "epollsig") == 0 || - strcmp(poll_strategy, "epoll-threadpool") == 0)) { - pollset_set_test_basic(); - pollset_set_test_dup_fds(); - pollset_set_test_empty_pollset(); - } else { - gpr_log(GPR_INFO, - "Skipping the test. The test is only relevant for 'epoll' " - "strategy. and the current strategy is: '%s'", - poll_strategy); + { + grpc_core::ExecCtx exec_ctx; + const char* poll_strategy = grpc_get_poll_strategy_name(); + + if (poll_strategy != nullptr && + (strcmp(poll_strategy, "epollsig") == 0 || + strcmp(poll_strategy, "epoll-threadpool") == 0)) { + pollset_set_test_basic(); + pollset_set_test_dup_fds(); + pollset_set_test_empty_pollset(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epoll' " + "strategy. and the current strategy is: '%s'", + poll_strategy); + } } - - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 1a5eb9ace1..e36315333c 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -46,29 +46,29 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} -void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_init(args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); args->addrs = nullptr; } -void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_finish(args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); - grpc_pollset_set_destroy(exec_ctx, args->pollset_set); + grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_destroy(args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(args->pollset, &do_nothing_cb); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(exec_ctx); - grpc_pollset_destroy(exec_ctx, args->pollset); + grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -79,36 +79,33 @@ static grpc_millis n_sec_deadline(int seconds) { static void actually_poll(void* argsp) { args_struct* args = static_cast<args_struct*>(argsp); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = n_sec_deadline(10); while (true) { + grpc_core::ExecCtx exec_ctx; bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(&exec_ctx); } 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, "grpc_poll_pollset", actually_poll, args, nullptr); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, - grpc_error* err) { +static void must_succeed(void* argsp, grpc_error* err) { args_struct* args = static_cast<args_struct*>(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); @@ -116,29 +113,28 @@ static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, gpr_atm_rel_store(&args->done_atm, 1); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { +static void must_fail(void* argsp, grpc_error* err) { args_struct* args = static_cast<args_struct*>(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); } static void test_unix_socket(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); poll_pollset_until_request_done(&args); grpc_resolve_address( - &exec_ctx, "unix:/path/name", nullptr, args.pollset_set, + "unix:/path/name", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_unix_socket_path_name_too_long(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); const char prefix[] = "unix:/path/name"; size_t path_name_length = GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) + 6; @@ -150,22 +146,23 @@ static void test_unix_socket_path_name_too_long(void) { poll_pollset_until_request_done(&args); grpc_resolve_address( - &exec_ctx, path_name, nullptr, args.pollset_set, + path_name, nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); gpr_free(path_name); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_unix_socket(); - test_unix_socket_path_name_too_long(); - grpc_executor_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + test_unix_socket(); + test_unix_socket_path_name_too_long(); + } + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index 1c5aa38a95..a0dc484f3e 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -39,32 +39,32 @@ typedef struct args_struct { grpc_pollset_set* pollset_set; } args_struct; -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} -void args_init(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_init(args_struct* args) { gpr_event_init(&args->ev); args->pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args->pollset, &args->mu); args->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset); + grpc_pollset_set_add_pollset(args->pollset_set, args->pollset); args->addrs = nullptr; gpr_atm_rel_store(&args->done_atm, 0); } -void args_finish(grpc_exec_ctx* exec_ctx, args_struct* args) { +void args_finish(args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); grpc_resolved_addresses_destroy(args->addrs); - grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset); - grpc_pollset_set_destroy(exec_ctx, args->pollset_set); + grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); + grpc_pollset_set_destroy(args->pollset_set); grpc_closure do_nothing_cb; GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); gpr_mu_lock(args->mu); - grpc_pollset_shutdown(exec_ctx, args->pollset, &do_nothing_cb); + grpc_pollset_shutdown(args->pollset, &do_nothing_cb); gpr_mu_unlock(args->mu); // exec_ctx needs to be flushed before calling grpc_pollset_destroy() - grpc_exec_ctx_flush(exec_ctx); - grpc_pollset_destroy(exec_ctx, args->pollset); + grpc_core::ExecCtx::Get()->Flush(); + grpc_pollset_destroy(args->pollset); gpr_free(args->pollset); } @@ -74,119 +74,109 @@ static grpc_millis n_sec_deadline(int seconds) { } static void poll_pollset_until_request_done(args_struct* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = n_sec_deadline(10); while (true) { bool done = gpr_atm_acq_load(&args->done_atm) != 0; if (done) { break; } - grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx); + grpc_millis time_left = deadline - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left); GPR_ASSERT(time_left >= 0); grpc_pollset_worker* worker = nullptr; gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, - n_sec_deadline(1))); + GRPC_LOG_IF_ERROR("pollset_work", grpc_pollset_work(args->pollset, &worker, + n_sec_deadline(1))); gpr_mu_unlock(args->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } gpr_event_set(&args->ev, (void*)1); - grpc_exec_ctx_finish(&exec_ctx); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, - grpc_error* err) { +static void must_succeed(void* argsp, grpc_error* err) { args_struct* args = static_cast<args_struct*>(argsp); GPR_ASSERT(err == GRPC_ERROR_NONE); GPR_ASSERT(args->addrs != nullptr); GPR_ASSERT(args->addrs->naddrs > 0); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* argsp, grpc_error* err) { +static void must_fail(void* argsp, grpc_error* err) { args_struct* args = static_cast<args_struct*>(argsp); GPR_ASSERT(err != GRPC_ERROR_NONE); gpr_atm_rel_store(&args->done_atm, 1); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } static void test_localhost(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost:1", nullptr, args.pollset_set, + "localhost:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", "1", args.pollset_set, + "localhost", "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_non_numeric_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", "https", args.pollset_set, + "localhost", "https", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_missing_default_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "localhost", nullptr, args.pollset_set, + "localhost", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_ipv6_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, "[2001:db8::1]:1", nullptr, args.pollset_set, + "[2001:db8::1]:1", nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } static void test_ipv6_without_port(void) { @@ -197,17 +187,16 @@ static void test_ipv6_without_port(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], "80", args.pollset_set, + kCases[i], "80", args.pollset_set, GRPC_CLOSURE_CREATE(must_succeed, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } @@ -218,17 +207,16 @@ static void test_invalid_ip_addresses(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], nullptr, args.pollset_set, + kCases[i], nullptr, args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } @@ -238,34 +226,35 @@ static void test_unparseable_hostports(void) { }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; args_struct args; - args_init(&exec_ctx, &args); + args_init(&args); grpc_resolve_address( - &exec_ctx, kCases[i], "1", args.pollset_set, + kCases[i], "1", args.pollset_set, GRPC_CLOSURE_CREATE(must_fail, &args, grpc_schedule_on_exec_ctx), &args.addrs); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); poll_pollset_until_request_done(&args); - args_finish(&exec_ctx, &args); - grpc_exec_ctx_finish(&exec_ctx); + args_finish(&args); } } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_localhost(); - test_default_port(); - test_non_numeric_default_port(); - test_missing_default_port(); - test_ipv6_with_port(); - test_ipv6_without_port(); - test_invalid_ip_addresses(); - test_unparseable_hostports(); - grpc_executor_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + test_localhost(); + test_default_port(); + test_non_numeric_default_port(); + test_missing_default_port(); + test_ipv6_with_port(); + test_ipv6_without_port(); + test_invalid_ip_addresses(); + test_unparseable_hostports(); + grpc_executor_shutdown(); + } + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index 6851702e67..ae26f72701 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -27,7 +27,7 @@ gpr_mu g_mu; gpr_cv g_cv; -static void inc_int_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void inc_int_cb(void* a, grpc_error* error) { gpr_mu_lock(&g_mu); ++*(int*)a; gpr_cv_signal(&g_cv); @@ -43,7 +43,7 @@ static void assert_counter_becomes(int* ctr, int value) { gpr_mu_unlock(&g_mu); } -static void set_event_cb(grpc_exec_ctx* exec_ctx, void* a, grpc_error* error) { +static void set_event_cb(void* a, grpc_error* error) { gpr_event_set((gpr_event*)a, (void*)1); } grpc_closure* set_event(gpr_event* ev) { @@ -56,13 +56,12 @@ typedef struct { grpc_closure* then; } reclaimer_args; -static void reclaimer_cb(grpc_exec_ctx* exec_ctx, void* args, - grpc_error* error) { +static void reclaimer_cb(void* args, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); reclaimer_args* a = static_cast<reclaimer_args*>(args); - grpc_resource_user_free(exec_ctx, a->resource_user, a->size); - grpc_resource_user_finish_reclamation(exec_ctx, a->resource_user); - GRPC_CLOSURE_RUN(exec_ctx, a->then, GRPC_ERROR_NONE); + grpc_resource_user_free(a->resource_user, a->size); + grpc_resource_user_finish_reclamation(a->resource_user); + GRPC_CLOSURE_RUN(a->then, GRPC_ERROR_NONE); gpr_free(a); } @@ -75,10 +74,9 @@ grpc_closure* make_reclaimer(grpc_resource_user* resource_user, size_t size, return GRPC_CLOSURE_CREATE(reclaimer_cb, a, grpc_schedule_on_exec_ctx); } -static void unused_reclaimer_cb(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void unused_reclaimer_cb(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_CANCELLED); - GRPC_CLOSURE_RUN(exec_ctx, static_cast<grpc_closure*>(arg), GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(static_cast<grpc_closure*>(arg), GRPC_ERROR_NONE); } grpc_closure* make_unused_reclaimer(grpc_closure* then) { return GRPC_CLOSURE_CREATE(unused_reclaimer_cb, then, @@ -86,9 +84,8 @@ grpc_closure* make_unused_reclaimer(grpc_closure* then) { } static void destroy_user(grpc_resource_user* usr) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } static void test_no_op(void) { @@ -120,14 +117,12 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -140,10 +135,9 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -158,16 +152,15 @@ static void test_simple_async_alloc(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -182,9 +175,9 @@ static void test_async_alloc_blocked_by_size(void) { gpr_event ev; gpr_event_init(&ev); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } @@ -193,9 +186,8 @@ static void test_async_alloc_blocked_by_size(void) { nullptr); ; { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -210,32 +202,30 @@ static void test_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr1, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr1, 1024); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -251,33 +241,32 @@ static void test_scavenge_blocked(void) { gpr_event ev; { gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait( &ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr1, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr1, 1024); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -293,9 +282,9 @@ static void test_blocked_until_scheduled_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -303,18 +292,16 @@ static void test_blocked_until_scheduled_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -322,9 +309,8 @@ static void test_blocked_until_scheduled_reclaim(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -340,9 +326,9 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr1, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -350,18 +336,16 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr1, false, - make_reclaimer(usr1, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr1, false, make_reclaimer(usr1, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr2, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -369,9 +353,8 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr2, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr2, 1024); } grpc_resource_quota_unref(q); destroy_user(usr1); @@ -387,9 +370,9 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; @@ -397,18 +380,16 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { gpr_event reclaim_done; gpr_event_init(&reclaim_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_reclaimer(usr, 1024, set_event(&reclaim_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_reclaimer(usr, 1024, set_event(&reclaim_done))); } { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaim_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != @@ -416,9 +397,8 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -435,13 +415,12 @@ static void test_unused_reclaim_is_cancelled(void) { gpr_event destructive_done; gpr_event_init(&destructive_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, make_unused_reclaimer(set_event(&benign_done))); + usr, false, make_unused_reclaimer(set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_unused_reclaimer(set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -470,22 +449,20 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&benign_done))); + usr, false, make_reclaimer(usr, 1024, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_unused_reclaimer(set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_unused_reclaimer(set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -496,9 +473,9 @@ static void test_benign_reclaim_is_preferred(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -508,9 +485,8 @@ static void test_benign_reclaim_is_preferred(void) { nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -533,22 +509,20 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 512, set_event(&benign_done))); + usr, false, make_reclaimer(usr, 512, set_event(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, usr, true, - make_reclaimer(usr, 512, set_event(&destructive_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, true, make_reclaimer(usr, 512, set_event(&destructive_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -559,9 +533,9 @@ static void test_multiple_reclaims_can_be_triggered(void) { { gpr_event ev; gpr_event_init(&ev); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&ev)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&benign_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); GPR_ASSERT(gpr_event_wait(&destructive_done, @@ -571,9 +545,8 @@ static void test_multiple_reclaims_can_be_triggered(void) { ; } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); destroy_user(usr); @@ -591,20 +564,17 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, NULL); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_quota_unref(q); - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_resource_user_unref(usr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } } @@ -624,11 +594,10 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( gpr_event reclaimer_cancelled; gpr_event_init(&reclaimer_cancelled); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_unused_reclaimer(set_event(&reclaimer_cancelled))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_unused_reclaimer(set_event(&reclaimer_cancelled))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -636,27 +605,27 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( - 5)) != nullptr); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(gpr_event_wait(&allocated, + grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_seconds_to_deadline(5)) != nullptr); @@ -674,9 +643,9 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline(5)) != nullptr); } @@ -684,11 +653,10 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { gpr_event reclaimer_done; gpr_event_init(&reclaimer_done); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resource_user_post_reclaimer( - &exec_ctx, usr, false, - make_reclaimer(usr, 1024, set_event(&reclaimer_done))); - grpc_exec_ctx_finish(&exec_ctx); + usr, false, make_reclaimer(usr, 1024, set_event(&reclaimer_done))); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -696,20 +664,19 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { gpr_event allocated; gpr_event_init(&allocated); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated)); - grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( - 5)) != nullptr); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(gpr_event_wait(&allocated, + grpc_timeout_seconds_to_deadline(5)) != NULL); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); } } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_free(usr, 1024); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -732,16 +699,15 @@ static void test_one_slice(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } destroy_user(usr); grpc_resource_quota_unref(q); @@ -765,23 +731,21 @@ static void test_one_slice_deleted_late(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } } @@ -809,9 +773,9 @@ static void test_negative_rq_free_pool(void) { { const int start_allocs = num_allocs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_alloc_slices(&alloc, 1024, 1, &buffer); + grpc_core::ExecCtx::Get()->Flush(); assert_counter_becomes(&num_allocs, start_allocs + 1); } @@ -822,16 +786,14 @@ static void test_negative_rq_free_pool(void) { GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_unref(&exec_ctx, usr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_resource_user_unref(usr); } grpc_resource_quota_unref(q); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer_destroy_internal(&buffer); } } diff --git a/test/core/iomgr/tcp_client_posix_test.cc b/test/core/iomgr/tcp_client_posix_test.cc index 9fb1a2d770..40a050ed9f 100644 --- a/test/core/iomgr/tcp_client_posix_test.cc +++ b/test/core/iomgr/tcp_client_posix_test.cc @@ -53,26 +53,24 @@ static grpc_millis test_deadline(void) { static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(&exec_ctx, g_pollset, nullptr))); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); + gpr_mu_unlock(g_mu); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting != nullptr); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown( - exec_ctx, g_connecting, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); - grpc_endpoint_destroy(exec_ctx, g_connecting); + grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "must_succeed called")); + grpc_endpoint_destroy(g_connecting); g_connecting = nullptr; finish_connection(); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == nullptr); GPR_ASSERT(error != GRPC_ERROR_NONE); finish_connection(); @@ -85,7 +83,7 @@ void test_succeeds(void) { int r; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -108,8 +106,8 @@ void test_succeeds(void) { GPR_ASSERT(getsockname(svr_fd, (struct sockaddr*)addr, (socklen_t*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, - nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); /* await the connection */ do { @@ -125,17 +123,15 @@ void test_succeeds(void) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -143,7 +139,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -157,8 +153,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, nullptr, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, - nullptr, &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, g_pollset_set, nullptr, + &resolved_addr, GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -166,7 +162,7 @@ void test_fails(void) { while (g_connections_complete == connections_complete_before) { grpc_pollset_worker* worker = nullptr; grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { + switch (grpc_timer_check(&polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -174,42 +170,43 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - polling_deadline))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset_set = grpc_pollset_set_create(); - g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset); - grpc_exec_ctx_finish(&exec_ctx); - test_succeeds(); - gpr_log(GPR_ERROR, "End of first test"); - test_fails(); - grpc_pollset_set_destroy(&exec_ctx, g_pollset_set); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + g_pollset_set = grpc_pollset_set_create(); + g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + grpc_pollset_set_add_pollset(g_pollset_set, g_pollset); + + test_succeeds(); + gpr_log(GPR_ERROR, "End of first test"); + test_fails(); + grpc_pollset_set_destroy(g_pollset_set); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index 101d7bf6b5..0c6250ed7f 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -46,30 +46,28 @@ static grpc_millis test_deadline(void) { return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); } -static void finish_connection(grpc_exec_ctx* exec_ctx) { +static void finish_connection() { gpr_mu_lock(g_mu); g_connections_complete++; - GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, NULL))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); gpr_mu_unlock(g_mu); } -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting != NULL); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_endpoint_shutdown( - exec_ctx, g_connecting, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called")); - grpc_endpoint_destroy(exec_ctx, g_connecting); + grpc_endpoint_shutdown(g_connecting, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "must_succeed called")); + grpc_endpoint_destroy(g_connecting); g_connecting = NULL; - finish_connection(exec_ctx); + finish_connection(); } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(g_connecting == NULL); GPR_ASSERT(error != GRPC_ERROR_NONE); - finish_connection(exec_ctx); + finish_connection(); } static void close_cb(uv_handle_t* handle) { gpr_free(handle); } @@ -89,7 +87,7 @@ void test_succeeds(void) { uv_tcp_t* svr_handle = static_cast<uv_tcp_t*>(gpr_malloc(sizeof(uv_tcp_t))); int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -110,8 +108,8 @@ void test_succeeds(void) { GPR_ASSERT(uv_tcp_getsockname(svr_handle, (struct sockaddr*)addr, (int*)&resolved_addr.len) == 0); GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, + GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -119,11 +117,11 @@ void test_succeeds(void) { grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } @@ -131,8 +129,6 @@ void test_succeeds(void) { uv_close((uv_handle_t*)svr_handle, close_cb); gpr_mu_unlock(g_mu); - - grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -140,7 +136,7 @@ void test_fails(void) { struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int connections_complete_before; grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_fails"); @@ -154,8 +150,8 @@ void test_fails(void) { /* connect to a broken address */ GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL, - &resolved_addr, GRPC_MILLIS_INF_FUTURE); + grpc_tcp_client_connect(&done, &g_connecting, NULL, NULL, &resolved_addr, + GRPC_MILLIS_INF_FUTURE); gpr_mu_lock(g_mu); @@ -164,7 +160,7 @@ void test_fails(void) { grpc_pollset_worker* worker = NULL; gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); grpc_millis polling_deadline = test_deadline(); - switch (grpc_timer_check(&exec_ctx, &polling_deadline)) { + switch (grpc_timer_check(&polling_deadline)) { case GRPC_TIMERS_FIRED: break; case GRPC_TIMERS_NOT_CHECKED: @@ -172,39 +168,37 @@ void test_fails(void) { /* fall through */ case GRPC_TIMERS_CHECKED_AND_EMPTY: GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - polling_deadline))); + "pollset_work", + grpc_pollset_work(g_pollset, &worker, polling_deadline))); break; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast<grpc_pollset*>(gpr_malloc(grpc_pollset_size())); grpc_pollset_init(g_pollset, &g_mu); - grpc_exec_ctx_finish(&exec_ctx); + test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/tcp_posix_test.cc b/test/core/iomgr/tcp_posix_test.cc index 7986dc2b19..f4acba8302 100644 --- a/test/core/iomgr/tcp_posix_test.cc +++ b/test/core/iomgr/tcp_posix_test.cc @@ -131,8 +131,7 @@ static size_t count_slices(grpc_slice* slices, size_t nslices, return num_bytes; } -static void read_cb(grpc_exec_ctx* exec_ctx, void* user_data, - grpc_error* error) { +static void read_cb(void* user_data, grpc_error* error) { struct read_socket_state* state = (struct read_socket_state*)user_data; size_t read_bytes; int current_data; @@ -147,11 +146,11 @@ static void read_cb(grpc_exec_ctx* exec_ctx, void* user_data, gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } else { - grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); + grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb); gpr_mu_unlock(g_mu); } } @@ -164,7 +163,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, num_bytes, slice_size); @@ -175,9 +174,8 @@ static void read_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, - "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -188,24 +186,22 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(ep); } /* Write to a socket until it fills up, then read from it using the grpc_tcp @@ -217,7 +213,7 @@ static void large_read_test(size_t slice_size) { ssize_t written_bytes; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -228,9 +224,8 @@ static void large_read_test(size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "large_read_test"), - &args, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -241,24 +236,22 @@ static void large_read_test(size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_endpoint_destroy(&exec_ctx, ep); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_endpoint_destroy(ep); } struct write_socket_state { @@ -289,16 +282,15 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, return slices; } -static void write_done(grpc_exec_ctx* exec_ctx, - void* user_data /* write_socket_state */, +static void write_done(void* user_data /* write_socket_state */, grpc_error* error) { struct write_socket_state* state = (struct write_socket_state*)user_data; gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); state->write_done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -309,7 +301,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { int flags; int current = 0; int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -319,11 +311,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { gpr_mu_lock(g_mu); GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(10))))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + do { bytes_read = read(fd, buf, bytes_left > read_size ? read_size : bytes_left); @@ -356,7 +348,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_closure write_done_closure; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "Start write test with %" PRIuPTR " bytes, slice size %" PRIuPTR, @@ -368,9 +360,8 @@ static void write_test(size_t num_bytes, size_t slice_size) { a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE); a[0].type = GRPC_ARG_INTEGER, a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "write_test"), &args, - "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), &args, "test"); + grpc_endpoint_add_to_pollset(ep, g_pollset); state.ep = ep; state.write_done = 0; @@ -382,7 +373,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { GRPC_CLOSURE_INIT(&write_done_closure, write_done, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); + grpc_endpoint_write(ep, &outgoing, &write_done_closure); drain_socket_blocking(sv[0], num_bytes, num_bytes); gpr_mu_lock(g_mu); for (;;) { @@ -391,25 +382,23 @@ static void write_test(size_t num_bytes, size_t slice_size) { break; } GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(g_mu); } gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); - grpc_endpoint_destroy(&exec_ctx, ep); + grpc_slice_buffer_destroy_internal(&outgoing); + grpc_endpoint_destroy(ep); gpr_free(slices); - grpc_exec_ctx_finish(&exec_ctx); } -void on_fd_released(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* errors) { +void on_fd_released(void* arg, grpc_error* errors) { int* done = (int*)arg; *done = 1; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); } /* Do a read_test, then release fd and try to read/write again. Verify that @@ -422,7 +411,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { int fd; grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure fd_released_cb; int fd_released_done = 0; GRPC_CLOSURE_INIT(&fd_released_cb, &on_fd_released, &fd_released_done, @@ -439,10 +428,9 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - ep = grpc_tcp_create(&exec_ctx, grpc_fd_create(sv[1], "read_test"), &args, - "test"); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), &args, "test"); GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); + grpc_endpoint_add_to_pollset(ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %" PRIuPTR " bytes", written_bytes); @@ -453,38 +441,35 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer_init(&state.incoming); GRPC_CLOSURE_INIT(&state.read_cb, read_cb, &state, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); + grpc_endpoint_read(ep, &state.incoming, &state.read_cb); gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR, state.read_bytes, state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(g_mu); - grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming); - grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb); - grpc_exec_ctx_flush(&exec_ctx); + grpc_slice_buffer_destroy_internal(&state.incoming); + grpc_tcp_destroy_and_release_fd(ep, &fd, &fd_released_cb); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); while (!fd_released_done) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done); } gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); - grpc_exec_ctx_finish(&exec_ctx); written_bytes = fill_socket_partial(sv[0], num_bytes); drain_socket_blocking(fd, written_bytes, written_bytes); @@ -522,7 +507,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( size_t slice_size) { int sv[2]; grpc_endpoint_test_fixture f; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; create_sockets(sv); grpc_resource_quota* resource_quota = @@ -532,15 +517,13 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( a[0].type = GRPC_ARG_INTEGER; a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; - f.client_ep = grpc_tcp_create( - &exec_ctx, grpc_fd_create(sv[0], "fixture:client"), &args, "test"); - f.server_ep = grpc_tcp_create( - &exec_ctx, grpc_fd_create(sv[1], "fixture:server"), &args, "test"); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); - - grpc_exec_ctx_finish(&exec_ctx); + f.client_ep = + grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), &args, "test"); + f.server_ep = + grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), &args, "test"); + grpc_resource_quota_unref_internal(resource_quota); + grpc_endpoint_add_to_pollset(f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(f.server_ep, g_pollset); return f; } @@ -549,24 +532,26 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - run_tests(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + run_tests(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + + grpc_core::ExecCtx::Get()->Flush(); + } grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 48d8d425a5..3c9ca2109e 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -110,8 +110,7 @@ static void on_connect_result_set(on_connect_result* result, result->server, acceptor->port_index, acceptor->fd_index); } -static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void server_weak_ref_shutdown(void* arg, grpc_error* error) { server_weak_ref* weak_ref = static_cast<server_weak_ref*>(arg); weak_ref->server = nullptr; } @@ -145,12 +144,11 @@ static void test_addr_init_str(test_addr* addr) { } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, - grpc_pollset* pollset, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -159,38 +157,33 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); + grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_unref(s); } static void test_no_op_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -201,17 +194,15 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void test_no_op_with_port_and_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(nullptr, nullptr, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port = -1; @@ -222,13 +213,12 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(&exec_ctx, s, nullptr, 0, on_connect, nullptr); + grpc_tcp_server_start(s, nullptr, 0, on_connect, nullptr); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } -static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, +static grpc_error* tcp_connect(const test_addr* remote, on_connect_result* result) { grpc_millis deadline = grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); @@ -254,17 +244,17 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, } gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && - deadline > grpc_exec_ctx_now(exec_ctx)) { + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = nullptr; grpc_error* err; - if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)) != + if ((err = grpc_pollset_work(g_pollset, &worker, deadline)) != GRPC_ERROR_NONE) { gpr_mu_unlock(g_mu); close(clifd); return err; } gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(exec_ctx); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -279,7 +269,7 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, gpr_mu_unlock(g_mu); gpr_log(GPR_INFO, "Result (%d, %d) fd %d", result->port_index, result->fd_index, result->server_fd); - grpc_tcp_server_unref(exec_ctx, result->server); + grpc_tcp_server_unref(result->server); return GRPC_ERROR_NONE; } @@ -292,7 +282,7 @@ static grpc_error* tcp_connect(grpc_exec_ctx* exec_ctx, const test_addr* remote, static void test_connect(size_t num_connects, const grpc_channel_args* channel_args, test_addrs* dst_addrs, bool test_dst_addrs) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* const addr = @@ -307,7 +297,7 @@ static void test_connect(size_t num_connects, grpc_tcp_server* s; const unsigned num_ports = 2; GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, nullptr, channel_args, &s)); + grpc_tcp_server_create(nullptr, channel_args, &s)); unsigned port_num; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -352,7 +342,7 @@ static void test_connect(size_t num_connects, svr1_fd_count = grpc_tcp_server_port_fd_count(s, 1); GPR_ASSERT(svr1_fd_count >= 1); - grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, nullptr); + grpc_tcp_server_start(s, &g_pollset, 1, on_connect, nullptr); if (dst_addrs != nullptr) { int ports[] = {svr_port, svr1_port}; @@ -372,7 +362,7 @@ static void test_connect(size_t num_connects, test_addr_init_str(&dst); ++num_tested; on_connect_result_init(&result); - if ((err = tcp_connect(&exec_ctx, &dst, &result)) == GRPC_ERROR_NONE && + if ((err = tcp_connect(&dst, &result)) == GRPC_ERROR_NONE && result.server_fd >= 0 && result.server == s) { continue; } @@ -403,8 +393,8 @@ static void test_connect(size_t num_connects, for (connect_num = 0; connect_num < num_connects; ++connect_num) { on_connect_result result; on_connect_result_init(&result); - GPR_ASSERT(GRPC_LOG_IF_ERROR("tcp_connect", - tcp_connect(&exec_ctx, &dst, &result))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("tcp_connect", tcp_connect(&dst, &result))); GPR_ASSERT(result.server_fd == fd); GPR_ASSERT(result.port_index == port_num); GPR_ASSERT(result.fd_index == fd_num); @@ -420,21 +410,19 @@ static void test_connect(size_t num_connects, GPR_ASSERT(weak_ref.server != nullptr); GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 0) >= 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == nullptr); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_arg chan_args[1]; chan_args[0].type = GRPC_ARG_INTEGER; chan_args[0].key = const_cast<char*>(GRPC_ARG_EXPAND_WILDCARD_ADDRS); @@ -447,58 +435,61 @@ int main(int argc, char** argv) { static_cast<test_addrs*>(gpr_zalloc(sizeof(*dst_addrs))); grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_start(); + + if (getifaddrs(&ifa) != 0 || ifa == nullptr) { + gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); + return EXIT_FAILURE; + } + dst_addrs->naddrs = 0; + for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; + ifa_it = ifa_it->ifa_next) { + if (ifa_it->ifa_addr == nullptr) { + continue; + } else if (ifa_it->ifa_addr->sa_family == AF_INET) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = + sizeof(struct sockaddr_in); + } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { + dst_addrs->addrs[dst_addrs->naddrs].addr.len = + sizeof(struct sockaddr_in6); + } else { + continue; + } + memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, + dst_addrs->addrs[dst_addrs->naddrs].addr.len); + GPR_ASSERT( + grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); + test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); + ++dst_addrs->naddrs; + } + freeifaddrs(ifa); + ifa = nullptr; - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_start(); + /* Connect to same addresses as listeners. */ + test_connect(1, nullptr, nullptr, false); + test_connect(10, nullptr, nullptr, false); - if (getifaddrs(&ifa) != 0 || ifa == nullptr) { - gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); - return EXIT_FAILURE; - } - dst_addrs->naddrs = 0; - for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS; - ifa_it = ifa_it->ifa_next) { - if (ifa_it->ifa_addr == nullptr) { - continue; - } else if (ifa_it->ifa_addr->sa_family == AF_INET) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = sizeof(struct sockaddr_in); - } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { - dst_addrs->addrs[dst_addrs->naddrs].addr.len = - sizeof(struct sockaddr_in6); - } else { - continue; - } - memcpy(dst_addrs->addrs[dst_addrs->naddrs].addr.addr, ifa_it->ifa_addr, - dst_addrs->addrs[dst_addrs->naddrs].addr.len); - GPR_ASSERT( - grpc_sockaddr_set_port(&dst_addrs->addrs[dst_addrs->naddrs].addr, 0)); - test_addr_init_str(&dst_addrs->addrs[dst_addrs->naddrs]); - ++dst_addrs->naddrs; + /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a + "::" listener. */ + test_connect(1, nullptr, dst_addrs, true); + + /* Test connect(2) with dst_addrs. */ + test_connect(1, &channel_args, dst_addrs, false); + /* Test connect(2) with dst_addrs. */ + test_connect(10, &channel_args, dst_addrs, false); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); } - freeifaddrs(ifa); - ifa = nullptr; - - /* Connect to same addresses as listeners. */ - test_connect(1, nullptr, nullptr, false); - test_connect(10, nullptr, nullptr, false); - - /* Set dst_addrs->addrs[i].len=0 for dst_addrs that are unreachable with a - "::" listener. */ - test_connect(1, nullptr, dst_addrs, true); - - /* Test connect(2) with dst_addrs. */ - test_connect(1, &channel_args, dst_addrs, false); - /* Test connect(2) with dst_addrs. */ - test_connect(10, &channel_args, dst_addrs, false); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(dst_addrs); gpr_free(g_pollset); diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index dd047a0498..35d62b51b7 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -74,8 +74,7 @@ static void on_connect_result_set(on_connect_result* result, result->fd_index = acceptor->fd_index; } -static void server_weak_ref_shutdown(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void server_weak_ref_shutdown(void* arg, grpc_error* error) { server_weak_ref* weak_ref = static_cast<server_weak_ref*>(arg); weak_ref->server = NULL; } @@ -97,12 +96,11 @@ static void server_weak_ref_set(server_weak_ref* weak_ref, weak_ref->server = server; } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, - grpc_pollset* pollset, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* pollset, grpc_tcp_server_acceptor* acceptor) { - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); on_connect_result temp_result; on_connect_result_set(&temp_result, acceptor); @@ -111,38 +109,33 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_mu_lock(g_mu); g_result = temp_result; g_nconnects++; - GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, g_pollset, NULL))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); gpr_mu_unlock(g_mu); } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); + grpc_tcp_server_unref(s); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); + grpc_tcp_server_unref(s); } static void test_no_op_with_port(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_port"); memset(&resolved_addr, 0, sizeof(resolved_addr)); @@ -153,17 +146,15 @@ static void test_no_op_with_port(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void test_no_op_with_port_and_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); LOG_TEST("test_no_op_with_port_and_start"); int port; @@ -174,10 +165,9 @@ static void test_no_op_with_port_and_start(void) { GRPC_ERROR_NONE && port > 0); - grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); + grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); } static void connect_cb(uv_connect_t* req, int status) { @@ -187,8 +177,8 @@ static void connect_cb(uv_connect_t* req, int status) { static void close_cb(uv_handle_t* handle) { gpr_free(handle); } -static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, - socklen_t remote_len, on_connect_result* result) { +static void tcp_connect(const struct sockaddr* remote, socklen_t remote_len, + on_connect_result* result) { gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10); uv_tcp_t* client_handle = static_cast<uv_tcp_t*>(gpr_malloc(sizeof(uv_tcp_t))); @@ -208,10 +198,10 @@ static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(exec_ctx, g_pollset, &worker, + grpc_pollset_work(g_pollset, &worker, grpc_timespec_to_millis_round_up(deadline)))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_finish(exec_ctx); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); @@ -224,7 +214,7 @@ static void tcp_connect(grpc_exec_ctx* exec_ctx, const struct sockaddr* remote, /* Tests a tcp server with multiple ports. */ static void test_connect(unsigned n) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; grpc_resolved_address resolved_addr1; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -233,8 +223,7 @@ static void test_connect(unsigned n) { int svr_port; int svr1_port; grpc_tcp_server* s; - GPR_ASSERT(GRPC_ERROR_NONE == - grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s)); + GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); unsigned i; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -257,48 +246,45 @@ static void test_connect(unsigned n) { GRPC_ERROR_NONE && svr_port == svr1_port); - grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, NULL); + grpc_tcp_server_start(s, &g_pollset, 1, on_connect, NULL); GPR_ASSERT(uv_ip6_addr("::", svr_port, (struct sockaddr_in6*)addr1) == 0); for (i = 0; i < n; i++) { on_connect_result result; on_connect_result_init(&result); - tcp_connect(&exec_ctx, (struct sockaddr*)addr, (socklen_t)resolved_addr.len, - &result); + tcp_connect((struct sockaddr*)addr, (socklen_t)resolved_addr.len, &result); GPR_ASSERT(result.port_index == 0); GPR_ASSERT(result.server == s); if (weak_ref.server == NULL) { server_weak_ref_set(&weak_ref, result.server); } - grpc_tcp_server_unref(&exec_ctx, result.server); + grpc_tcp_server_unref(result.server); on_connect_result_init(&result); - tcp_connect(&exec_ctx, (struct sockaddr*)addr1, - (socklen_t)resolved_addr1.len, &result); + tcp_connect((struct sockaddr*)addr1, (socklen_t)resolved_addr1.len, + &result); GPR_ASSERT(result.port_index == 1); GPR_ASSERT(result.server == s); - grpc_tcp_server_unref(&exec_ctx, result.server); + grpc_tcp_server_unref(result.server); } /* Weak ref to server valid until final unref. */ GPR_ASSERT(weak_ref.server != NULL); - grpc_tcp_server_unref(&exec_ctx, s); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); g_pollset = static_cast<grpc_pollset*>(gpr_malloc(grpc_pollset_size())); @@ -313,8 +299,8 @@ int main(int argc, char** argv) { GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_shutdown(); gpr_free(g_pollset); return 0; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index d74ea4fc96..deb8c4d87e 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -25,6 +25,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/log.h> #include "src/core/lib/debug/trace.h" #include "test/core/util/test_config.h" @@ -37,127 +38,125 @@ extern grpc_core::TraceFlag grpc_timer_check_trace; static int cb_called[MAX_CB][2]; -static void cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void cb(void* arg, grpc_error* error) { cb_called[(intptr_t)arg][error == GRPC_ERROR_NONE]++; } static void add_test(void) { int i; grpc_timer timers[20]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "add_test"); - grpc_timer_list_init(&exec_ctx); + grpc_timer_list_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); - grpc_millis start = grpc_exec_ctx_now(&exec_ctx); + grpc_millis start = grpc_core::ExecCtx::Get()->Now(); /* 10 ms timers. will expire in the current epoch */ for (i = 0; i < 10; i++) { grpc_timer_init( - &exec_ctx, &timers[i], start + 10, + &timers[i], start + 10, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* 1010 ms timers. will expire in the next epoch */ for (i = 10; i < 20; i++) { grpc_timer_init( - &exec_ctx, &timers[i], start + 1010, + &timers[i], start + 1010, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)i, grpc_schedule_on_exec_ctx)); } /* collect timers. Only the first batch should be ready. */ - exec_ctx.now = start + 500; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 500); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx.now = start + 600; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == - GRPC_TIMERS_CHECKED_AND_EMPTY); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 600); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the timers */ - exec_ctx.now = start + 1500; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1500); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - exec_ctx.now = start + 1600; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == - GRPC_TIMERS_CHECKED_AND_EMPTY); + grpc_core::ExecCtx::Get()->TestOnlySetNow(start + 1600); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_CHECKED_AND_EMPTY); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - grpc_timer_list_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_list_shutdown(); } /* Cleaning up a list with pending timers. */ void destruction_test(void) { grpc_timer timers[5]; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_INFO, "destruction_test"); - exec_ctx.now_is_valid = true; - exec_ctx.now = 0; - grpc_timer_list_init(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(0); + grpc_timer_list_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( - &exec_ctx, &timers[0], 100, + &timers[0], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)0, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[1], 3, + &timers[1], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)1, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[2], 100, + &timers[2], 100, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)2, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[3], 3, + &timers[3], 3, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)3, grpc_schedule_on_exec_ctx)); grpc_timer_init( - &exec_ctx, &timers[4], 1, + &timers[4], 1, GRPC_CLOSURE_CREATE(cb, (void*)(intptr_t)4, grpc_schedule_on_exec_ctx)); - exec_ctx.now = 2; - GPR_ASSERT(grpc_timer_check(&exec_ctx, nullptr) == GRPC_TIMERS_FIRED); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->TestOnlySetNow(2); + GPR_ASSERT(grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[4][1]); - grpc_timer_cancel(&exec_ctx, &timers[0]); - grpc_timer_cancel(&exec_ctx, &timers[3]); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_cancel(&timers[0]); + grpc_timer_cancel(&timers[3]); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); - grpc_timer_list_shutdown(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_timer_list_shutdown(); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_core::ExecCtx::GlobalInit(); gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); add_test(); destruction_test(); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 6e17be9cd6..0deb534abd 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -50,7 +50,7 @@ static int g_number_of_writes = 0; static int g_number_of_bytes_read = 0; static int g_number_of_orphan_calls = 0; -static bool on_read(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data) { +static bool on_read(grpc_fd* emfd, void* user_data) { char read_buffer[512]; ssize_t byte_count; @@ -61,27 +61,27 @@ static bool on_read(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data) { g_number_of_reads++; g_number_of_bytes_read += (int)byte_count; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); return false; } -static void on_write(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, void* user_data, +static void on_write(grpc_fd* emfd, void* user_data, grpc_closure* notify_on_write_closure) { gpr_mu_lock(g_mu); g_number_of_writes++; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr))); + GPR_ASSERT( + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } -static void on_fd_orphaned(grpc_exec_ctx* exec_ctx, grpc_fd* emfd, - grpc_closure* closure, void* user_data) { +static void on_fd_orphaned(grpc_fd* emfd, grpc_closure* closure, + void* user_data) { gpr_log(GPR_INFO, "gRPC FD about to be orphaned: %d", grpc_fd_wrapped_fd(emfd)); - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); g_number_of_orphan_calls++; } @@ -130,24 +130,22 @@ static test_socket_factory* test_socket_factory_create(void) { } static void test_no_op(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); } static void test_no_op_with_start(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_start"); - grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_start(s, nullptr, 0, nullptr); + grpc_udp_server_destroy(s, nullptr); } static void test_no_op_with_port(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -159,8 +157,7 @@ static void test_no_op_with_port(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); @@ -168,7 +165,7 @@ static void test_no_op_with_port(void) { static void test_no_op_with_port_and_socket_factory(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; @@ -178,7 +175,7 @@ static void test_no_op_with_port_and_socket_factory(void) { grpc_channel_args* channel_args = grpc_channel_args_copy_and_add(nullptr, &socket_factory_arg, 1); grpc_udp_server* s = grpc_udp_server_create(channel_args); - grpc_channel_args_destroy(&exec_ctx, channel_args); + grpc_channel_args_destroy(channel_args); LOG_TEST("test_no_op_with_port_and_socket_factory"); @@ -190,8 +187,8 @@ static void test_no_op_with_port_and_socket_factory(void) { GPR_ASSERT(socket_factory->number_of_socket_calls == 1); GPR_ASSERT(socket_factory->number_of_bind_calls == 1); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); + grpc_socket_factory_unref(&socket_factory->base); /* The server had a single FD, which should have been orphaned. */ @@ -200,7 +197,7 @@ static void test_no_op_with_port_and_socket_factory(void) { static void test_no_op_with_port_and_start(void) { g_number_of_orphan_calls = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; grpc_udp_server* s = grpc_udp_server_create(nullptr); @@ -212,10 +209,9 @@ static void test_no_op_with_port_and_start(void) { GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, on_fd_orphaned)); - grpc_udp_server_start(&exec_ctx, s, nullptr, 0, nullptr); + grpc_udp_server_start(s, nullptr, 0, nullptr); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ @@ -223,7 +219,7 @@ static void test_no_op_with_port_and_start(void) { } static void test_receive(int number_of_clients) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int clifd, svrfd; @@ -250,7 +246,7 @@ static void test_receive(int number_of_clients) { GPR_ASSERT(resolved_addr.len <= sizeof(struct sockaddr_storage)); pollsets[0] = g_pollset; - grpc_udp_server_start(&exec_ctx, s, pollsets, 1, nullptr); + grpc_udp_server_start(s, pollsets, 1, nullptr); gpr_mu_lock(g_mu); @@ -266,13 +262,12 @@ static void test_receive(int number_of_clients) { (socklen_t)resolved_addr.len) == 0); GPR_ASSERT(5 == write(clifd, "hello", 5)); while (g_number_of_bytes_read < (number_of_bytes_read_before + 5) && - deadline > grpc_exec_ctx_now(&exec_ctx)) { + deadline > grpc_core::ExecCtx::Get()->Now()) { grpc_pollset_worker* worker = nullptr; GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline))); + "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } close(clifd); @@ -281,40 +276,40 @@ static void test_receive(int number_of_clients) { gpr_mu_unlock(g_mu); - grpc_udp_server_destroy(&exec_ctx, s, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ GPR_ASSERT(g_number_of_orphan_calls == 1); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(p)); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_socket_factory(); - test_no_op_with_port_and_start(); - test_receive(1); - test_receive(10); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); - gpr_free(g_pollset); + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_socket_factory(); + test_no_op_with_port_and_start(); + test_receive(1); + test_receive(10); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(g_pollset); + } grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index dc1d77a0ab..d4e05bd7ef 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, "grpc_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, "grpc_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, "grpc_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, "grpc_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, "grpc_background_poll", &background_poll, &pargs, &opt); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 0); diff --git a/test/core/nanopb/fuzzer_response.cc b/test/core/nanopb/fuzzer_response.cc index 7039c801cb..3a70dea5e9 100644 --- a/test/core/nanopb/fuzzer_response.cc +++ b/test/core/nanopb/fuzzer_response.cc @@ -19,6 +19,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -29,6 +30,7 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_initial_response* response; @@ -36,5 +38,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_initial_response_destroy(response); } grpc_slice_unref(slice); + grpc_shutdown(); return 0; } diff --git a/test/core/nanopb/fuzzer_serverlist.cc b/test/core/nanopb/fuzzer_serverlist.cc index 0a6b1767a1..d0af117ef9 100644 --- a/test/core/nanopb/fuzzer_serverlist.cc +++ b/test/core/nanopb/fuzzer_serverlist.cc @@ -19,6 +19,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -29,6 +30,7 @@ bool leak_check = true; static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + grpc_init(); if (squelch) gpr_set_log_function(dont_log); grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); grpc_grpclb_serverlist* serverlist; @@ -36,5 +38,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_grpclb_destroy_serverlist(serverlist); } grpc_slice_unref(slice); + grpc_shutdown(); return 0; } diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 2ae9a45d7c..96b0745f52 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -583,7 +583,7 @@ 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_wrap, server_args, nullptr); + gpr_thd_new(&tid, "server_thread", server_thread_wrap, server_args, nullptr); client_thread(client_args); return 0; } diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 64d383ad0a..ecc61928f5 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -148,41 +148,37 @@ static grpc_httpcli_response http_response(int status, const char* body) { /* -- Tests. -- */ static void test_empty_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); GPR_ASSERT(md_array.md == nullptr); GPR_ASSERT(md_array.size == 0); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_add_to_empty_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_credentials_mdelem_array_add(&md_array, md); GPR_ASSERT(md_array.size == 1); GPR_ASSERT(grpc_mdelem_eq(md, md_array.md[0])); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_add_abunch_to_md_array(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_credentials_mdelem_array md_array; memset(&md_array, 0, sizeof(md_array)); const char* key = "hello"; const char* value = "there blah blah blah blah blah blah blah"; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); size_t num_entries = 1000; for (size_t i = 0; i < num_entries; ++i) { grpc_credentials_mdelem_array_add(&md_array, md); @@ -190,57 +186,52 @@ static void test_add_abunch_to_md_array(void) { for (size_t i = 0; i < num_entries; ++i) { GPR_ASSERT(grpc_mdelem_eq(md_array.md[i], md)); } - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_credentials_mdelem_array_destroy(&md_array); } static void test_oauth2_token_fetcher_creds_parsing_ok(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == - GRPC_CREDENTIALS_OK); + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_OK); GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md), "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); - GRPC_MDELEM_UNREF(&exec_ctx, token_md); + GRPC_MDELEM_UNREF(token_md); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(401, valid_oauth2_json_response); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, ""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -249,14 +240,13 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\""); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = http_response(200, @@ -264,14 +254,13 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) { " \"expires_in\":3599, " " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -280,15 +269,14 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) { " \"expires_in\":3599, " "}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem token_md = GRPC_MDNULL; grpc_millis token_lifetime; grpc_httpcli_response response = @@ -296,10 +284,9 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime( "{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\"," " \"token_type\":\"Bearer\"}"); GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response( - &exec_ctx, &response, &token_md, &token_lifetime) == + &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_ERROR); grpc_http_response_destroy(&response); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -336,8 +323,7 @@ static void check_metadata(const expected_md* expected, } } -static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void check_request_metadata(void* arg, grpc_error* error) { request_metadata_state* state = (request_metadata_state*)arg; gpr_log(GPR_INFO, "expected_error: %s", grpc_error_string(state->expected_error)); @@ -358,9 +344,8 @@ static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg, state->expected_size, state->md_array.size); GPR_ASSERT(state->md_array.size == state->expected_size); check_metadata(state->expected, &state->md_array); - grpc_credentials_mdelem_array_destroy(exec_ctx, &state->md_array); - grpc_pollset_set_destroy(exec_ctx, - grpc_polling_entity_pollset_set(&state->pollent)); + grpc_credentials_mdelem_array_destroy(&state->md_array); + grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&state->pollent)); gpr_free(state); } @@ -379,22 +364,21 @@ static request_metadata_state* make_request_metadata_state( return state; } -static void run_request_metadata_test(grpc_exec_ctx* exec_ctx, - grpc_call_credentials* creds, +static void run_request_metadata_test(grpc_call_credentials* creds, grpc_auth_metadata_context auth_md_ctx, request_metadata_state* state) { grpc_error* error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - exec_ctx, creds, &state->pollent, auth_md_ctx, &state->md_array, + creds, &state->pollent, auth_md_ctx, &state->md_array, &state->on_request_metadata, &error)) { // Synchronous result. Invoke the callback directly. - check_request_metadata(exec_ctx, state, error); + check_request_metadata(state, error); GRPC_ERROR_UNREF(error); } } static void test_google_iam_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -406,13 +390,12 @@ static void test_google_iam_creds(void) { nullptr); grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); } static void test_access_token_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); @@ -421,16 +404,14 @@ static void test_access_token_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); } static grpc_security_status check_channel_oauth2_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); @@ -438,7 +419,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector( } static void test_channel_oauth2_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_create_security_connector, nullptr}; @@ -452,14 +433,13 @@ static void test_channel_oauth2_composite_creds(void) { grpc_channel_credentials_release(channel_creds); grpc_call_credentials_release(oauth2_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - &exec_ctx, channel_oauth2_creds, nullptr, nullptr, nullptr, - &new_args) == GRPC_SECURITY_OK); + channel_oauth2_creds, nullptr, nullptr, nullptr, &new_args) == + GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_creds); - grpc_exec_ctx_finish(&exec_ctx); } static void test_oauth2_google_iam_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -471,15 +451,15 @@ static void test_oauth2_google_iam_composite_creds(void) { grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( - &exec_ctx, "authorization", test_oauth2_bearer_token, 0); + "authorization", test_oauth2_bearer_token, 0); grpc_call_credentials* google_iam_creds = grpc_google_iam_credentials_create( test_google_iam_authorization_token, test_google_iam_authority_selector, nullptr); grpc_call_credentials* composite_creds = grpc_composite_call_credentials_create(oauth2_creds, google_iam_creds, nullptr); - grpc_call_credentials_unref(&exec_ctx, oauth2_creds); - grpc_call_credentials_unref(&exec_ctx, google_iam_creds); + grpc_call_credentials_unref(oauth2_creds); + grpc_call_credentials_unref(google_iam_creds); GPR_ASSERT( strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); const grpc_call_credentials_array* creds_array = @@ -489,17 +469,15 @@ static void test_oauth2_google_iam_composite_creds(void) { GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); - run_request_metadata_test(&exec_ctx, composite_creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, composite_creds); - grpc_exec_ctx_finish(&exec_ctx); + run_request_metadata_test(composite_creds, auth_md_ctx, state); + grpc_call_credentials_unref(composite_creds); } static grpc_security_status check_channel_oauth2_google_iam_create_security_connector( - grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c, - grpc_call_credentials* call_creds, const char* target, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { + grpc_channel_credentials* c, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { const grpc_call_credentials_array* creds_array; GPR_ASSERT(strcmp(c->type, "mock") == 0); GPR_ASSERT(call_creds != nullptr); @@ -514,7 +492,7 @@ check_channel_oauth2_google_iam_create_security_connector( } static void test_channel_oauth2_google_iam_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_args* new_args; grpc_channel_credentials_vtable vtable = { nullptr, check_channel_oauth2_google_iam_create_security_connector, @@ -538,11 +516,10 @@ static void test_channel_oauth2_google_iam_composite_creds(void) { grpc_call_credentials_release(google_iam_creds); GPR_ASSERT(grpc_channel_credentials_create_security_connector( - &exec_ctx, channel_oauth2_iam_creds, nullptr, nullptr, nullptr, + channel_oauth2_iam_creds, nullptr, nullptr, nullptr, &new_args) == GRPC_SECURITY_OK); grpc_channel_credentials_release(channel_oauth2_iam_creds); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_compute_engine_http_request( @@ -559,35 +536,32 @@ static void validate_compute_engine_http_request( } static int compute_engine_httpcli_get_success_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int compute_engine_httpcli_get_failure_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { validate_compute_engine_http_request(request); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int httpcli_post_should_not_be_called( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body_bytes, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body_bytes, + size_t body_size, grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } -static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -596,7 +570,7 @@ static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, } static void test_compute_engine_creds_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_call_credentials* creds = @@ -609,24 +583,23 @@ static void test_compute_engine_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_compute_engine_creds_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -637,10 +610,9 @@ static void test_compute_engine_creds_failure(void) { grpc_google_compute_engine_credentials_create(nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_refresh_token_http_request( @@ -667,27 +639,27 @@ static void validate_refresh_token_http_request( } static int refresh_token_httpcli_post_success( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body, size_t body_size, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(200, valid_oauth2_json_response); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static int refresh_token_httpcli_post_failure( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body, size_t body_size, + grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { validate_refresh_token_http_request(request, body, body_size); *response = http_response(403, "Not Authorized."); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_refresh_token_creds_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, @@ -700,24 +672,23 @@ static void test_refresh_token_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_refresh_token_creds_failure(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; request_metadata_state* state = make_request_metadata_state( GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error occured when fetching oauth2 token."), @@ -728,10 +699,9 @@ static void test_refresh_token_creds_failure(void) { test_refresh_token_str, nullptr); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_failure); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_call_credentials_unref(&exec_ctx, creds); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_call_credentials_unref(creds); grpc_httpcli_set_override(nullptr, nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void validate_jwt_encode_and_sign_params( @@ -821,7 +791,7 @@ static void test_jwt_creds_lifetime(void) { static void test_jwt_creds_success(void) { char* json_key_string = test_json_key_str(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_md_value; @@ -835,16 +805,16 @@ static void test_jwt_creds_success(void) { request_metadata_state* state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Second request: the cached token should be served directly. */ state = make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ @@ -852,19 +822,18 @@ static void test_jwt_creds_success(void) { make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); auth_md_ctx.service_url = other_test_service_url; grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); gpr_free(json_key_string); gpr_free(expected_md_value); grpc_jwt_encode_and_sign_set_override(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void test_jwt_creds_signing_failure(void) { char* json_key_string = test_json_key_str(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* state = make_request_metadata_state( @@ -875,12 +844,11 @@ static void test_jwt_creds_signing_failure(void) { json_key_string, grpc_max_auth_token_lifetime(), nullptr); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state); + run_request_metadata_test(creds, auth_md_ctx, state); gpr_free(json_key_string); - grpc_call_credentials_unref(&exec_ctx, creds); + grpc_call_credentials_unref(creds); grpc_jwt_encode_and_sign_set_override(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static void set_google_default_creds_env_var_with_file_contents( @@ -897,7 +865,7 @@ static void set_google_default_creds_env_var_with_file_contents( } static void test_google_default_creds_auth_key(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_service_account_jwt_access_credentials* jwt; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); @@ -913,13 +881,12 @@ static void test_google_default_creds_auth_key(void) { strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(&exec_ctx); } static void test_google_default_creds_refresh_token(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_google_refresh_token_credentials* refresh; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); @@ -931,15 +898,13 @@ static void test_google_default_creds_refresh_token(void) { refresh = (grpc_google_refresh_token_credentials*)creds->call_creds; GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ - grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_success_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, ""); grpc_http_header* headers = static_cast<grpc_http_header*>(gpr_malloc(sizeof(*headers) * 1)); @@ -949,14 +914,14 @@ static int default_creds_gce_detection_httpcli_get_success_override( response->hdrs = headers; GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static char* null_well_known_creds_path_getter(void) { return nullptr; } static void test_google_default_creds_gce(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; expected_md emd[] = { {"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}}; request_metadata_state* state = @@ -981,8 +946,8 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(creds->call_creds != nullptr); grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - run_request_metadata_test(&exec_ctx, creds->call_creds, auth_md_ctx, state); - grpc_exec_ctx_flush(&exec_ctx); + run_request_metadata_test(creds->call_creds, auth_md_ctx, state); + grpc_core::ExecCtx::Get()->Flush(); /* Check that we get a cached creds if we call grpc_google_default_credentials_create again. @@ -994,22 +959,20 @@ static void test_google_default_creds_gce(void) { GPR_ASSERT(cached_creds == &creds->base); /* Cleanup. */ - grpc_channel_credentials_unref(&exec_ctx, cached_creds); - grpc_channel_credentials_unref(&exec_ctx, &creds->base); + grpc_channel_credentials_unref(cached_creds); + grpc_channel_credentials_unref(&creds->base); grpc_httpcli_set_override(nullptr, nullptr); grpc_override_well_known_credentials_path_getter(nullptr); - grpc_exec_ctx_finish(&exec_ctx); } static int default_creds_gce_detection_httpcli_get_failure_override( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { /* No magic header. */ GPR_ASSERT(strcmp(request->http.path, "/") == 0); GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0); *response = http_response(200, ""); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } @@ -1093,7 +1056,7 @@ static void plugin_destroy(void* state) { static void test_metadata_plugin_success(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; request_metadata_state* md_state = make_request_metadata_state( @@ -1106,17 +1069,17 @@ static void test_metadata_plugin_success(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); + run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_call_credentials_unref(creds); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } static void test_metadata_plugin_failure(void) { plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, nullptr, nullptr}; char* expected_error; @@ -1134,10 +1097,10 @@ static void test_metadata_plugin_failure(void) { grpc_call_credentials* creds = grpc_metadata_credentials_create_from_plugin(plugin, nullptr); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state); + run_request_metadata_test(creds, auth_md_ctx, md_state); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_call_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_call_credentials_unref(creds); + GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); } @@ -1158,7 +1121,7 @@ static void test_get_well_known_google_credentials_file_path(void) { } static void test_channel_creds_duplicate_without_call_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_credentials* channel_creds = grpc_fake_transport_security_credentials_create(); @@ -1167,23 +1130,21 @@ static void test_channel_creds_duplicate_without_call_creds(void) { grpc_channel_credentials_duplicate_without_call_credentials( channel_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(&exec_ctx, dup); + grpc_channel_credentials_unref(dup); grpc_call_credentials* call_creds = grpc_access_token_credentials_create("blah", nullptr); grpc_channel_credentials* composite_creds = grpc_composite_channel_credentials_create(channel_creds, call_creds, nullptr); - grpc_call_credentials_unref(&exec_ctx, call_creds); + grpc_call_credentials_unref(call_creds); dup = grpc_channel_credentials_duplicate_without_call_credentials( composite_creds); GPR_ASSERT(dup == channel_creds); - grpc_channel_credentials_unref(&exec_ctx, dup); - - grpc_channel_credentials_unref(&exec_ctx, channel_creds); - grpc_channel_credentials_unref(&exec_ctx, composite_creds); + grpc_channel_credentials_unref(dup); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_credentials_unref(channel_creds); + grpc_channel_credentials_unref(composite_creds); } typedef struct { diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc index 0b6ccd5e37..aac9cc0029 100644 --- a/test/core/security/json_token_test.cc +++ b/test/core/security/json_token_test.cc @@ -207,7 +207,7 @@ static void test_parse_json_key_failure_no_private_key(void) { static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, char** scratchpad) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; char* b64; char* decoded; grpc_json* json; @@ -215,7 +215,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, b64 = static_cast<char*>(gpr_malloc(len + 1)); strncpy(b64, str, len); b64[len] = '\0'; - slice = grpc_base64_decode(&exec_ctx, b64, 1); + slice = grpc_base64_decode(b64, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice)); decoded = static_cast<char*>(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); strncpy(decoded, (const char*)GRPC_SLICE_START_PTR(slice), @@ -225,7 +225,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len, gpr_free(b64); *scratchpad = decoded; grpc_slice_unref(slice); - grpc_exec_ctx_finish(&exec_ctx); + return json; } @@ -327,12 +327,12 @@ static void check_jwt_claim(grpc_json* claim, const char* expected_audience, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, const char* signed_data, size_t signed_data_size) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); EVP_PKEY* key = EVP_PKEY_new(); - grpc_slice sig = grpc_base64_decode(&exec_ctx, b64_signature, 1); + grpc_slice sig = grpc_base64_decode(b64_signature, 1); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); GPR_ASSERT(GRPC_SLICE_LENGTH(sig) == 128); @@ -347,11 +347,9 @@ static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, GPR_ASSERT(EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(sig), GRPC_SLICE_LENGTH(sig)) == 1); - grpc_slice_unref_internal(&exec_ctx, sig); + grpc_slice_unref_internal(sig); if (key != nullptr) EVP_PKEY_free(key); if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); - - grpc_exec_ctx_finish(&exec_ctx); } static char* service_account_creds_jwt_encode_and_sign( @@ -485,6 +483,7 @@ static void test_parse_refresh_token_failure_no_refresh_token(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_parse_json_key_success(); test_parse_json_key_failure_bad_json(); test_parse_json_key_failure_no_type(); @@ -499,5 +498,6 @@ int main(int argc, char** argv) { test_parse_refresh_token_failure_no_client_id(); test_parse_refresh_token_failure_no_client_secret(); test_parse_refresh_token_failure_no_refresh_token(); + grpc_shutdown(); return 0; } diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc index df0ebe5607..e219260b1d 100644 --- a/test/core/security/jwt_verifier_test.cc +++ b/test/core/security/jwt_verifier_test.cc @@ -209,8 +209,8 @@ static void test_claims_success(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -219,8 +219,7 @@ static void test_claims_success(void) { GPR_ASSERT(strcmp(grpc_jwt_claims_id(claims), "jwtuniqueid") == 0); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_OK); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_expired_claims_failure(void) { @@ -232,8 +231,8 @@ static void test_expired_claims_failure(void) { gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_json(claims) == json); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0); @@ -246,17 +245,15 @@ static void test_expired_claims_failure(void) { GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_invalid_claims_failure(void) { grpc_slice s = grpc_slice_from_copied_string(invalid_claims); grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_jwt_claims_from_json(&exec_ctx, json, s) == nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr); } static void test_bad_audience_claims_failure(void) { @@ -265,13 +262,12 @@ static void test_bad_audience_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") == GRPC_JWT_VERIFIER_BAD_AUDIENCE); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static void test_bad_subject_claims_failure(void) { @@ -280,13 +276,12 @@ static void test_bad_subject_claims_failure(void) { grpc_json* json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s)); GPR_ASSERT(json != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - claims = grpc_jwt_claims_from_json(&exec_ctx, json, s); + grpc_core::ExecCtx exec_ctx; + claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != nullptr); GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") == GRPC_JWT_VERIFIER_BAD_SUBJECT); - grpc_jwt_claims_destroy(&exec_ctx, claims); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_claims_destroy(claims); } static char* json_key_str(const char* last_part) { @@ -323,17 +318,16 @@ static grpc_httpcli_response http_response(int status, char* body) { } static int httpcli_post_should_not_be_called( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - const char* body_bytes, size_t body_size, grpc_millis deadline, - grpc_closure* on_done, grpc_httpcli_response* response) { + const grpc_httpcli_request* request, const char* body_bytes, + size_t body_size, grpc_millis deadline, grpc_closure* on_done, + grpc_httpcli_response* response) { GPR_ASSERT("HTTP POST should not be called" == nullptr); return 1; } static int httpcli_get_google_keys_for_email( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, good_google_email_keys()); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); @@ -341,22 +335,22 @@ static int httpcli_get_google_keys_for_email( "/robot/v1/metadata/x509/" "777-abaslkan11hlb6nmim3bpspl31ud@developer." "gserviceaccount.com") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } -static void on_verification_success(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_verification_success(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_OK); GPR_ASSERT(claims != nullptr); GPR_ASSERT(user_data == (void*)expected_user_data); GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), expected_audience) == 0); - grpc_jwt_claims_destroy(exec_ctx, claims); + grpc_jwt_claims_destroy(claims); } static void test_jwt_verifier_google_email_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -369,28 +363,27 @@ static void test_jwt_verifier_google_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static int httpcli_get_custom_keys_for_email( - grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request, - grpc_millis deadline, grpc_closure* on_done, - grpc_httpcli_response* response) { + const grpc_httpcli_request* request, grpc_millis deadline, + grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "keys.bar.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/jwk/foo@bar.com") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_custom_email_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -403,28 +396,26 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_jwk_set(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_jwk_set(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup(good_jwk_set)); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); GPR_ASSERT(strcmp(request->http.path, "/oauth2/v3/certs") == 0); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } -static int httpcli_get_openid_config(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_openid_config(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -434,12 +425,12 @@ static int httpcli_get_openid_config(grpc_exec_ctx* exec_ctx, GPR_ASSERT(strcmp(request->http.path, GRPC_OPENID_CONFIG_URL_SUFFIX) == 0); grpc_httpcli_set_override(httpcli_get_jwk_set, httpcli_post_should_not_be_called); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_success(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -452,16 +443,15 @@ static void test_jwt_verifier_url_issuer_success(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_success, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } -static void on_verification_key_retrieval_error(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_verification_key_retrieval_error(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR); @@ -469,18 +459,17 @@ static void on_verification_key_retrieval_error(grpc_exec_ctx* exec_ctx, GPR_ASSERT(user_data == (void*)expected_user_data); } -static int httpcli_get_bad_json(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_bad_json(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { *response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}")); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); - GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE); return 1; } static void test_jwt_verifier_url_issuer_bad_config(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -493,17 +482,17 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } static void test_jwt_verifier_bad_json_key(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -516,11 +505,11 @@ static void test_jwt_verifier_bad_json_key(void) { nullptr); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_key_retrieval_error, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(jwt); grpc_httpcli_set_override(nullptr, nullptr); } @@ -532,9 +521,8 @@ static void corrupt_jwt_sig(char* jwt) { char* last_dot = strrchr(jwt, '.'); GPR_ASSERT(last_dot != nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - sig = grpc_base64_decode(&exec_ctx, last_dot + 1, 1); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + sig = grpc_base64_decode(last_dot + 1, 1); } GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig)); sig_bytes = GRPC_SLICE_START_PTR(sig); @@ -546,8 +534,7 @@ static void corrupt_jwt_sig(char* jwt) { grpc_slice_unref(sig); } -static void on_verification_bad_signature(grpc_exec_ctx* exec_ctx, - void* user_data, +static void on_verification_bad_signature(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_SIGNATURE); @@ -556,7 +543,7 @@ static void on_verification_bad_signature(grpc_exec_ctx* exec_ctx, } static void test_jwt_verifier_bad_signature(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); char* jwt = nullptr; char* key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -570,17 +557,16 @@ static void test_jwt_verifier_bad_signature(void) { grpc_auth_json_key_destruct(&key); corrupt_jwt_sig(jwt); GPR_ASSERT(jwt != nullptr); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, jwt, expected_audience, + grpc_jwt_verifier_verify(verifier, nullptr, jwt, expected_audience, on_verification_bad_signature, (void*)expected_user_data); gpr_free(jwt); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); grpc_httpcli_set_override(nullptr, nullptr); } -static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, - const grpc_httpcli_request* request, +static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request, grpc_millis deadline, grpc_closure* on_done, grpc_httpcli_response* response) { @@ -588,7 +574,7 @@ static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx, return 1; } -static void on_verification_bad_format(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_verification_bad_format(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { GPR_ASSERT(status == GRPC_JWT_VERIFIER_BAD_FORMAT); @@ -597,15 +583,15 @@ static void on_verification_bad_format(grpc_exec_ctx* exec_ctx, void* user_data, } static void test_jwt_verifier_bad_format(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_jwt_verifier* verifier = grpc_jwt_verifier_create(nullptr, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_jwt_verifier_verify(&exec_ctx, verifier, nullptr, "bad jwt", - expected_audience, on_verification_bad_format, + grpc_jwt_verifier_verify(verifier, nullptr, "bad jwt", expected_audience, + on_verification_bad_format, (void*)expected_user_data); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + grpc_core::ExecCtx::Get()->Flush(); grpc_httpcli_set_override(nullptr, nullptr); } diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc index 602041eecc..0d3a1279af 100644 --- a/test/core/security/oauth2_utils.cc +++ b/test/core/security/oauth2_utils.cc @@ -39,8 +39,7 @@ typedef struct { grpc_closure closure; } oauth2_request; -static void on_oauth2_response(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_oauth2_response(void* arg, grpc_error* error) { oauth2_request* request = (oauth2_request*)arg; char* token = nullptr; grpc_slice token_slice; @@ -54,25 +53,23 @@ static void on_oauth2_response(grpc_exec_ctx* exec_ctx, void* arg, GRPC_SLICE_LENGTH(token_slice)); token[GRPC_SLICE_LENGTH(token_slice)] = '\0'; } - grpc_credentials_mdelem_array_destroy(exec_ctx, &request->md_array); + grpc_credentials_mdelem_array_destroy(&request->md_array); gpr_mu_lock(request->mu); request->is_done = true; request->token = token; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&request->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&request->pops), nullptr)); gpr_mu_unlock(request->mu); } -static void do_nothing(grpc_exec_ctx* exec_ctx, void* unused, - grpc_error* error) {} +static void do_nothing(void* unused, grpc_error* error) {} char* grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials* creds) { oauth2_request request; memset(&request, 0, sizeof(request)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr}; @@ -88,31 +85,30 @@ char* grpc_test_fetch_oauth2_token_with_credentials( grpc_schedule_on_exec_ctx); grpc_error* error = GRPC_ERROR_NONE; - if (grpc_call_credentials_get_request_metadata( - &exec_ctx, creds, &request.pops, null_ctx, &request.md_array, - &request.closure, &error)) { + if (grpc_call_credentials_get_request_metadata(creds, &request.pops, null_ctx, + &request.md_array, + &request.closure, &error)) { // Synchronous result; invoke callback directly. - on_oauth2_response(&exec_ctx, &request, error); + on_oauth2_response(&request, error); GRPC_ERROR_UNREF(error); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(request.mu); while (!request.is_done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, - grpc_polling_entity_pollset(&request.pops), + grpc_pollset_work(grpc_polling_entity_pollset(&request.pops), &worker, GRPC_MILLIS_INF_FUTURE))) { request.is_done = true; } } gpr_mu_unlock(request.mu); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&request.pops), + grpc_pollset_shutdown(grpc_polling_entity_pollset(&request.pops), &do_nothing_closure); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(grpc_polling_entity_pollset(&request.pops)); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index f4acf023bd..b3742f58a8 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -41,8 +41,7 @@ typedef struct { grpc_closure on_request_metadata; } synchronizer; -static void on_metadata_response(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_metadata_response(void* arg, grpc_error* error) { synchronizer* sync = static_cast<synchronizer*>(arg); if (error != GRPC_ERROR_NONE) { fprintf(stderr, "Fetching token failed: %s\n", grpc_error_string(error)); @@ -57,14 +56,13 @@ static void on_metadata_response(grpc_exec_ctx* exec_ctx, void* arg, sync->is_done = true; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&sync->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&sync->pops), nullptr)); gpr_mu_unlock(sync->mu); } int main(int argc, char** argv) { int result = 0; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; synchronizer sync; grpc_channel_credentials* creds = nullptr; const char* service_url = "https://test.foo.google.com/Foo"; @@ -97,11 +95,10 @@ int main(int argc, char** argv) { error = GRPC_ERROR_NONE; if (grpc_call_credentials_get_request_metadata( - &exec_ctx, ((grpc_composite_channel_credentials*)creds)->call_creds, - &sync.pops, context, &sync.md_array, &sync.on_request_metadata, - &error)) { + ((grpc_composite_channel_credentials*)creds)->call_creds, &sync.pops, + context, &sync.md_array, &sync.on_request_metadata, &error)) { // Synchronous response. Invoke callback directly. - on_metadata_response(&exec_ctx, &sync, error); + on_metadata_response(&sync, error); GRPC_ERROR_UNREF(error); } @@ -110,18 +107,15 @@ int main(int argc, char** argv) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, - grpc_polling_entity_pollset(&sync.pops), &worker, + grpc_pollset_work(grpc_polling_entity_pollset(&sync.pops), &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); - grpc_exec_ctx_finish(&exec_ctx); - grpc_channel_credentials_release(creds); gpr_free(grpc_polling_entity_pollset(&sync.pops)); diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc index a12af02479..38c78fed42 100644 --- a/test/core/security/secure_endpoint_test.cc +++ b/test/core/security/secure_endpoint_test.cc @@ -38,7 +38,7 @@ static grpc_pollset* g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, grpc_slice* leftover_slices, size_t leftover_nslices, bool use_zero_copy_protector) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; tsi_frame_protector* fake_read_protector = tsi_create_fake_frame_protector(nullptr); tsi_frame_protector* fake_write_protector = @@ -60,8 +60,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( a[0].value.integer = (int)slice_size; grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; tcp = grpc_iomgr_create_endpoint_pair("fixture", &args); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset); + grpc_endpoint_add_to_pollset(tcp.client, g_pollset); + grpc_endpoint_add_to_pollset(tcp.server, g_pollset); if (leftover_nslices == 0) { f.client_ep = grpc_secure_endpoint_create(fake_read_protector, @@ -117,7 +117,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( f.server_ep = grpc_secure_endpoint_create(fake_write_protector, fake_write_zero_copy_protector, tcp.server, nullptr, 0); - grpc_exec_ctx_finish(&exec_ctx); + return f; } @@ -165,65 +165,62 @@ static grpc_endpoint_test_config configs[] = { clean_up}, }; -static void inc_call_ctr(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - ++*(int*)arg; -} +static void inc_call_ctr(void* arg, grpc_error* error) { ++*(int*)arg; } static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_endpoint_test_fixture f = config.create_fixture(slice_size); grpc_slice_buffer incoming; grpc_slice s = grpc_slice_from_copied_string("hello world 12345678900987654321"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; int n = 0; grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); grpc_slice_buffer_init(&incoming); GRPC_CLOSURE_INIT(&done_closure, inc_call_ctr, &n, grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, &done_closure); - grpc_exec_ctx_finish(&exec_ctx); + grpc_endpoint_read(f.client_ep, &incoming, &done_closure); + + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); grpc_endpoint_shutdown( - &exec_ctx, f.client_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + f.client_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); grpc_endpoint_shutdown( - &exec_ctx, f.server_ep, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); - grpc_endpoint_destroy(&exec_ctx, f.client_ep); - grpc_endpoint_destroy(&exec_ctx, f.server_ep); - grpc_exec_ctx_finish(&exec_ctx); - grpc_slice_unref_internal(&exec_ctx, s); - grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); + f.server_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end")); + grpc_endpoint_destroy(f.client_ep); + grpc_endpoint_destroy(f.server_ep); + + grpc_slice_unref_internal(s); + grpc_slice_buffer_destroy_internal(&incoming); clean_up(); } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, (grpc_pollset*)p); +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy((grpc_pollset*)p); } int main(int argc, char** argv) { grpc_closure destroyed; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); - grpc_init(); - g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(g_pollset, &g_mu); - grpc_endpoint_tests(configs[0], g_pollset, g_mu); - grpc_endpoint_tests(configs[1], g_pollset, g_mu); - test_leftover(configs[2], 1); - test_leftover(configs[3], 1); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); - grpc_exec_ctx_finish(&exec_ctx); + + { + grpc_core::ExecCtx exec_ctx; + g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + grpc_endpoint_tests(configs[1], g_pollset, g_mu); + test_leftover(configs[2], 1); + test_leftover(configs[3], 1); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + } + grpc_shutdown(); gpr_free(g_pollset); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index d83ebb18d2..6e30698562 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -40,8 +40,7 @@ struct handshake_state { bool done_callback_called; }; -static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshaker_args* args = static_cast<grpc_handshaker_args*>(arg); struct handshake_state* state = static_cast<struct handshake_state*>(args->user_data); @@ -56,67 +55,70 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("ssl_server_fuzzer"); - grpc_endpoint* mock_endpoint = - grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - - grpc_mock_endpoint_put_read( - &exec_ctx, mock_endpoint, - grpc_slice_from_copied_buffer((const char*)data, size)); - - // Load key pair and establish server SSL credentials. - grpc_ssl_pem_key_cert_pair pem_key_cert_pair; - grpc_slice ca_slice, cert_slice, key_slice; - ca_slice = grpc_slice_from_static_string(test_root_cert); - cert_slice = grpc_slice_from_static_string(test_server1_cert); - key_slice = grpc_slice_from_static_string(test_server1_key); - const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); - pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice); - pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice); - grpc_server_credentials* creds = grpc_ssl_server_credentials_create( - ca_cert, &pem_key_cert_pair, 1, 0, nullptr); - - // Create security connector - grpc_server_security_connector* sc = nullptr; - grpc_security_status status = - grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); - GPR_ASSERT(status == GRPC_SECURITY_OK); - grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(&exec_ctx); - - struct handshake_state state; - state.done_callback_called = false; - grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); - grpc_server_security_connector_add_handshakers(&exec_ctx, sc, handshake_mgr); - grpc_handshake_manager_do_handshake( - &exec_ctx, handshake_mgr, nullptr /* interested_parties */, mock_endpoint, - nullptr /* channel_args */, deadline, nullptr /* acceptor */, - on_handshake_done, &state); - grpc_exec_ctx_flush(&exec_ctx); - - // If the given string happens to be part of the correct client hello, the - // server will wait for more data. Explicitly fail the server by shutting down - // the endpoint. - if (!state.done_callback_called) { - grpc_endpoint_shutdown( - &exec_ctx, mock_endpoint, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); - grpc_exec_ctx_flush(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("ssl_server_fuzzer"); + grpc_endpoint* mock_endpoint = + grpc_mock_endpoint_create(discard_write, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); + + grpc_mock_endpoint_put_read( + mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size)); + + // Load key pair and establish server SSL credentials. + grpc_ssl_pem_key_cert_pair pem_key_cert_pair; + grpc_slice ca_slice, cert_slice, key_slice; + ca_slice = grpc_slice_from_static_string(test_root_cert); + cert_slice = grpc_slice_from_static_string(test_server1_cert); + key_slice = grpc_slice_from_static_string(test_server1_key); + const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice); + pem_key_cert_pair.private_key = + (const char*)GRPC_SLICE_START_PTR(key_slice); + pem_key_cert_pair.cert_chain = + (const char*)GRPC_SLICE_START_PTR(cert_slice); + grpc_server_credentials* creds = grpc_ssl_server_credentials_create( + ca_cert, &pem_key_cert_pair, 1, 0, nullptr); + + // Create security connector + grpc_server_security_connector* sc = nullptr; + grpc_security_status status = + grpc_server_credentials_create_security_connector(creds, &sc); + GPR_ASSERT(status == GRPC_SECURITY_OK); + grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now(); + + struct handshake_state state; + state.done_callback_called = false; + grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); + grpc_server_security_connector_add_handshakers(sc, handshake_mgr); + grpc_handshake_manager_do_handshake( + handshake_mgr, nullptr /* interested_parties */, mock_endpoint, + nullptr /* channel_args */, deadline, nullptr /* acceptor */, + on_handshake_done, &state); + grpc_core::ExecCtx::Get()->Flush(); + + // If the given string happens to be part of the correct client hello, the + // server will wait for more data. Explicitly fail the server by shutting + // down the endpoint. + if (!state.done_callback_called) { + grpc_endpoint_shutdown( + mock_endpoint, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close")); + grpc_core::ExecCtx::Get()->Flush(); + } + + GPR_ASSERT(state.done_callback_called); + + grpc_handshake_manager_destroy(handshake_mgr); + GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test"); + grpc_server_credentials_release(creds); + grpc_slice_unref(cert_slice); + grpc_slice_unref(key_slice); + grpc_slice_unref(ca_slice); + grpc_core::ExecCtx::Get()->Flush(); } - GPR_ASSERT(state.done_callback_called); - - grpc_handshake_manager_destroy(&exec_ctx, handshake_mgr); - GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "test"); - grpc_server_credentials_release(creds); - grpc_slice_unref(cert_slice); - grpc_slice_unref(key_slice); - grpc_slice_unref(ca_slice); - grpc_exec_ctx_flush(&exec_ctx); - grpc_shutdown(); if (leak_check) { counters = grpc_memory_counters_snapshot(); diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index 787d58bc37..e039970c67 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -44,7 +44,7 @@ static void print_usage_and_exit(gpr_cmdline* cl, const char* argv0) { exit(1); } -static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, +static void on_jwt_verification_done(void* user_data, grpc_jwt_verifier_status status, grpc_jwt_claims* claims) { synchronizer* sync = static_cast<synchronizer*>(user_data); @@ -57,7 +57,7 @@ static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, grpc_json_dump_to_string((grpc_json*)grpc_jwt_claims_json(claims), 2); printf("Claims: \n\n%s\n", claims_str); gpr_free(claims_str); - grpc_jwt_claims_destroy(exec_ctx, claims); + grpc_jwt_claims_destroy(claims); } else { GPR_ASSERT(claims == nullptr); fprintf(stderr, "Verification failed with error %s\n", @@ -66,8 +66,7 @@ static void on_jwt_verification_done(grpc_exec_ctx* exec_ctx, void* user_data, gpr_mu_lock(sync->mu); sync->is_done = 1; - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, sync->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(sync->pollset, nullptr)); gpr_mu_unlock(sync->mu); } @@ -77,7 +76,7 @@ int main(int argc, char** argv) { gpr_cmdline* cl; const char* jwt = nullptr; const char* aud = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_init(); cl = gpr_cmdline_create("JWT verifier tool"); @@ -96,26 +95,26 @@ int main(int argc, char** argv) { grpc_pollset_init(sync.pollset, &sync.mu); sync.is_done = 0; - grpc_jwt_verifier_verify(&exec_ctx, verifier, sync.pollset, jwt, aud, + grpc_jwt_verifier_verify(verifier, sync.pollset, jwt, aud, on_jwt_verification_done, &sync); gpr_mu_lock(sync.mu); while (!sync.is_done) { grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR("pollset_work", - grpc_pollset_work(&exec_ctx, sync.pollset, &worker, - GRPC_MILLIS_INF_FUTURE))) + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work(sync.pollset, &worker, GRPC_MILLIS_INF_FUTURE))) sync.is_done = true; gpr_mu_unlock(sync.mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(sync.mu); } gpr_mu_unlock(sync.mu); gpr_free(sync.pollset); - grpc_jwt_verifier_destroy(&exec_ctx, verifier); - grpc_exec_ctx_finish(&exec_ctx); + grpc_jwt_verifier_destroy(verifier); + gpr_cmdline_destroy(cl); grpc_shutdown(); return !sync.success; diff --git a/test/core/slice/b64_test.cc b/test/core/slice/b64_test.cc index 479198f9f9..94785fd1e2 100644 --- a/test/core/slice/b64_test.cc +++ b/test/core/slice/b64_test.cc @@ -20,6 +20,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/slice.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -44,14 +45,14 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char* hello = "hello"; char* hello_b64 = grpc_base64_encode(hello, strlen(hello), url_safe, multiline); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice hello_slice = grpc_base64_decode(&exec_ctx, hello_b64, url_safe); + grpc_core::ExecCtx exec_ctx; + grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello)); GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello, GRPC_SLICE_LENGTH(hello_slice)) == 0); - grpc_slice_unref_internal(&exec_ctx, hello_slice); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(hello_slice); + gpr_free(hello_b64); } @@ -64,15 +65,14 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { /* Try all the different paddings. */ for (i = 0; i < 3; i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); + orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i)); GPR_ASSERT(buffers_are_equal(orig, GRPC_SLICE_START_PTR(orig_decoded), sizeof(orig) - i)); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); + grpc_slice_unref_internal(orig_decoded); gpr_free(b64); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -116,19 +116,18 @@ static void test_url_safe_unsafe_mismatch_failure(void) { int url_safe = 1; for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, !url_safe); + orig_decoded = grpc_base64_decode(b64, !url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); + grpc_slice_unref_internal(orig_decoded); b64 = grpc_base64_encode(orig, sizeof(orig), !url_safe, 0); - orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe); + orig_decoded = grpc_base64_decode(b64, url_safe); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded)); gpr_free(b64); - grpc_slice_unref_internal(&exec_ctx, orig_decoded); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_unref_internal(orig_decoded); } static void test_rfc4648_test_vectors(void) { @@ -166,44 +165,44 @@ static void test_rfc4648_test_vectors(void) { static void test_unpadded_decode(void) { grpc_slice decoded; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmFy", 0); + grpc_core::ExecCtx exec_ctx; + decoded = grpc_base64_decode("Zm9vYmFy", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmE", 0); + decoded = grpc_base64_decode("Zm9vYmE", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fooba") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9vYg", 0); + decoded = grpc_base64_decode("Zm9vYg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foob") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm9v", 0); + decoded = grpc_base64_decode("Zm9v", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "foo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zm8", 0); + decoded = grpc_base64_decode("Zm8", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "fo") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "Zg", 0); + decoded = grpc_base64_decode("Zg", 0); GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded)); GPR_ASSERT(grpc_slice_str_cmp(decoded, "f") == 0); grpc_slice_unref(decoded); - decoded = grpc_base64_decode(&exec_ctx, "", 0); + decoded = grpc_base64_decode("", 0); GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded)); - grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_simple_encode_decode_b64_no_multiline(); test_simple_encode_decode_b64_multiline(); test_simple_encode_decode_b64_urlsafe_no_multiline(); @@ -215,5 +214,6 @@ int main(int argc, char** argv) { test_url_safe_unsafe_mismatch_failure(); test_rfc4648_test_vectors(); test_unpadded_decode(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/percent_decode_fuzzer.cc b/test/core/slice/percent_decode_fuzzer.cc index 3603177c47..81eb031014 100644 --- a/test/core/slice/percent_decode_fuzzer.cc +++ b/test/core/slice/percent_decode_fuzzer.cc @@ -20,6 +20,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -31,6 +32,7 @@ bool leak_check = true; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { struct grpc_memory_counters counters; + grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output; @@ -46,6 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_slice_unref(input); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); + grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); return 0; } diff --git a/test/core/slice/percent_encode_fuzzer.cc b/test/core/slice/percent_encode_fuzzer.cc index c8e3849fc8..201ae2790e 100644 --- a/test/core/slice/percent_encode_fuzzer.cc +++ b/test/core/slice/percent_encode_fuzzer.cc @@ -20,6 +20,7 @@ #include <stdint.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -31,6 +32,7 @@ bool leak_check = true; static void test(const uint8_t* data, size_t size, const uint8_t* dict) { struct grpc_memory_counters counters; + grpc_init(); grpc_memory_counters_init(); grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size); grpc_slice output = grpc_percent_encode_slice(input, dict); @@ -48,6 +50,7 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) { grpc_slice_unref(permissive_decoded_output); counters = grpc_memory_counters_snapshot(); grpc_memory_counters_destroy(); + grpc_shutdown(); GPR_ASSERT(counters.total_size_relative == 0); } diff --git a/test/core/slice/percent_encoding_test.cc b/test/core/slice/percent_encoding_test.cc index 253240faad..11f3995f98 100644 --- a/test/core/slice/percent_encoding_test.cc +++ b/test/core/slice/percent_encoding_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/slice/percent_encoding.h" +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -118,6 +119,7 @@ static void test_nonconformant_vector(const char* encoded, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); TEST_VECTOR( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", @@ -140,5 +142,6 @@ int main(int argc, char** argv) { grpc_url_percent_encoding_unreserved_bytes); TEST_NONCONFORMANT_VECTOR("\0", "\0", grpc_url_percent_encoding_unreserved_bytes); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_buffer_test.cc b/test/core/slice/slice_buffer_test.cc index 338e8079dc..e59986730b 100644 --- a/test/core/slice/slice_buffer_test.cc +++ b/test/core/slice/slice_buffer_test.cc @@ -16,6 +16,7 @@ * */ +#include <grpc/grpc.h> #include <grpc/slice_buffer.h> #include <grpc/support/log.h> #include "test/core/util/test_config.h" @@ -106,9 +107,11 @@ void test_slice_buffer_move_first() { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_slice_buffer_add(); test_slice_buffer_move_first(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc index 0ee4e8617d..9fad9a614e 100644 --- a/test/core/slice/slice_hash_table_test.cc +++ b/test/core/slice/slice_hash_table_test.cc @@ -59,9 +59,7 @@ static void check_non_existent_value(const char* key_string, grpc_slice_unref(key); } -static void destroy_string(grpc_exec_ctx* exec_ctx, void* value) { - gpr_free(value); -} +static void destroy_string(void* value) { gpr_free(value); } static grpc_slice_hash_table* create_table_from_entries( const test_entry* test_entries, size_t num_test_entries, @@ -121,9 +119,8 @@ static void test_slice_hash_table() { check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); // Clean up. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table); } static int value_cmp_fn(void* a, void* b) { @@ -149,10 +146,9 @@ static void test_slice_hash_table_eq() { create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table_a); - grpc_slice_hash_table_unref(&exec_ctx, table_b); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table_a); + grpc_slice_hash_table_unref(table_b); } static void test_slice_hash_table_not_eq() { @@ -221,23 +217,24 @@ static void test_slice_hash_table_not_eq() { create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn); GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_hash_table_unref(&exec_ctx, table_a); - grpc_slice_hash_table_unref(&exec_ctx, table_b_larger); - grpc_slice_hash_table_unref(&exec_ctx, table_b_smaller); - grpc_slice_hash_table_unref(&exec_ctx, table_c); - grpc_slice_hash_table_unref(&exec_ctx, table_d); - grpc_slice_hash_table_unref(&exec_ctx, table_e); - grpc_slice_hash_table_unref(&exec_ctx, table_f); - grpc_slice_hash_table_unref(&exec_ctx, table_g); - grpc_slice_hash_table_unref(&exec_ctx, table_h); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_slice_hash_table_unref(table_a); + grpc_slice_hash_table_unref(table_b_larger); + grpc_slice_hash_table_unref(table_b_smaller); + grpc_slice_hash_table_unref(table_c); + grpc_slice_hash_table_unref(table_d); + grpc_slice_hash_table_unref(table_e); + grpc_slice_hash_table_unref(table_f); + grpc_slice_hash_table_unref(table_g); + grpc_slice_hash_table_unref(table_h); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_core::ExecCtx::GlobalInit(); test_slice_hash_table(); test_slice_hash_table_eq(); test_slice_hash_table_not_eq(); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/slice/slice_string_helpers_test.cc b/test/core/slice/slice_string_helpers_test.cc index 260f8c80d5..f1d470461a 100644 --- a/test/core/slice/slice_string_helpers_test.cc +++ b/test/core/slice/slice_string_helpers_test.cc @@ -23,6 +23,7 @@ #include <stdlib.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> @@ -130,7 +131,9 @@ static void test_strsplit(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_dump_slice(); test_strsplit(); + grpc_shutdown(); return 0; } diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index 02f6b1ea79..e40154dd0e 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -292,6 +292,7 @@ static void test_static_slice_copy_interning(void) { int main(int argc, char** argv) { unsigned length; grpc_test_init(argc, argv); + grpc_init(); test_slice_malloc_returns_something_sensible(); test_slice_new_returns_something_sensible(); test_slice_new_with_user_data(); @@ -305,5 +306,6 @@ int main(int argc, char** argv) { test_slice_interning(); test_static_slice_interning(); test_static_slice_copy_interning(); + grpc_shutdown(); return 0; } diff --git a/test/core/support/arena_test.cc b/test/core/support/arena_test.cc index 244d860639..ada0f43854 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], "grpc_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..6e04feedaa 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/support/cpu_test.cc @@ -110,7 +110,8 @@ 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, "grpc_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..1b83f7d5be 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], "grpc_mt_test", 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], "grpc_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], "grpc_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..58d5fcd42b 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], "grpc_create_threads", body, m, &opt)); } } diff --git a/test/core/support/sync_test.cc b/test/core/support/sync_test.cc index 86e78ce0b5..3f534de820 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, "grpc_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..b755bf18f3 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, "grpc_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], "grpc_joinable_thread_test", + &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..743b10f090 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], "grpc_tls_test", thd_body, nullptr, &opt); } for (i = 0; i < NUM_THREADS; i++) { gpr_thd_join(threads[i]); diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index e5d2d7c78d..94a8615b3c 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -132,10 +132,8 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, memset(GRPC_SLICE_START_PTR(input_slice), 'a', input_size); grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT( - grpc_msg_compress(&exec_ctx, algorithm, &sliceb_in, &sliceb_out)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_msg_compress(algorithm, &sliceb_in, &sliceb_out)); } buffer = grpc_raw_compressed_byte_buffer_create(sliceb_out.slices, @@ -267,6 +265,7 @@ static void test_byte_buffer_copy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_read_one_slice(); test_read_one_slice_malloc(); test_read_none_compressed_slice(); @@ -276,5 +275,6 @@ int main(int argc, char** argv) { test_byte_buffer_from_reader(); test_byte_buffer_copy(); test_readall(); + grpc_shutdown(); return 0; } diff --git a/test/core/surface/channel_create_test.cc b/test/core/surface/channel_create_test.cc index f358b0fc8d..37247f89d0 100644 --- a/test/core/surface/channel_create_test.cc +++ b/test/core/surface/channel_create_test.cc @@ -35,11 +35,10 @@ void test_unknown_scheme_target(void) { chan = grpc_insecure_channel_create("blah://blah", nullptr, nullptr); GPR_ASSERT(chan != nullptr); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx_finish(&exec_ctx); grpc_channel_destroy(chan); } diff --git a/test/core/surface/completion_queue_test.cc b/test/core/surface/completion_queue_test.cc index c6e13d2386..fefbb3c185 100644 --- a/test/core/surface/completion_queue_test.cc +++ b/test/core/surface/completion_queue_test.cc @@ -121,8 +121,7 @@ static void test_wait_empty(void) { } } -static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* c) {} +static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} static void test_cq_end_op(void) { grpc_event ev; @@ -131,8 +130,6 @@ static void test_cq_end_op(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); LOG_TEST("test_cq_end_op"); @@ -140,14 +137,14 @@ static void test_cq_end_op(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completion); + grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, + &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -156,7 +153,6 @@ static void test_cq_end_op(void) { GPR_ASSERT(ev.success); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -167,8 +163,6 @@ static void test_cq_tls_cache_full(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* tag = create_test_tag(); void* res_tag; int ok; @@ -178,15 +172,15 @@ static void test_cq_tls_cache_full(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); grpc_completion_queue_thread_local_cache_init(cc); GPR_ASSERT(grpc_cq_begin_op(cc, tag)); - grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completion); + grpc_cq_end_op(cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion, nullptr, + &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); @@ -202,7 +196,6 @@ static void test_cq_tls_cache_full(void) { GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -211,8 +204,6 @@ static void test_cq_tls_cache_empty(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; void* res_tag; int ok; @@ -221,7 +212,7 @@ static void test_cq_tls_cache_empty(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; for (size_t i = 0; i < GPR_ARRAY_SIZE(polling_types); i++) { - exec_ctx = init_exec_ctx; // Reset exec_ctx + grpc_core::ExecCtx exec_ctx; // Reset exec_ctx attr.cq_polling_type = polling_types[i]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); @@ -232,7 +223,6 @@ static void test_cq_tls_cache_empty(void) { GPR_ASSERT( grpc_completion_queue_thread_local_cache_flush(cc, &res_tag, &ok) == 0); shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } @@ -289,8 +279,6 @@ static void test_pluck(void) { grpc_cq_polling_type polling_types[] = { GRPC_CQ_DEFAULT_POLLING, GRPC_CQ_NON_LISTENING, GRPC_CQ_NON_POLLING}; grpc_completion_queue_attributes attr; - grpc_exec_ctx init_exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_exec_ctx exec_ctx; unsigned i, j; LOG_TEST("test_pluck"); @@ -305,15 +293,15 @@ static void test_pluck(void) { attr.version = 1; attr.cq_completion_type = GRPC_CQ_PLUCK; for (size_t pidx = 0; pidx < GPR_ARRAY_SIZE(polling_types); pidx++) { - exec_ctx = init_exec_ctx; // reset exec_ctx + grpc_core::ExecCtx exec_ctx; // reset exec_ctx attr.cq_polling_type = polling_types[pidx]; cc = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -324,8 +312,8 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -336,7 +324,6 @@ static void test_pluck(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index af54e00c4a..4a9e818b45 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -59,8 +59,7 @@ static void shutdown_and_destroy(grpc_completion_queue* cc) { grpc_completion_queue_destroy(cc); } -static void do_nothing_end_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* c) {} +static void do_nothing_end_completion(void* arg, grpc_cq_completion* c) {} struct thread_state { grpc_completion_queue* cc; @@ -81,7 +80,7 @@ static void test_too_many_plucks(void) { gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)]; struct thread_state thread_states[GPR_ARRAY_SIZE(tags)]; gpr_thd_options thread_options = gpr_thd_options_default(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); @@ -96,7 +95,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, "grpc_pluck_test", pluck_one, thread_states + i, + &thread_options); } /* wait until all other threads are plucking */ @@ -108,8 +108,8 @@ static void test_too_many_plucks(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { GPR_ASSERT(grpc_cq_begin_op(cc, tags[i])); - grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE, - do_nothing_end_completion, nullptr, &completions[i]); + grpc_cq_end_op(cc, tags[i], GRPC_ERROR_NONE, do_nothing_end_completion, + nullptr, &completions[i]); } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { @@ -117,7 +117,6 @@ static void test_too_many_plucks(void) { } shutdown_and_destroy(cc); - grpc_exec_ctx_finish(&exec_ctx); } #define TEST_THREAD_EVENTS 10000 @@ -137,15 +136,13 @@ gpr_timespec ten_seconds_time(void) { return grpc_timeout_seconds_to_deadline(10); } -static void free_completion(grpc_exec_ctx* exec_ctx, void* arg, - grpc_cq_completion* completion) { +static void free_completion(void* arg, grpc_cq_completion* completion) { gpr_free(completion); } static void producer_thread(void* arg) { test_thread_options* opt = static_cast<test_thread_options*>(arg); int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "producer %d started", opt->id); gpr_event_set(&opt->on_started, (void*)(intptr_t)1); @@ -162,17 +159,16 @@ static void producer_thread(void* arg) { gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { - grpc_cq_end_op(&exec_ctx, opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, + grpc_core::ExecCtx exec_ctx; + grpc_cq_end_op(opt->cc, (void*)(intptr_t)1, GRPC_ERROR_NONE, free_completion, nullptr, static_cast<grpc_cq_completion*>( gpr_malloc(sizeof(grpc_cq_completion)))); opt->events_triggered++; - grpc_exec_ctx_finish(&exec_ctx); } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); gpr_event_set(&opt->on_finished, (void*)(intptr_t)1); - grpc_exec_ctx_finish(&exec_ctx); } static void consumer_thread(void* arg) { @@ -234,6 +230,7 @@ static void test_threading(size_t producers, size_t consumers) { 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)); 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 c7611b0dd1..235d136376 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -103,29 +103,28 @@ void server_thread(void* vargs) { GPR_ASSERT(detag(ev.tag) == 0xd1e); } -static void on_connect(grpc_exec_ctx* exec_ctx, void* vargs, grpc_endpoint* tcp, +static void on_connect(void* vargs, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); gpr_mu_lock(args->mu); - GRPC_LOG_IF_ERROR("pollset_kick", - grpc_pollset_kick(exec_ctx, args->pollset, nullptr)); + GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, nullptr)); gpr_mu_unlock(args->mu); } void bad_server_thread(void* vargs) { struct server_thread_args* args = (struct server_thread_args*)vargs; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; int port; grpc_tcp_server* s; - grpc_error* error = grpc_tcp_server_create(&exec_ctx, nullptr, nullptr, &s); + grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); GPR_ASSERT(error == GRPC_ERROR_NONE); memset(&resolved_addr, 0, sizeof(resolved_addr)); addr->ss_family = AF_INET; @@ -134,35 +133,32 @@ void bad_server_thread(void* vargs) { GPR_ASSERT(port > 0); gpr_asprintf(&args->addr, "localhost:%d", port); - grpc_tcp_server_start(&exec_ctx, s, &args->pollset, 1, on_connect, args); + grpc_tcp_server_start(s, &args->pollset, 1, on_connect, args); gpr_event_set(&args->ready, (void*)1); gpr_mu_lock(args->mu); while (gpr_atm_acq_load(&args->stop) == 0) { - grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 100; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 100; grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, args->pollset, &worker, deadline))) { + grpc_pollset_work(args->pollset, &worker, deadline))) { gpr_atm_rel_store(&args->stop, 1); } gpr_mu_unlock(args->mu); - grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(args->mu); } gpr_mu_unlock(args->mu); - grpc_tcp_server_unref(&exec_ctx, s); - - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_unref(s); gpr_free(args->addr); } -static void done_pollset_shutdown(grpc_exec_ctx* exec_ctx, void* pollset, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(pollset)); +static void done_pollset_shutdown(void* pollset, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(pollset)); gpr_free(pollset); } @@ -182,7 +178,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], "grpc_wave_1", create_loop_destroy, localhost, + &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); @@ -198,10 +195,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, "grpc_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], "grpc_wave_2", create_loop_destroy, args.addr, + &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); @@ -218,11 +216,13 @@ 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, "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], create_loop_destroy, args.addr, &options); + 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]); @@ -230,11 +230,12 @@ int run_concurrent_connectivity_test() { gpr_atm_rel_store(&args.stop, 1); gpr_thd_join(server); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_shutdown(&exec_ctx, args.pollset, - GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, - grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); + { + 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(); return 0; @@ -280,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], "grpc_short_watches", 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/lame_client_test.cc b/test/core/surface/lame_client_test.cc index f3df7f35a7..4bf40569e6 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -32,20 +32,19 @@ grpc_closure transport_op_cb; static void* tag(intptr_t x) { return (void*)x; } -void verify_connectivity(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +void verify_connectivity(void* arg, grpc_error* error) { grpc_connectivity_state* state = static_cast<grpc_connectivity_state*>(arg); GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *state); GPR_ASSERT(error == GRPC_ERROR_NONE); } -void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +void do_nothing(void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { grpc_transport_op* op; grpc_channel_element* elem; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, grpc_schedule_on_exec_ctx); @@ -54,14 +53,12 @@ void test_transport_op(grpc_channel* channel) { op->on_connectivity_state_change = &transport_op_cb; op->connectivity_state = &state; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); - elem->filter->start_transport_op(&exec_ctx, elem, op); - grpc_exec_ctx_finish(&exec_ctx); + elem->filter->start_transport_op(elem, op); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); op = grpc_make_transport_op(&transport_op_cb); - elem->filter->start_transport_op(&exec_ctx, elem, op); - grpc_exec_ctx_finish(&exec_ctx); + elem->filter->start_transport_op(elem, op); } int main(int argc, char** argv) { diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index f78d333673..9cdd299ae3 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -178,9 +178,8 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/surface/secure_channel_create_test.cc b/test/core/surface/secure_channel_create_test.cc index c31c61430c..fa22cd6873 100644 --- a/test/core/surface/secure_channel_create_test.cc +++ b/test/core/surface/secure_channel_create_test.cc @@ -37,10 +37,9 @@ void test_unknown_scheme_target(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_channel_credentials_unref(&exec_ctx, creds); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); + grpc_channel_credentials_unref(creds); } void test_security_connector_already_in_arg(void) { @@ -56,9 +55,8 @@ void test_security_connector_already_in_arg(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } void test_null_creds(void) { @@ -67,9 +65,8 @@ void test_null_creds(void) { grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + GRPC_CHANNEL_INTERNAL_UNREF(chan, "test"); } int main(int argc, char** argv) { diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 015db92cb0..ac49bd9823 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -70,7 +70,7 @@ 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, "grpc_server", server_thread_func, &sta, &thdopt); grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channels[NUM_CONNECTIONS]; @@ -156,9 +156,8 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel* channel = grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } grpc_channel_credentials_release(ssl_creds); return channel; diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index d1272607f2..445823b628 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -58,7 +58,7 @@ namespace { void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { estimator->AddIncomingBytes(1234567); inc_time(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; estimator->SchedulePing(); estimator->StartPing(); for (size_t i = 0; i < n; i++) { @@ -66,9 +66,8 @@ void AddSamples(BdpEstimator* estimator, int64_t* samples, size_t n) { } gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(1, GPR_TIMESPAN))); - grpc_exec_ctx_invalidate_now(&exec_ctx); - estimator->CompletePing(&exec_ctx); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->InvalidateNow(); + estimator->CompletePing(); } void AddSample(BdpEstimator* estimator, int64_t sample) { diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 0e34fd7651..2aab6e9262 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/transport/byte_stream.h" +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> @@ -30,14 +31,13 @@ // grpc_slice_buffer_stream tests // -static void not_called_closure(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void not_called_closure(void* arg, grpc_error* error) { GPR_ASSERT(false); } static void test_slice_buffer_stream_basic(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_basic"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -57,23 +57,21 @@ static void test_slice_buffer_stream_basic(void) { grpc_schedule_on_exec_ctx); // Read each slice. Note that next() always returns synchronously. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_slice_buffer_stream_shutdown(void) { gpr_log(GPR_DEBUG, "test_slice_buffer_stream_shutdown"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -92,29 +90,25 @@ static void test_slice_buffer_stream_shutdown(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read the first slice. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Now shutdown. grpc_error* shutdown_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown error"); - grpc_byte_stream_shutdown(&exec_ctx, &stream.base, - GRPC_ERROR_REF(shutdown_error)); + grpc_byte_stream_shutdown(&stream.base, GRPC_ERROR_REF(shutdown_error)); // After shutdown, the next pull() should return the error. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == shutdown_error); GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(shutdown_error); // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_slice_buffer_destroy_internal(&buffer); } // @@ -123,7 +117,7 @@ static void test_slice_buffer_stream_shutdown(void) { static void test_caching_byte_stream_basic(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_basic"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -147,24 +141,22 @@ static void test_caching_byte_stream_basic(void) { // Read each slice. Note that next() always returns synchronously, // because the underlying byte stream always does. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_caching_byte_stream_reset(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_reset"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -186,34 +178,31 @@ static void test_caching_byte_stream_reset(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Reset the caching stream. The reads should start over from the // first slice. grpc_caching_byte_stream_reset(&stream); for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } static void test_caching_byte_stream_shared_cache(void) { gpr_log(GPR_DEBUG, "test_caching_byte_stream_shared_cache"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; // Create and populate slice buffer byte stream. grpc_slice_buffer buffer; grpc_slice_buffer_init(&buffer); @@ -237,43 +226,41 @@ static void test_caching_byte_stream_shared_cache(void) { GRPC_CLOSURE_INIT(&closure, not_called_closure, nullptr, grpc_schedule_on_exec_ctx); // Read one slice from stream1. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); + GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); grpc_slice output; - grpc_error* error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); + grpc_error* error = grpc_byte_stream_pull(&stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[0], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Read all slices from stream2. for (size_t i = 0; i < GPR_ARRAY_SIZE(input); ++i) { - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream2.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream2.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream2.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream2.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[i], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); } // Now read the second slice from stream1. - GPR_ASSERT( - grpc_byte_stream_next(&exec_ctx, &stream1.base, ~(size_t)0, &closure)); - error = grpc_byte_stream_pull(&exec_ctx, &stream1.base, &output); + GPR_ASSERT(grpc_byte_stream_next(&stream1.base, ~(size_t)0, &closure)); + error = grpc_byte_stream_pull(&stream1.base, &output); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(grpc_slice_eq(input[1], output)); - grpc_slice_unref_internal(&exec_ctx, output); + grpc_slice_unref_internal(output); // Clean up. - grpc_byte_stream_destroy(&exec_ctx, &stream1.base); - grpc_byte_stream_destroy(&exec_ctx, &stream2.base); - grpc_byte_stream_cache_destroy(&exec_ctx, &cache); - grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_byte_stream_destroy(&stream1.base); + grpc_byte_stream_destroy(&stream2.base); + grpc_byte_stream_cache_destroy(&cache); + grpc_slice_buffer_destroy_internal(&buffer); } int main(int argc, char** argv) { + grpc_init(); grpc_test_init(argc, argv); test_slice_buffer_stream_basic(); test_slice_buffer_stream_shutdown(); test_caching_byte_stream_basic(); test_caching_byte_stream_reset(); test_caching_byte_stream_shared_cache(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index a29ec8a13f..6d70a4261b 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -20,6 +20,7 @@ #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" @@ -29,8 +30,8 @@ static int all_ok = 1; -static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected, - grpc_slice slice, const char* debug, int line) { +static void expect_slice_eq(grpc_slice expected, grpc_slice slice, + const char* debug, int line) { if (!grpc_slice_eq(slice, expected)) { char* hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char* he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -40,104 +41,97 @@ static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected, gpr_free(he); all_ok = 0; } - grpc_slice_unref_internal(exec_ctx, expected); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(expected); + grpc_slice_unref_internal(slice); } -static grpc_slice base64_encode(grpc_exec_ctx* exec_ctx, const char* s) { +static grpc_slice base64_encode(const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); grpc_slice out = grpc_chttp2_base64_encode(ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode(grpc_exec_ctx* exec_ctx, const char* s) { +static grpc_slice base64_decode(const char* s) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = grpc_chttp2_base64_decode(exec_ctx, ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode(ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode_with_length(grpc_exec_ctx* exec_ctx, - const char* s, +static grpc_slice base64_decode_with_length(const char* s, size_t output_length) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = - grpc_chttp2_base64_decode_with_length(exec_ctx, ss, output_length); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); + grpc_slice_unref_internal(ss); return out; } -#define EXPECT_SLICE_EQ(exec_ctx, expected, slice) \ - expect_slice_eq( \ - exec_ctx, grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), \ - slice, #slice, __LINE__); +#define EXPECT_SLICE_EQ(expected, slice) \ + expect_slice_eq( \ + grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \ + #slice, __LINE__); -#define ENCODE_AND_DECODE(exec_ctx, s) \ - EXPECT_SLICE_EQ(exec_ctx, s, \ - grpc_chttp2_base64_decode_with_length( \ - exec_ctx, base64_encode(exec_ctx, s), strlen(s))); +#define ENCODE_AND_DECODE(s) \ + EXPECT_SLICE_EQ( \ + s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); int main(int argc, char** argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which - takes encoded base64 strings without pad chars, but output length is - required. */ - /* Base64 test vectors from RFC 4648 */ - ENCODE_AND_DECODE(&exec_ctx, ""); - ENCODE_AND_DECODE(&exec_ctx, "f"); - ENCODE_AND_DECODE(&exec_ctx, "foo"); - ENCODE_AND_DECODE(&exec_ctx, "fo"); - ENCODE_AND_DECODE(&exec_ctx, "foob"); - ENCODE_AND_DECODE(&exec_ctx, "fooba"); - ENCODE_AND_DECODE(&exec_ctx, "foobar"); - - ENCODE_AND_DECODE(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5"); - - /* Base64 test vectors from RFC 4648, with pad chars */ - /* BASE64("") = "" */ - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "")); - /* BASE64("f") = "Zg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "f", base64_decode(&exec_ctx, "Zg==")); - /* BASE64("fo") = "Zm8=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fo", base64_decode(&exec_ctx, "Zm8=")); - /* BASE64("foo") = "Zm9v" */ - EXPECT_SLICE_EQ(&exec_ctx, "foo", base64_decode(&exec_ctx, "Zm9v")); - /* BASE64("foob") = "Zm9vYg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "foob", base64_decode(&exec_ctx, "Zm9vYg==")); - /* BASE64("fooba") = "Zm9vYmE=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fooba", base64_decode(&exec_ctx, "Zm9vYmE=")); - /* BASE64("foobar") = "Zm9vYmFy" */ - EXPECT_SLICE_EQ(&exec_ctx, "foobar", base64_decode(&exec_ctx, "Zm9vYmFy")); - - EXPECT_SLICE_EQ(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5", - base64_decode(&exec_ctx, "wMHCw8TF")); - - // Test illegal input length in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "a")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "ab")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "abc")); - - // Test illegal charactors in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm:v")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm=v")); - - // Test output_length longer than max possible output length in - // grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode_with_length(&exec_ctx, "Zg", 2)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm8", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm9v", 4)); - - // Test illegal charactors in grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm:v", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm=v", 3)); - - grpc_exec_ctx_finish(&exec_ctx); - + grpc_init(); + { + grpc_core::ExecCtx exec_ctx; + + /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which + takes encoded base64 strings without pad chars, but output length is + required. */ + /* Base64 test vectors from RFC 4648 */ + ENCODE_AND_DECODE(""); + ENCODE_AND_DECODE("f"); + ENCODE_AND_DECODE("foo"); + ENCODE_AND_DECODE("fo"); + ENCODE_AND_DECODE("foob"); + ENCODE_AND_DECODE("fooba"); + ENCODE_AND_DECODE("foobar"); + + ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); + + /* Base64 test vectors from RFC 4648, with pad chars */ + /* BASE64("") = "" */ + EXPECT_SLICE_EQ("", base64_decode("")); + /* BASE64("f") = "Zg==" */ + EXPECT_SLICE_EQ("f", base64_decode("Zg==")); + /* BASE64("fo") = "Zm8=" */ + EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); + /* BASE64("foo") = "Zm9v" */ + EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); + /* BASE64("foob") = "Zm9vYg==" */ + EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); + /* BASE64("fooba") = "Zm9vYmE=" */ + EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); + /* BASE64("foobar") = "Zm9vYmFy" */ + EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); + + EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); + + // Test illegal input length in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("a")); + EXPECT_SLICE_EQ("", base64_decode("ab")); + EXPECT_SLICE_EQ("", base64_decode("abc")); + + // Test illegal charactors in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("Zm:v")); + EXPECT_SLICE_EQ("", base64_decode("Zm=v")); + + // Test output_length longer than max possible output length in + // grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); + + // Test illegal charactors in grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); + } + grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 78b8808c41..44f5de8a50 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -99,6 +99,8 @@ static void expect_binary_header(const char* hdr, int binary) { } int main(int argc, char** argv) { + grpc_init(); + /* Base64 test vectors from RFC 4648, with padding removed */ /* BASE64("") = "" */ EXPECT_SLICE_EQ("", B64("")); @@ -169,5 +171,6 @@ int main(int argc, char** argv) { expect_binary_header("foo-bar", 0); expect_binary_header("-bin", 0); + grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index 2d18b72504..d2dbd4a798 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -51,8 +51,8 @@ typedef struct { /* verify that the output generated by encoding the stream matches the hexstring passed in */ -static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, - const char* expected, size_t nheaders, ...) { +static void verify(const verify_params params, const char* expected, + size_t nheaders, ...) { grpc_slice_buffer output; grpc_slice merged; grpc_slice expect = parse_hexstring(expected); @@ -77,8 +77,7 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, value_slice = grpc_slice_intern(value_slice); } e[i].md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - value_slice); + grpc_slice_intern(grpc_slice_from_static_string(key)), value_slice); } e[0].prev = nullptr; e[nheaders - 1].next = nullptr; @@ -106,11 +105,10 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, 16384, /* max_frame_size */ &stats /* stats */ }; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, - &output); + grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); merged = grpc_slice_merge(output.slices, output.count); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); if (!grpc_slice_eq(merged, expect)) { char* expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -123,11 +121,11 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params, g_failure = 1; } - grpc_slice_unref_internal(exec_ctx, merged); - grpc_slice_unref_internal(exec_ctx, expect); + grpc_slice_unref_internal(merged); + grpc_slice_unref_internal(expect); } -static void test_basic_headers(grpc_exec_ctx* exec_ctx) { +static void test_basic_headers() { int i; verify_params params = { @@ -135,24 +133,22 @@ static void test_basic_headers(grpc_exec_ctx* exec_ctx) { false, false, }; - verify(exec_ctx, params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); - verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", - "b", "c"); - verify(exec_ctx, params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); - verify(exec_ctx, params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); + verify(params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); + verify(params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(params, "000001 0104 deadbeef be", 1, "a", "a"); + verify(params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", "c"); + verify(params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); + verify(params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); /* flush out what's there to make a few values look very popular */ for (i = 0; i < 350; i++) { - verify(exec_ctx, params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", - "c", "a", "d"); + verify(params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", "c", "a", + "d"); } - verify(exec_ctx, params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", - "k", "v"); + verify(params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", "k", "v"); /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify(exec_ctx, params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); + verify(params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); } static void encode_int_to_str(int i, char* p) { @@ -163,7 +159,7 @@ static void encode_int_to_str(int i, char* p) { p[2] = 0; } -static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) { +static void test_decode_table_overflow() { int i; char key[3], value[3]; char* expect; @@ -192,26 +188,24 @@ static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) { } if (i > 0) { - verify(exec_ctx, params, expect, 2, "aa", "ba", key, value); + verify(params, expect, 2, "aa", "ba", key, value); } else { - verify(exec_ctx, params, expect, 1, key, value); + verify(params, expect, 1, key, value); } gpr_free(expect); } /* if the above passes, then we must have just knocked this pair out of the decoder stack, and so we'll be forced to re-encode it */ - verify(exec_ctx, params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", - "ba"); + verify(params, "000007 0104 deadbeef 40 026161 026261", 1, "aa", "ba"); } -static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx, - const char* key, +static void verify_table_size_change_match_elem_size(const char* key, const char* value, bool use_true_binary) { grpc_slice_buffer output; grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(key)), grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, use_true_binary); size_t initial_table_size = g_compressor.table_size; @@ -235,41 +229,38 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx, use_true_binary, /* use_true_binary_metadata */ 16384, /* max_frame_size */ &stats /* stats */}; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt, - &output); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_chttp2_encode_header(&g_compressor, nullptr, 0, &b, &hopt, &output); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); GPR_ASSERT(g_compressor.table_size == elem_size + initial_table_size); gpr_free(e); } -static void test_encode_header_size(grpc_exec_ctx* exec_ctx) { - verify_table_size_change_match_elem_size(exec_ctx, "hello", "world", false); - verify_table_size_change_match_elem_size(exec_ctx, "hello-bin", "world", - false); - verify_table_size_change_match_elem_size(exec_ctx, "true-binary-bin", +static void test_encode_header_size() { + verify_table_size_change_match_elem_size("hello", "world", false); + verify_table_size_change_match_elem_size("hello-bin", "world", false); + verify_table_size_change_match_elem_size("true-binary-bin", "I_am_true_binary_value", true); } -static void test_interned_key_indexed(grpc_exec_ctx* exec_ctx) { +static void test_interned_key_indexed() { int i; verify_params params = {false, false, true}; - verify(exec_ctx, params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, - "a", "b", "a", "c"); + verify(params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, "a", "b", + "a", "c"); for (i = 0; i < 10; i++) { - verify(exec_ctx, params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", - "b", "a", "c"); + verify(params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", "b", "a", + "c"); } } -static void run_test(void (*test)(grpc_exec_ctx* exec_ctx), const char* name) { +static void run_test(void (*test)(), const char* name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hpack_compressor_init(&g_compressor); - test(&exec_ctx); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &g_compressor); - grpc_exec_ctx_finish(&exec_ctx); + test(); + grpc_chttp2_hpack_compressor_destroy(&g_compressor); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index 942f25e0b7..9a195daee0 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -29,9 +29,7 @@ bool squelch = true; bool leak_check = true; -static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); -} +static void onhdr(void* ud, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } static void dont_log(gpr_log_func_args* args) {} extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { @@ -39,13 +37,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - parser.on_header = onhdr; - GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_exec_ctx_finish(&exec_ctx); + { + grpc_core::ExecCtx exec_ctx; + grpc_chttp2_hpack_parser_init(&parser); + parser.on_header = onhdr; + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &parser, grpc_slice_from_static_buffer(data, size))); + grpc_chttp2_hpack_parser_destroy(&parser); + } grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc index 82fb20aced..9d3456a873 100644 --- a/test/core/transport/chttp2/hpack_parser_test.cc +++ b/test/core/transport/chttp2/hpack_parser_test.cc @@ -32,7 +32,7 @@ typedef struct { va_list args; } test_checker; -static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { +static void onhdr(void* ud, grpc_mdelem md) { const char *ekey, *evalue; test_checker* chk = static_cast<test_checker*>(ud); ekey = va_arg(chk->args, char*); @@ -41,7 +41,7 @@ static void onhdr(grpc_exec_ctx* exec_ctx, void* ud, grpc_mdelem md) { GPR_ASSERT(evalue); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } static void test_vector(grpc_chttp2_hpack_parser* parser, @@ -62,10 +62,9 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == + grpc_core::ExecCtx exec_ctx; + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); } for (i = 0; i < nslices; i++) { @@ -80,9 +79,9 @@ static void test_vector(grpc_chttp2_hpack_parser* parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ test_vector(&parser, mode, "400a 6375 7374 6f6d 2d6b 6579 0d63 7573" @@ -98,9 +97,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "password", "secret", NULL); /* D.2.4 */ test_vector(&parser, mode, "82", ":method", "GET", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.3.1 */ test_vector(&parser, mode, "8286 8441 0f77 7777 2e65 7861 6d70 6c65" @@ -118,9 +117,9 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.4.1 */ test_vector(&parser, mode, "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4" @@ -138,11 +137,11 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.5.1 */ test_vector(&parser, mode, "4803 3330 3258 0770 7269 7661 7465 611d" @@ -172,11 +171,11 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.6.1 */ test_vector(&parser, mode, "4882 6402 5885 aec3 771a 4b61 96d0 7abe" @@ -203,9 +202,7 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hpack_parser_destroy(&parser); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index ff7c2de538..3f3cb2ee9d 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -44,10 +44,10 @@ static void assert_index(const grpc_chttp2_hptbl* tbl, uint32_t idx, } static void test_static_lookup(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + grpc_chttp2_hptbl_init(&tbl); LOG_TEST("test_static_lookup"); assert_index(&tbl, 1, ":authority", ""); @@ -112,8 +112,7 @@ static void test_static_lookup(void) { assert_index(&tbl, 60, "via", ""); assert_index(&tbl, 61, "www-authenticate", ""); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } static void test_many_additions(void) { @@ -124,18 +123,17 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + grpc_core::ExecCtx exec_ctx; + grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 100000; i++) { grpc_mdelem elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); gpr_free(key); gpr_free(value); @@ -148,25 +146,23 @@ static void test_many_additions(void) { } } - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl* tbl, const char* key, const char* value) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_core::ExecCtx exec_ctx; + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + return r; } static void test_find(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; @@ -175,21 +171,19 @@ static void test_find(void) { LOG_TEST("test_find"); - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("xyz")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("123")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), + grpc_chttp2_hptbl_init(&tbl); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("xyz")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("123")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("x"), grpc_slice_from_static_string("1")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); r = find_simple(&tbl, "abc", "123"); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); @@ -238,11 +232,10 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_slices(&exec_ctx, - grpc_slice_from_static_string("test"), + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("test"), grpc_slice_from_copied_string(buffer)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); } r = find_simple(&tbl, "abc", "123"); @@ -270,8 +263,7 @@ static void test_find(void) { GPR_ASSERT(r.index != 0); GPR_ASSERT(r.has_value == 0); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); } int main(int argc, char** argv) { diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 670eae1f79..08473c72b6 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -97,7 +97,7 @@ class Client { : server_address_(server_address) {} void Connect() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_resolved_addresses* server_addresses = nullptr; grpc_error* error = grpc_blocking_resolve_address(server_address_, "80", &server_addresses); @@ -106,56 +106,53 @@ class Client { pollset_ = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(pollset_, &mu_); grpc_pollset_set* pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(&exec_ctx, pollset_set, pollset_); + grpc_pollset_set_add_pollset(pollset_set, pollset_); EventState state; - grpc_tcp_client_connect(&exec_ctx, state.closure(), &endpoint_, pollset_set, + grpc_tcp_client_connect(state.closure(), &endpoint_, pollset_set, nullptr /* channel_args */, server_addresses->addrs, 1000); ASSERT_TRUE(PollUntilDone( - &exec_ctx, &state, + &state, grpc_timespec_to_millis_round_up(gpr_inf_future(GPR_CLOCK_MONOTONIC)))); ASSERT_EQ(GRPC_ERROR_NONE, state.error()); - grpc_pollset_set_destroy(&exec_ctx, pollset_set); - grpc_endpoint_add_to_pollset(&exec_ctx, endpoint_, pollset_); + grpc_pollset_set_destroy(pollset_set); + grpc_endpoint_add_to_pollset(endpoint_, pollset_); grpc_resolved_addresses_destroy(server_addresses); - grpc_exec_ctx_finish(&exec_ctx); } // Reads until an error is returned. // Returns true if an error was encountered before the deadline. bool ReadUntilError() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_slice_buffer read_buffer; grpc_slice_buffer_init(&read_buffer); bool retval = true; // Use a deadline of 3 seconds, which is a lot more than we should // need for a 1-second timeout, but this helps avoid flakes. - grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 3000; + grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 3000; while (true) { EventState state; - grpc_endpoint_read(&exec_ctx, endpoint_, &read_buffer, state.closure()); - if (!PollUntilDone(&exec_ctx, &state, deadline)) { + grpc_endpoint_read(endpoint_, &read_buffer, state.closure()); + if (!PollUntilDone(&state, deadline)) { retval = false; break; } if (state.error() != GRPC_ERROR_NONE) break; gpr_log(GPR_INFO, "client read %" PRIuPTR " bytes", read_buffer.length); - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &read_buffer); + grpc_slice_buffer_reset_and_unref_internal(&read_buffer); } - grpc_endpoint_shutdown(&exec_ctx, endpoint_, + grpc_endpoint_shutdown(endpoint_, GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown")); - grpc_slice_buffer_destroy_internal(&exec_ctx, &read_buffer); - grpc_exec_ctx_finish(&exec_ctx); + grpc_slice_buffer_destroy_internal(&read_buffer); return retval; } void Shutdown() { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_destroy(&exec_ctx, endpoint_); - grpc_pollset_shutdown(&exec_ctx, pollset_, + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_destroy(endpoint_); + grpc_pollset_shutdown(pollset_, GRPC_CLOSURE_CREATE(&Client::PollsetDestroy, pollset_, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); } private: @@ -177,8 +174,7 @@ class Client { grpc_error* error() const { return error_; } private: - static void OnEventDone(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { + static void OnEventDone(void* arg, grpc_error* error) { gpr_log(GPR_INFO, "OnEventDone(): %s", grpc_error_string(error)); EventState* state = (EventState*)arg; state->error_ = GRPC_ERROR_REF(error); @@ -191,24 +187,23 @@ class Client { }; // Returns true if done, or false if deadline exceeded. - bool PollUntilDone(grpc_exec_ctx* exec_ctx, EventState* state, - grpc_millis deadline) { + bool PollUntilDone(EventState* state, grpc_millis deadline) { while (true) { grpc_pollset_worker* worker = nullptr; gpr_mu_lock(mu_); - GRPC_LOG_IF_ERROR("grpc_pollset_work", - grpc_pollset_work(exec_ctx, pollset_, &worker, - grpc_exec_ctx_now(exec_ctx) + 1000)); + GRPC_LOG_IF_ERROR( + "grpc_pollset_work", + grpc_pollset_work(pollset_, &worker, + grpc_core::ExecCtx::Get()->Now() + 1000)); gpr_mu_unlock(mu_); if (state != nullptr && state->done()) return true; - if (grpc_exec_ctx_now(exec_ctx) >= deadline) return false; + if (grpc_core::ExecCtx::Get()->Now() >= deadline) return false; } } - static void PollsetDestroy(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { + static void PollsetDestroy(void* arg, grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } diff --git a/test/core/transport/chttp2/varint_test.cc b/test/core/transport/chttp2/varint_test.cc index 413b461b3a..36760d0c72 100644 --- a/test/core/transport/chttp2/varint_test.cc +++ b/test/core/transport/chttp2/varint_test.cc @@ -18,6 +18,7 @@ #include "src/core/ext/transport/chttp2/transport/varint.h" +#include <grpc/grpc.h> #include <grpc/slice.h> #include <grpc/support/log.h> @@ -44,11 +45,13 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); TEST_VARINT(0, 1, 0, "\x00"); TEST_VARINT(128, 1, 0, "\x7f\x01"); TEST_VARINT(16384, 1, 0, "\x7f\x81\x7f"); TEST_VARINT(2097152, 1, 0, "\x7f\x81\xff\x7f"); TEST_VARINT(268435456, 1, 0, "\x7f\x81\xff\xff\x7f"); TEST_VARINT(0xffffffff, 1, 0, "\x7f\x80\xff\xff\xff\x0f"); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 11046e126e..f5894599e5 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -29,14 +29,13 @@ int g_counter; -static void must_succeed(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void must_succeed(void* arg, grpc_error* error) { GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; } -static void must_fail(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { +static void must_fail(void* arg, grpc_error* error) { GPR_ASSERT(error != GRPC_ERROR_NONE); GPR_ASSERT(arg == THE_ARG); g_counter++; @@ -59,7 +58,7 @@ static void test_connectivity_state_name(void) { static void test_check(void) { grpc_connectivity_state_tracker tracker; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_error* error; gpr_log(GPR_DEBUG, "test_check"); grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); @@ -67,8 +66,7 @@ static void test_check(void) { GRPC_CHANNEL_IDLE); GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); GPR_ASSERT(error == GRPC_ERROR_NONE); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); } static void test_subscribe_then_unsubscribe(void) { @@ -76,23 +74,21 @@ static void test_subscribe_then_unsubscribe(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, - &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, nullptr, - closure); - grpc_exec_ctx_flush(&exec_ctx); + grpc_connectivity_state_notify_on_state_change(&tracker, nullptr, closure); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 1); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); } static void test_subscribe_then_destroy(void) { @@ -100,17 +96,18 @@ static void test_subscribe_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, - &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_IDLE); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); + + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } @@ -120,28 +117,30 @@ static void test_subscribe_with_failure_then_destroy(void) { grpc_closure* closure = GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); g_counter = 0; grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( - &exec_ctx, &tracker, &state, closure)); - grpc_exec_ctx_flush(&exec_ctx); + &tracker, &state, closure)); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&exec_ctx, &tracker); - grpc_exec_ctx_finish(&exec_ctx); + grpc_connectivity_state_destroy(&tracker); + grpc_core::ExecCtx::Get()->Flush(); GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); GPR_ASSERT(g_counter == 1); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); test_subscribe_then_destroy(); test_subscribe_with_failure_then_destroy(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index b60a9619fb..5c52ae8d5f 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -60,15 +60,15 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; m1 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m2 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); m3 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("c"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(m1, m2)); GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); @@ -77,10 +77,10 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); - GRPC_MDELEM_UNREF(&exec_ctx, m1); - GRPC_MDELEM_UNREF(&exec_ctx, m2); - GRPC_MDELEM_UNREF(&exec_ctx, m3); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(m1); + GRPC_MDELEM_UNREF(m2); + GRPC_MDELEM_UNREF(m3); + grpc_shutdown(); } @@ -95,19 +95,15 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_copied_string(buffer), - intern_values))); + GRPC_MDELEM_UNREF(grpc_mdelem_from_slices( + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); } @@ -121,28 +117,28 @@ static void test_create_many_persistant_metadata(void) { gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); created[i] = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_static_string(buffer))); GPR_ASSERT(grpc_mdelem_eq(md, created[i])); - GRPC_MDELEM_UNREF(&exec_ctx, md); + GRPC_MDELEM_UNREF(md); } /* cleanup phase */ for (i = 0; i < MANY; i++) { - GRPC_MDELEM_UNREF(&exec_ctx, created[i]); + GRPC_MDELEM_UNREF(created[i]); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); gpr_free(created); @@ -155,31 +151,25 @@ static void test_spin_creating_the_same_thing(bool intern_keys, intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( - &exec_ctx, a = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( - &exec_ctx, b = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( - &exec_ctx, c = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); if (intern_keys && intern_values) { GPR_ASSERT(a.payload == b.payload); GPR_ASSERT(a.payload == c.payload); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); } @@ -188,16 +178,16 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { intern_keys, intern_values); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_mdelem a, b, c; a = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); b = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); c = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(a, a)); GPR_ASSERT(grpc_mdelem_eq(b, b)); @@ -216,10 +206,10 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { GPR_ASSERT(a.payload != c.payload); GPR_ASSERT(b.payload != c.payload); } - GRPC_MDELEM_UNREF(&exec_ctx, a); - GRPC_MDELEM_UNREF(&exec_ctx, b); - GRPC_MDELEM_UNREF(&exec_ctx, c); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(a); + GRPC_MDELEM_UNREF(b); + GRPC_MDELEM_UNREF(c); + grpc_shutdown(); } @@ -235,7 +225,7 @@ static void test_things_stick_around(void) { gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); @@ -246,7 +236,7 @@ static void test_things_stick_around(void) { for (i = 0; i < nstrs; i++) { grpc_slice_ref_internal(strs[i]); - grpc_slice_unref_internal(&exec_ctx, strs[i]); + grpc_slice_unref_internal(strs[i]); } for (i = 0; i < nstrs; i++) { @@ -258,18 +248,17 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - grpc_slice_unref_internal(&exec_ctx, strs[shuf[i]]); + grpc_slice_unref_internal(strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); test = grpc_slice_intern(grpc_slice_from_static_string(buffer)); GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); - grpc_slice_unref_internal(&exec_ctx, test); + grpc_slice_unref_internal(test); gpr_free(buffer); } } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_free(strs); gpr_free(shuf); @@ -282,39 +271,38 @@ static void test_user_data_works(void) { gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; ud1 = static_cast<int*>(gpr_malloc(sizeof(int))); *ud1 = 1; ud2 = static_cast<int*>(gpr_malloc(sizeof(int))); *ud2 = 2; md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("123"))); grpc_mdelem_set_user_data(md, gpr_free, ud1); grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_shutdown(); } -static void verify_ascii_header_size(grpc_exec_ctx* exec_ctx, const char* key, - const char* value, bool intern_key, - bool intern_value) { +static void verify_ascii_header_size(const char* key, const char* value, + bool intern_key, bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_string(value), intern_value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); - GRPC_MDELEM_UNREF(exec_ctx, elem); + GRPC_MDELEM_UNREF(elem); } -static void verify_binary_header_size(grpc_exec_ctx* exec_ctx, const char* key, - const uint8_t* value, size_t value_len, - bool intern_key, bool intern_value) { +static void verify_binary_header_size(const char* key, const uint8_t* value, + size_t value_len, bool intern_key, + bool intern_value) { grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_buffer(value, value_len), intern_value)); GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); @@ -324,9 +312,9 @@ static void verify_binary_header_size(grpc_exec_ctx* exec_ctx, const char* key, grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice); size_t expected_size = 32 + strlen(key) + GRPC_SLICE_LENGTH(base64_encoded); GPR_ASSERT(expected_size == elem_size); - grpc_slice_unref_internal(exec_ctx, value_slice); - grpc_slice_unref_internal(exec_ctx, base64_encoded); - GRPC_MDELEM_UNREF(exec_ctx, elem); + grpc_slice_unref_internal(value_slice); + grpc_slice_unref_internal(base64_encoded); + GRPC_MDELEM_UNREF(elem); } #define BUFFER_SIZE 64 @@ -334,27 +322,23 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", intern_key, intern_value); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; uint8_t binary_value[BUFFER_SIZE] = {0}; for (uint8_t i = 0; i < BUFFER_SIZE; i++) { binary_value[i] = i; } - verify_ascii_header_size(&exec_ctx, "hello", "world", intern_key, - intern_value); - verify_ascii_header_size(&exec_ctx, "hello", - "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", intern_key, - intern_value); - verify_ascii_header_size(&exec_ctx, ":scheme", "http", intern_key, - intern_value); + verify_ascii_header_size("hello", "world", intern_key, intern_value); + verify_ascii_header_size("hello", "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + intern_key, intern_value); + verify_ascii_header_size(":scheme", "http", intern_key, intern_value); for (uint8_t i = 0; i < BUFFER_SIZE; i++) { - verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i, - intern_key, intern_value); + verify_binary_header_size("hello-bin", binary_value, i, intern_key, + intern_value); } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -362,13 +346,13 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, dup_value); grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], GRPC_MDELEM_STORAGE_STATIC); grpc_mdelem q = - grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), + grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), maybe_dup(GRPC_MDVALUE(p), dup_value)); GPR_ASSERT(grpc_mdelem_eq(p, q)); if (dup_key || dup_value) { @@ -376,16 +360,16 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { } else { GPR_ASSERT(p.payload == q.payload); } - GRPC_MDELEM_UNREF(&exec_ctx, p); - GRPC_MDELEM_UNREF(&exec_ctx, q); + GRPC_MDELEM_UNREF(p); + GRPC_MDELEM_UNREF(q); } - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_no_op(); for (int k = 0; k <= 1; k++) { for (int v = 0; v <= 1; v++) { @@ -400,5 +384,6 @@ int main(int argc, char** argv) { test_create_many_persistant_metadata(); test_things_stick_around(); test_user_data_works(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index 7af5d12cb7..1ed6ccfba6 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -22,12 +22,11 @@ #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \ GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) -#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ - do { \ - grpc_exec_ctx my_exec_ctx = GRPC_EXEC_CTX_INIT; \ - GPR_ASSERT(grpc_http2_error_to_grpc_status(&my_exec_ctx, a, deadline) == \ - (b)); \ - grpc_exec_ctx_finish(&my_exec_ctx); \ +#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ + do { \ + grpc_core::ExecCtx exec_ctx; \ + GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \ + \ } while (0) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) diff --git a/test/core/transport/stream_owned_slice_test.cc b/test/core/transport/stream_owned_slice_test.cc index e82df2117d..7831f67a04 100644 --- a/test/core/transport/stream_owned_slice_test.cc +++ b/test/core/transport/stream_owned_slice_test.cc @@ -20,12 +20,14 @@ #include "test/core/util/test_config.h" +#include <grpc/grpc.h> #include <grpc/support/log.h> -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); uint8_t buffer[] = "abc123"; grpc_stream_refcount r; @@ -39,5 +41,6 @@ int main(int argc, char** argv) { grpc_slice_unref(slice); GPR_ASSERT(r.refs.count == 1); + grpc_shutdown(); return 0; } diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index d9545efa49..4b35a581b1 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -40,13 +40,13 @@ typedef struct grpc_mock_endpoint { grpc_resource_user* resource_user; } grpc_mock_endpoint; -static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -54,44 +54,41 @@ static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, gpr_mu_unlock(&m->mu); } -static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } -static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read) { - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Endpoint Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->mu); - grpc_resource_user_shutdown(exec_ctx, m->resource_user); + grpc_resource_user_shutdown(m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void me_destroy(grpc_endpoint* ep) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; grpc_slice_buffer_destroy(&m->read_buffer); - grpc_resource_user_unref(exec_ctx, m->resource_user); + grpc_resource_user_unref(m->resource_user); gpr_free(m); } @@ -134,13 +131,12 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), return &m->base; } -void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice slice) { +void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) { grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; gpr_mu_lock(&m->mu); if (m->on_read != nullptr) { grpc_slice_buffer_add(m->on_read_out, slice); - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { grpc_slice_buffer_add(&m->read_buffer, slice); diff --git a/test/core/util/mock_endpoint.h b/test/core/util/mock_endpoint.h index ccabaf7c3b..6521d3e8e8 100644 --- a/test/core/util/mock_endpoint.h +++ b/test/core/util/mock_endpoint.h @@ -23,8 +23,7 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota); -void grpc_mock_endpoint_put_read(grpc_exec_ctx* exec_ctx, - grpc_endpoint* mock_endpoint, +void grpc_mock_endpoint_put_read(grpc_endpoint* mock_endpoint, grpc_slice slice); #endif diff --git a/test/core/util/one_corpus_entry_fuzzer.cc b/test/core/util/one_corpus_entry_fuzzer.cc index c0b67da1e2..c745eb5dc6 100644 --- a/test/core/util/one_corpus_entry_fuzzer.cc +++ b/test/core/util/one_corpus_entry_fuzzer.cc @@ -18,7 +18,10 @@ #include <stdbool.h> +#include <grpc/grpc.h> + #include <grpc/support/log.h> +#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/load_file.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); @@ -30,10 +33,15 @@ int main(int argc, char** argv) { grpc_slice buffer; squelch = false; leak_check = false; + /* TODO(yashkt) Calling grpc_init breaks tests. Fix the tests and replace + * grpc_core::ExecCtx::GlobalInit with grpc_init and GlobalShutdown with + * grpc_shutdown */ GPR_ASSERT( GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer))); LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), GRPC_SLICE_LENGTH(buffer)); + grpc_core::ExecCtx::GlobalInit(); grpc_slice_unref(buffer); + grpc_core::ExecCtx::GlobalShutdown(); return 0; } diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index a9efe22b69..5f127cb960 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -49,22 +49,22 @@ struct passthru_endpoint { int halves; grpc_passthru_endpoint_stats* stats; grpc_passthru_endpoint_stats - dummy_stats; // used if constructor stats == NULL + dummy_stats; // used if constructor stats == nullptr bool shutdown; half client; half server; }; -static void me_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { GRPC_CLOSURE_SCHED( - exec_ctx, cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); + cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown")); } else if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -77,8 +77,8 @@ static half* other_half(half* h) { return &h->parent->client; } -static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { half* m = other_half((half*)ep); gpr_mu_lock(&m->parent->mu); grpc_error* error = GRPC_ERROR_NONE; @@ -89,7 +89,7 @@ static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, for (size_t i = 0; i < slices->count; i++) { grpc_slice_buffer_add(m->on_read_out, grpc_slice_copy(slices->slices[i])); } - GRPC_CLOSURE_SCHED(exec_ctx, m->on_read, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(m->on_read, GRPC_ERROR_NONE); m->on_read = nullptr; } else { for (size_t i = 0; i < slices->count; i++) { @@ -98,52 +98,49 @@ static void me_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } } gpr_mu_unlock(&m->parent->mu); - GRPC_CLOSURE_SCHED(exec_ctx, cb, error); + GRPC_CLOSURE_SCHED(cb, error); } -static void me_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) {} +static void me_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) {} -static void me_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void me_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} -static void me_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { half* m = (half*)ep; gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { GRPC_CLOSURE_SCHED( - exec_ctx, m->on_read, + m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } m = other_half(m); if (m->on_read) { GRPC_CLOSURE_SCHED( - exec_ctx, m->on_read, + m->on_read, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1)); m->on_read = nullptr; } gpr_mu_unlock(&m->parent->mu); - grpc_resource_user_shutdown(exec_ctx, m->resource_user); + grpc_resource_user_shutdown(m->resource_user); GRPC_ERROR_UNREF(why); } -static void me_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void me_destroy(grpc_endpoint* ep) { passthru_endpoint* p = ((half*)ep)->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { gpr_mu_unlock(&p->mu); gpr_mu_destroy(&p->mu); - grpc_slice_buffer_destroy_internal(exec_ctx, &p->client.read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &p->server.read_buffer); - grpc_resource_user_unref(exec_ctx, p->client.resource_user); - grpc_resource_user_unref(exec_ctx, p->server.resource_user); + grpc_slice_buffer_destroy_internal(&p->client.read_buffer); + grpc_slice_buffer_destroy_internal(&p->server.read_buffer); + grpc_resource_user_unref(p->client.resource_user); + grpc_resource_user_unref(p->server.resource_user); gpr_free(p); } else { gpr_mu_unlock(&p->mu); diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index edec50b424..7e76c8063f 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -40,22 +40,19 @@ typedef struct freereq { int done; } freereq; -static void destroy_pops_and_shutdown(grpc_exec_ctx* exec_ctx, void* p, - grpc_error* error) { +static void destroy_pops_and_shutdown(void* p, grpc_error* error) { grpc_pollset* pollset = grpc_polling_entity_pollset((grpc_polling_entity*)p); - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } -static void freed_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void freed_port_from_server(void* arg, grpc_error* error) { freereq* pr = (freereq*)arg; gpr_mu_lock(pr->mu); pr->done = 1; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); } @@ -65,7 +62,7 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_response rsp; freereq pr; char* path; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_closure* shutdown_closure; grpc_init(); @@ -87,30 +84,30 @@ void grpc_free_port_using_server(int port) { grpc_httpcli_context_init(&context); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/free"); - grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_exec_ctx_flush(&exec_ctx); + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { pr.done = 1; } } gpr_mu_unlock(pr.mu); - grpc_httpcli_context_destroy(&exec_ctx, &context); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), + grpc_httpcli_context_destroy(&context); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), shutdown_closure); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(path); grpc_http_response_destroy(&rsp); @@ -127,8 +124,7 @@ typedef struct portreq { grpc_httpcli_response response; } portreq; -static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void got_port_from_server(void* arg, grpc_error* error) { size_t i; int port = 0; portreq* pr = (portreq*)arg; @@ -154,8 +150,7 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, pr->port = 0; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); return; } @@ -172,12 +167,12 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, memset(&pr->response, 0, sizeof(pr->response)); grpc_resource_quota* resource_quota = grpc_resource_quota_create("port_server_client/pick_retry"); - grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req, - grpc_exec_ctx_now(exec_ctx) + 30 * GPR_MS_PER_SEC, + grpc_httpcli_get(pr->ctx, &pr->pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, GRPC_CLOSURE_CREATE(got_port_from_server, pr, grpc_schedule_on_exec_ctx), &pr->response); - grpc_resource_quota_unref_internal(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(resource_quota); return; } GPR_ASSERT(response); @@ -191,8 +186,7 @@ static void got_port_from_server(grpc_exec_ctx* exec_ctx, void* arg, pr->port = port; GRPC_LOG_IF_ERROR( "pollset_kick", - grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops), - nullptr)); + grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), nullptr)); gpr_mu_unlock(pr->mu); } @@ -200,53 +194,55 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure* shutdown_closure; grpc_init(); + { + grpc_core::ExecCtx exec_ctx; + memset(&pr, 0, sizeof(pr)); + memset(&req, 0, sizeof(req)); + grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(pollset, &pr.mu); + pr.pops = grpc_polling_entity_create_from_pollset(pollset); + shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); + pr.port = -1; + pr.server = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); + pr.ctx = &context; + + req.host = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); + req.http.path = const_cast<char*>("/get"); - memset(&pr, 0, sizeof(pr)); - memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(pollset, &pr.mu); - pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, - grpc_schedule_on_exec_ctx); - pr.port = -1; - pr.server = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); - pr.ctx = &context; + grpc_httpcli_context_init(&context); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("port_server_client/pick"); + grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + GRPC_CLOSURE_CREATE(got_port_from_server, &pr, + grpc_schedule_on_exec_ctx), + &pr.response); + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::Get()->Flush(); + gpr_mu_lock(pr.mu); + while (pr.port == -1) { + grpc_pollset_worker* worker = nullptr; + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + pr.port = 0; + } + } + gpr_mu_unlock(pr.mu); - req.host = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); - req.http.path = const_cast<char*>("/get"); + grpc_http_response_destroy(&pr.response); + grpc_httpcli_context_destroy(&context); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), + shutdown_closure); - grpc_httpcli_context_init(&context); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("port_server_client/pick"); - grpc_httpcli_get( - &exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC, - GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), - &pr.response); - grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); - grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(pr.mu); - while (pr.port == -1) { - grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - &worker, - grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) { - pr.port = 0; - } + grpc_core::ExecCtx::Get()->Flush(); } - gpr_mu_unlock(pr.mu); - - grpc_http_response_destroy(&pr.response); - grpc_httpcli_context_destroy(&exec_ctx, &context); - grpc_pollset_shutdown(&exec_ctx, grpc_polling_entity_pollset(&pr.pops), - shutdown_closure); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return pr.port; diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index 4775b074eb..bcafc4e898 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -55,7 +55,7 @@ static void pretty_print_backoffs(reconnect_server* server) { } } -static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, +static void on_connect(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); @@ -65,9 +65,9 @@ static void on_connect(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; peer = grpc_endpoint_get_peer(tcp); - grpc_endpoint_shutdown(exec_ctx, tcp, + grpc_endpoint_shutdown(tcp, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected")); - grpc_endpoint_destroy(exec_ctx, tcp); + grpc_endpoint_destroy(tcp); if (peer) { last_colon = strrchr(peer, ':'); if (server->peer == nullptr) { diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index da34da6fd0..5f6af4e707 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -33,8 +33,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static void on_server_destroyed(grpc_exec_ctx* exec_ctx, void* data, - grpc_error* error) { +static void on_server_destroyed(void* data, grpc_error* error) { test_tcp_server* server = static_cast<test_tcp_server*>(data); server->shutdown = 1; } @@ -56,51 +55,46 @@ void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; int port_added; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; addr->sin_family = AF_INET; addr->sin_port = htons((uint16_t)port); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); - grpc_error* error = grpc_tcp_server_create( - &exec_ctx, &server->shutdown_complete, nullptr, &server->tcp_server); + grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, + nullptr, &server->tcp_server); GPR_ASSERT(error == GRPC_ERROR_NONE); error = grpc_tcp_server_add_port(server->tcp_server, &resolved_addr, &port_added); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(port_added == port); - grpc_tcp_server_start(&exec_ctx, server->tcp_server, &server->pollset, 1, + grpc_tcp_server_start(server->tcp_server, &server->pollset, 1, server->on_connect, server->cb_data); gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port); - - grpc_exec_ctx_finish(&exec_ctx); } void test_tcp_server_poll(test_tcp_server* server, int seconds) { grpc_pollset_worker* worker = nullptr; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_millis deadline = grpc_timespec_to_millis_round_up( grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); - GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work(&exec_ctx, server->pollset, &worker, deadline)); + GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(server->pollset, &worker, deadline)); gpr_mu_unlock(server->mu); - grpc_exec_ctx_finish(&exec_ctx); } -static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -static void finish_pollset(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { - grpc_pollset_destroy(exec_ctx, static_cast<grpc_pollset*>(arg)); +static void do_nothing(void* arg, grpc_error* error) {} +static void finish_pollset(void* arg, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(arg)); } void test_tcp_server_destroy(test_tcp_server* server) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; - grpc_tcp_server_unref(&exec_ctx, server->tcp_server); + grpc_tcp_server_unref(server->tcp_server); GRPC_CLOSURE_INIT(&do_nothing_cb, do_nothing, nullptr, grpc_schedule_on_exec_ctx); shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), @@ -109,10 +103,10 @@ void test_tcp_server_destroy(test_tcp_server* server) { gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), shutdown_deadline) < 0) { test_tcp_server_poll(server, 1); } - grpc_pollset_shutdown(&exec_ctx, server->pollset, + grpc_pollset_shutdown(server->pollset, GRPC_CLOSURE_CREATE(finish_pollset, server->pollset, grpc_schedule_on_exec_ctx)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index 4544fb7f49..f95ed62463 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -45,24 +45,23 @@ typedef struct { grpc_closure* write_cb; } trickle_endpoint; -static void te_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void te_read(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_read(exec_ctx, te->wrapped, slices, cb); + grpc_endpoint_read(te->wrapped, slices, cb); } -static void maybe_call_write_cb_locked(grpc_exec_ctx* exec_ctx, - trickle_endpoint* te) { +static void maybe_call_write_cb_locked(trickle_endpoint* te) { if (te->write_cb != nullptr && (te->error != GRPC_ERROR_NONE || te->write_buffer.length <= WRITE_BUFFER_SIZE)) { - GRPC_CLOSURE_SCHED(exec_ctx, te->write_cb, GRPC_ERROR_REF(te->error)); + GRPC_CLOSURE_SCHED(te->write_cb, GRPC_ERROR_REF(te->error)); te->write_cb = nullptr; } } -static void te_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_slice_buffer* slices, grpc_closure* cb) { +static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); GPR_ASSERT(te->write_cb == nullptr); @@ -74,47 +73,44 @@ static void te_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_slice_copy(slices->slices[i])); } te->write_cb = cb; - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); gpr_mu_unlock(&te->mu); } -static void te_add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_pollset* pollset) { +static void te_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset(exec_ctx, te->wrapped, pollset); + grpc_endpoint_add_to_pollset(te->wrapped, pollset); } -static void te_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, +static void te_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_add_to_pollset_set(exec_ctx, te->wrapped, pollset_set); + grpc_endpoint_add_to_pollset_set(te->wrapped, pollset_set); } -static void te_delete_from_pollset_set(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep, +static void te_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_delete_from_pollset_set(exec_ctx, te->wrapped, pollset_set); + grpc_endpoint_delete_from_pollset_set(te->wrapped, pollset_set); } -static void te_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, - grpc_error* why) { +static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (te->error == GRPC_ERROR_NONE) { te->error = GRPC_ERROR_REF(why); } - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); gpr_mu_unlock(&te->mu); - grpc_endpoint_shutdown(exec_ctx, te->wrapped, why); + grpc_endpoint_shutdown(te->wrapped, why); } -static void te_destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { +static void te_destroy(grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; - grpc_endpoint_destroy(exec_ctx, te->wrapped); + grpc_endpoint_destroy(te->wrapped); gpr_mu_destroy(&te->mu); - grpc_slice_buffer_destroy_internal(exec_ctx, &te->write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &te->writing_buffer); + grpc_slice_buffer_destroy_internal(&te->write_buffer); + grpc_slice_buffer_destroy_internal(&te->writing_buffer); GRPC_ERROR_UNREF(te->error); gpr_free(te); } @@ -134,8 +130,7 @@ static int te_get_fd(grpc_endpoint* ep) { return grpc_endpoint_get_fd(te->wrapped); } -static void te_finish_write(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void te_finish_write(void* arg, grpc_error* error) { trickle_endpoint* te = (trickle_endpoint*)arg; gpr_mu_lock(&te->mu); te->writing = false; @@ -173,8 +168,7 @@ static double ts2dbl(gpr_timespec s) { return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; } -size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, - grpc_endpoint* ep) { +size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { trickle_endpoint* te = (trickle_endpoint*)ep; gpr_mu_lock(&te->mu); if (!te->writing && te->write_buffer.length > 0) { @@ -189,9 +183,9 @@ size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, te->writing = true; te->last_write = now; grpc_endpoint_write( - exec_ctx, te->wrapped, &te->writing_buffer, + te->wrapped, &te->writing_buffer, GRPC_CLOSURE_CREATE(te_finish_write, te, grpc_schedule_on_exec_ctx)); - maybe_call_write_cb_locked(exec_ctx, te); + maybe_call_write_cb_locked(te); } } size_t backlog = te->write_buffer.length; diff --git a/test/core/util/trickle_endpoint.h b/test/core/util/trickle_endpoint.h index 11c113bda8..cd07de905a 100644 --- a/test/core/util/trickle_endpoint.h +++ b/test/core/util/trickle_endpoint.h @@ -25,8 +25,7 @@ grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second); /* Allow up to \a bytes through the endpoint. Returns the new backlog. */ -size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx* exec_ctx, - grpc_endpoint* endpoint); +size_t grpc_trickle_endpoint_trickle(grpc_endpoint* endpoint); size_t grpc_trickle_get_backlog(grpc_endpoint* endpoint); |