diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-12-06 09:05:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 09:05:05 -0800 |
commit | ad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch) | |
tree | 6a657f8c6179d873b34505cdc24bce9462ca68eb /test/core/client_channel | |
parent | a3df36cc2505a89c2f481eea4a66a87b3002844a (diff) |
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'test/core/client_channel')
8 files changed, 138 insertions, 133 deletions
diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 847ea0066b..5f8d3b84cc 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -651,8 +651,9 @@ 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_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(args); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, args); + grpc_exec_ctx_finish(&exec_ctx); } // Ensures that resolver returns. grpc_channel_check_connectivity_state(channel, true /* try_to_connect */); @@ -958,7 +959,7 @@ static void verify_rebirth_round_robin(const servers_fixture* f, } int main(int argc, char** argv) { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; test_spec* spec; size_t i; const size_t NUM_ITERS = 10; @@ -968,9 +969,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("this-lb-policy-does-not-exist", nullptr) == - nullptr); - GPR_ASSERT(grpc_lb_policy_create(nullptr, nullptr) == nullptr); + 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); spec = test_spec_create(NUM_ITERS, NUM_SERVERS); /* everything is fine, all servers stay up the whole time and life's peachy @@ -1024,6 +1025,7 @@ 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 6d56961d84..94f76da920 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -24,7 +24,6 @@ #include <sys/un.h> #endif -#include <grpc/grpc.h> #include <grpc/support/log.h> #include "src/core/lib/iomgr/exec_ctx.h" @@ -34,8 +33,8 @@ #ifdef GRPC_HAVE_UNIX_SOCKET static void test_grpc_parse_unix(const char* uri_text, const char* pathname) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; GPR_ASSERT(1 == grpc_parse_unix(uri, &addr)); @@ -44,6 +43,7 @@ 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_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET_ADDRSTRLEN]; @@ -68,12 +68,13 @@ 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_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); grpc_resolved_address addr; char ntop_buf[INET6_ADDRSTRLEN]; @@ -87,16 +88,14 @@ 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 18a795fbcb..dcf315eba5 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,7 +35,8 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(const char* addr, const char* default_port, +static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -54,13 +55,13 @@ static void my_resolve_address(const char* addr, const char* default_port, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); } static 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, + 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) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", addr)); @@ -75,26 +76,27 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); return nullptr; } -static grpc_resolver* create_resolver(const char* name) { +static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, + const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(name, 0); + grpc_uri* uri = grpc_uri_parse(exec_ctx, 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(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(void* ev, grpc_error* error) { +static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -105,8 +107,9 @@ 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_core::ExecCtx exec_ctx; - grpc_timer_check(nullptr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_check(&exec_ctx, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } return false; } @@ -117,14 +120,16 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(void* arg, +static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error_unused) { next_args* a = static_cast<next_args*>(arg); - grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast<next_args*>(gpr_malloc(sizeof(*a))); @@ -132,6 +137,7 @@ static void call_resolver_next_after_locking(grpc_resolver* resolver, 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); @@ -147,31 +153,30 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - { - 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_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_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 80667908ef..4c040caeb9 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_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -38,15 +38,16 @@ 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(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver != nullptr); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); + GRPC_RESOLVER_UNREF(&exec_ctx, 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_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -55,9 +56,10 @@ 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(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -80,8 +82,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } 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 d85cbb1d03..d5538e9621 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_combiner* combiner, + grpc_exec_ctx* exec_ctx, 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(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, 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(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, 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,23 +66,24 @@ void on_resolution_cb(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(res->resolver_result); - grpc_channel_args_destroy(res->expected_resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->expected_resolver_result); gpr_event_set(&res->ev, (void*)1); } static void test_fake_resolver() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; 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(combiner, response_generator); + grpc_resolver* resolver = + build_fake_resolver(&exec_ctx, combiner, response_generator); GPR_ASSERT(resolver != nullptr); // Setup expectations. - grpc_uri* uris[] = {grpc_uri_parse("ipv4:10.2.1.1:1234", true), - grpc_uri_parse("ipv4:127.0.0.1:4321", true)}; + 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)}; const char* balancer_names[] = {"name1", "name2"}; const bool is_balancer[] = {true, false}; grpc_lb_addresses* addresses = grpc_lb_addresses_create(3, nullptr); @@ -95,7 +96,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(addresses); + grpc_lb_addresses_destroy(&exec_ctx, addresses); on_resolution_arg on_res_arg; memset(&on_res_arg, 0, sizeof(on_res_arg)); on_res_arg.expected_resolver_result = results; @@ -105,16 +106,17 @@ 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(response_generator, - results); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, results); + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); 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("ipv4:192.168.1.0:31416", true)}; + grpc_uri* uris_update[] = { + grpc_uri_parse(&exec_ctx, "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); @@ -129,7 +131,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(addresses_update); + grpc_lb_addresses_destroy(&exec_ctx, addresses_update); // Setup expectations for the update. on_resolution_arg on_res_arg_update; @@ -140,27 +142,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(response_generator, - results_update); - grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, - on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + 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); 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(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); - GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); - GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); - + 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_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 4d16a77924..dfa2d12b5e 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(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { on_resolution_arg* res = static_cast<on_resolution_arg*>(arg); - grpc_channel_args_destroy(res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, 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(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, 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(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); - + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -78,9 +78,10 @@ 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(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -111,8 +112,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); diff --git a/test/core/client_channel/uri_fuzzer_test.cc b/test/core/client_channel/uri_fuzzer_test.cc index ee38453166..ba31793ff3 100644 --- a/test/core/client_channel/uri_fuzzer_test.cc +++ b/test/core/client_channel/uri_fuzzer_test.cc @@ -20,7 +20,6 @@ #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" @@ -34,18 +33,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { memcpy(s, data, size); s[size] = 0; - 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 exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* x; + if ((x = grpc_uri_parse(&exec_ctx, s, 1))) { + grpc_uri_destroy(x); } - - grpc_shutdown(); + grpc_exec_ctx_finish(&exec_ctx); + gpr_free(s); return 0; } diff --git a/test/core/client_channel/uri_parser_test.cc b/test/core/client_channel/uri_parser_test.cc index 254bfddfb3..30183f9f57 100644 --- a/test/core/client_channel/uri_parser_test.cc +++ b/test/core/client_channel/uri_parser_test.cc @@ -20,7 +20,6 @@ #include <string.h> -#include <grpc/grpc.h> #include <grpc/support/log.h> #include "src/core/lib/iomgr/exec_ctx.h" @@ -29,28 +28,29 @@ static void test_succeeds(const char* uri_text, const char* scheme, const char* authority, const char* path, const char* query, const char* fragment) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, 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_core::ExecCtx exec_ctx; - GPR_ASSERT(nullptr == grpc_uri_parse(uri_text, 0)); + 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); } static void test_query_parts() { { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://foo/path?a&b=B&c=&#frag"; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, 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_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://auth/path?foo=bar=baz&foobar=="; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -96,13 +96,14 @@ 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_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; const char* uri_text = "http://foo/path"; - grpc_uri* uri = grpc_uri_parse(uri_text, 0); + grpc_uri* uri = grpc_uri_parse(&exec_ctx, uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp("http", uri->scheme)); @@ -113,14 +114,13 @@ 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,6 +148,5 @@ int main(int argc, char** argv) { test_fails("http://foo?bar#lol#"); test_query_parts(); - grpc_shutdown(); return 0; } |