diff options
Diffstat (limited to 'test')
56 files changed, 1167 insertions, 996 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c index 41ac83b7b7..9c09f00e56 100644 --- a/test/core/bad_client/bad_client.c +++ b/test/core/bad_client/bad_client.c @@ -59,7 +59,7 @@ static void thd_func(void *arg) { gpr_event_set(&a->done_thd, (void *)1); } -static void done_write(void *arg, int success) { +static void done_write(grpc_exec_ctx *exec_ctx, void *arg, int success) { thd_args *a = arg; gpr_event_set(&a->done_write, (void *)1); } @@ -69,9 +69,11 @@ static void server_setup_transport(void *ts, grpc_transport *transport, thd_args *a = ts; static grpc_channel_filter const *extra_filters[] = { &grpc_http_server_filter}; - grpc_server_setup_transport(a->server, transport, extra_filters, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, a->server, transport, extra_filters, GPR_ARRAY_SIZE(extra_filters), mdctx, grpc_server_get_channel_args(a->server)); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, @@ -86,7 +88,8 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, gpr_slice slice = gpr_slice_from_copied_buffer(client_payload, client_payload_length); gpr_slice_buffer outgoing; - grpc_iomgr_closure done_write_closure; + grpc_closure done_write_closure; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; hex = gpr_dump(client_payload, client_payload_length, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -110,13 +113,15 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, a.validator = validator; grpc_server_register_completion_queue(a.server, a.cq, NULL); grpc_server_start(a.server); - transport = grpc_create_chttp2_transport(NULL, sfd.server, mdctx, 0); + transport = + grpc_create_chttp2_transport(&exec_ctx, NULL, sfd.server, mdctx, 0); server_setup_transport(&a, transport, mdctx); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + grpc_exec_ctx_finish(&exec_ctx); /* Bind everything into the same pollset */ - grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); - grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq)); + 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)); /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); @@ -126,27 +131,20 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, gpr_slice_buffer_init(&outgoing); gpr_slice_buffer_add(&outgoing, slice); - grpc_iomgr_closure_init(&done_write_closure, done_write, &a); + grpc_closure_init(&done_write_closure, done_write, &a); /* Write data */ - switch (grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure)) { - case GRPC_ENDPOINT_DONE: - done_write(&a, 1); - break; - case GRPC_ENDPOINT_PENDING: - break; - case GRPC_ENDPOINT_ERROR: - done_write(&a, 0); - break; - } + grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); + grpc_exec_ctx_finish(&exec_ctx); /* Await completion */ GPR_ASSERT( gpr_event_wait(&a.done_write, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))); if (flags & GRPC_BAD_CLIENT_DISCONNECT) { - grpc_endpoint_shutdown(sfd.client); - grpc_endpoint_destroy(sfd.client); + grpc_endpoint_shutdown(&exec_ctx, sfd.client); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); sfd.client = NULL; } @@ -154,8 +152,9 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, /* Shutdown */ if (sfd.client) { - grpc_endpoint_shutdown(sfd.client); - grpc_endpoint_destroy(sfd.client); + grpc_endpoint_shutdown(&exec_ctx, sfd.client); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); } grpc_server_shutdown_and_notify(a.server, a.cq, NULL); GPR_ASSERT(grpc_completion_queue_pluck( @@ -165,5 +164,6 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator, grpc_completion_queue_destroy(a.cq); gpr_slice_buffer_destroy(&outgoing); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } diff --git a/test/core/bad_client/gen_build_yaml.py b/test/core/bad_client/gen_build_yaml.py index 02dda10be0..3df889ecda 100755 --- a/test/core/bad_client/gen_build_yaml.py +++ b/test/core/bad_client/gen_build_yaml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 # Copyright 2015, Google Inc. # All rights reserved. # diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index 60129afc43..2939027891 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -41,7 +41,8 @@ #include "test/core/util/test_config.h" -static void channel_init_func(grpc_channel_element *elem, grpc_channel *master, +static void channel_init_func(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem, grpc_channel *master, const grpc_channel_args *args, grpc_mdctx *metadata_context, int is_first, int is_last) { @@ -54,28 +55,34 @@ static void channel_init_func(grpc_channel_element *elem, grpc_channel *master, *(int *)(elem->channel_data) = 0; } -static void call_init_func(grpc_call_element *elem, +static void call_init_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, const void *server_transport_data, grpc_transport_stream_op *initial_op) { ++*(int *)(elem->channel_data); *(int *)(elem->call_data) = 0; } -static void channel_destroy_func(grpc_channel_element *elem) {} +static void channel_destroy_func(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem) {} -static void call_destroy_func(grpc_call_element *elem) { +static void call_destroy_func(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem) { ++*(int *)(elem->channel_data); } -static void call_func(grpc_call_element *elem, grpc_transport_stream_op *op) { +static void call_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_transport_stream_op *op) { ++*(int *)(elem->call_data); } -static void channel_func(grpc_channel_element *elem, grpc_transport_op *op) { +static void channel_func(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, + grpc_transport_op *op) { ++*(int *)(elem->channel_data); } -static char *get_peer(grpc_call_element *elem) { return gpr_strdup("peer"); } +static char *get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { + return gpr_strdup("peer"); +} static void test_create_channel_stack(void) { const grpc_channel_filter filter = {call_func, channel_func, @@ -93,6 +100,7 @@ static void test_create_channel_stack(void) { grpc_mdctx *metadata_context; int *channel_data; int *call_data; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; metadata_context = grpc_mdctx_create(); @@ -104,15 +112,15 @@ static void test_create_channel_stack(void) { chan_args.args = &arg; channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1)); - grpc_channel_stack_init(&filters, 1, NULL, &chan_args, metadata_context, - channel_stack); + grpc_channel_stack_init(&exec_ctx, &filters, 1, NULL, &chan_args, + metadata_context, channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_data = (int *)channel_elem->channel_data; GPR_ASSERT(*channel_data == 0); call_stack = gpr_malloc(channel_stack->call_stack_size); - grpc_call_stack_init(channel_stack, NULL, NULL, call_stack); + grpc_call_stack_init(&exec_ctx, channel_stack, NULL, NULL, call_stack); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); GPR_ASSERT(call_elem->filter == channel_elem->filter); @@ -121,14 +129,16 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); - grpc_call_stack_destroy(call_stack); + grpc_call_stack_destroy(&exec_ctx, call_stack); gpr_free(call_stack); GPR_ASSERT(*channel_data == 2); - grpc_channel_stack_destroy(channel_stack); + grpc_channel_stack_destroy(&exec_ctx, channel_stack); gpr_free(channel_stack); grpc_mdctx_unref(metadata_context); + + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char **argv) { diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c index 4e7c59569c..b5f75dc3e8 100644 --- a/test/core/client_config/lb_policies_test.c +++ b/test/core/client_config/lb_policies_test.c @@ -387,13 +387,15 @@ static void assert_channel_connectivity( grpc_channel_stack *client_stack; grpc_channel_element *client_channel_filter; grpc_connectivity_state actual_conn_state; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; va_list ap; client_stack = grpc_channel_get_channel_stack(ch); client_channel_filter = grpc_channel_stack_last_element(client_stack); actual_conn_state = grpc_client_channel_check_connectivity_state( - client_channel_filter, 0 /* don't try to connect */); + &exec_ctx, client_channel_filter, 0 /* don't try to connect */); + grpc_exec_ctx_finish(&exec_ctx); va_start(ap, accepted_conn_state); for (i = 0; i < num_accepted_conn_states; i++) { if (actual_conn_state == accepted_conn_state) { @@ -607,26 +609,57 @@ static void verify_rebirth_round_robin(const servers_fixture *f, const int *actual_connection_sequence, const size_t num_iters) { int *expected_connection_sequence; - size_t i; + size_t i, j, unique_seq_last_idx, unique_seq_first_idx; const size_t expected_seq_length = f->num_servers; + uint8_t *seen_elements; /* verify conn. seq. expectation */ - /* get the first sequence of "num_servers" elements */ + /* get the first unique run of length "num_servers". */ expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence + 4, + seen_elements = gpr_malloc(sizeof(int) * expected_seq_length); + + unique_seq_last_idx = ~(size_t)0; + + memset(seen_elements, 0, sizeof(uint8_t) * expected_seq_length); + for (i = 0; i < num_iters; i++) { + if (actual_connection_sequence[i] < 0 || + seen_elements[actual_connection_sequence[i]] != 0) { + /* if anything breaks the uniqueness of the run, back to square zero */ + memset(seen_elements, 0, sizeof(uint8_t) * expected_seq_length); + continue; + } + seen_elements[actual_connection_sequence[i]] = 1; + for (j = 0; j < expected_seq_length; j++) { + if (seen_elements[j] == 0) break; + } + if (j == expected_seq_length) { /* seen all the elements */ + unique_seq_last_idx = i; + break; + } + } + /* make sure we found a valid run */ + for (j = 0; j < expected_seq_length; j++) { + GPR_ASSERT(seen_elements[j] != 0); + } + + GPR_ASSERT(unique_seq_last_idx != ~(size_t)0); + + unique_seq_first_idx = (unique_seq_last_idx - expected_seq_length + 1); + memcpy(expected_connection_sequence, + actual_connection_sequence + unique_seq_first_idx, sizeof(int) * expected_seq_length); /* first iteration succeeds */ GPR_ASSERT(actual_connection_sequence[0] != -1); + /* then we fail for a while... */ + GPR_ASSERT(actual_connection_sequence[1] == -1); + /* ... but should be up at "unique_seq_first_idx" */ + GPR_ASSERT(actual_connection_sequence[unique_seq_first_idx] != -1); - /* back up on the third (or maybe fourth) iteration */ - i = 3; - if (actual_connection_sequence[i] == -1) { - i = 4; - } - for (; i < num_iters; i++) { + for (j = 0, i = unique_seq_first_idx; i < num_iters; i++) { const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; + const int expected = + expected_connection_sequence[j++ % expected_seq_length]; if (actual != expected) { gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); @@ -640,6 +673,7 @@ static void verify_rebirth_round_robin(const servers_fixture *f, /* things are fine once the servers are brought back up */ assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); gpr_free(expected_connection_sequence); + gpr_free(seen_elements); } int main(int argc, char **argv) { diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c index 580c18b699..df12d6b4cb 100644 --- a/test/core/client_config/uri_parser_test.c +++ b/test/core/client_config/uri_parser_test.c @@ -41,7 +41,7 @@ static void test_succeeds(const char *uri_text, const char *scheme, const char *authority, const char *path, - const char *query, const char* fragment) { + const char *query, const char *fragment) { grpc_uri *uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c index 4df0acae37..633fbd97f4 100644 --- a/test/core/compression/compression_test.c +++ b/test/core/compression/compression_test.c @@ -42,15 +42,15 @@ static void test_compression_algorithm_parse(void) { size_t i; - const char* valid_names[] = {"identity", "gzip", "deflate"}; + const char *valid_names[] = {"identity", "gzip", "deflate"}; const grpc_compression_algorithm valid_algorithms[] = { GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_DEFLATE}; - const char* invalid_names[] = {"gzip2", "foo", "", "2gzip"}; + const char *invalid_names[] = {"gzip2", "foo", "", "2gzip"}; gpr_log(GPR_DEBUG, "test_compression_algorithm_parse"); for (i = 0; i < GPR_ARRAY_SIZE(valid_names); i++) { - const char* valid_name = valid_names[i]; + const char *valid_name = valid_names[i]; grpc_compression_algorithm algorithm; int success; success = grpc_compression_algorithm_parse(valid_name, strlen(valid_name), @@ -60,7 +60,7 @@ static void test_compression_algorithm_parse(void) { } for (i = 0; i < GPR_ARRAY_SIZE(invalid_names); i++) { - const char* invalid_name = invalid_names[i]; + const char *invalid_name = invalid_names[i]; grpc_compression_algorithm algorithm; int success; success = grpc_compression_algorithm_parse( @@ -70,7 +70,7 @@ static void test_compression_algorithm_parse(void) { } } -int main(int argc, char** argv) { +int main(int argc, char **argv) { test_compression_algorithm_parse(); return 0; diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index fec9667db8..ca72d71dc1 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -63,6 +63,7 @@ static void drain_cq(grpc_completion_queue *cq) { } static void do_nothing(void *ignored) {} + void test_connect(const char *server_host, const char *client_host, int port, int expect_ok) { char *client_hostport; @@ -125,7 +126,7 @@ void test_connect(const char *server_host, const char *client_host, int port, gpr_slice_new((char *)client_host, strlen(client_host), do_nothing); gpr_slice_buffer_init(&uri_parts); gpr_slice_split(uri_slice, ",", &uri_parts); - hosts_with_port = gpr_malloc(sizeof(char*) * uri_parts.count); + hosts_with_port = gpr_malloc(sizeof(char *) * uri_parts.count); for (i = 0; i < uri_parts.count; i++) { char *uri_part_str = gpr_dump_slice(uri_parts.slices[i], GPR_DUMP_ASCII); gpr_asprintf(&hosts_with_port[i], "%s:%d", uri_part_str, port); @@ -322,19 +323,19 @@ int main(int argc, char **argv) { if (!external_dns_works("loopback46.unittest.grpc.io")) { gpr_log(GPR_INFO, "Skipping tests that depend on *.unittest.grpc.io."); } else { - test_connect("loopback46.unittest.grpc.io", - "loopback4.unittest.grpc.io", 0, 1); - test_connect("loopback4.unittest.grpc.io", - "loopback46.unittest.grpc.io", 0, 1); + test_connect("loopback46.unittest.grpc.io", "loopback4.unittest.grpc.io", + 0, 1); + test_connect("loopback4.unittest.grpc.io", "loopback46.unittest.grpc.io", + 0, 1); if (do_ipv6) { test_connect("loopback46.unittest.grpc.io", "loopback6.unittest.grpc.io", 0, 1); test_connect("loopback6.unittest.grpc.io", "loopback46.unittest.grpc.io", 0, 1); - test_connect("loopback4.unittest.grpc.io", - "loopback6.unittest.grpc.io", 0, 0); - test_connect("loopback6.unittest.grpc.io", - "loopback4.unittest.grpc.io", 0, 0); + test_connect("loopback4.unittest.grpc.io", "loopback6.unittest.grpc.io", + 0, 0); + test_connect("loopback6.unittest.grpc.io", "loopback4.unittest.grpc.io", + 0, 0); } } } diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.c index 60f042e2eb..10db6c2c6a 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.c @@ -67,9 +67,7 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md, return NULL; } -typedef struct { - size_t pseudo_refcount; -} test_processor_state; +typedef struct { size_t pseudo_refcount; } test_processor_state; static void process_oauth2_success(void *state, grpc_auth_context *ctx, const grpc_metadata *md, size_t md_count, diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c index 588c4b23e1..1f5051f0ab 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.c +++ b/test/core/end2end/fixtures/h2_sockpair+trace.c @@ -62,9 +62,11 @@ static void server_setup_transport(void *ts, grpc_transport *transport, grpc_end2end_test_fixture *f = ts; static grpc_channel_filter const *extra_filters[] = { &grpc_http_server_filter}; - grpc_server_setup_transport(f->server, transport, extra_filters, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters, GPR_ARRAY_SIZE(extra_filters), mdctx, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -72,7 +74,8 @@ typedef struct { grpc_channel_args *client_args; } sp_client_setup; -static void client_setup_transport(void *ts, grpc_transport *transport, +static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, + grpc_transport *transport, grpc_mdctx *mdctx) { sp_client_setup *cs = ts; @@ -80,8 +83,9 @@ static void client_setup_transport(void *ts, grpc_transport *transport, &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); - grpc_channel *channel = grpc_channel_create_from_filters( - "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); + grpc_channel *channel = + grpc_channel_create_from_filters(exec_ctx, "socketpair-target", filters, + nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; @@ -105,20 +109,24 @@ 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_endpoint_pair *sfd = f->fixture_data; grpc_transport *transport; grpc_mdctx *mdctx = grpc_mdctx_create(); sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1); - client_setup_transport(&cs, transport, mdctx); + transport = grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, + mdctx, 1); + client_setup_transport(&exec_ctx, &cs, transport, mdctx); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + 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_endpoint_pair *sfd = f->fixture_data; grpc_mdctx *mdctx = grpc_mdctx_create(); grpc_transport *transport; @@ -126,9 +134,11 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, f->server = grpc_server_create_from_filters(NULL, 0, server_args); grpc_server_register_completion_queue(f->server, f->cq, NULL); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0); + transport = grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, + mdctx, 0); server_setup_transport(f, transport, mdctx); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { @@ -144,6 +154,7 @@ 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 */ @@ -156,6 +167,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); 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.c b/test/core/end2end/fixtures/h2_sockpair.c index 16a04fbebf..b61fe98610 100644 --- a/test/core/end2end/fixtures/h2_sockpair.c +++ b/test/core/end2end/fixtures/h2_sockpair.c @@ -61,9 +61,11 @@ static void server_setup_transport(void *ts, grpc_transport *transport, grpc_end2end_test_fixture *f = ts; static grpc_channel_filter const *extra_filters[] = { &grpc_http_server_filter}; - grpc_server_setup_transport(f->server, transport, extra_filters, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters, GPR_ARRAY_SIZE(extra_filters), mdctx, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -71,7 +73,8 @@ typedef struct { grpc_channel_args *client_args; } sp_client_setup; -static void client_setup_transport(void *ts, grpc_transport *transport, +static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, + grpc_transport *transport, grpc_mdctx *mdctx) { sp_client_setup *cs = ts; @@ -79,8 +82,9 @@ static void client_setup_transport(void *ts, grpc_transport *transport, &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); - grpc_channel *channel = grpc_channel_create_from_filters( - "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); + grpc_channel *channel = + grpc_channel_create_from_filters(exec_ctx, "socketpair-target", filters, + nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; @@ -104,20 +108,24 @@ 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_endpoint_pair *sfd = f->fixture_data; grpc_transport *transport; grpc_mdctx *mdctx = grpc_mdctx_create(); sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1); - client_setup_transport(&cs, transport, mdctx); + transport = grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, + mdctx, 1); + client_setup_transport(&exec_ctx, &cs, transport, mdctx); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + 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_endpoint_pair *sfd = f->fixture_data; grpc_mdctx *mdctx = grpc_mdctx_create(); grpc_transport *transport; @@ -125,9 +133,11 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, f->server = grpc_server_create_from_filters(NULL, 0, server_args); grpc_server_register_completion_queue(f->server, f->cq, NULL); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0); + transport = grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, + mdctx, 0); server_setup_transport(f, transport, mdctx); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + 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_sockpair_1byte.c b/test/core/end2end/fixtures/h2_sockpair_1byte.c index 94fc36f5ec..9f0fd2ea9a 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.c +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.c @@ -61,9 +61,11 @@ static void server_setup_transport(void *ts, grpc_transport *transport, grpc_end2end_test_fixture *f = ts; static grpc_channel_filter const *extra_filters[] = { &grpc_http_server_filter}; - grpc_server_setup_transport(f->server, transport, extra_filters, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters, GPR_ARRAY_SIZE(extra_filters), mdctx, grpc_server_get_channel_args(f->server)); + grpc_exec_ctx_finish(&exec_ctx); } typedef struct { @@ -71,7 +73,8 @@ typedef struct { grpc_channel_args *client_args; } sp_client_setup; -static void client_setup_transport(void *ts, grpc_transport *transport, +static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, + grpc_transport *transport, grpc_mdctx *mdctx) { sp_client_setup *cs = ts; @@ -79,8 +82,9 @@ static void client_setup_transport(void *ts, grpc_transport *transport, &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); - grpc_channel *channel = grpc_channel_create_from_filters( - "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); + grpc_channel *channel = + grpc_channel_create_from_filters(exec_ctx, "socketpair-target", filters, + nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; @@ -104,20 +108,24 @@ 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_endpoint_pair *sfd = f->fixture_data; grpc_transport *transport; grpc_mdctx *mdctx = grpc_mdctx_create(); sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1); - client_setup_transport(&cs, transport, mdctx); + transport = grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, + mdctx, 1); + client_setup_transport(&exec_ctx, &cs, transport, mdctx); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + 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_endpoint_pair *sfd = f->fixture_data; grpc_mdctx *mdctx = grpc_mdctx_create(); grpc_transport *transport; @@ -125,9 +133,11 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, f->server = grpc_server_create_from_filters(NULL, 0, server_args); grpc_server_register_completion_queue(f->server, f->cq, NULL); grpc_server_start(f->server); - transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0); + transport = grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, + mdctx, 0); server_setup_transport(f, transport, mdctx); - grpc_chttp2_transport_start_reading(transport, NULL, 0); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); + grpc_exec_ctx_finish(&exec_ctx); } static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index 0090cf42f2..434e75dd15 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -100,6 +100,10 @@ grpc_end2end_proxy *grpc_end2end_proxy_create( gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port); gpr_join_host_port(&proxy->server_port, "localhost", server_port); + + gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port, + proxy->server_port); + proxy->cq = grpc_completion_queue_create(NULL); proxy->server = def->create_server(proxy->proxy_port); proxy->client = def->create_client(proxy->server_port); @@ -142,8 +146,6 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) { } static void unrefpc(proxy_call *pc, const char *reason) { - gpr_log(GPR_DEBUG, "unref %p: %s %d -> %d", pc, reason, pc->refs.count, - pc->refs.count - 1); if (gpr_unref(&pc->refs)) { grpc_call_destroy(pc->c2p); grpc_call_destroy(pc->p2s); @@ -155,11 +157,7 @@ static void unrefpc(proxy_call *pc, const char *reason) { } } -static void refpc(proxy_call *pc, const char *reason) { - gpr_log(GPR_DEBUG, "ref %p: %s %d -> %d", pc, reason, pc->refs.count, - pc->refs.count + 1); - gpr_ref(&pc->refs); -} +static void refpc(proxy_call *pc, const char *reason) { gpr_ref(&pc->refs); } static void on_c2p_sent_initial_metadata(void *arg, int success) { proxy_call *pc = arg; diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 46cdb80c86..9988950a6e 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 # Copyright 2015, Google Inc. # All rights reserved. # diff --git a/test/core/end2end/tests/graceful_server_shutdown.c b/test/core/end2end/tests/graceful_server_shutdown.c index df420a9846..6b786aa89a 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.c +++ b/test/core/end2end/tests/graceful_server_shutdown.c @@ -97,7 +97,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_end2end_test_config config) { grpc_call *c; grpc_call *s; - gpr_timespec deadline = five_seconds_time(); + gpr_timespec deadline = n_seconds_time(10); grpc_end2end_test_fixture f = begin_test( config, "test_early_server_shutdown_finishes_inflight_calls", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 5aace03520..67631e5a07 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -268,7 +268,7 @@ int main(int argc, char **argv) { } else { GPR_ASSERT(shutdown_started); } - /* request_call(); + /* request_call(); */ break; case FLING_SERVER_READ_FOR_STREAMING: diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index cf2b10c021..4012f995c7 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -53,7 +53,8 @@ static gpr_timespec n_seconds_time(int seconds) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(seconds); } -static void on_finish(void *arg, const grpc_httpcli_response *response) { +static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, + const grpc_httpcli_response *response) { const char *expect = "<html><head><title>Hello world!</title></head>" "<body><p>This is a test</p></body></html>"; @@ -71,6 +72,7 @@ static void on_finish(void *arg, const grpc_httpcli_response *response) { static void test_get(int use_ssl, int port) { grpc_httpcli_request req; char *host; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "running %s with use_ssl=%d.", "test_get", use_ssl); @@ -83,13 +85,16 @@ static void test_get(int use_ssl, int port) { req.path = "/get"; req.handshaker = use_ssl ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext; - grpc_httpcli_get(&g_context, &g_pollset, &req, n_seconds_time(15), on_finish, - (void *)42); + grpc_httpcli_get(&exec_ctx, &g_context, &g_pollset, &req, n_seconds_time(15), + on_finish, (void *)42); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!g_done) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - n_seconds_time(20)); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_free(host); @@ -98,6 +103,7 @@ static void test_get(int use_ssl, int port) { static void test_post(int use_ssl, int port) { grpc_httpcli_request req; char *host; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; g_done = 0; gpr_log(GPR_INFO, "running %s with use_ssl=%d.", "test_post", (int)use_ssl); @@ -110,21 +116,28 @@ static void test_post(int use_ssl, int port) { req.path = "/post"; req.handshaker = use_ssl ? &grpc_httpcli_ssl : &grpc_httpcli_plaintext; - grpc_httpcli_post(&g_context, &g_pollset, &req, "hello", 5, + grpc_httpcli_post(&exec_ctx, &g_context, &g_pollset, &req, "hello", 5, n_seconds_time(15), on_finish, (void *)42); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!g_done) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - n_seconds_time(20)); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_free(host); } -static void destroy_pollset(void *ignored) { grpc_pollset_destroy(&g_pollset); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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, '/'); @@ -161,7 +174,9 @@ int main(int argc, char **argv) { test_post(0, port); grpc_httpcli_context_destroy(&g_context); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, NULL); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_subprocess_destroy(server); diff --git a/test/core/httpcli/test_server.py b/test/core/httpcli/test_server.py index babfe84ddc..4aaf5e30f8 100755 --- a/test/core/httpcli/test_server.py +++ b/test/core/httpcli/test_server.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 """Server for httpcli_test""" diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index 56d662e61a..6656a8fa3b 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -42,11 +42,8 @@ #define MAX_CB 30 static int cb_called[MAX_CB][2]; -static int kicks; -void grpc_kick_poller(void) { ++kicks; } - -static void cb(void *arg, int success) { +static void cb(grpc_exec_ctx *exec_ctx, void *arg, int success) { cb_called[(gpr_intptr)arg][success]++; } @@ -54,54 +51,59 @@ static void add_test(void) { gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); int i; grpc_alarm alarms[20]; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_alarm_list_init(start); memset(cb_called, 0, sizeof(cb_called)); /* 10 ms alarms. will expire in the current epoch */ for (i = 0; i < 10; i++) { - grpc_alarm_init(&alarms[i], + grpc_alarm_init(&exec_ctx, &alarms[i], gpr_time_add(start, gpr_time_from_millis(10, GPR_TIMESPAN)), cb, (void *)(gpr_intptr)i, start); } /* 1010 ms alarms. will expire in the next epoch */ for (i = 10; i < 20; i++) { - grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis( - 1010, GPR_TIMESPAN)), - cb, (void *)(gpr_intptr)i, start); + grpc_alarm_init( + &exec_ctx, &alarms[i], + gpr_time_add(start, gpr_time_from_millis(1010, GPR_TIMESPAN)), cb, + (void *)(gpr_intptr)i, start); } /* collect alarms. Only the first batch should be ready. */ - GPR_ASSERT(10 == grpc_alarm_check(NULL, + GPR_ASSERT(10 == grpc_alarm_check(&exec_ctx, gpr_time_add(start, gpr_time_from_millis( 500, GPR_TIMESPAN)), NULL)); + grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == grpc_alarm_check( - NULL, gpr_time_add( - start, gpr_time_from_millis(600, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(0 == grpc_alarm_check(&exec_ctx, + gpr_time_add(start, gpr_time_from_millis( + 600, GPR_TIMESPAN)), + NULL)); + grpc_exec_ctx_finish(&exec_ctx); 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 alarms */ - GPR_ASSERT( - 10 == grpc_alarm_check(NULL, gpr_time_add(start, gpr_time_from_millis( - 1500, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(10 == grpc_alarm_check( + &exec_ctx, gpr_time_add(start, gpr_time_from_millis( + 1500, GPR_TIMESPAN)), + NULL)); + grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == grpc_alarm_check(NULL, + GPR_ASSERT(0 == grpc_alarm_check(&exec_ctx, gpr_time_add(start, gpr_time_from_millis( 1600, GPR_TIMESPAN)), NULL)); @@ -110,7 +112,8 @@ static void add_test(void) { GPR_ASSERT(cb_called[i][0] == 0); } - grpc_alarm_list_shutdown(); + grpc_alarm_list_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); } static gpr_timespec tfm(int m) { @@ -122,28 +125,32 @@ static gpr_timespec tfm(int m) { /* Cleaning up a list with pending alarms. */ void destruction_test(void) { grpc_alarm alarms[5]; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_alarm_list_init(gpr_time_0(GPR_CLOCK_REALTIME)); memset(cb_called, 0, sizeof(cb_called)); - grpc_alarm_init(&alarms[0], tfm(100), cb, (void *)(gpr_intptr)0, + grpc_alarm_init(&exec_ctx, &alarms[0], tfm(100), cb, (void *)(gpr_intptr)0, gpr_time_0(GPR_CLOCK_REALTIME)); - grpc_alarm_init(&alarms[1], tfm(3), cb, (void *)(gpr_intptr)1, + grpc_alarm_init(&exec_ctx, &alarms[1], tfm(3), cb, (void *)(gpr_intptr)1, gpr_time_0(GPR_CLOCK_REALTIME)); - grpc_alarm_init(&alarms[2], tfm(100), cb, (void *)(gpr_intptr)2, + grpc_alarm_init(&exec_ctx, &alarms[2], tfm(100), cb, (void *)(gpr_intptr)2, gpr_time_0(GPR_CLOCK_REALTIME)); - grpc_alarm_init(&alarms[3], tfm(3), cb, (void *)(gpr_intptr)3, + grpc_alarm_init(&exec_ctx, &alarms[3], tfm(3), cb, (void *)(gpr_intptr)3, gpr_time_0(GPR_CLOCK_REALTIME)); - grpc_alarm_init(&alarms[4], tfm(1), cb, (void *)(gpr_intptr)4, + grpc_alarm_init(&exec_ctx, &alarms[4], tfm(1), cb, (void *)(gpr_intptr)4, gpr_time_0(GPR_CLOCK_REALTIME)); - GPR_ASSERT(1 == grpc_alarm_check(NULL, tfm(2), NULL)); + GPR_ASSERT(1 == grpc_alarm_check(&exec_ctx, tfm(2), NULL)); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[4][1]); - grpc_alarm_cancel(&alarms[0]); - grpc_alarm_cancel(&alarms[3]); + grpc_alarm_cancel(&exec_ctx, &alarms[0]); + grpc_alarm_cancel(&exec_ctx, &alarms[3]); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[0][0]); GPR_ASSERT(1 == cb_called[3][0]); - grpc_alarm_list_shutdown(); + grpc_alarm_list_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(1 == cb_called[1][0]); GPR_ASSERT(1 == cb_called[2][0]); } diff --git a/test/core/iomgr/alarm_test.c b/test/core/iomgr/alarm_test.c deleted file mode 100644 index 55aa517529..0000000000 --- a/test/core/iomgr/alarm_test.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* Test gRPC event manager with a simple TCP upload server and client. */ -#include "src/core/iomgr/alarm.h" - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <grpc/grpc.h> -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> -#include <grpc/support/sync.h> -#include <grpc/support/time.h> -#include "test/core/util/test_config.h" - -#define SUCCESS_NOT_SET (-1) - -/* Dummy gRPC callback */ -void no_op_cb(void *arg, int success) {} - -typedef struct { - gpr_cv cv; - gpr_mu mu; - grpc_iomgr_closure *followup_closure; - int counter; - int done_success_ctr; - int done_cancel_ctr; - int done; - gpr_event fcb_arg; - int success; -} alarm_arg; - -static void followup_cb(void *arg, int success) { - gpr_event_set((gpr_event *)arg, arg); -} - -/* Called when an alarm expires. */ -static void alarm_cb(void *arg /* alarm_arg */, int success) { - alarm_arg *a = arg; - gpr_mu_lock(&a->mu); - if (success) { - a->counter++; - a->done_success_ctr++; - } else { - a->done_cancel_ctr++; - } - a->done = 1; - a->success = success; - gpr_cv_signal(&a->cv); - gpr_mu_unlock(&a->mu); - grpc_iomgr_closure_init(a->followup_closure, followup_cb, &a->fcb_arg); - grpc_iomgr_add_callback(a->followup_closure); -} - -/* Test grpc_alarm add and cancel. */ -static void test_grpc_alarm(void) { - grpc_alarm alarm; - grpc_alarm alarm_to_cancel; - /* Timeout on the alarm cond. var, so make big enough to absorb time - deviations. Otherwise, operations after wait will not be properly ordered - */ - gpr_timespec alarm_deadline; - gpr_timespec followup_deadline; - - alarm_arg arg; - alarm_arg arg2; - void *fdone; - - grpc_init(); - - arg.counter = 0; - arg.success = SUCCESS_NOT_SET; - arg.done_success_ctr = 0; - arg.done_cancel_ctr = 0; - arg.done = 0; - gpr_mu_init(&arg.mu); - gpr_cv_init(&arg.cv); - arg.followup_closure = gpr_malloc(sizeof(grpc_iomgr_closure)); - gpr_event_init(&arg.fcb_arg); - - grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg, - gpr_now(GPR_CLOCK_MONOTONIC)); - - alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); - gpr_mu_lock(&arg.mu); - while (arg.done == 0) { - if (gpr_cv_wait(&arg.cv, &arg.mu, alarm_deadline)) { - gpr_log(GPR_ERROR, "alarm deadline exceeded"); - break; - } - } - gpr_mu_unlock(&arg.mu); - - followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); - fdone = gpr_event_wait(&arg.fcb_arg, followup_deadline); - - if (arg.counter != 1) { - gpr_log(GPR_ERROR, "Alarm callback not called"); - GPR_ASSERT(0); - } else if (arg.done_success_ctr != 1) { - gpr_log(GPR_ERROR, "Alarm done callback not called with success"); - GPR_ASSERT(0); - } else if (arg.done_cancel_ctr != 0) { - gpr_log(GPR_ERROR, "Alarm done callback called with cancel"); - GPR_ASSERT(0); - } else if (arg.success == SUCCESS_NOT_SET) { - gpr_log(GPR_ERROR, "Alarm callback without status"); - GPR_ASSERT(0); - } else { - gpr_log(GPR_INFO, "Alarm callback called successfully"); - } - - if (fdone != (void *)&arg.fcb_arg) { - gpr_log(GPR_ERROR, "Followup callback #1 not invoked properly %p %p", fdone, - &arg.fcb_arg); - GPR_ASSERT(0); - } - gpr_cv_destroy(&arg.cv); - gpr_mu_destroy(&arg.mu); - gpr_free(arg.followup_closure); - - arg2.counter = 0; - arg2.success = SUCCESS_NOT_SET; - arg2.done_success_ctr = 0; - arg2.done_cancel_ctr = 0; - arg2.done = 0; - gpr_mu_init(&arg2.mu); - gpr_cv_init(&arg2.cv); - arg2.followup_closure = gpr_malloc(sizeof(grpc_iomgr_closure)); - - gpr_event_init(&arg2.fcb_arg); - - grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), - alarm_cb, &arg2, gpr_now(GPR_CLOCK_MONOTONIC)); - grpc_alarm_cancel(&alarm_to_cancel); - - alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); - gpr_mu_lock(&arg2.mu); - while (arg2.done == 0) { - gpr_cv_wait(&arg2.cv, &arg2.mu, alarm_deadline); - } - gpr_mu_unlock(&arg2.mu); - - gpr_log(GPR_INFO, "alarm done = %d", arg2.done); - - followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); - fdone = gpr_event_wait(&arg2.fcb_arg, followup_deadline); - - if (arg2.counter != arg2.done_success_ctr) { - gpr_log(GPR_ERROR, "Alarm callback called but didn't lead to done success"); - GPR_ASSERT(0); - } else if (arg2.done_success_ctr && arg2.done_cancel_ctr) { - gpr_log(GPR_ERROR, "Alarm done callback called with success and cancel"); - GPR_ASSERT(0); - } else if (arg2.done_cancel_ctr + arg2.done_success_ctr != 1) { - gpr_log(GPR_ERROR, "Alarm done callback called incorrect number of times"); - GPR_ASSERT(0); - } else if (arg2.success == SUCCESS_NOT_SET) { - gpr_log(GPR_ERROR, "Alarm callback without status"); - GPR_ASSERT(0); - } else if (arg2.done_success_ctr) { - gpr_log(GPR_INFO, "Alarm callback executed before cancel"); - gpr_log(GPR_INFO, "Current value of triggered is %d\n", - alarm_to_cancel.triggered); - } else if (arg2.done_cancel_ctr) { - gpr_log(GPR_INFO, "Alarm callback canceled"); - gpr_log(GPR_INFO, "Current value of triggered is %d\n", - alarm_to_cancel.triggered); - } else { - gpr_log(GPR_ERROR, "Alarm cancel test should not be here"); - GPR_ASSERT(0); - } - - if (fdone != (void *)&arg2.fcb_arg) { - gpr_log(GPR_ERROR, "Followup callback #2 not invoked properly %p %p", fdone, - &arg2.fcb_arg); - GPR_ASSERT(0); - } - gpr_cv_destroy(&arg2.cv); - gpr_mu_destroy(&arg2.mu); - gpr_free(arg2.followup_closure); - - grpc_shutdown(); -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - test_grpc_alarm(); - return 0; -} diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c index 3abde5ac35..ff590cf2d5 100644 --- a/test/core/iomgr/endpoint_pair_test.c +++ b/test/core/iomgr/endpoint_pair_test.c @@ -48,13 +48,15 @@ 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_endpoint_test_fixture f; grpc_endpoint_pair p = grpc_iomgr_create_endpoint_pair("test", slice_size); f.client_ep = p.client; f.server_ep = p.server; - grpc_endpoint_add_to_pollset(f.client_ep, &g_pollset); - grpc_endpoint_add_to_pollset(f.server_ep, &g_pollset); + 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); return f; } @@ -63,14 +65,20 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, }; -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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(); grpc_pollset_init(&g_pollset); grpc_endpoint_tests(configs[0], &g_pollset); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 853b9a32c2..4b72590819 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -122,14 +122,14 @@ struct read_and_write_test_state { int write_done; gpr_slice_buffer incoming; gpr_slice_buffer outgoing; - grpc_iomgr_closure done_read; - grpc_iomgr_closure done_write; + grpc_closure done_read; + grpc_closure done_write; }; -static void read_and_write_test_read_handler(void *data, int success) { +static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, + void *data, int success) { struct read_and_write_test_state *state = data; -loop: state->bytes_read += count_slices( state->incoming.slices, state->incoming.count, &state->current_read_data); if (state->bytes_read == state->target_bytes || !success) { @@ -139,56 +139,35 @@ loop: grpc_pollset_kick(g_pollset, NULL); gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); } else if (success) { - switch (grpc_endpoint_read(state->read_ep, &state->incoming, - &state->done_read)) { - case GRPC_ENDPOINT_ERROR: - success = 0; - goto loop; - case GRPC_ENDPOINT_DONE: - success = 1; - goto loop; - case GRPC_ENDPOINT_PENDING: - break; - } + grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, + &state->done_read); } } -static void read_and_write_test_write_handler(void *data, int success) { +static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx, + void *data, int success) { struct read_and_write_test_state *state = data; gpr_slice *slices = NULL; size_t nslices; - grpc_endpoint_op_status write_status; if (success) { - for (;;) { - /* Need to do inline writes until they don't succeed synchronously or we - finish writing */ - state->bytes_written += state->current_write_size; - if (state->target_bytes - state->bytes_written < - state->current_write_size) { - state->current_write_size = state->target_bytes - state->bytes_written; - } - if (state->current_write_size == 0) { - break; - } - + state->bytes_written += state->current_write_size; + if (state->target_bytes - state->bytes_written < + state->current_write_size) { + state->current_write_size = state->target_bytes - state->bytes_written; + } + if (state->current_write_size != 0) { slices = allocate_blocks(state->current_write_size, 8192, &nslices, &state->current_write_data); gpr_slice_buffer_reset_and_unref(&state->outgoing); gpr_slice_buffer_addn(&state->outgoing, slices, nslices); - write_status = grpc_endpoint_write(state->write_ep, &state->outgoing, - &state->done_write); + grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing, + &state->done_write); free(slices); - if (write_status == GRPC_ENDPOINT_PENDING) { - return; - } else if (write_status == GRPC_ENDPOINT_ERROR) { - goto cleanup; - } + return; } - GPR_ASSERT(state->bytes_written == state->target_bytes); } -cleanup: gpr_log(GPR_INFO, "Write handler done"); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); state->write_done = 1 + success; @@ -207,6 +186,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", slice_size); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "num_bytes=%d write_size=%d slice_size=%d shutdown=%d", num_bytes, write_size, slice_size, shutdown); @@ -227,10 +207,9 @@ static void read_and_write_test(grpc_endpoint_test_config config, state.write_done = 0; state.current_read_data = 0; state.current_write_data = 0; - grpc_iomgr_closure_init(&state.done_read, read_and_write_test_read_handler, - &state); - grpc_iomgr_closure_init(&state.done_write, read_and_write_test_write_handler, - &state); + grpc_closure_init(&state.done_read, read_and_write_test_read_handler, &state); + grpc_closure_init(&state.done_write, read_and_write_test_write_handler, + &state); gpr_slice_buffer_init(&state.outgoing); gpr_slice_buffer_init(&state.incoming); @@ -239,41 +218,36 @@ 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(&state, 1); + read_and_write_test_write_handler(&exec_ctx, &state, 1); + grpc_exec_ctx_finish(&exec_ctx); - switch ( - grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read)) { - case GRPC_ENDPOINT_PENDING: - break; - case GRPC_ENDPOINT_ERROR: - read_and_write_test_read_handler(&state, 0); - break; - case GRPC_ENDPOINT_DONE: - read_and_write_test_read_handler(&state, 1); - break; - } + grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming, + &state.done_read); if (shutdown) { gpr_log(GPR_DEBUG, "shutdown read"); - grpc_endpoint_shutdown(state.read_ep); + grpc_endpoint_shutdown(&exec_ctx, state.read_ep); gpr_log(GPR_DEBUG, "shutdown write"); - grpc_endpoint_shutdown(state.write_ep); + grpc_endpoint_shutdown(&exec_ctx, state.write_ep); } + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!state.read_done || !state.write_done) { grpc_pollset_worker worker; GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0); - grpc_pollset_work(g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); end_test(config); gpr_slice_buffer_destroy(&state.outgoing); gpr_slice_buffer_destroy(&state.incoming); - grpc_endpoint_destroy(state.read_ep); - grpc_endpoint_destroy(state.write_ep); + grpc_endpoint_destroy(&exec_ctx, state.read_ep); + grpc_endpoint_destroy(&exec_ctx, state.write_ep); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_endpoint_tests(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/fd_conservation_posix_test.c b/test/core/iomgr/fd_conservation_posix_test.c index 8327c681b8..401bf70a9e 100644 --- a/test/core/iomgr/fd_conservation_posix_test.c +++ b/test/core/iomgr/fd_conservation_posix_test.c @@ -43,6 +43,7 @@ int main(int argc, char **argv) { int i; struct rlimit rlim; grpc_endpoint_pair p; + grpc_test_init(argc, argv); grpc_iomgr_init(); @@ -53,9 +54,11 @@ int main(int argc, char **argv) { GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); for (i = 0; i < 100; i++) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; p = grpc_iomgr_create_endpoint_pair("test", 1); - grpc_endpoint_destroy(p.client); - grpc_endpoint_destroy(p.server); + grpc_endpoint_destroy(&exec_ctx, p.client); + grpc_endpoint_destroy(&exec_ctx, p.server); + grpc_exec_ctx_finish(&exec_ctx); } grpc_iomgr_shutdown(); diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 75959069c0..f592f63ba9 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -98,7 +98,7 @@ typedef struct { grpc_fd *em_fd; /* listening fd */ ssize_t read_bytes_total; /* total number of received bytes */ int done; /* set to 1 when a server finishes serving */ - grpc_iomgr_closure listen_closure; + grpc_closure listen_closure; } server; static void server_init(server *sv) { @@ -112,23 +112,23 @@ typedef struct { server *sv; /* not owned by a single session */ grpc_fd *em_fd; /* fd to read upload bytes */ char read_buf[BUF_SIZE]; /* buffer to store upload bytes */ - grpc_iomgr_closure session_read_closure; + grpc_closure session_read_closure; } session; /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ -static void session_shutdown_cb(void *arg, /*session*/ +static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ int success) { session *se = arg; server *sv = se->sv; - grpc_fd_orphan(se->em_fd, NULL, "a"); + grpc_fd_orphan(exec_ctx, se->em_fd, NULL, "a"); gpr_free(se); /* Start to shutdown listen fd. */ - grpc_fd_shutdown(sv->em_fd); + grpc_fd_shutdown(exec_ctx, sv->em_fd); } /* Called when data become readable in a session. */ -static void session_read_cb(void *arg, /*session*/ +static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ int success) { session *se = arg; int fd = se->em_fd->fd; @@ -137,7 +137,7 @@ static void session_read_cb(void *arg, /*session*/ ssize_t read_total = 0; if (!success) { - session_shutdown_cb(arg, 1); + session_shutdown_cb(exec_ctx, arg, 1); return; } @@ -152,7 +152,7 @@ static void session_read_cb(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(arg, 1); + session_shutdown_cb(exec_ctx, arg, 1); } else if (read_once == -1) { if (errno == EAGAIN) { /* An edge triggered event is cached in the kernel until next poll. @@ -163,7 +163,7 @@ static void session_read_cb(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(se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); } else { gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); abort(); @@ -173,10 +173,11 @@ static void session_read_cb(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(void *arg /*server*/, int success) { +static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, + int success) { server *sv = arg; - grpc_fd_orphan(sv->em_fd, NULL, "b"); + grpc_fd_orphan(exec_ctx, sv->em_fd, NULL, "b"); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); sv->done = 1; @@ -185,7 +186,7 @@ static void listen_shutdown_cb(void *arg /*server*/, int success) { } /* Called when a new TCP connection request arrives in the listening port. */ -static void listen_cb(void *arg, /*=sv_arg*/ +static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/ int success) { server *sv = arg; int fd; @@ -196,7 +197,7 @@ static void listen_cb(void *arg, /*=sv_arg*/ grpc_fd *listen_em_fd = sv->em_fd; if (!success) { - listen_shutdown_cb(arg, 1); + listen_shutdown_cb(exec_ctx, arg, 1); return; } @@ -208,12 +209,12 @@ static void listen_cb(void *arg, /*=sv_arg*/ se = gpr_malloc(sizeof(*se)); se->sv = sv; se->em_fd = grpc_fd_create(fd, "listener"); - grpc_pollset_add_fd(&g_pollset, se->em_fd); + grpc_pollset_add_fd(exec_ctx, &g_pollset, se->em_fd); se->session_read_closure.cb = session_read_cb; se->session_read_closure.cb_arg = se; - grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure); + grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); - grpc_fd_notify_on_read(listen_em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(exec_ctx, listen_em_fd, &sv->listen_closure); } /* Max number of connections pending to be accepted by listen(). */ @@ -223,7 +224,7 @@ static void listen_cb(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(server *sv) { +static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { int port = 0; int fd; struct sockaddr_in sin; @@ -237,11 +238,11 @@ static int server_start(server *sv) { GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); sv->em_fd = grpc_fd_create(fd, "server"); - grpc_pollset_add_fd(&g_pollset, sv->em_fd); + grpc_pollset_add_fd(exec_ctx, &g_pollset, sv->em_fd); /* Register to be interested in reading from listen_fd. */ sv->listen_closure.cb = listen_cb; sv->listen_closure.cb_arg = sv; - grpc_fd_notify_on_read(sv->em_fd, &sv->listen_closure); + grpc_fd_notify_on_read(exec_ctx, sv->em_fd, &sv->listen_closure); return port; } @@ -250,9 +251,14 @@ static int server_start(server *sv) { static void server_wait_and_shutdown(server *sv) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!sv->done) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } @@ -274,7 +280,7 @@ typedef struct { int client_write_cnt; int done; /* set to 1 when a client finishes sending */ - grpc_iomgr_closure write_closure; + grpc_closure write_closure; } client; static void client_init(client *cl) { @@ -285,15 +291,16 @@ static void client_init(client *cl) { } /* Called when a client upload session is ready to shutdown. */ -static void client_session_shutdown_cb(void *arg /*client*/, int success) { +static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx, + void *arg /*client */, int success) { client *cl = arg; - grpc_fd_orphan(cl->em_fd, NULL, "c"); + grpc_fd_orphan(exec_ctx, cl->em_fd, NULL, "c"); cl->done = 1; grpc_pollset_kick(&g_pollset, NULL); } /* Write as much as possible, then register notify_on_write. */ -static void client_session_write(void *arg, /*client*/ +static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ int success) { client *cl = arg; int fd = cl->em_fd->fd; @@ -301,7 +308,7 @@ static void client_session_write(void *arg, /*client*/ if (!success) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - client_session_shutdown_cb(arg, 1); + client_session_shutdown_cb(exec_ctx, arg, 1); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); return; } @@ -316,10 +323,10 @@ static void client_session_write(void *arg, /*client*/ if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { cl->write_closure.cb = client_session_write; cl->write_closure.cb_arg = cl; - grpc_fd_notify_on_write(cl->em_fd, &cl->write_closure); + grpc_fd_notify_on_write(exec_ctx, cl->em_fd, &cl->write_closure); cl->client_write_cnt++; } else { - client_session_shutdown_cb(arg, 1); + client_session_shutdown_cb(exec_ctx, arg, 1); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } else { @@ -329,7 +336,7 @@ static void client_session_write(void *arg, /*client*/ } /* Start a client to send a stream of bytes. */ -static void client_start(client *cl, int port) { +static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); @@ -350,9 +357,9 @@ static void client_start(client *cl, int port) { } cl->em_fd = grpc_fd_create(fd, "client"); - grpc_pollset_add_fd(&g_pollset, cl->em_fd); + grpc_pollset_add_fd(exec_ctx, &g_pollset, cl->em_fd); - client_session_write(cl, 1); + client_session_write(exec_ctx, cl, 1); } /* Wait for the signal to shutdown a client. */ @@ -360,8 +367,13 @@ static void client_wait_and_shutdown(client *cl) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!cl->done) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } @@ -373,11 +385,13 @@ static void test_grpc_fd(void) { server sv; client cl; int port; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; server_init(&sv); - port = server_start(&sv); + port = server_start(&exec_ctx, &sv); client_init(&cl); - client_start(&cl, port); + client_start(&exec_ctx, &cl, port); + grpc_exec_ctx_finish(&exec_ctx); client_wait_and_shutdown(&cl); server_wait_and_shutdown(&sv); GPR_ASSERT(sv.read_bytes_total == cl.write_bytes_total); @@ -385,14 +399,15 @@ static void test_grpc_fd(void) { } typedef struct fd_change_data { - void (*cb_that_ran)(void *, int success); + void (*cb_that_ran)(grpc_exec_ctx *exec_ctx, void *, int success); } fd_change_data; void init_change_data(fd_change_data *fdc) { fdc->cb_that_ran = NULL; } void destroy_change_data(fd_change_data *fdc) {} -static void first_read_callback(void *arg /* fd_change_data */, int success) { +static void first_read_callback(grpc_exec_ctx *exec_ctx, + void *arg /* fd_change_data */, int success) { fd_change_data *fdc = arg; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -401,7 +416,8 @@ static void first_read_callback(void *arg /* fd_change_data */, int success) { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } -static void second_read_callback(void *arg /* fd_change_data */, int success) { +static void second_read_callback(grpc_exec_ctx *exec_ctx, + void *arg /* fd_change_data */, int success) { fd_change_data *fdc = arg; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -421,8 +437,9 @@ static void test_grpc_fd_change(void) { int sv[2]; char data; ssize_t result; - grpc_iomgr_closure first_closure; - grpc_iomgr_closure second_closure; + grpc_closure first_closure; + grpc_closure second_closure; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; first_closure.cb = first_read_callback; first_closure.cb_arg = &a; @@ -439,10 +456,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(&g_pollset, em_fd); + grpc_pollset_add_fd(&exec_ctx, &g_pollset, em_fd); /* Register the first callback, then make its FD readable */ - grpc_fd_notify_on_read(em_fd, &first_closure); + grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -451,8 +468,12 @@ static void test_grpc_fd_change(void) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (a.cb_that_ran == NULL) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } GPR_ASSERT(a.cb_that_ran == first_read_callback); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); @@ -463,7 +484,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(em_fd, &second_closure); + grpc_fd_notify_on_read(&exec_ctx, em_fd, &second_closure); data = 0; result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); @@ -471,28 +492,39 @@ static void test_grpc_fd_change(void) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (b.cb_that_ran == NULL) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_fd_orphan(em_fd, NULL, "d"); + grpc_fd_orphan(&exec_ctx, em_fd, NULL, "d"); + grpc_exec_ctx_finish(&exec_ctx); destroy_change_data(&a); destroy_change_data(&b); close(sv[1]); } -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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_iomgr_init(); grpc_pollset_init(&g_pollset); test_grpc_fd(); test_grpc_fd_change(); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_iomgr_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c index 668c5399f9..1c95a9960e 100644 --- a/test/core/iomgr/resolve_address_test.c +++ b/test/core/iomgr/resolve_address_test.c @@ -42,16 +42,18 @@ static gpr_timespec test_deadline(void) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100); } -static void must_succeed(void* evp, grpc_resolved_addresses* p) { +static void must_succeed(grpc_exec_ctx *exec_ctx, void *evp, + grpc_resolved_addresses *p) { GPR_ASSERT(p); GPR_ASSERT(p->naddrs >= 1); grpc_resolved_addresses_destroy(p); - gpr_event_set(evp, (void*)1); + gpr_event_set(evp, (void *)1); } -static void must_fail(void* evp, grpc_resolved_addresses* p) { +static void must_fail(grpc_exec_ctx *exec_ctx, void *evp, + grpc_resolved_addresses *p) { GPR_ASSERT(!p); - gpr_event_set(evp, (void*)1); + gpr_event_set(evp, (void *)1); } static void test_localhost(void) { @@ -83,7 +85,7 @@ static void test_ipv6_with_port(void) { } static void test_ipv6_without_port(void) { - const char* const kCases[] = { + const char *const kCases[] = { "2001:db8::1", "2001:db8::1.2.3.4", "[2001:db8::1]", }; unsigned i; @@ -96,7 +98,7 @@ static void test_ipv6_without_port(void) { } static void test_invalid_ip_addresses(void) { - const char* const kCases[] = { + const char *const kCases[] = { "293.283.1238.3:1", "[2001:db8::11111]:1", }; unsigned i; @@ -109,7 +111,7 @@ static void test_invalid_ip_addresses(void) { } static void test_unparseable_hostports(void) { - const char* const kCases[] = { + const char *const kCases[] = { "[", "[::1", "[::1]bad", "[1.2.3.4]", "[localhost]", "[localhost]:1", }; unsigned i; @@ -121,7 +123,7 @@ static void test_unparseable_hostports(void) { } } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_localhost(); diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c index 72a0f71835..5009a641ea 100644 --- a/test/core/iomgr/sockaddr_utils_test.c +++ b/test/core/iomgr/sockaddr_utils_test.c @@ -63,9 +63,11 @@ static struct sockaddr_in6 make_addr6(const gpr_uint8 *data, size_t data_len) { static const gpr_uint8 kMapped[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 192, 0, 2, 1}; + static const gpr_uint8 kNotQuiteMapped[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 192, 0, 2, 99}; static const gpr_uint8 kIPv4[] = {192, 0, 2, 1}; + static const gpr_uint8 kIPv6[] = {0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index f0e2de24d9..a61cccdb02 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -50,6 +50,7 @@ static grpc_pollset_set g_pollset_set; static grpc_pollset g_pollset; static int g_connections_complete = 0; +static grpc_endpoint *g_connecting = NULL; static gpr_timespec test_deadline(void) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); @@ -62,15 +63,18 @@ static void finish_connection() { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } -static void must_succeed(void *arg, grpc_endpoint *tcp) { - GPR_ASSERT(tcp); - grpc_endpoint_shutdown(tcp); - grpc_endpoint_destroy(tcp); +static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, int success) { + GPR_ASSERT(g_connecting != NULL); + GPR_ASSERT(success); + grpc_endpoint_shutdown(exec_ctx, g_connecting); + grpc_endpoint_destroy(exec_ctx, g_connecting); + g_connecting = NULL; finish_connection(); } -static void must_fail(void *arg, grpc_endpoint *tcp) { - GPR_ASSERT(!tcp); +static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, int success) { + GPR_ASSERT(g_connecting == NULL); + GPR_ASSERT(!success); finish_connection(); } @@ -80,6 +84,8 @@ void test_succeeds(void) { int svr_fd; int r; int connections_complete_before; + grpc_closure done; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_succeeds"); @@ -98,7 +104,8 @@ void test_succeeds(void) { /* connect to it */ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0); - grpc_tcp_client_connect(must_succeed, NULL, &g_pollset_set, + grpc_closure_init(&done, must_succeed, NULL); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, (struct sockaddr *)&addr, addr_len, gpr_inf_future(GPR_CLOCK_REALTIME)); @@ -114,8 +121,12 @@ void test_succeeds(void) { while (g_connections_complete == connections_complete_before) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); @@ -125,6 +136,8 @@ void test_fails(void) { struct sockaddr_in addr; socklen_t addr_len = sizeof(addr); int connections_complete_before; + grpc_closure done; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_fails"); @@ -136,7 +149,8 @@ void test_fails(void) { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); /* connect to a broken address */ - grpc_tcp_client_connect(must_fail, NULL, &g_pollset_set, + grpc_closure_init(&done, must_fail, NULL); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, (struct sockaddr *)&addr, addr_len, gpr_inf_future(GPR_CLOCK_REALTIME)); @@ -145,8 +159,11 @@ void test_fails(void) { /* wait for the connection callback to finish */ while (g_connections_complete == connections_complete_before) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - test_deadline()); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), test_deadline()); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); @@ -162,6 +179,8 @@ void test_times_out(void) { int r; int connections_complete_before; gpr_timespec connect_deadline; + grpc_closure done; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "test_times_out"); @@ -195,7 +214,8 @@ void test_times_out(void) { connections_complete_before = g_connections_complete; gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_tcp_client_connect(must_fail, NULL, &g_pollset_set, + grpc_closure_init(&done, must_fail, NULL); + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, (struct sockaddr *)&addr, addr_len, connect_deadline); /* Make sure the event doesn't trigger early */ @@ -203,25 +223,31 @@ void test_times_out(void) { for (;;) { grpc_pollset_worker worker; gpr_timespec now = gpr_now(connect_deadline.clock_type); - gpr_timespec continue_verifying_time = gpr_time_from_seconds(2, GPR_TIMESPAN); - gpr_timespec grace_time = gpr_time_from_seconds(1, GPR_TIMESPAN); - gpr_timespec finish_time = gpr_time_add(connect_deadline, continue_verifying_time); - gpr_timespec restart_verifying_time = gpr_time_add(connect_deadline, grace_time); + gpr_timespec continue_verifying_time = + gpr_time_from_seconds(5, GPR_TIMESPAN); + gpr_timespec grace_time = gpr_time_from_seconds(3, GPR_TIMESPAN); + gpr_timespec finish_time = + gpr_time_add(connect_deadline, continue_verifying_time); + gpr_timespec restart_verifying_time = + gpr_time_add(connect_deadline, grace_time); int is_after_deadline = gpr_time_cmp(now, connect_deadline) > 0; if (gpr_time_cmp(now, finish_time) > 0) { break; } - gpr_log(GPR_DEBUG, "now=%d.%09d connect_deadline=%d.%09d", - now.tv_sec, now.tv_nsec, connect_deadline.tv_sec, connect_deadline.tv_nsec); - if (is_after_deadline && - gpr_time_cmp(now, restart_verifying_time) <= 0) { + gpr_log(GPR_DEBUG, "now=%d.%09d connect_deadline=%d.%09d", now.tv_sec, + now.tv_nsec, connect_deadline.tv_sec, connect_deadline.tv_nsec); + if (is_after_deadline && gpr_time_cmp(now, restart_verifying_time) <= 0) { /* allow some slack before insisting that things be done */ } else { GPR_ASSERT(g_connections_complete == connections_complete_before + is_after_deadline); } - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10)); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); @@ -231,20 +257,27 @@ void test_times_out(void) { } } -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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(); grpc_pollset_set_init(&g_pollset_set); grpc_pollset_init(&g_pollset); - grpc_pollset_set_add_pollset(&g_pollset_set, &g_pollset); + 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(); test_times_out(); grpc_pollset_set_destroy(&g_pollset_set); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 59c498edff..f676454b7f 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -119,7 +119,7 @@ struct read_socket_state { size_t read_bytes; size_t target_read_bytes; gpr_slice_buffer incoming; - grpc_iomgr_closure read_cb; + grpc_closure read_cb; }; static size_t count_slices(gpr_slice *slices, size_t nslices, @@ -138,7 +138,7 @@ static size_t count_slices(gpr_slice *slices, size_t nslices, return num_bytes; } -static void read_cb(void *user_data, int success) { +static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, int success) { struct read_socket_state *state = (struct read_socket_state *)user_data; size_t read_bytes; int current_data; @@ -155,19 +155,8 @@ static void read_cb(void *user_data, int success) { if (state->read_bytes >= state->target_read_bytes) { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } else { - switch (grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb)) { - case GRPC_ENDPOINT_DONE: - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - read_cb(user_data, 1); - break; - case GRPC_ENDPOINT_ERROR: - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - read_cb(user_data, 0); - break; - case GRPC_ENDPOINT_PENDING: - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - break; - } + grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } } @@ -178,6 +167,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { struct read_socket_state state; size_t written_bytes; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes, slice_size); @@ -185,7 +175,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { create_sockets(sv); ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test"); - grpc_endpoint_add_to_pollset(ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -194,30 +184,25 @@ static void read_test(size_t num_bytes, size_t slice_size) { state.read_bytes = 0; state.target_read_bytes = written_bytes; gpr_slice_buffer_init(&state.incoming); - grpc_iomgr_closure_init(&state.read_cb, read_cb, &state); + grpc_closure_init(&state.read_cb, read_cb, &state); - switch (grpc_endpoint_read(ep, &state.incoming, &state.read_cb)) { - case GRPC_ENDPOINT_DONE: - read_cb(&state, 1); - break; - case GRPC_ENDPOINT_ERROR: - read_cb(&state, 0); - break; - case GRPC_ENDPOINT_PENDING: - break; - } + grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_slice_buffer_destroy(&state.incoming); - grpc_endpoint_destroy(ep); + grpc_endpoint_destroy(&exec_ctx, ep); + grpc_exec_ctx_finish(&exec_ctx); } /* Write to a socket until it fills up, then read from it using the grpc_tcp @@ -228,6 +213,7 @@ static void large_read_test(size_t slice_size) { struct read_socket_state state; ssize_t written_bytes; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Start large read test, slice size %d", slice_size); @@ -235,7 +221,7 @@ static void large_read_test(size_t slice_size) { ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size, "test"); - grpc_endpoint_add_to_pollset(ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -244,30 +230,25 @@ static void large_read_test(size_t slice_size) { state.read_bytes = 0; state.target_read_bytes = (size_t)written_bytes; gpr_slice_buffer_init(&state.incoming); - grpc_iomgr_closure_init(&state.read_cb, read_cb, &state); + grpc_closure_init(&state.read_cb, read_cb, &state); - switch (grpc_endpoint_read(ep, &state.incoming, &state.read_cb)) { - case GRPC_ENDPOINT_DONE: - read_cb(&state, 1); - break; - case GRPC_ENDPOINT_ERROR: - read_cb(&state, 0); - break; - case GRPC_ENDPOINT_PENDING: - break; - } + grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (state.read_bytes < state.target_read_bytes) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_slice_buffer_destroy(&state.incoming); - grpc_endpoint_destroy(ep); + grpc_endpoint_destroy(&exec_ctx, ep); + grpc_exec_ctx_finish(&exec_ctx); } struct write_socket_state { @@ -298,7 +279,8 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, return slices; } -static void write_done(void *user_data /* write_socket_state */, int success) { +static void write_done(grpc_exec_ctx *exec_ctx, + void *user_data /* write_socket_state */, int success) { struct write_socket_state *state = (struct write_socket_state *)user_data; gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -315,6 +297,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; flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); @@ -322,9 +305,11 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { for (;;) { grpc_pollset_worker worker; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10)); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); do { bytes_read = read(fd, buf, bytes_left > read_size ? read_size : bytes_left); @@ -343,26 +328,6 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { gpr_free(buf); } -static ssize_t drain_socket(int fd) { - ssize_t read_bytes; - ssize_t total_bytes = 0; - unsigned char buf[256]; - int current = 0; - int i; - do { - read_bytes = read(fd, buf, 256); - if (read_bytes > 0) { - total_bytes += read_bytes; - for (i = 0; i < read_bytes; ++i) { - GPR_ASSERT(buf[i] == current); - current = (current + 1) % 256; - } - } - } while (read_bytes >= 0 || errno == EINTR); - GPR_ASSERT(errno == EAGAIN); - return total_bytes; -} - /* Write to a socket using the grpc_tcp API, then drain it directly. Note that if the write does not complete immediately we need to drain the socket in parallel with the read. */ @@ -370,13 +335,13 @@ static void write_test(size_t num_bytes, size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct write_socket_state state; - ssize_t read_bytes; size_t num_blocks; gpr_slice *slices; gpr_uint8 current_data = 0; gpr_slice_buffer outgoing; - grpc_iomgr_closure write_done_closure; + grpc_closure write_done_closure; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Start write test with %d bytes, slice size %d", num_bytes, slice_size); @@ -385,7 +350,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test"); - grpc_endpoint_add_to_pollset(ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); state.ep = ep; state.write_done = 0; @@ -394,35 +359,28 @@ static void write_test(size_t num_bytes, size_t slice_size) { gpr_slice_buffer_init(&outgoing); gpr_slice_buffer_addn(&outgoing, slices, num_blocks); - grpc_iomgr_closure_init(&write_done_closure, write_done, &state); + grpc_closure_init(&write_done_closure, write_done, &state); - switch (grpc_endpoint_write(ep, &outgoing, &write_done_closure)) { - case GRPC_ENDPOINT_DONE: - /* Write completed immediately */ - read_bytes = drain_socket(sv[0]); - GPR_ASSERT((size_t)read_bytes == num_bytes); - break; - case GRPC_ENDPOINT_PENDING: - drain_socket_blocking(sv[0], num_bytes, num_bytes); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - for (;;) { - grpc_pollset_worker worker; - if (state.write_done) { - break; - } - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); - } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); + drain_socket_blocking(sv[0], num_bytes, num_bytes); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + for (;;) { + grpc_pollset_worker worker; + if (state.write_done) { break; - case GRPC_ENDPOINT_ERROR: - gpr_log(GPR_ERROR, "endpoint got error"); - abort(); + } + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_slice_buffer_destroy(&outgoing); - grpc_endpoint_destroy(ep); + grpc_endpoint_destroy(&exec_ctx, ep); gpr_free(slices); + grpc_exec_ctx_finish(&exec_ctx); } void run_tests(void) { @@ -452,14 +410,17 @@ 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; create_sockets(sv); f.client_ep = grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), slice_size, "test"); f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), slice_size, "test"); - grpc_endpoint_add_to_pollset(f.client_ep, &g_pollset); - grpc_endpoint_add_to_pollset(f.server_ep, &g_pollset); + 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); return f; } @@ -468,15 +429,21 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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(); grpc_pollset_init(&g_pollset); run_tests(); grpc_endpoint_tests(configs[0], &g_pollset); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 29a20cba8e..530381e37f 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -48,9 +48,9 @@ static grpc_pollset g_pollset; static int g_nconnects = 0; -static void on_connect(void *arg, grpc_endpoint *tcp) { - grpc_endpoint_shutdown(tcp); - grpc_endpoint_destroy(tcp); +static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp) { + grpc_endpoint_shutdown(exec_ctx, tcp); + grpc_endpoint_destroy(exec_ctx, tcp); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); g_nconnects++; @@ -59,18 +59,23 @@ static void on_connect(void *arg, grpc_endpoint *tcp) { } static void test_no_op(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server *s = grpc_tcp_server_create(); - grpc_tcp_server_destroy(s, NULL, NULL); + grpc_tcp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_start(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_tcp_server *s = grpc_tcp_server_create(); LOG_TEST("test_no_op_with_start"); - grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); - grpc_tcp_server_destroy(s, NULL, NULL); + grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); + grpc_tcp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_tcp_server *s = grpc_tcp_server_create(); LOG_TEST("test_no_op_with_port"); @@ -80,10 +85,12 @@ static void test_no_op_with_port(void) { GPR_ASSERT( grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr))); - grpc_tcp_server_destroy(s, NULL, NULL); + grpc_tcp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port_and_start(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_tcp_server *s = grpc_tcp_server_create(); LOG_TEST("test_no_op_with_port_and_start"); @@ -93,12 +100,14 @@ static void test_no_op_with_port_and_start(void) { GPR_ASSERT( grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr))); - grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); + grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL); - grpc_tcp_server_destroy(s, NULL, NULL); + grpc_tcp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_connect(int n) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); int svrfd, clifd; @@ -120,7 +129,7 @@ static void test_connect(int n) { GPR_ASSERT(addr_len <= sizeof(addr)); pollsets[0] = &g_pollset; - grpc_tcp_server_start(s, pollsets, 1, on_connect, NULL); + grpc_tcp_server_start(&exec_ctx, s, pollsets, 1, on_connect, NULL); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -137,8 +146,11 @@ static void test_connect(int n) { while (g_nconnects == nconnects_before && gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } gpr_log(GPR_DEBUG, "wait done"); @@ -148,12 +160,17 @@ static void test_connect(int n) { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_tcp_server_destroy(s, NULL, NULL); + grpc_tcp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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_iomgr_init(); grpc_pollset_init(&g_pollset); @@ -165,7 +182,9 @@ int main(int argc, char **argv) { test_connect(1); test_connect(10); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_iomgr_shutdown(); return 0; } diff --git a/test/core/iomgr/time_averaged_stats_test.c b/test/core/iomgr/time_averaged_stats_test.c index 4206a1c58f..cb006d152a 100644 --- a/test/core/iomgr/time_averaged_stats_test.c +++ b/test/core/iomgr/time_averaged_stats_test.c @@ -189,7 +189,7 @@ static void some_regress_some_persist_test(void) { grpc_time_averaged_stats_add_sample(&tas, 4944.32); grpc_time_averaged_stats_update_average(&tas); /* (1 * 4944.32 + 0.6 * 2.384 * 2200 + 0.4 * 1000) / - (1 + 0.6 * 2.384 + 0.4) */ + (1 + 0.6 * 2.384 + 0.4) */ EXPECT_DOUBLE_EQ(3000, tas.aggregate_weighted_avg); EXPECT_DOUBLE_EQ(2.8304, tas.aggregate_total_weight); } diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 24b6b1c717..d56500707c 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -64,18 +64,23 @@ static void on_read(int fd) { } static void test_no_op(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_udp_server *s = grpc_udp_server_create(); - grpc_udp_server_destroy(s, NULL, NULL); + grpc_udp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_start(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_udp_server *s = grpc_udp_server_create(); LOG_TEST("test_no_op_with_start"); - grpc_udp_server_start(s, NULL, 0); - grpc_udp_server_destroy(s, NULL, NULL); + grpc_udp_server_start(&exec_ctx, s, NULL, 0); + grpc_udp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_udp_server *s = grpc_udp_server_create(); LOG_TEST("test_no_op_with_port"); @@ -85,10 +90,12 @@ static void test_no_op_with_port(void) { GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), on_read)); - grpc_udp_server_destroy(s, NULL, NULL); + grpc_udp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_no_op_with_port_and_start(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_in addr; grpc_udp_server *s = grpc_udp_server_create(); LOG_TEST("test_no_op_with_port_and_start"); @@ -98,12 +105,14 @@ static void test_no_op_with_port_and_start(void) { GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), on_read)); - grpc_udp_server_start(s, NULL, 0); + grpc_udp_server_start(&exec_ctx, s, NULL, 0); - grpc_udp_server_destroy(s, NULL, NULL); + grpc_udp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_receive(int number_of_clients) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; struct sockaddr_storage addr; socklen_t addr_len = sizeof(addr); int clifd, svrfd; @@ -128,7 +137,7 @@ static void test_receive(int number_of_clients) { GPR_ASSERT(addr_len <= sizeof(addr)); pollsets[0] = &g_pollset; - grpc_udp_server_start(s, pollsets, 1); + grpc_udp_server_start(&exec_ctx, s, pollsets, 1); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -144,8 +153,11 @@ static void test_receive(int number_of_clients) { while (g_number_of_reads == number_of_reads_before && gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) { grpc_pollset_worker worker; - grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); } GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1); close(clifd); @@ -154,12 +166,17 @@ static void test_receive(int number_of_clients) { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_udp_server_destroy(s, NULL, NULL); + grpc_udp_server_destroy(&exec_ctx, s, NULL); + grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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_iomgr_init(); grpc_pollset_init(&g_pollset); @@ -171,7 +188,9 @@ int main(int argc, char **argv) { test_receive(1); test_receive(10); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_iomgr_shutdown(); return 0; } diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c new file mode 100644 index 0000000000..90f7ba7a83 --- /dev/null +++ b/test/core/iomgr/workqueue_test.c @@ -0,0 +1,93 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/iomgr/workqueue.h" + +#include <grpc/grpc.h> +#include <grpc/support/log.h> + +#include "test/core/util/test_config.h" + +static grpc_pollset g_pollset; + +static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, int success) { + GPR_ASSERT(success == 1); + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + *(int *)p = 1; + grpc_pollset_kick(&g_pollset, NULL); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); +} + +static void test_add_closure(void) { + grpc_closure c; + int done = 0; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); + grpc_pollset_worker worker; + grpc_closure_init(&c, must_succeed, &done); + + grpc_workqueue_push(wq, &c, 1); + grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset); + + gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + GPR_ASSERT(!done); + grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + gpr_now(deadline.clock_type), deadline); + gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(done); + + GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy"); + grpc_exec_ctx_finish(&exec_ctx); +} + +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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(); + grpc_pollset_init(&g_pollset); + + test_add_closure(); + + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); + return 0; +} diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index 82cc4090f3..42fdbd6d54 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -41,37 +41,37 @@ #include "src/core/json/json_reader.h" #include "src/core/json/json_writer.h" -typedef struct json_writer_userdata { FILE* out; } json_writer_userdata; +typedef struct json_writer_userdata { FILE *out; } json_writer_userdata; typedef struct stacked_container { grpc_json_type type; - struct stacked_container* next; + struct stacked_container *next; } stacked_container; typedef struct json_reader_userdata { - FILE* in; - grpc_json_writer* writer; - char* scratchpad; - char* ptr; + FILE *in; + grpc_json_writer *writer; + char *scratchpad; + char *ptr; size_t free_space; size_t allocated; size_t string_len; - stacked_container* top; + stacked_container *top; } json_reader_userdata; -static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = userdata; +static void json_writer_output_char(void *userdata, char c) { + json_writer_userdata *state = userdata; fputc(c, state->out); } -static void json_writer_output_string(void* userdata, const char* str) { - json_writer_userdata* state = userdata; +static void json_writer_output_string(void *userdata, const char *str) { + json_writer_userdata *state = userdata; fputs(str, state->out); } -static void json_writer_output_string_with_len(void* userdata, const char* str, +static void json_writer_output_string_with_len(void *userdata, const char *str, size_t len) { - json_writer_userdata* state = userdata; + json_writer_userdata *state = userdata; fwrite(str, len, 1, state->out); } @@ -79,7 +79,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char, json_writer_output_string, json_writer_output_string_with_len}; -static void check_string(json_reader_userdata* state, size_t needed) { +static void check_string(json_reader_userdata *state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; needed = (needed + 0xffu) & ~0xffu; @@ -88,20 +88,20 @@ static void check_string(json_reader_userdata* state, size_t needed) { state->allocated += needed; } -static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_string_clear(void *userdata) { + json_reader_userdata *state = userdata; state->free_space = state->allocated; state->string_len = 0; } -static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { - json_reader_userdata* state = userdata; +static void json_reader_string_add_char(void *userdata, gpr_uint32 c) { + json_reader_userdata *state = userdata; check_string(state, 1); GPR_ASSERT(c < 256); state->scratchpad[state->string_len++] = (char)c; } -static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { +static void json_reader_string_add_utf32(void *userdata, gpr_uint32 c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); } else if (c <= 0x7ff) { @@ -128,18 +128,18 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { } } -static gpr_uint32 json_reader_read_char(void* userdata) { +static gpr_uint32 json_reader_read_char(void *userdata) { int r; - json_reader_userdata* state = userdata; + json_reader_userdata *state = userdata; r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; return (gpr_uint32)r; } -static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = userdata; - stacked_container* container = gpr_malloc(sizeof(stacked_container)); +static void json_reader_container_begins(void *userdata, grpc_json_type type) { + json_reader_userdata *state = userdata; + stacked_container *container = gpr_malloc(sizeof(stacked_container)); container->type = type; container->next = state->top; @@ -148,9 +148,9 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { grpc_json_writer_container_begins(state->writer, type); } -static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = userdata; - stacked_container* container = state->top; +static grpc_json_type json_reader_container_ends(void *userdata) { + json_reader_userdata *state = userdata; + stacked_container *container = state->top; grpc_json_writer_container_ends(state->writer, container->type); state->top = container->next; @@ -158,22 +158,22 @@ static grpc_json_type json_reader_container_ends(void* userdata) { return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL; } -static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_key(void *userdata) { + json_reader_userdata *state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_object_key(state->writer, state->scratchpad); } -static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_string(void *userdata) { + json_reader_userdata *state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_value_string(state->writer, state->scratchpad); } -static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = userdata; +static int json_reader_set_number(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, state->string_len); @@ -181,20 +181,20 @@ static int json_reader_set_number(void* userdata) { return 1; } -static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_true(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "true", 4); } -static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_false(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "false", 5); } -static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_null(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "null", 4); } @@ -207,7 +207,7 @@ static grpc_json_reader_vtable reader_vtable = { json_reader_set_number, json_reader_set_true, json_reader_set_false, json_reader_set_null}; -int rewrite(FILE* in, FILE* out, int indent) { +int rewrite(FILE *in, FILE *out, int indent) { grpc_json_writer writer; grpc_json_reader reader; grpc_json_reader_status status; @@ -231,7 +231,7 @@ int rewrite(FILE* in, FILE* out, int indent) { free(reader_user.scratchpad); while (reader_user.top) { - stacked_container* container = reader_user.top; + stacked_container *container = reader_user.top; reader_user.top = container->next; free(container); } @@ -239,9 +239,9 @@ int rewrite(FILE* in, FILE* out, int indent) { return status == GRPC_JSON_DONE; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int indent = 2; - gpr_cmdline* cl; + gpr_cmdline *cl; cl = gpr_cmdline_create(NULL); gpr_cmdline_add_int(cl, "indent", NULL, &indent); diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c index d26ef53b2d..644a1426e9 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.c @@ -42,27 +42,27 @@ #include "src/core/json/json_reader.h" #include "src/core/json/json_writer.h" -typedef struct json_writer_userdata { FILE* cmp; } json_writer_userdata; +typedef struct json_writer_userdata { FILE *cmp; } json_writer_userdata; typedef struct stacked_container { grpc_json_type type; - struct stacked_container* next; + struct stacked_container *next; } stacked_container; typedef struct json_reader_userdata { - FILE* in; - grpc_json_writer* writer; - char* scratchpad; - char* ptr; + FILE *in; + grpc_json_writer *writer; + char *scratchpad; + char *ptr; size_t free_space; size_t allocated; size_t string_len; - stacked_container* top; + stacked_container *top; int did_eagain; } json_reader_userdata; -static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = userdata; +static void json_writer_output_char(void *userdata, char c) { + json_writer_userdata *state = userdata; int cmp = fgetc(state->cmp); /* treat CRLF as LF */ @@ -72,13 +72,13 @@ static void json_writer_output_char(void* userdata, char c) { GPR_ASSERT(cmp == c); } -static void json_writer_output_string(void* userdata, const char* str) { +static void json_writer_output_string(void *userdata, const char *str) { while (*str) { json_writer_output_char(userdata, *str++); } } -static void json_writer_output_string_with_len(void* userdata, const char* str, +static void json_writer_output_string_with_len(void *userdata, const char *str, size_t len) { size_t i; for (i = 0; i < len; i++) { @@ -90,7 +90,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char, json_writer_output_string, json_writer_output_string_with_len}; -static void check_string(json_reader_userdata* state, size_t needed) { +static void check_string(json_reader_userdata *state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; needed = (needed + 0xffu) & ~0xffu; @@ -99,20 +99,20 @@ static void check_string(json_reader_userdata* state, size_t needed) { state->allocated += needed; } -static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_string_clear(void *userdata) { + json_reader_userdata *state = userdata; state->free_space = state->allocated; state->string_len = 0; } -static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { - json_reader_userdata* state = userdata; +static void json_reader_string_add_char(void *userdata, gpr_uint32 c) { + json_reader_userdata *state = userdata; check_string(state, 1); GPR_ASSERT(c <= 256); state->scratchpad[state->string_len++] = (char)c; } -static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { +static void json_reader_string_add_utf32(void *userdata, gpr_uint32 c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); } else if (c <= 0x7ffu) { @@ -139,9 +139,9 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { } } -static gpr_uint32 json_reader_read_char(void* userdata) { +static gpr_uint32 json_reader_read_char(void *userdata) { int r; - json_reader_userdata* state = userdata; + json_reader_userdata *state = userdata; if (!state->did_eagain) { state->did_eagain = 1; @@ -155,9 +155,9 @@ static gpr_uint32 json_reader_read_char(void* userdata) { return (gpr_uint32)r; } -static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = userdata; - stacked_container* container = gpr_malloc(sizeof(stacked_container)); +static void json_reader_container_begins(void *userdata, grpc_json_type type) { + json_reader_userdata *state = userdata; + stacked_container *container = gpr_malloc(sizeof(stacked_container)); container->type = type; container->next = state->top; @@ -166,9 +166,9 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { grpc_json_writer_container_begins(state->writer, type); } -static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = userdata; - stacked_container* container = state->top; +static grpc_json_type json_reader_container_ends(void *userdata) { + json_reader_userdata *state = userdata; + stacked_container *container = state->top; grpc_json_writer_container_ends(state->writer, container->type); state->top = container->next; @@ -176,22 +176,22 @@ static grpc_json_type json_reader_container_ends(void* userdata) { return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL; } -static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_key(void *userdata) { + json_reader_userdata *state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_object_key(state->writer, state->scratchpad); } -static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_string(void *userdata) { + json_reader_userdata *state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_value_string(state->writer, state->scratchpad); } -static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = userdata; +static int json_reader_set_number(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, state->string_len); @@ -199,20 +199,20 @@ static int json_reader_set_number(void* userdata) { return 1; } -static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_true(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "true", 4); } -static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_false(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "false", 5); } -static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = userdata; +static void json_reader_set_null(void *userdata) { + json_reader_userdata *state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "null", 4); } @@ -225,7 +225,7 @@ static grpc_json_reader_vtable reader_vtable = { json_reader_set_number, json_reader_set_true, json_reader_set_false, json_reader_set_null}; -int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { +int rewrite_and_compare(FILE *in, FILE *cmp, int indent) { grpc_json_writer writer; grpc_json_reader reader; grpc_json_reader_status status; @@ -255,7 +255,7 @@ int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { free(reader_user.scratchpad); while (reader_user.top) { - stacked_container* container = reader_user.top; + stacked_container *container = reader_user.top; reader_user.top = container->next; free(container); } @@ -264,8 +264,8 @@ int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { } typedef struct test_file { - const char* input; - const char* cmp; + const char *input; + const char *cmp; int indent; } test_file; @@ -284,9 +284,9 @@ void test_rewrites() { unsigned i; for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) { - test_file* test = test_files + i; - FILE* input = fopen(test->input, "rb"); - FILE* cmp = fopen(test->cmp, "rb"); + test_file *test = test_files + i; + FILE *input = fopen(test->input, "rb"); + FILE *cmp = fopen(test->cmp, "rb"); int status; gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", test->input, test->cmp, test->indent); @@ -297,7 +297,7 @@ void test_rewrites() { } } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_rewrites(); gpr_log(GPR_INFO, "json_rewrite_test success"); diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c index a500effcea..8575331cab 100644 --- a/test/core/json/json_test.c +++ b/test/core/json/json_test.c @@ -43,8 +43,8 @@ #include "test/core/util/test_config.h" typedef struct testing_pair { - const char* input; - const char* output; + const char *input; + const char *output; } testing_pair; static testing_pair testing_pairs[] = { @@ -131,16 +131,16 @@ static void test_pairs() { unsigned i; for (i = 0; i < GPR_ARRAY_SIZE(testing_pairs); i++) { - testing_pair* pair = testing_pairs + i; - char* scratchpad = gpr_strdup(pair->input); - grpc_json* json; + testing_pair *pair = testing_pairs + i; + char *scratchpad = gpr_strdup(pair->input); + grpc_json *json; gpr_log(GPR_INFO, "parsing string %i - should %s", i, pair->output ? "succeed" : "fail"); json = grpc_json_parse_string(scratchpad); if (pair->output) { - char* output; + char *output; GPR_ASSERT(json); output = grpc_json_dump_to_string(json, 0); @@ -160,9 +160,9 @@ static void test_pairs() { } static void test_atypical() { - char* scratchpad = gpr_strdup("[[],[]]"); - grpc_json* json = grpc_json_parse_string(scratchpad); - grpc_json* brother; + char *scratchpad = gpr_strdup("[[],[]]"); + grpc_json *json = grpc_json_parse_string(scratchpad); + grpc_json *brother; GPR_ASSERT(json); GPR_ASSERT(json->child); @@ -173,7 +173,7 @@ static void test_atypical() { gpr_free(scratchpad); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_pairs(); test_atypical(); diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c index 6d49b6d1a1..a8f784d4fa 100644 --- a/test/core/security/base64_test.c +++ b/test/core/security/base64_test.c @@ -52,6 +52,7 @@ static int buffers_are_equal(const unsigned char *buf1, } return 1; } + static void test_simple_encode_decode_b64(int url_safe, int multiline) { const char *hello = "hello"; char *hello_b64 = diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index b8cc864317..5c1e0f4b94 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -315,7 +315,7 @@ static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems, } } -static void check_google_iam_metadata(void *user_data, +static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { @@ -331,16 +331,20 @@ static void check_google_iam_metadata(void *user_data, } static void test_google_iam_creds(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *creds = grpc_google_iam_credentials_create( test_google_iam_authorization_token, test_google_iam_authority_selector, NULL); GPR_ASSERT(grpc_credentials_has_request_metadata(creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds)); - grpc_credentials_get_request_metadata(creds, NULL, test_service_url, + grpc_credentials_get_request_metadata(&exec_ctx, creds, NULL, + test_service_url, check_google_iam_metadata, creds); + grpc_exec_ctx_finish(&exec_ctx); } -static void check_access_token_metadata(void *user_data, +static void check_access_token_metadata(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { @@ -353,17 +357,20 @@ static void check_access_token_metadata(void *user_data, } static void test_access_token_creds(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *creds = grpc_access_token_credentials_create("blah", NULL); GPR_ASSERT(grpc_credentials_has_request_metadata(creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds)); GPR_ASSERT(strcmp(creds->type, GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); - grpc_credentials_get_request_metadata(creds, NULL, test_service_url, + grpc_credentials_get_request_metadata(&exec_ctx, creds, NULL, + test_service_url, check_access_token_metadata, creds); + grpc_exec_ctx_finish(&exec_ctx); } static void check_ssl_oauth2_composite_metadata( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { grpc_credentials *c = (grpc_credentials *)user_data; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}}; @@ -374,6 +381,7 @@ static void check_ssl_oauth2_composite_metadata( } static void test_ssl_oauth2_composite_creds(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); const grpc_credentials_array *creds_array; @@ -393,9 +401,10 @@ static void test_ssl_oauth2_composite_creds(void) { GRPC_CREDENTIALS_TYPE_SSL) == 0); GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); - grpc_credentials_get_request_metadata(composite_creds, NULL, test_service_url, - check_ssl_oauth2_composite_metadata, - composite_creds); + grpc_credentials_get_request_metadata( + &exec_ctx, composite_creds, NULL, test_service_url, + check_ssl_oauth2_composite_metadata, composite_creds); + grpc_exec_ctx_finish(&exec_ctx); } void test_ssl_fake_transport_security_composite_creds_failure(void) { @@ -411,8 +420,8 @@ void test_ssl_fake_transport_security_composite_creds_failure(void) { } static void check_ssl_oauth2_google_iam_composite_metadata( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { grpc_credentials *c = (grpc_credentials *)user_data; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, @@ -427,6 +436,7 @@ static void check_ssl_oauth2_google_iam_composite_metadata( } static void test_ssl_oauth2_google_iam_composite_creds(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); const grpc_credentials_array *creds_array; @@ -456,13 +466,14 @@ static void test_ssl_oauth2_google_iam_composite_creds(void) { GPR_ASSERT(strcmp(creds_array->creds_array[2]->type, GRPC_CREDENTIALS_TYPE_IAM) == 0); grpc_credentials_get_request_metadata( - composite_creds, NULL, test_service_url, + &exec_ctx, composite_creds, NULL, test_service_url, check_ssl_oauth2_google_iam_composite_metadata, composite_creds); + grpc_exec_ctx_finish(&exec_ctx); } static void on_oauth2_creds_get_metadata_success( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "Authorization") == 0); @@ -474,8 +485,8 @@ static void on_oauth2_creds_get_metadata_success( } static void on_oauth2_creds_get_metadata_failure( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); GPR_ASSERT(num_md == 0); GPR_ASSERT(user_data != NULL); @@ -496,40 +507,44 @@ static void validate_compute_engine_http_request( } static int compute_engine_httpcli_get_success_override( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { grpc_httpcli_response response = http_response(200, valid_oauth2_json_response); validate_compute_engine_http_request(request); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); return 1; } static int compute_engine_httpcli_get_failure_override( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { grpc_httpcli_response response = http_response(403, "Not Authorized."); validate_compute_engine_http_request(request); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); return 1; } static int httpcli_post_should_not_be_called( - const grpc_httpcli_request *request, const char *body_bytes, - size_t body_size, gpr_timespec deadline, + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + const char *body_bytes, size_t body_size, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data) { GPR_ASSERT("HTTP POST should not be called" == NULL); return 1; } static int httpcli_get_should_not_be_called( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { GPR_ASSERT("HTTP GET should not be called" == NULL); return 1; } static void test_compute_engine_creds_success(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *compute_engine_creds = grpc_google_compute_engine_credentials_create(NULL); GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds)); @@ -539,21 +554,24 @@ static void test_compute_engine_creds_success(void) { grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); grpc_credentials_get_request_metadata( - compute_engine_creds, NULL, test_service_url, + &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); grpc_credentials_get_request_metadata( - compute_engine_creds, NULL, test_service_url, + &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_finish(&exec_ctx); grpc_credentials_unref(compute_engine_creds); grpc_httpcli_set_override(NULL, NULL); } static void test_compute_engine_creds_failure(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *compute_engine_creds = grpc_google_compute_engine_credentials_create(NULL); grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override, @@ -561,10 +579,11 @@ static void test_compute_engine_creds_failure(void) { GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(compute_engine_creds)); grpc_credentials_get_request_metadata( - compute_engine_creds, NULL, test_service_url, + &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_failure, (void *)test_user_data); grpc_credentials_unref(compute_engine_creds); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void validate_refresh_token_http_request( @@ -590,27 +609,28 @@ static void validate_refresh_token_http_request( } static int refresh_token_httpcli_post_success( - const grpc_httpcli_request *request, const char *body, size_t body_size, - gpr_timespec deadline, grpc_httpcli_response_cb on_response, - void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + const char *body, size_t body_size, gpr_timespec deadline, + grpc_httpcli_response_cb on_response, void *user_data) { grpc_httpcli_response response = http_response(200, valid_oauth2_json_response); validate_refresh_token_http_request(request, body, body_size); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); return 1; } static int refresh_token_httpcli_post_failure( - const grpc_httpcli_request *request, const char *body, size_t body_size, - gpr_timespec deadline, grpc_httpcli_response_cb on_response, - void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + const char *body, size_t body_size, gpr_timespec deadline, + grpc_httpcli_response_cb on_response, void *user_data) { grpc_httpcli_response response = http_response(403, "Not Authorized."); validate_refresh_token_http_request(request, body, body_size); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); return 1; } static void test_refresh_token_creds_success(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *refresh_token_creds = grpc_google_refresh_token_credentials_create(test_refresh_token_str, NULL); @@ -621,21 +641,25 @@ static void test_refresh_token_creds_success(void) { grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); grpc_credentials_get_request_metadata( - refresh_token_creds, NULL, test_service_url, + &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); grpc_credentials_get_request_metadata( - refresh_token_creds, NULL, test_service_url, + &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); grpc_credentials_unref(refresh_token_creds); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_refresh_token_creds_failure(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_credentials *refresh_token_creds = grpc_google_refresh_token_credentials_create(test_refresh_token_str, NULL); @@ -644,10 +668,11 @@ static void test_refresh_token_creds_failure(void) { GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(refresh_token_creds)); grpc_credentials_get_request_metadata( - refresh_token_creds, NULL, test_service_url, + &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_failure, (void *)test_user_data); grpc_credentials_unref(refresh_token_creds); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void validate_jwt_encode_and_sign_params( @@ -693,9 +718,11 @@ static char *encode_and_sign_jwt_should_not_be_called( const grpc_auth_json_key *json_key, const char *audience, gpr_timespec token_lifetime, const char *scope) { GPR_ASSERT("grpc_jwt_encode_and_sign should not be called" == NULL); + return NULL; } -static void on_jwt_creds_get_metadata_success(void *user_data, +static void on_jwt_creds_get_metadata_success(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { @@ -710,7 +737,8 @@ static void on_jwt_creds_get_metadata_success(void *user_data, gpr_free(expected_md_value); } -static void on_jwt_creds_get_metadata_failure(void *user_data, +static void on_jwt_creds_get_metadata_failure(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { @@ -722,6 +750,7 @@ static void on_jwt_creds_get_metadata_failure(void *user_data, 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_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( json_key_string, grpc_max_auth_token_lifetime, NULL); @@ -730,23 +759,26 @@ static void test_jwt_creds_success(void) { /* First request: jwt_encode_and_sign should be called. */ grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - grpc_credentials_get_request_metadata(jwt_creds, NULL, test_service_url, - on_jwt_creds_get_metadata_success, - (void *)test_user_data); + grpc_credentials_get_request_metadata( + &exec_ctx, jwt_creds, NULL, test_service_url, + on_jwt_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); /* Second request: the cached token should be served directly. */ grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); - grpc_credentials_get_request_metadata(jwt_creds, NULL, test_service_url, - on_jwt_creds_get_metadata_success, - (void *)test_user_data); + grpc_credentials_get_request_metadata( + &exec_ctx, jwt_creds, NULL, test_service_url, + on_jwt_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - grpc_credentials_get_request_metadata(jwt_creds, NULL, other_test_service_url, - on_jwt_creds_get_metadata_success, - (void *)test_user_data); + grpc_credentials_get_request_metadata( + &exec_ctx, jwt_creds, NULL, other_test_service_url, + on_jwt_creds_get_metadata_success, (void *)test_user_data); + grpc_exec_ctx_flush(&exec_ctx); gpr_free(json_key_string); grpc_credentials_unref(jwt_creds); @@ -755,6 +787,7 @@ static void test_jwt_creds_success(void) { 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_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( json_key_string, grpc_max_auth_token_lifetime, NULL); @@ -762,13 +795,14 @@ static void test_jwt_creds_signing_failure(void) { GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); - grpc_credentials_get_request_metadata(jwt_creds, NULL, test_service_url, - on_jwt_creds_get_metadata_failure, - (void *)test_user_data); + grpc_credentials_get_request_metadata( + &exec_ctx, jwt_creds, NULL, test_service_url, + on_jwt_creds_get_metadata_failure, (void *)test_user_data); gpr_free(json_key_string); grpc_credentials_unref(jwt_creds); grpc_jwt_encode_and_sign_set_override(NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void set_google_default_creds_env_var_with_file_contents( @@ -874,8 +908,8 @@ static void plugin_get_metadata_failure(void *state, const char *service_url, } static void on_plugin_metadata_received_success( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { size_t i = 0; GPR_ASSERT(user_data == NULL); GPR_ASSERT(md_elems != NULL); @@ -887,8 +921,8 @@ static void on_plugin_metadata_received_success( } static void on_plugin_metadata_received_failure( - void *user_data, grpc_credentials_md *md_elems, size_t num_md, - grpc_credentials_status status) { + grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { GPR_ASSERT(user_data == NULL); GPR_ASSERT(md_elems == NULL); GPR_ASSERT(num_md == 0); @@ -904,6 +938,7 @@ static void test_metadata_plugin_success(void) { grpc_credentials *creds; plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; plugin.state = &state; plugin.get_metadata = plugin_get_metadata_success; @@ -912,16 +947,19 @@ static void test_metadata_plugin_success(void) { creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); grpc_credentials_get_request_metadata( - creds, NULL, test_service_url, on_plugin_metadata_received_success, NULL); + &exec_ctx, creds, NULL, test_service_url, + on_plugin_metadata_received_success, NULL); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); grpc_credentials_release(creds); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); + grpc_exec_ctx_finish(&exec_ctx); } static void test_metadata_plugin_failure(void) { grpc_credentials *creds; plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; plugin.state = &state; plugin.get_metadata = plugin_get_metadata_failure; @@ -930,10 +968,12 @@ static void test_metadata_plugin_failure(void) { creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); grpc_credentials_get_request_metadata( - creds, NULL, test_service_url, on_plugin_metadata_received_failure, NULL); + &exec_ctx, creds, NULL, test_service_url, + on_plugin_metadata_received_failure, NULL); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); grpc_credentials_release(creds); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char **argv) { diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c index 5cc8b2e9be..9c526a7b5d 100644 --- a/test/core/security/jwt_verifier_test.c +++ b/test/core/security/jwt_verifier_test.c @@ -274,16 +274,17 @@ static grpc_httpcli_response http_response(int status, char *body) { } static int httpcli_post_should_not_be_called( - const grpc_httpcli_request *request, const char *body_bytes, - size_t body_size, gpr_timespec deadline, + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + const char *body_bytes, size_t body_size, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data) { GPR_ASSERT("HTTP POST should not be called" == NULL); return 1; } static int httpcli_get_google_keys_for_email( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { grpc_httpcli_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); @@ -291,7 +292,7 @@ static int httpcli_get_google_keys_for_email( "/robot/v1/metadata/x509/" "777-abaslkan11hlb6nmim3bpspl31ud@developer." "gserviceaccount.com") == 0); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); gpr_free(response.body); return 1; } @@ -307,6 +308,7 @@ static void on_verification_success(void *user_data, } static void test_jwt_verifier_google_email_issuer_success(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -319,26 +321,29 @@ static void test_jwt_verifier_google_email_issuer_success(void) { NULL); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_success, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static int httpcli_get_custom_keys_for_email( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { grpc_httpcli_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->path, "/jwk/foo@bar.com") == 0); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); gpr_free(response.body); return 1; } static void test_jwt_verifier_custom_email_issuer_success(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(&custom_mapping, 1); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_custom_email_issuer); @@ -351,14 +356,16 @@ static void test_jwt_verifier_custom_email_issuer_success(void) { NULL); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_success, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } -static int httpcli_get_jwk_set(const grpc_httpcli_request *request, +static int httpcli_get_jwk_set(grpc_exec_ctx *exec_ctx, + const grpc_httpcli_request *request, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data) { @@ -366,12 +373,13 @@ static int httpcli_get_jwk_set(const grpc_httpcli_request *request, GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); GPR_ASSERT(strcmp(request->path, "/oauth2/v3/certs") == 0); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); gpr_free(response.body); return 1; } -static int httpcli_get_openid_config(const grpc_httpcli_request *request, +static int httpcli_get_openid_config(grpc_exec_ctx *exec_ctx, + const grpc_httpcli_request *request, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data) { @@ -382,12 +390,13 @@ static int httpcli_get_openid_config(const grpc_httpcli_request *request, GPR_ASSERT(strcmp(request->path, GRPC_OPENID_CONFIG_URL_SUFFIX) == 0); grpc_httpcli_set_override(httpcli_get_jwk_set, httpcli_post_should_not_be_called); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); gpr_free(response.body); return 1; } static void test_jwt_verifier_url_issuer_success(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -400,11 +409,12 @@ static void test_jwt_verifier_url_issuer_success(void) { NULL); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_success, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void on_verification_key_retrieval_error(void *user_data, @@ -415,19 +425,21 @@ static void on_verification_key_retrieval_error(void *user_data, GPR_ASSERT(user_data == (void *)expected_user_data); } -static int httpcli_get_bad_json(const grpc_httpcli_request *request, +static int httpcli_get_bad_json(grpc_exec_ctx *exec_ctx, + const grpc_httpcli_request *request, gpr_timespec deadline, grpc_httpcli_response_cb on_response, void *user_data) { grpc_httpcli_response response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}")); GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl); - on_response(user_data, &response); + on_response(exec_ctx, user_data, &response); gpr_free(response.body); return 1; } static void test_jwt_verifier_url_issuer_bad_config(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -440,15 +452,17 @@ static void test_jwt_verifier_url_issuer_bad_config(void) { NULL); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_key_retrieval_error, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void test_jwt_verifier_bad_json_key(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_google_email_issuer); @@ -461,12 +475,13 @@ static void test_jwt_verifier_bad_json_key(void) { NULL); grpc_auth_json_key_destruct(&key); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_key_retrieval_error, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static void corrupt_jwt_sig(char *jwt) { @@ -495,6 +510,7 @@ static void on_verification_bad_signature(void *user_data, } static void test_jwt_verifier_bad_signature(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); char *jwt = NULL; char *key_str = json_key_str(json_key_str_part3_for_url_issuer); @@ -508,17 +524,19 @@ static void test_jwt_verifier_bad_signature(void) { grpc_auth_json_key_destruct(&key); corrupt_jwt_sig(jwt); GPR_ASSERT(jwt != NULL); - grpc_jwt_verifier_verify(verifier, NULL, jwt, expected_audience, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, jwt, expected_audience, on_verification_bad_signature, (void *)expected_user_data); gpr_free(jwt); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } static int httpcli_get_should_not_be_called( - const grpc_httpcli_request *request, gpr_timespec deadline, - grpc_httpcli_response_cb on_response, void *user_data) { + grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request, + gpr_timespec deadline, grpc_httpcli_response_cb on_response, + void *user_data) { GPR_ASSERT(0); return 1; } @@ -532,14 +550,16 @@ static void on_verification_bad_format(void *user_data, } static void test_jwt_verifier_bad_format(void) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_jwt_verifier *verifier = grpc_jwt_verifier_create(NULL, 0); grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_jwt_verifier_verify(verifier, NULL, "bad jwt", expected_audience, - on_verification_bad_format, + grpc_jwt_verifier_verify(&exec_ctx, verifier, NULL, "bad jwt", + expected_audience, on_verification_bad_format, (void *)expected_user_data); grpc_jwt_verifier_destroy(verifier); grpc_httpcli_set_override(NULL, NULL); + grpc_exec_ctx_finish(&exec_ctx); } /* find verification key: bad jks, cannot find key in jks */ diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c index 7df6fade6b..f99d170592 100644 --- a/test/core/security/oauth2_utils.c +++ b/test/core/security/oauth2_utils.c @@ -50,8 +50,9 @@ typedef struct { char *token; } oauth2_request; -static void on_oauth2_response(void *user_data, grpc_credentials_md *md_elems, - size_t num_md, grpc_credentials_status status) { +static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_credentials_md *md_elems, size_t num_md, + grpc_credentials_status status) { oauth2_request *request = user_data; char *token = NULL; gpr_slice token_slice; @@ -72,25 +73,33 @@ static void on_oauth2_response(void *user_data, grpc_credentials_md *md_elems, gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset)); } -static void do_nothing(void *unused) {} +static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, int success) {} char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds) { oauth2_request request; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_closure do_nothing_closure; grpc_pollset_init(&request.pollset); request.is_done = 0; - grpc_credentials_get_request_metadata(creds, &request.pollset, "", + grpc_closure_init(&do_nothing_closure, do_nothing, NULL); + + grpc_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset, "", on_oauth2_response, &request); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset)); while (!request.is_done) { grpc_pollset_worker worker; - grpc_pollset_work(&request.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &request.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset)); - grpc_pollset_shutdown(&request.pollset, do_nothing, NULL); + grpc_pollset_shutdown(&exec_ctx, &request.pollset, &do_nothing_closure); + grpc_exec_ctx_finish(&exec_ctx); grpc_pollset_destroy(&request.pollset); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index 753221cada..f207e05794 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -49,8 +49,8 @@ typedef struct { int is_done; } synchronizer; -static void on_metadata_response(void *user_data, grpc_credentials_md *md_elems, - size_t num_md, +static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { synchronizer *sync = user_data; if (status == GRPC_CREDENTIALS_ERROR) { @@ -70,6 +70,7 @@ static void on_metadata_response(void *user_data, grpc_credentials_md *md_elems, int main(int argc, char **argv) { int result = 0; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; synchronizer sync; grpc_credentials *creds = NULL; char *service_url = "https://test.foo.google.com/Foo"; @@ -90,14 +91,19 @@ int main(int argc, char **argv) { grpc_pollset_init(&sync.pollset); sync.is_done = 0; - grpc_credentials_get_request_metadata(creds, &sync.pollset, service_url, - on_metadata_response, &sync); + grpc_credentials_get_request_metadata(&exec_ctx, creds, &sync.pollset, + service_url, on_metadata_response, + &sync); gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); while (!sync.is_done) { grpc_pollset_worker worker; - grpc_pollset_work(&sync.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &sync.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index 047d37748d..8aa80cca18 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -49,14 +49,15 @@ static grpc_pollset g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, gpr_slice *leftover_slices, size_t leftover_nslices) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; tsi_frame_protector *fake_read_protector = tsi_create_fake_protector(NULL); tsi_frame_protector *fake_write_protector = tsi_create_fake_protector(NULL); grpc_endpoint_test_fixture f; grpc_endpoint_pair tcp; tcp = grpc_iomgr_create_endpoint_pair("fixture", slice_size); - grpc_endpoint_add_to_pollset(tcp.client, &g_pollset); - grpc_endpoint_add_to_pollset(tcp.server, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, &g_pollset); if (leftover_nslices == 0) { f.client_ep = @@ -109,6 +110,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( f.server_ep = grpc_secure_endpoint_create(fake_write_protector, tcp.server, NULL, 0); + grpc_exec_ctx_finish(&exec_ctx); return f; } @@ -136,39 +138,55 @@ static grpc_endpoint_test_config configs[] = { secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up}, }; +static void inc_call_ctr(grpc_exec_ctx *exec_ctx, void *arg, int success) { + ++*(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); gpr_slice_buffer incoming; gpr_slice s = gpr_slice_from_copied_string("hello world 12345678900987654321"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + int n = 0; + grpc_closure done_closure; gpr_log(GPR_INFO, "Start test left over"); gpr_slice_buffer_init(&incoming); - GPR_ASSERT(grpc_endpoint_read(f.client_ep, &incoming, NULL) == - GRPC_ENDPOINT_DONE); + grpc_closure_init(&done_closure, inc_call_ctr, &n); + grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, &done_closure); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); GPR_ASSERT(0 == gpr_slice_cmp(s, incoming.slices[0])); - grpc_endpoint_shutdown(f.client_ep); - grpc_endpoint_shutdown(f.server_ep); - grpc_endpoint_destroy(f.client_ep); - grpc_endpoint_destroy(f.server_ep); + grpc_endpoint_shutdown(&exec_ctx, f.client_ep); + grpc_endpoint_shutdown(&exec_ctx, f.server_ep); + grpc_endpoint_destroy(&exec_ctx, f.client_ep); + grpc_endpoint_destroy(&exec_ctx, f.server_ep); + grpc_exec_ctx_finish(&exec_ctx); gpr_slice_unref(s); gpr_slice_buffer_destroy(&incoming); clean_up(); } -static void destroy_pollset(void *p) { grpc_pollset_destroy(p); } +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { + grpc_pollset_destroy(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(); grpc_pollset_init(&g_pollset); grpc_endpoint_tests(configs[0], &g_pollset); test_leftover(configs[1], 1); - grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); + grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); + grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); return 0; diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c index f4432667ee..378a37f26c 100644 --- a/test/core/security/verify_jwt.c +++ b/test/core/security/verify_jwt.c @@ -89,6 +89,7 @@ int main(int argc, char **argv) { gpr_cmdline *cl; char *jwt = NULL; char *aud = NULL; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; cl = gpr_cmdline_create("JWT verifier tool"); gpr_cmdline_add_string(cl, "jwt", "JSON web token to verify", &jwt); @@ -105,14 +106,18 @@ int main(int argc, char **argv) { grpc_pollset_init(&sync.pollset); sync.is_done = 0; - grpc_jwt_verifier_verify(verifier, &sync.pollset, jwt, aud, + grpc_jwt_verifier_verify(&exec_ctx, verifier, &sync.pollset, jwt, aud, on_jwt_verification_done, &sync); gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); while (!sync.is_done) { grpc_pollset_worker worker; - grpc_pollset_work(&sync.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &sync.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); + gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); + grpc_exec_ctx_finish(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 3292f8a64d..6968a5646d 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -46,22 +46,22 @@ /* Fills in 'record' of size 'size'. Each byte in record is filled in with the same value. The value is extracted from 'record' pointer. */ -static void write_record(char* record, size_t size) { +static void write_record(char *record, size_t size) { char data = (gpr_uintptr)record % 255; memset(record, data, size); } /* Reads fixed size records. Returns the number of records read in 'num_records'. */ -static void read_records(size_t record_size, const char* buffer, - size_t buffer_size, gpr_int32* num_records) { +static void read_records(size_t record_size, const char *buffer, + size_t buffer_size, gpr_int32 *num_records) { gpr_int32 ix; GPR_ASSERT(buffer_size >= record_size); GPR_ASSERT(buffer_size % record_size == 0); *num_records = buffer_size / record_size; for (ix = 0; ix < *num_records; ++ix) { size_t jx; - const char* record = buffer + (record_size * ix); + const char *record = buffer + (record_size * ix); char data = (gpr_uintptr)record % 255; for (jx = 0; jx < record_size; ++jx) { GPR_ASSERT(data == record[jx]); @@ -80,13 +80,13 @@ static size_t write_records_to_log(int writer_id, gpr_int32 record_size, for (ix = 0; ix < num_records; ++ix) { gpr_int32 jx; gpr_int32 spin_count = max_spin_count ? rand() % max_spin_count : 0; - char* record; + char *record; if (counter++ == num_records / 10) { printf(" Writer %d: %d out of %d written\n", writer_id, ix, num_records); counter = 0; } - record = (char*)(census_log_start_write(record_size)); + record = (char *)(census_log_start_write(record_size)); if (record == NULL) { return ix; } @@ -101,13 +101,13 @@ static size_t write_records_to_log(int writer_id, gpr_int32 record_size, /* Performs a single read iteration. Returns the number of records read. */ static size_t perform_read_iteration(size_t record_size) { - const void* read_buffer = NULL; + const void *read_buffer = NULL; size_t bytes_available; size_t records_read = 0; census_log_init_reader(); while ((read_buffer = census_log_read_next(&bytes_available))) { gpr_int32 num_records = 0; - read_records(record_size, (const char*)read_buffer, bytes_available, + read_records(record_size, (const char *)read_buffer, bytes_available, &num_records); records_read += num_records; } @@ -177,15 +177,15 @@ typedef struct writer_thread_args { /* Number of records to write. */ gpr_int32 num_records; /* Used to signal when writer is complete */ - gpr_cv* done; - gpr_mu* mu; - int* count; + gpr_cv *done; + gpr_mu *mu; + int *count; } writer_thread_args; /* Writes the given number of records of random size (up to kMaxRecordSize) and random data to the specified log. */ -static void writer_thread(void* arg) { - writer_thread_args* args = (writer_thread_args*)arg; +static void writer_thread(void *arg) { + writer_thread_args *args = (writer_thread_args *)arg; /* Maximum number of times to spin between writes. */ static const gpr_int32 MAX_SPIN_COUNT = 50; int records_written = 0; @@ -222,17 +222,17 @@ typedef struct reader_thread_args { gpr_cv stop; int stop_flag; /* Used to signal when reader has finished */ - gpr_cv* done; - gpr_mu* mu; + gpr_cv *done; + gpr_mu *mu; int running; } reader_thread_args; /* Reads and verifies the specified number of records. Reader can also be stopped via gpr_cv_signal(&args->stop). Sleeps for 'read_interval_in_msec' between read iterations. */ -static void reader_thread(void* arg) { +static void reader_thread(void *arg) { gpr_int32 records_read = 0; - reader_thread_args* args = (reader_thread_args*)arg; + reader_thread_args *args = (reader_thread_args *)arg; gpr_int32 num_iterations = 0; gpr_timespec interval; int counter = 0; @@ -350,7 +350,7 @@ static void setup_test(int circular_log) { void test_invalid_record_size(void) { static const size_t INVALID_SIZE = CENSUS_LOG_MAX_RECORD_SIZE + 1; static const size_t VALID_SIZE = 1; - void* record; + void *record; printf("Starting test: invalid record size\n"); setup_test(0); record = census_log_start_write(INVALID_SIZE); @@ -373,8 +373,8 @@ void test_invalid_record_size(void) { void test_end_write_with_different_size(void) { static const size_t START_WRITE_SIZE = 10; static const size_t END_WRITE_SIZE = 7; - void* record_written; - const void* record_read; + void *record_written; + const void *record_read; size_t bytes_available; printf("Starting test: end write with different size\n"); setup_test(0); @@ -393,8 +393,8 @@ void test_end_write_with_different_size(void) { void test_read_pending_record(void) { static const size_t PR_RECORD_SIZE = 1024; size_t bytes_available; - const void* record_read; - void* record_written; + const void *record_read; + void *record_written; printf("Starting test: read pending record\n"); setup_test(0); /* Start a write. */ @@ -420,9 +420,9 @@ void test_read_beyond_pending_record(void) { gpr_uint32 incomplete_record_size = 10; gpr_uint32 complete_record_size = 20; size_t bytes_available; - void* complete_record; - const void* record_read; - void* incomplete_record; + void *complete_record; + const void *record_read; + void *incomplete_record; printf("Starting test: read beyond pending record\n"); setup_test(0); incomplete_record = census_log_start_write(incomplete_record_size); @@ -457,8 +457,8 @@ void test_read_beyond_pending_record(void) { void test_detached_while_reading(void) { static const size_t DWR_RECORD_SIZE = 10; size_t bytes_available; - const void* record_read; - void* record_written; + const void *record_read; + void *record_written; gpr_uint32 block_read = 0; printf("Starting test: detached while reading\n"); setup_test(0); @@ -571,7 +571,7 @@ void test_performance(void) { setup_test(0); start_time = gpr_now(GPR_CLOCK_REALTIME); while (1) { - void* record = census_log_start_write(write_size); + void *record = census_log_start_write(write_size); if (record == NULL) { break; } diff --git a/test/core/statistics/census_stub_test.c b/test/core/statistics/census_stub_test.c index 26a45ae58a..8e409a3726 100644 --- a/test/core/statistics/census_stub_test.c +++ b/test/core/statistics/census_stub_test.c @@ -43,7 +43,7 @@ /* Tests census noop stubs in a simulated rpc flow */ void test_census_stubs(void) { census_op_id op_id; - census_rpc_stats* stats = census_rpc_stats_create_empty(); + census_rpc_stats *stats = census_rpc_stats_create_empty(); census_aggregated_rpc_stats data_map = {0, NULL}; /* Initializes census library at server start up time. */ @@ -70,7 +70,7 @@ void test_census_stubs(void) { census_shutdown(); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_census_stubs(); return 0; diff --git a/test/core/statistics/hash_table_test.c b/test/core/statistics/hash_table_test.c index 2568e96cba..453755f40a 100644 --- a/test/core/statistics/hash_table_test.c +++ b/test/core/statistics/hash_table_test.c @@ -44,27 +44,27 @@ #include <grpc/support/time.h> #include "test/core/util/test_config.h" -static gpr_uint64 hash64(const void* k) { +static gpr_uint64 hash64(const void *k) { size_t len = strlen(k); - gpr_uint64 higher = gpr_murmur_hash3((const char*)k, len / 2, 0); + gpr_uint64 higher = gpr_murmur_hash3((const char *)k, len / 2, 0); return higher << 32 | - gpr_murmur_hash3((const char*)(k) + len / 2, len - len / 2, 0); + gpr_murmur_hash3((const char *)(k) + len / 2, len - len / 2, 0); } -static int cmp_str_keys(const void* k1, const void* k2) { - return strcmp((const char*)k1, (const char*)k2); +static int cmp_str_keys(const void *k1, const void *k2) { + return strcmp((const char *)k1, (const char *)k2); } -static gpr_uint64 force_collision(const void* k) { +static gpr_uint64 force_collision(const void *k) { return (1997 + hash64(k) % 3); } -static void free_data(void* data) { gpr_free(data); } +static void free_data(void *data) { gpr_free(data); } /* Basic tests that empty hash table can be created and destroyed. */ static void test_create_table(void) { /* Create table with uint64 key type */ - census_ht* ht = NULL; + census_ht *ht = NULL; census_ht_option ht_options = { CENSUS_HT_UINT64, 1999, NULL, NULL, NULL, NULL}; ht = census_ht_create(&ht_options); @@ -84,11 +84,11 @@ static void test_create_table(void) { static void test_table_with_int_key(void) { census_ht_option opt = {CENSUS_HT_UINT64, 7, NULL, NULL, NULL, NULL}; - census_ht* ht = census_ht_create(&opt); + census_ht *ht = census_ht_create(&opt); gpr_uint64 i = 0; gpr_uint64 sum_of_keys = 0; size_t num_elements; - census_ht_kv* elements = NULL; + census_ht_kv *elements = NULL; GPR_ASSERT(ht != NULL); GPR_ASSERT(census_ht_get_size(ht) == 0); elements = census_ht_get_all_elements(ht, &num_elements); @@ -97,15 +97,15 @@ static void test_table_with_int_key(void) { for (i = 0; i < 20; ++i) { census_ht_key key; key.val = i; - census_ht_insert(ht, key, (void*)(gpr_intptr)i); + census_ht_insert(ht, key, (void *)(gpr_intptr)i); GPR_ASSERT(census_ht_get_size(ht) == i + 1); } for (i = 0; i < 20; i++) { - gpr_uint64* val = NULL; + gpr_uint64 *val = NULL; census_ht_key key; key.val = i; val = census_ht_find(ht, key); - GPR_ASSERT(val == (void*)(gpr_intptr)i); + GPR_ASSERT(val == (void *)(gpr_intptr)i); } elements = census_ht_get_all_elements(ht, &num_elements); GPR_ASSERT(elements != NULL); @@ -122,10 +122,10 @@ static void test_table_with_int_key(void) { static void test_value_and_key_deleter(void) { census_ht_option opt = {CENSUS_HT_POINTER, 7, &hash64, &cmp_str_keys, &free_data, &free_data}; - census_ht* ht = census_ht_create(&opt); + census_ht *ht = census_ht_create(&opt); census_ht_key key; - char* val = NULL; - char* val2 = NULL; + char *val = NULL; + char *val2 = NULL; key.ptr = gpr_malloc(100); val = gpr_malloc(10); strcpy(val, "value"); @@ -151,14 +151,14 @@ static void test_value_and_key_deleter(void) { /* Test simple insert and erase operations. */ static void test_simple_add_and_erase(void) { census_ht_option opt = {CENSUS_HT_UINT64, 7, NULL, NULL, NULL, NULL}; - census_ht* ht = census_ht_create(&opt); + census_ht *ht = census_ht_create(&opt); GPR_ASSERT(ht != NULL); GPR_ASSERT(census_ht_get_size(ht) == 0); { census_ht_key key; int val = 3; key.val = 2; - census_ht_insert(ht, key, (void*)&val); + census_ht_insert(ht, key, (void *)&val); GPR_ASSERT(census_ht_get_size(ht) == 1); census_ht_erase(ht, key); GPR_ASSERT(census_ht_get_size(ht) == 0); @@ -166,11 +166,11 @@ static void test_simple_add_and_erase(void) { census_ht_erase(ht, key); GPR_ASSERT(census_ht_get_size(ht) == 0); /* Erasing a non-existant key from a table should be noop. */ - census_ht_insert(ht, key, (void*)&val); + census_ht_insert(ht, key, (void *)&val); key.val = 3; - census_ht_insert(ht, key, (void*)&val); + census_ht_insert(ht, key, (void *)&val); key.val = 9; - census_ht_insert(ht, key, (void*)&val); + census_ht_insert(ht, key, (void *)&val); GPR_ASSERT(census_ht_get_size(ht) == 3); key.val = 1; census_ht_erase(ht, key); @@ -187,7 +187,7 @@ static void test_simple_add_and_erase(void) { static void test_insertion_and_deletion_with_high_collision_rate(void) { census_ht_option opt = {CENSUS_HT_POINTER, 13, &force_collision, &cmp_str_keys, NULL, NULL}; - census_ht* ht = census_ht_create(&opt); + census_ht *ht = census_ht_create(&opt); char key_str[1000][GPR_LTOA_MIN_BUFSIZE]; gpr_uint64 val = 0; unsigned i = 0; @@ -195,7 +195,7 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) { census_ht_key key; key.ptr = key_str[i]; gpr_ltoa(i, key_str[i]); - census_ht_insert(ht, key, (void*)(&val)); + census_ht_insert(ht, key, (void *)(&val)); gpr_log(GPR_INFO, "%d\n", i); GPR_ASSERT(census_ht_get_size(ht) == (i + 1)); } @@ -211,8 +211,8 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) { static void test_table_with_string_key(void) { census_ht_option opt = {CENSUS_HT_POINTER, 7, &hash64, &cmp_str_keys, NULL, NULL}; - census_ht* ht = census_ht_create(&opt); - const char* keys[] = { + census_ht *ht = census_ht_create(&opt); + const char *keys[] = { "k1", "a", "000", "apple", "banana_a_long_long_long_banana", "%$", "111", "foo", "b"}; const int vals[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -221,23 +221,23 @@ static void test_table_with_string_key(void) { GPR_ASSERT(census_ht_get_size(ht) == 0); for (i = 0; i < 9; i++) { census_ht_key key; - key.ptr = (void*)(keys[i]); - census_ht_insert(ht, key, (void*)(vals + i)); + key.ptr = (void *)(keys[i]); + census_ht_insert(ht, key, (void *)(vals + i)); } GPR_ASSERT(census_ht_get_size(ht) == 9); for (i = 0; i < 9; i++) { census_ht_key key; - int* val_ptr; - key.ptr = (void*)(keys[i]); + int *val_ptr; + key.ptr = (void *)(keys[i]); val_ptr = census_ht_find(ht, key); GPR_ASSERT(*val_ptr == vals[i]); } { /* inserts duplicate keys */ census_ht_key key; - int* val_ptr = NULL; - key.ptr = (void*)(keys[2]); - census_ht_insert(ht, key, (void*)(vals + 8)); + int *val_ptr = NULL; + key.ptr = (void *)(keys[2]); + census_ht_insert(ht, key, (void *)(vals + 8)); /* expect value to be over written by new insertion */ GPR_ASSERT(census_ht_get_size(ht) == 9); val_ptr = census_ht_find(ht, key); @@ -245,10 +245,10 @@ static void test_table_with_string_key(void) { } for (i = 0; i < 9; i++) { census_ht_key key; - int* val_ptr; + int *val_ptr; gpr_uint32 expected_tbl_sz = 9 - i; GPR_ASSERT(census_ht_get_size(ht) == expected_tbl_sz); - key.ptr = (void*)(keys[i]); + key.ptr = (void *)(keys[i]); val_ptr = census_ht_find(ht, key); GPR_ASSERT(val_ptr != NULL); census_ht_erase(ht, key); @@ -261,34 +261,34 @@ static void test_table_with_string_key(void) { static void test_insertion_with_same_key(void) { census_ht_option opt = {CENSUS_HT_UINT64, 11, NULL, NULL, NULL, NULL}; - census_ht* ht = census_ht_create(&opt); + census_ht *ht = census_ht_create(&opt); census_ht_key key; const char vals[] = {'a', 'b', 'c'}; - char* val_ptr; + char *val_ptr; key.val = 3; - census_ht_insert(ht, key, (void*)&(vals[0])); + census_ht_insert(ht, key, (void *)&(vals[0])); GPR_ASSERT(census_ht_get_size(ht) == 1); - val_ptr = (char*)census_ht_find(ht, key); + val_ptr = (char *)census_ht_find(ht, key); GPR_ASSERT(val_ptr != NULL); GPR_ASSERT(*val_ptr == 'a'); key.val = 4; - val_ptr = (char*)census_ht_find(ht, key); + val_ptr = (char *)census_ht_find(ht, key); GPR_ASSERT(val_ptr == NULL); key.val = 3; - census_ht_insert(ht, key, (void*)&(vals[1])); + census_ht_insert(ht, key, (void *)&(vals[1])); GPR_ASSERT(census_ht_get_size(ht) == 1); - val_ptr = (char*)census_ht_find(ht, key); + val_ptr = (char *)census_ht_find(ht, key); GPR_ASSERT(val_ptr != NULL); GPR_ASSERT(*val_ptr == 'b'); - census_ht_insert(ht, key, (void*)&(vals[2])); + census_ht_insert(ht, key, (void *)&(vals[2])); GPR_ASSERT(census_ht_get_size(ht) == 1); - val_ptr = (char*)census_ht_find(ht, key); + val_ptr = (char *)census_ht_find(ht, key); GPR_ASSERT(val_ptr != NULL); GPR_ASSERT(*val_ptr == 'c'); census_ht_destroy(ht); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_create_table(); test_simple_add_and_erase(); diff --git a/test/core/statistics/rpc_stats_test.c b/test/core/statistics/rpc_stats_test.c index df076b9c1e..b1d8814cfa 100644 --- a/test/core/statistics/rpc_stats_test.c +++ b/test/core/statistics/rpc_stats_test.c @@ -54,7 +54,7 @@ static void test_init_shutdown(void) { } static void test_create_and_destroy(void) { - census_rpc_stats* stats = NULL; + census_rpc_stats *stats = NULL; census_aggregated_rpc_stats agg_stats = {0, NULL}; stats = census_rpc_stats_create_empty(); @@ -69,7 +69,7 @@ static void test_create_and_destroy(void) { GPR_ASSERT(agg_stats.num_entries == 0); GPR_ASSERT(agg_stats.stats == NULL); agg_stats.num_entries = 1; - agg_stats.stats = (census_per_method_rpc_stats*)gpr_malloc( + agg_stats.stats = (census_per_method_rpc_stats *)gpr_malloc( sizeof(census_per_method_rpc_stats)); agg_stats.stats[0].method = gpr_strdup("foo"); census_aggregated_rpc_stats_set_empty(&agg_stats); @@ -113,7 +113,8 @@ static void test_record_and_get_stats(void) { census_aggregated_rpc_stats_set_empty(&agg_stats); census_shutdown(); - /* Record both server (once) and client (twice) stats with different op_ids.*/ + /* Record both server (once) and client (twice) stats with different op_ids. + */ census_init(); id = census_tracing_start_op(); census_add_method_tag(id, "m2"); @@ -186,7 +187,7 @@ static void test_record_stats_with_trace_store_uninitialized(void) { census_stats_store_shutdown(); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_init_shutdown(); test_create_and_destroy(); diff --git a/test/core/statistics/trace_test.c b/test/core/statistics/trace_test.c index 187884d90f..75904040ff 100644 --- a/test/core/statistics/trace_test.c +++ b/test/core/statistics/trace_test.c @@ -85,7 +85,7 @@ static void test_get_trace_method_name(void) { census_add_method_tag(id, write_name); census_internal_lock_trace_store(); { - const char* read_name = + const char *read_name = census_get_trace_method_name(census_get_trace_obj_locked(id)); GPR_ASSERT(strcmp(read_name, write_name) == 0); } @@ -99,12 +99,12 @@ typedef struct thd_arg { gpr_mu mu; } thd_arg; -static void mimic_trace_op_sequences(void* arg) { +static void mimic_trace_op_sequences(void *arg) { census_op_id id; - const char* method_name = "service_foo/method_bar"; + const char *method_name = "service_foo/method_bar"; int i = 0; const int num_iter = 200; - thd_arg* args = (thd_arg*)arg; + thd_arg *args = (thd_arg *)arg; GPR_ASSERT(args != NULL); gpr_log(GPR_INFO, "Start trace op sequence thread."); for (i = 0; i < num_iter; i++) { @@ -155,7 +155,7 @@ static void test_add_method_tag_to_unknown_op_id(void) { static void test_trace_print(void) { census_op_id id; int i; - const char* annotation_txt[4] = {"abc", "", "$%^ *()_"}; + const char *annotation_txt[4] = {"abc", "", "$%^ *()_"}; char long_txt[CENSUS_MAX_ANNOTATION_LENGTH + 10]; memset(long_txt, 'a', GPR_ARRAY_SIZE(long_txt)); @@ -181,8 +181,8 @@ static int ids_equal(census_op_id id1, census_op_id id2) { static void test_get_active_ops(void) { census_op_id id_1, id_2, id_3; - census_trace_obj** active_ops; - const char* annotation_txt[] = {"annotation 1", "a2"}; + census_trace_obj **active_ops; + const char *annotation_txt[] = {"annotation 1", "a2"}; int i = 0; int n = 0; @@ -218,7 +218,7 @@ static void test_get_active_ops(void) { gpr_free(active_ops); active_ops = NULL; - /* End the second op and add annotations to the third ops*/ + /* End the second op and add annotations to the third ops */ census_tracing_end_op(id_2); census_tracing_print(id_3, annotation_txt[0]); census_tracing_print(id_3, annotation_txt[1]); @@ -242,7 +242,7 @@ static void test_get_active_ops(void) { census_tracing_shutdown(); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { grpc_test_init(argc, argv); test_init_shutdown(); test_start_op_generates_locally_unique_ids(); diff --git a/test/core/statistics/window_stats_test.c b/test/core/statistics/window_stats_test.c index 9e637ccce9..578138fdd2 100644 --- a/test/core/statistics/window_stats_test.c +++ b/test/core/statistics/window_stats_test.c @@ -42,16 +42,16 @@ typedef struct test_stat { int value2; } test_stat; -void add_test_stat(void* base, const void* addme) { - test_stat* b = (test_stat*)base; - const test_stat* a = (const test_stat*)addme; +void add_test_stat(void *base, const void *addme) { + test_stat *b = (test_stat *)base; + const test_stat *a = (const test_stat *)addme; b->value1 += a->value1; b->value2 += a->value2; } -void add_proportion_test_stat(double p, void* base, const void* addme) { - test_stat* b = (test_stat*)base; - const test_stat* a = (const test_stat*)addme; +void add_proportion_test_stat(double p, void *base, const void *addme) { + test_stat *b = (test_stat *)base; + const test_stat *a = (const test_stat *)addme; b->value1 += p * a->value1; b->value2 += p * a->value2 + 0.5; /* +0.5 is poor mans (no c99) round() */ } @@ -77,7 +77,7 @@ void empty_test(void) { census_window_stats_sums result; const gpr_timespec zero = {0, 0}; test_stat sum; - struct census_window_stats* stats = + struct census_window_stats *stats = census_window_stats_create(1, &kMinInterval, 5, &kMyStatInfo); GPR_ASSERT(stats != NULL); result.statistic = ∑ @@ -95,7 +95,7 @@ void one_interval_test(void) { census_window_stats_sums result; test_stat sum; /* granularity == 5 so width of internal windows should be 12s */ - struct census_window_stats* stats = + struct census_window_stats *stats = census_window_stats_create(1, &kMinInterval, 5, &kMyStatInfo); GPR_ASSERT(stats != NULL); /* phase 1: insert a single value at t=0s, and check that various measurement @@ -205,7 +205,7 @@ void many_interval_test(void) { census_window_stats_sums result[4]; test_stat sums[4]; int i; - struct census_window_stats* stats; + struct census_window_stats *stats; intervals[0] = kMilliSecInterval; intervals[1] = kSecInterval; intervals[2] = kMinInterval; @@ -265,7 +265,7 @@ void rolling_time_test(void) { test_stat sum; int i; gpr_timespec increment = {0, 0}; - struct census_window_stats* stats = + struct census_window_stats *stats = census_window_stats_create(1, &kMinInterval, 7, &kMyStatInfo); GPR_ASSERT(stats != NULL); srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); @@ -281,6 +281,7 @@ void rolling_time_test(void) { GPR_ASSERT(compare_double(result.count, 1200, 100) == 0); census_window_stats_destroy(stats); } + #include <stdio.h> void infinite_interval_test(void) { const test_stat value = {0.1, 4}; @@ -290,7 +291,7 @@ void infinite_interval_test(void) { int i; const int count = 100000; gpr_timespec increment = {0, 0}; - struct census_window_stats* stats = census_window_stats_create( + struct census_window_stats *stats = census_window_stats_create( 1, &gpr_inf_future(GPR_CLOCK_REALTIME), 10, &kMyStatInfo); srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); for (i = 0; i < count; i++) { @@ -306,7 +307,7 @@ void infinite_interval_test(void) { census_window_stats_destroy(stats); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { grpc_test_init(argc, argv); empty_test(); one_interval_test(); diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index f729eb0b92..220b16b60f 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -53,9 +53,9 @@ typedef struct queue { gpr_cv non_empty; /* Signalled when length becomes non-zero. */ gpr_cv non_full; /* Signalled when length becomes non-N. */ gpr_mu mu; /* Protects all fields below. - (That is, except during initialization or - destruction, the fields below should be accessed - only by a thread that holds mu.) */ + (That is, except during initialization or + destruction, the fields below should be accessed + only by a thread that holds mu.) */ int head; /* Index of head of queue 0..N-1. */ int length; /* Number of valid elements in queue 0..N. */ int elem[N]; /* elem[head .. head+length-1] are queue elements. */ diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index 0eeb5dac45..e3fc789788 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -75,12 +75,14 @@ static void test_wait_empty(void) { shutdown_and_destroy(cc); } -static void do_nothing_end_completion(void *arg, grpc_cq_completion *c) {} +static void do_nothing_end_completion(grpc_exec_ctx *exec_ctx, void *arg, + grpc_cq_completion *c) {} static void test_cq_end_op(void) { grpc_event ev; grpc_completion_queue *cc; grpc_cq_completion completion; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; void *tag = create_test_tag(); LOG_TEST("test_cq_end_op"); @@ -88,7 +90,8 @@ static void test_cq_end_op(void) { cc = grpc_completion_queue_create(NULL); grpc_cq_begin_op(cc); - grpc_cq_end_op(cc, tag, 1, do_nothing_end_completion, NULL, &completion); + grpc_cq_end_op(&exec_ctx, cc, tag, 1, do_nothing_end_completion, NULL, + &completion); ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); @@ -96,6 +99,7 @@ static void test_cq_end_op(void) { GPR_ASSERT(ev.success); shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } static void test_shutdown_then_next_polling(void) { @@ -129,6 +133,7 @@ static void test_pluck(void) { grpc_completion_queue *cc; void *tags[128]; grpc_cq_completion completions[GPR_ARRAY_SIZE(tags)]; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; unsigned i, j; LOG_TEST("test_pluck"); @@ -144,7 +149,7 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { grpc_cq_begin_op(cc); - grpc_cq_end_op(cc, tags[i], 1, do_nothing_end_completion, NULL, + grpc_cq_end_op(&exec_ctx, cc, tags[i], 1, do_nothing_end_completion, NULL, &completions[i]); } @@ -156,7 +161,7 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { grpc_cq_begin_op(cc); - grpc_cq_end_op(cc, tags[i], 1, do_nothing_end_completion, NULL, + grpc_cq_end_op(&exec_ctx, cc, tags[i], 1, do_nothing_end_completion, NULL, &completions[i]); } @@ -167,6 +172,7 @@ static void test_pluck(void) { } shutdown_and_destroy(cc); + grpc_exec_ctx_finish(&exec_ctx); } #define TEST_THREAD_EVENTS 10000 @@ -186,13 +192,15 @@ gpr_timespec ten_seconds_time(void) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); } -static void free_completion(void *arg, grpc_cq_completion *completion) { +static void free_completion(grpc_exec_ctx *exec_ctx, void *arg, + grpc_cq_completion *completion) { gpr_free(completion); } static void producer_thread(void *arg) { test_thread_options *opt = 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 *)(gpr_intptr)1); @@ -209,13 +217,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(opt->cc, (void *)(gpr_intptr)1, 1, free_completion, NULL, + grpc_cq_end_op(&exec_ctx, opt->cc, (void *)(gpr_intptr)1, 1, + free_completion, NULL, 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 *)(gpr_intptr)1); + grpc_exec_ctx_finish(&exec_ctx); } static void consumer_thread(void *arg) { diff --git a/test/core/tsi/transport_security_test.c b/test/core/tsi/transport_security_test.c index bec3866166..858b92fc9d 100644 --- a/test/core/tsi/transport_security_test.c +++ b/test/core/tsi/transport_security_test.c @@ -73,8 +73,8 @@ const cert_name_test_entry cert_name_test_entries[] = { {1, "www.test.fr", "common.name", "*.test.com,*.test.co.uk,*.test.de,*.test.fr"}, /* - {1, "wwW.tESt.fr", "common.name", ",*.*,*.test.de,*.test.FR,www"}, - */ + {1, "wwW.tESt.fr", "common.name", ",*.*,*.test.de,*.test.FR,www"}, + */ {0, "f.uk", ".uk", NULL}, {0, "w.bar.foo.com", "?.bar.foo.com", NULL}, {0, "www.foo.com", "(www|ftp).foo.com", NULL}, @@ -90,9 +90,9 @@ const cert_name_test_entry cert_name_test_entries[] = { {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", NULL}, {0, "wally.bar.foo.com", "*Ly.bar.foo.com", NULL}, /* - {1, "ww%57.foo.com", "", "www.foo.com"}, - {1, "www&.foo.com", "www%26.foo.com", NULL}, - */ + {1, "ww%57.foo.com", "", "www.foo.com"}, + {1, "www&.foo.com", "www%26.foo.com", NULL}, + */ /* Common name must not be used if subject alternative name was provided. */ {0, "www.test.co.jp", "www.test.co.jp", @@ -111,8 +111,8 @@ const cert_name_test_entry cert_name_test_entries[] = { /* The following are adapted from the examples quoted from http://tools.ietf.org/html/rfc6125#section-6.4.3 - (e.g., *.example.com would match foo.example.com but - not bar.foo.example.com or example.com). */ + (e.g., *.example.com would match foo.example.com but + not bar.foo.example.com or example.com). */ {1, "foo.example.com", "*.example.com", NULL}, {0, "bar.foo.example.com", "*.example.com", NULL}, {0, "example.com", "*.example.com", NULL}, @@ -133,8 +133,8 @@ const cert_name_test_entry cert_name_test_entries[] = { {1, "test.example.co.uk", "*.example.co.uk", NULL}, {0, "test.example", "*.example", NULL}, /* - {0, "example.co.uk", "*.co.uk", NULL}, - */ + {0, "example.co.uk", "*.co.uk", NULL}, + */ {0, "foo.com", "*.com", NULL}, {0, "foo.us", "*.us", NULL}, {0, "foo", "*", NULL}, @@ -143,8 +143,8 @@ const cert_name_test_entry cert_name_test_entries[] = { {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL}, {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", NULL}, /* - {0, "xn--poema-9qae5a.com.br", "*.com.br", NULL}, - */ + {0, "xn--poema-9qae5a.com.br", "*.com.br", NULL}, + */ {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", NULL}, /* Wildcards should be permissible for 'private' registry controlled @@ -175,9 +175,9 @@ const cert_name_test_entry cert_name_test_entries[] = { {0, "foo.", "*.", NULL}, {0, "foo", "*.", NULL}, /* - {0, "foo.co.uk", "*.co.uk.", NULL}, - {0, "foo.co.uk.", "*.co.uk.", NULL}, - */ + {0, "foo.co.uk", "*.co.uk.", NULL}, + {0, "foo.co.uk.", "*.co.uk.", NULL}, + */ /* An empty CN is OK. */ {1, "test.foo.com", "", "test.foo.com"}, diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 03f4c4912e..887079e0f8 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -72,12 +72,13 @@ typedef struct freereq { int done; } freereq; -static void destroy_pollset_and_shutdown(void *p) { +static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, + int success) { grpc_pollset_destroy(p); grpc_shutdown(); } -static void freed_port_from_server(void *arg, +static void freed_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, const grpc_httpcli_response *response) { freereq *pr = arg; gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset)); @@ -91,35 +92,42 @@ static void free_port_using_server(char *server, int port) { grpc_httpcli_request req; freereq pr; char *path; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_closure shutdown_closure; grpc_init(); memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); grpc_pollset_init(&pr.pollset); + grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, + &pr.pollset); req.host = server; gpr_asprintf(&path, "/drop/%d", port); req.path = path; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server, &pr); gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); while (!pr.done) { grpc_pollset_worker worker; - grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); } gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset); + grpc_exec_ctx_finish(&exec_ctx); + grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &shutdown_closure); + grpc_exec_ctx_finish(&exec_ctx); gpr_free(path); } -static void free_chosen_ports() { +static void free_chosen_ports() { char *env = gpr_getenv("GRPC_TEST_PORT_SERVER"); if (env != NULL) { size_t i; @@ -129,7 +137,7 @@ static void free_chosen_ports() { gpr_free(env); } - gpr_free(chosen_ports); + gpr_free(chosen_ports); } static void chose_port(int port) { @@ -200,11 +208,12 @@ typedef struct portreq { grpc_httpcli_context *ctx; } portreq; -static void got_port_from_server(void *arg, +static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, const grpc_httpcli_response *response) { size_t i; int port = 0; portreq *pr = arg; + if (!response || response->status != 200) { grpc_httpcli_request req; memset(&req, 0, sizeof(req)); @@ -214,8 +223,9 @@ static void got_port_from_server(void *arg, req.path = "/get"; gpr_log(GPR_DEBUG, "failed port pick from server: retrying"); sleep(1); - grpc_httpcli_get(pr->ctx, &pr->pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), - got_port_from_server, pr); + grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pollset, &req, + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, + pr); return; } GPR_ASSERT(response); @@ -235,12 +245,16 @@ static int pick_port_using_server(char *server) { 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(); memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); grpc_pollset_init(&pr.pollset); + grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, + &pr.pollset); pr.port = -1; pr.server = server; pr.ctx = &context; @@ -249,19 +263,22 @@ static int pick_port_using_server(char *server) { req.path = "/get"; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, &pr); + grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); while (pr.port == -1) { grpc_pollset_worker worker; - grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); } gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset); + grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &shutdown_closure); + grpc_exec_ctx_finish(&exec_ctx); return pr.port; } diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c index a57fe692e1..60ad9b4f2a 100644 --- a/test/core/util/port_windows.c +++ b/test/core/util/port_windows.c @@ -65,7 +65,7 @@ static int has_port_been_chosen(int port) { return 0; } -static void free_chosen_ports() { gpr_free(chosen_ports); } +static void free_chosen_ports(void) { gpr_free(chosen_ports); } static void chose_port(int port) { if (chosen_ports == NULL) { @@ -133,7 +133,7 @@ typedef struct portreq { int port; } portreq; -static void got_port_from_server(void *arg, +static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, const grpc_httpcli_response *response) { size_t i; int port = 0; @@ -151,7 +151,8 @@ static void got_port_from_server(void *arg, gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset)); } -static void destroy_pollset_and_shutdown(void *p) { +static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, + int success) { grpc_pollset_destroy(p); grpc_shutdown(); } @@ -160,6 +161,8 @@ static int pick_port_using_server(char *server) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_closure destroy_pollset_closure; grpc_init(); @@ -172,20 +175,27 @@ static int pick_port_using_server(char *server) { req.path = "/get"; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, &pr); gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); while (pr.port == -1) { grpc_pollset_worker worker; - grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); + gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); + grpc_exec_ctx_flush(&exec_ctx); + gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); } gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset); + grpc_closure_init(&destroy_pollset_closure, destroy_pollset_and_shutdown, + &pr.pollset); + grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &destroy_pollset_closure); + grpc_exec_ctx_finish(&exec_ctx); return pr.port; } @@ -244,7 +254,7 @@ int grpc_pick_unused_port(void) { } /* TODO(ctiller): consider caching this port in some structure, to avoid - handing it out again */ + handing it out again */ chose_port(port); return port; diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c index 71fb69b54f..ee481ef674 100644 --- a/test/core/util/reconnect_server.c +++ b/test/core/util/reconnect_server.c @@ -65,15 +65,15 @@ static void pretty_print_backoffs(reconnect_server *server) { } } -static void on_connect(void *arg, grpc_endpoint *tcp) { +static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp) { char *peer; char *last_colon; reconnect_server *server = (reconnect_server *)arg; gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list *new_tail; peer = grpc_endpoint_get_peer(tcp); - grpc_endpoint_shutdown(tcp); - grpc_endpoint_destroy(tcp); + grpc_endpoint_shutdown(exec_ctx, tcp); + grpc_endpoint_destroy(exec_ctx, tcp); if (peer) { last_colon = strrchr(peer, ':'); if (server->peer == NULL) { @@ -114,6 +114,7 @@ void reconnect_server_init(reconnect_server *server) { void reconnect_server_start(reconnect_server *server, int port) { struct sockaddr_in addr; int port_added; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; addr.sin_family = AF_INET; addr.sin_port = htons((gpr_uint16)port); @@ -124,9 +125,11 @@ void reconnect_server_start(reconnect_server *server, int port) { grpc_tcp_server_add_port(server->tcp_server, &addr, sizeof(addr)); GPR_ASSERT(port_added == port); - grpc_tcp_server_start(server->tcp_server, server->pollsets, 1, on_connect, - server); + grpc_tcp_server_start(&exec_ctx, server->tcp_server, server->pollsets, 1, + on_connect, server); gpr_log(GPR_INFO, "reconnect tcp server listening on 0.0.0.0:%d", port); + + grpc_exec_ctx_finish(&exec_ctx); } void reconnect_server_poll(reconnect_server *server, int seconds) { @@ -134,10 +137,12 @@ void reconnect_server_poll(reconnect_server *server, int seconds) { gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(seconds, GPR_TIMESPAN)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(GRPC_POLLSET_MU(&server->pollset)); - grpc_pollset_work(&server->pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), - deadline); + grpc_pollset_work(&exec_ctx, &server->pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline); gpr_mu_unlock(GRPC_POLLSET_MU(&server->pollset)); + grpc_exec_ctx_finish(&exec_ctx); } void reconnect_server_clear_timestamps(reconnect_server *server) { @@ -152,12 +157,18 @@ void reconnect_server_clear_timestamps(reconnect_server *server) { server->peer = NULL; } -static void do_nothing(void *ignored) {} +static void do_nothing(grpc_exec_ctx *exec_ctx, void *ignored, int success) {} void reconnect_server_destroy(reconnect_server *server) { - grpc_tcp_server_destroy(server->tcp_server, do_nothing, NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_closure do_nothing_closure[2]; + grpc_closure_init(&do_nothing_closure[0], do_nothing, NULL); + grpc_closure_init(&do_nothing_closure[1], do_nothing, NULL); + grpc_tcp_server_destroy(&exec_ctx, server->tcp_server, + &do_nothing_closure[0]); reconnect_server_clear_timestamps(server); - grpc_pollset_shutdown(&server->pollset, do_nothing, NULL); + grpc_pollset_shutdown(&exec_ctx, &server->pollset, &do_nothing_closure[1]); + grpc_exec_ctx_finish(&exec_ctx); grpc_pollset_destroy(&server->pollset); grpc_shutdown(); } diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c index f5d5cdb57c..168b98fe63 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -51,7 +51,7 @@ static unsigned seed(void) { return _getpid(); } #endif #if GPR_WINDOWS_CRASH_HANDLER -LONG crash_handler(struct _EXCEPTION_POINTERS* ex_info) { +LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) { gpr_log(GPR_DEBUG, "Exception handler called, dumping information"); while (ex_info->ExceptionRecord) { DWORD code = ex_info->ExceptionRecord->ExceptionCode; @@ -87,7 +87,7 @@ static void install_crash_handler() { static void install_crash_handler() {} #endif -void grpc_test_init(int argc, char** argv) { +void grpc_test_init(int argc, char **argv) { install_crash_handler(); gpr_log(GPR_DEBUG, "test slowdown: machine=%f build=%f total=%f", (double)GRPC_TEST_SLOWDOWN_MACHINE_FACTOR, diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 5017e8a230..2659b0e213 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -1161,8 +1161,8 @@ TEST_F(End2endTest, ChannelStateTimeout) { auto state = GRPC_CHANNEL_IDLE; for (int i = 0; i < 10; i++) { - channel->WaitForStateChange(state, std::chrono::system_clock::now() + - std::chrono::seconds(1)); + channel->WaitForStateChange( + state, std::chrono::system_clock::now() + std::chrono::seconds(1)); state = channel->GetState(false); } } diff --git a/test/proto/test.proto b/test/proto/test.proto index 92aff23929..d3166a6540 100644 --- a/test/proto/test.proto +++ b/test/proto/test.proto @@ -45,7 +45,6 @@ service TestService { rpc EmptyCall(grpc.testing.Empty) returns (grpc.testing.Empty); // One request followed by one response. - // TODO(Issue 527): Describe required server behavior. rpc UnaryCall(SimpleRequest) returns (SimpleResponse); // One request followed by a sequence of responses (streamed download). |