diff options
Diffstat (limited to 'test/core/end2end/fixtures')
-rw-r--r-- | test/core/end2end/fixtures/h2_census.cc (renamed from test/core/end2end/fixtures/h2_census.c) | 58 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_compress.cc (renamed from test/core/end2end/fixtures/h2_compress.c) | 78 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_fakesec.cc (renamed from test/core/end2end/fixtures/h2_fakesec.c) | 67 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_fd.cc (renamed from test/core/end2end/fixtures/h2_fd.c) | 45 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_full+pipe.cc (renamed from test/core/end2end/fixtures/h2_full+pipe.c) | 48 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_full+trace.cc (renamed from test/core/end2end/fixtures/h2_full+trace.c) | 48 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_full+workarounds.cc (renamed from test/core/end2end/fixtures/h2_full+workarounds.c) | 59 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_full.cc (renamed from test/core/end2end/fixtures/h2_full.c) | 46 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_http_proxy.cc (renamed from test/core/end2end/fixtures/h2_http_proxy.c) | 56 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_load_reporting.cc (renamed from test/core/end2end/fixtures/h2_load_reporting.c) | 45 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_oauth2.cc (renamed from test/core/end2end/fixtures/h2_oauth2.c) | 140 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_proxy.cc (renamed from test/core/end2end/fixtures/h2_proxy.c) | 59 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_sockpair+trace.cc (renamed from test/core/end2end/fixtures/h2_sockpair+trace.c) | 84 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_sockpair.cc (renamed from test/core/end2end/fixtures/h2_sockpair.c) | 80 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_sockpair_1byte.cc (renamed from test/core/end2end/fixtures/h2_sockpair_1byte.c) | 101 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_ssl.cc (renamed from test/core/end2end/fixtures/h2_ssl.c) | 99 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_ssl_cert.c | 371 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_ssl_proxy.cc (renamed from test/core/end2end/fixtures/h2_ssl_proxy.c) | 135 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_uds.cc (renamed from test/core/end2end/fixtures/h2_uds.c) | 48 | ||||
-rw-r--r-- | test/core/end2end/fixtures/http_proxy_fixture.cc (renamed from test/core/end2end/fixtures/http_proxy_fixture.c) | 294 | ||||
-rw-r--r-- | test/core/end2end/fixtures/inproc.cc (renamed from test/core/end2end/fixtures/inproc.c) | 29 | ||||
-rw-r--r-- | test/core/end2end/fixtures/proxy.cc (renamed from test/core/end2end/fixtures/proxy.c) | 194 | ||||
-rw-r--r-- | test/core/end2end/fixtures/proxy.h | 20 |
23 files changed, 962 insertions, 1242 deletions
diff --git a/test/core/end2end/fixtures/h2_census.c b/test/core/end2end/fixtures/h2_census.cc index 9870ccb34a..75c80aa1ff 100644 --- a/test/core/end2end/fixtures/h2_census.c +++ b/test/core/end2end/fixtures/h2_census.cc @@ -37,21 +37,22 @@ #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } @@ -59,60 +60,63 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( static grpc_arg make_census_enable_arg(void) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; - arg.key = GRPC_ARG_ENABLE_CENSUS; + arg.key = const_cast<char*>(GRPC_ARG_ENABLE_CENSUS); arg.value.integer = 1; return arg; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); grpc_arg arg = make_census_enable_arg(); client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1); - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(client_args); } } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); grpc_arg arg = make_census_enable_arg(); if (f->server) { grpc_server_destroy(f->server); } server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); - f->server = grpc_server_create(server_args, NULL); + f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } - grpc_server_register_completion_queue(f->server, f->cq, NULL); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack+census", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack+census", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_compress.c b/test/core/end2end/fixtures/h2_compress.cc index 9866dea7eb..3625afefcd 100644 --- a/test/core/end2end/fixtures/h2_compress.c +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -37,84 +37,86 @@ #include "test/core/util/test_config.h" typedef struct fullstack_compression_fixture_data { - char *localaddr; - grpc_channel_args *client_args_compression; - grpc_channel_args *server_args_compression; + char* localaddr; + grpc_channel_args* client_args_compression; + grpc_channel_args* server_args_compression; } fullstack_compression_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_compression_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_compression_fixture_data)); + fullstack_compression_fixture_data* ffd = + static_cast<fullstack_compression_fixture_data*>( + gpr_malloc(sizeof(fullstack_compression_fixture_data))); memset(ffd, 0, sizeof(fullstack_compression_fixture_data)); gpr_join_host_port(&ffd->localaddr, "localhost", port); memset(&f, 0, sizeof(f)); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_compression_fixture_data *ffd = f->fixture_data; - if (ffd->client_args_compression != NULL) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_exec_ctx_finish(&exec_ctx); +void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_compression_fixture_data* ffd = + static_cast<fullstack_compression_fixture_data*>(f->fixture_data); + if (ffd->client_args_compression != nullptr) { + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->client_args_compression); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( - client_args, GRPC_COMPRESS_GZIP); - f->client = grpc_insecure_channel_create(ffd->localaddr, - ffd->client_args_compression, NULL); + client_args, GRPC_COMPRESS_MESSAGE_GZIP); + f->client = grpc_insecure_channel_create( + ffd->localaddr, ffd->client_args_compression, nullptr); } -void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_compression_fixture_data *ffd = f->fixture_data; - if (ffd->server_args_compression != NULL) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); - grpc_exec_ctx_finish(&exec_ctx); +void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_compression_fixture_data* ffd = + static_cast<fullstack_compression_fixture_data*>(f->fixture_data); + if (ffd->server_args_compression != nullptr) { + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( - server_args, GRPC_COMPRESS_GZIP); + server_args, GRPC_COMPRESS_MESSAGE_GZIP); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(ffd->server_args_compression, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(ffd->server_args_compression, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture *f) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - fullstack_compression_fixture_data *ffd = f->fixture_data; - grpc_channel_args_destroy(&exec_ctx, ffd->client_args_compression); - grpc_channel_args_destroy(&exec_ctx, ffd->server_args_compression); +void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { + grpc_core::ExecCtx exec_ctx; + fullstack_compression_fixture_data* ffd = + static_cast<fullstack_compression_fixture_data*>(f->fixture_data); + grpc_channel_args_destroy(ffd->client_args_compression); + grpc_channel_args_destroy(ffd->server_args_compression); gpr_free(ffd->localaddr); gpr_free(ffd); - grpc_exec_ctx_finish(&exec_ctx); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack_compression", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack_compression", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack_compression, chttp2_init_client_fullstack_compression, chttp2_init_server_fullstack_compression, chttp2_tear_down_fullstack_compression}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_fakesec.c b/test/core/end2end/fixtures/h2_fakesec.cc index e622d952be..87d4668d50 100644 --- a/test/core/end2end/fixtures/h2_fakesec.c +++ b/test/core/end2end/fixtures/h2_fakesec.cc @@ -31,75 +31,79 @@ #include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { - char *localaddr; + char* localaddr; } fullstack_secure_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_secure_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_secure_fixture_data)); + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>( + gpr_malloc(sizeof(fullstack_secure_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -static void process_auth_failure(void *state, grpc_auth_context *ctx, - const grpc_metadata *md, size_t md_count, +static void process_auth_failure(void* state, grpc_auth_context* ctx, + const grpc_metadata* md, size_t md_count, grpc_process_auth_metadata_done_cb cb, - void *user_data) { - GPR_ASSERT(state == NULL); - cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); + void* user_data) { + GPR_ASSERT(state == nullptr); + cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr); } static void chttp2_init_client_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - grpc_channel_credentials *creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* client_args, + grpc_channel_credentials* creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); f->client = - grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); - GPR_ASSERT(f->client != NULL); + grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr); + GPR_ASSERT(f->client != nullptr); grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args, - grpc_server_credentials *server_creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* server_args, + grpc_server_credentials* server_creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(f->server); } -void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { - fullstack_secure_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } static void chttp2_init_client_fake_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_channel_credentials *fake_ts_creds = + grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { + grpc_channel_credentials* fake_ts_creds = grpc_fake_transport_security_credentials_create(); chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds); } -static int fail_server_auth_check(grpc_channel_args *server_args) { +static int fail_server_auth_check(grpc_channel_args* server_args) { size_t i; - if (server_args == NULL) return 0; + if (server_args == nullptr) return 0; for (i = 0; i < server_args->num_args; i++) { if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) { @@ -110,11 +114,12 @@ static int fail_server_auth_check(grpc_channel_args *server_args) { } static void chttp2_init_server_fake_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { - grpc_server_credentials *fake_ts_creds = + grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { + grpc_server_credentials* fake_ts_creds = grpc_fake_transport_security_server_credentials_create(); if (fail_server_auth_check(server_args)) { - grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL}; + grpc_auth_metadata_processor processor = {process_auth_failure, nullptr, + nullptr}; grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds, processor); } @@ -135,7 +140,7 @@ static grpc_end2end_test_config configs[] = { chttp2_tear_down_secure_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); diff --git a/test/core/end2end/fixtures/h2_fd.c b/test/core/end2end/fixtures/h2_fd.cc index e82c120221..9157ab04d0 100644 --- a/test/core/end2end/fixtures/h2_fd.c +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -35,7 +35,9 @@ #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "test/core/util/test_config.h" -typedef struct { int fd_pair[2]; } sp_fixture_data; +typedef struct { + int fd_pair[2]; +} sp_fixture_data; static void create_sockets(int sv[2]) { int flags; @@ -49,49 +51,46 @@ static void create_sockets(int sv[2]) { } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( - grpc_channel_args *client_args, grpc_channel_args *server_args) { - sp_fixture_data *fixture_data = gpr_malloc(sizeof(*fixture_data)); + grpc_channel_args* client_args, grpc_channel_args* server_args) { + sp_fixture_data* fixture_data = + static_cast<sp_fixture_data*>(gpr_malloc(sizeof(*fixture_data))); grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); f.fixture_data = fixture_data; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); create_sockets(fixture_data->fd_pair); return f; } -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; - sp_fixture_data *sfd = f->fixture_data; +static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + grpc_core::ExecCtx exec_ctx; + sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data); GPR_ASSERT(!f->client); f->client = grpc_insecure_channel_create_from_fd( "fixture_client", sfd->fd_pair[0], client_args); GPR_ASSERT(f->client); - - grpc_exec_ctx_finish(&exec_ctx); } -static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - sp_fixture_data *sfd = f->fixture_data; +static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + grpc_core::ExecCtx exec_ctx; + sp_fixture_data* sfd = static_cast<sp_fixture_data*>(f->fixture_data); GPR_ASSERT(!f->server); - f->server = grpc_server_create(server_args, NULL); + f->server = grpc_server_create(server_args, nullptr); GPR_ASSERT(f->server); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - grpc_server_add_insecure_channel_from_fd(f->server, NULL, sfd->fd_pair[1]); - - grpc_exec_ctx_finish(&exec_ctx); + grpc_server_add_insecure_channel_from_fd(f->server, nullptr, sfd->fd_pair[1]); } -static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { +static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { gpr_free(f->fixture_data); } @@ -102,7 +101,7 @@ static grpc_end2end_test_config configs[] = { chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); @@ -120,6 +119,6 @@ int main(int argc, char **argv) { #else /* GRPC_POSIX_SOCKET */ -int main(int argc, char **argv) { return 1; } +int main(int argc, char** argv) { return 1; } #endif /* GRPC_POSIX_SOCKET */ diff --git a/test/core/end2end/fixtures/h2_full+pipe.c b/test/core/end2end/fixtures/h2_full+pipe.cc index c764bd704a..b080591e85 100644 --- a/test/core/end2end/fixtures/h2_full+pipe.c +++ b/test/core/end2end/fixtures/h2_full+pipe.cc @@ -42,60 +42,66 @@ #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_allow_specialized_wakeup_fd = 0; @@ -115,6 +121,6 @@ int main(int argc, char **argv) { #else /* GRPC_POSIX_WAKEUP_FD */ -int main(int argc, char **argv) { return 1; } +int main(int argc, char** argv) { return 1; } #endif /* GRPC_POSIX_WAKEUP_FD */ diff --git a/test/core/end2end/fixtures/h2_full+trace.c b/test/core/end2end/fixtures/h2_full+trace.cc index 7eb29e0d32..7104fbc581 100644 --- a/test/core/end2end/fixtures/h2_full+trace.c +++ b/test/core/end2end/fixtures/h2_full+trace.cc @@ -35,67 +35,73 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; /* force tracing on, with a value to force many diff --git a/test/core/end2end/fixtures/h2_full+workarounds.c b/test/core/end2end/fixtures/h2_full+workarounds.cc index a98e5ad57f..237841d185 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.c +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -36,77 +36,82 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -static char *workarounds_arg[GRPC_MAX_WORKAROUND_ID] = { - GRPC_ARG_WORKAROUND_CRONET_COMPRESSION}; +static char* workarounds_arg[GRPC_MAX_WORKAROUND_ID] = { + const_cast<char*>(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION)}; typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { int i; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - fullstack_fixture_data *ffd = f->fixture_data; + grpc_core::ExecCtx exec_ctx; + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); grpc_arg args[GRPC_MAX_WORKAROUND_ID]; for (i = 0; i < GRPC_MAX_WORKAROUND_ID; i++) { args[i].key = workarounds_arg[i]; args[i].type = GRPC_ARG_INTEGER; args[i].value.integer = 1; } - grpc_channel_args *server_args_new = + grpc_channel_args* server_args_new = grpc_channel_args_copy_and_add(server_args, args, GRPC_MAX_WORKAROUND_ID); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args_new, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args_new, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); - grpc_channel_args_destroy(&exec_ctx, server_args_new); - grpc_exec_ctx_finish(&exec_ctx); + grpc_channel_args_destroy(server_args_new); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER | - FEATURE_MASK_SUPPORTS_WORKAROUNDS, + {"chttp2/fullstack", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER | + FEATURE_MASK_SUPPORTS_WORKAROUNDS, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_full.c b/test/core/end2end/fixtures/h2_full.cc index ae68bd9698..6d15c28662 100644 --- a/test/core/end2end/fixtures/h2_full.c +++ b/test/core/end2end/fixtures/h2_full.cc @@ -36,60 +36,66 @@ #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_http_proxy.c b/test/core/end2end/fixtures/h2_http_proxy.cc index 6145892365..e8e81f0930 100644 --- a/test/core/end2end/fixtures/h2_http_proxy.c +++ b/test/core/end2end/fixtures/h2_http_proxy.cc @@ -31,7 +31,7 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/fixtures/http_proxy_fixture.h" @@ -39,15 +39,16 @@ #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *server_addr; - grpc_end2end_http_proxy *proxy; + char* server_addr; + grpc_end2end_http_proxy* proxy; } fullstack_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); const int server_port = grpc_pick_unused_port_or_die(); gpr_join_host_port(&ffd->server_addr, "localhost", server_port); @@ -56,21 +57,22 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( ffd->proxy = grpc_end2end_http_proxy_create(client_args); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - char *proxy_uri; +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + char* proxy_uri; /* If testing for proxy auth, add credentials to proxy uri */ - const grpc_arg *proxy_auth_arg = + const grpc_arg* proxy_auth_arg = grpc_channel_args_find(client_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS); - if (proxy_auth_arg == NULL || proxy_auth_arg->type != GRPC_ARG_STRING) { + if (proxy_auth_arg == nullptr || proxy_auth_arg->type != GRPC_ARG_STRING) { gpr_asprintf(&proxy_uri, "http://%s", grpc_end2end_http_proxy_get_proxy_name(ffd->proxy)); } else { @@ -79,24 +81,27 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, } gpr_setenv("http_proxy", proxy_uri); gpr_free(proxy_uri); - f->client = grpc_insecure_channel_create(ffd->server_addr, client_args, NULL); + f->client = + grpc_insecure_channel_create(ffd->server_addr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->server_addr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->server_addr); grpc_end2end_http_proxy_destroy(ffd->proxy); gpr_free(ffd); @@ -104,14 +109,15 @@ void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_load_reporting.c b/test/core/end2end/fixtures/h2_load_reporting.cc index 8a05bb722a..fda5f4b052 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.c +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -38,54 +38,57 @@ #include "test/core/util/test_config.h" typedef struct load_reporting_fixture_data { - char *localaddr; + char* localaddr; } load_reporting_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_load_reporting( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - load_reporting_fixture_data *ffd = - gpr_malloc(sizeof(load_reporting_fixture_data)); + load_reporting_fixture_data* ffd = static_cast<load_reporting_fixture_data*>( + gpr_malloc(sizeof(load_reporting_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_load_reporting(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - load_reporting_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_load_reporting(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + load_reporting_fixture_data* ffd = + static_cast<load_reporting_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_load_reporting(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - load_reporting_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_load_reporting(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + load_reporting_fixture_data* ffd = + static_cast<load_reporting_fixture_data*>(f->fixture_data); grpc_arg arg = grpc_load_reporting_enable_arg(); if (f->server) { grpc_server_destroy(f->server); } server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); - f->server = grpc_server_create(server_args, NULL); + f->server = grpc_server_create(server_args, nullptr); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, server_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(server_args); } - grpc_server_register_completion_queue(f->server, f->cq, NULL); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_load_reporting(grpc_end2end_test_fixture *f) { - load_reporting_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_load_reporting(grpc_end2end_test_fixture* f) { + load_reporting_fixture_data* ffd = + static_cast<load_reporting_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } @@ -100,7 +103,7 @@ static grpc_end2end_test_config configs[] = { chttp2_init_server_load_reporting, chttp2_tear_down_load_reporting}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.cc index ee1d0b1416..5fed4434de 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.cc @@ -32,16 +32,16 @@ #include "test/core/util/test_config.h" static const char oauth2_md[] = "Bearer aaslkfjs424535asdf"; -static const char *client_identity_property_name = "smurf_name"; -static const char *client_identity = "Brainy Smurf"; +static const char* client_identity_property_name = "smurf_name"; +static const char* client_identity = "Brainy Smurf"; typedef struct fullstack_secure_fixture_data { - char *localaddr; + char* localaddr; } fullstack_secure_fixture_data; -static const grpc_metadata *find_metadata(const grpc_metadata *md, - size_t md_count, const char *key, - const char *value) { +static const grpc_metadata* find_metadata(const grpc_metadata* md, + size_t md_count, const char* key, + const char* value) { size_t i; for (i = 0; i < md_count; i++) { if (grpc_slice_str_cmp(md[i].key, key) == 0 && @@ -49,116 +49,123 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md, return &md[i]; } } - return NULL; + return nullptr; } -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, +static void process_oauth2_success(void* state, grpc_auth_context* ctx, + const grpc_metadata* md, size_t md_count, grpc_process_auth_metadata_done_cb cb, - void *user_data) { - const grpc_metadata *oauth2 = + void* user_data) { + const grpc_metadata* oauth2 = find_metadata(md, md_count, "authorization", oauth2_md); - test_processor_state *s; + test_processor_state* s; - GPR_ASSERT(state != NULL); - s = (test_processor_state *)state; + GPR_ASSERT(state != nullptr); + s = (test_processor_state*)state; GPR_ASSERT(s->pseudo_refcount == 1); - GPR_ASSERT(oauth2 != NULL); + GPR_ASSERT(oauth2 != nullptr); grpc_auth_context_add_cstring_property(ctx, client_identity_property_name, client_identity); GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name( ctx, client_identity_property_name) == 1); - cb(user_data, oauth2, 1, NULL, 0, GRPC_STATUS_OK, NULL); + cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_OK, nullptr); } -static void process_oauth2_failure(void *state, grpc_auth_context *ctx, - const grpc_metadata *md, size_t md_count, +static void process_oauth2_failure(void* state, grpc_auth_context* ctx, + const grpc_metadata* md, size_t md_count, grpc_process_auth_metadata_done_cb cb, - void *user_data) { - const grpc_metadata *oauth2 = + void* user_data) { + const grpc_metadata* oauth2 = find_metadata(md, md_count, "authorization", oauth2_md); - test_processor_state *s; - GPR_ASSERT(state != NULL); - s = (test_processor_state *)state; + test_processor_state* s; + GPR_ASSERT(state != nullptr); + s = (test_processor_state*)state; GPR_ASSERT(s->pseudo_refcount == 1); - GPR_ASSERT(oauth2 != NULL); - cb(user_data, oauth2, 1, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); + GPR_ASSERT(oauth2 != nullptr); + cb(user_data, oauth2, 1, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr); } static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_secure_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_secure_fixture_data)); + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>( + gpr_malloc(sizeof(fullstack_secure_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } static void chttp2_init_client_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - grpc_channel_credentials *creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* client_args, + grpc_channel_credentials* creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); f->client = - grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); - GPR_ASSERT(f->client != NULL); + grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr); + GPR_ASSERT(f->client != nullptr); grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args, - grpc_server_credentials *server_creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* server_args, + grpc_server_credentials* server_creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(f->server); } -void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { - fullstack_secure_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_credentials *ssl_creds = - grpc_ssl_credentials_create(test_root_cert, NULL, NULL); - grpc_call_credentials *oauth2_creds = grpc_md_only_test_credentials_create( - &exec_ctx, "authorization", oauth2_md, true /* is_async */); - grpc_channel_credentials *ssl_oauth2_creds = - grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, NULL); - grpc_arg ssl_name_override = {GRPC_ARG_STRING, - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, - {"foo.test.google.fr"}}; - grpc_channel_args *new_client_args = + grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { + grpc_core::ExecCtx exec_ctx; + grpc_channel_credentials* ssl_creds = + grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr); + grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create( + "authorization", oauth2_md, true /* is_async */); + grpc_channel_credentials* ssl_oauth2_creds = + grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, + nullptr); + grpc_arg ssl_name_override = { + GRPC_ARG_STRING, + const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), + {const_cast<char*>("foo.test.google.fr")}}; + grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds); - grpc_channel_args_destroy(&exec_ctx, new_client_args); + grpc_channel_args_destroy(new_client_args); grpc_channel_credentials_release(ssl_creds); grpc_call_credentials_release(oauth2_creds); - grpc_exec_ctx_finish(&exec_ctx); } -static int fail_server_auth_check(grpc_channel_args *server_args) { +static int fail_server_auth_check(grpc_channel_args* server_args) { size_t i; - if (server_args == NULL) return 0; + if (server_args == nullptr) return 0; for (i = 0; i < server_args->num_args; i++) { if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) { @@ -168,14 +175,15 @@ static int fail_server_auth_check(grpc_channel_args *server_args) { return 0; } -static void processor_destroy(void *state) { - test_processor_state *s = (test_processor_state *)state; +static void processor_destroy(void* state) { + test_processor_state* s = (test_processor_state*)state; GPR_ASSERT((s->pseudo_refcount--) == 1); gpr_free(s); } static grpc_auth_metadata_processor test_processor_create(int failing) { - test_processor_state *s = gpr_malloc(sizeof(*s)); + test_processor_state* s = + static_cast<test_processor_state*>(gpr_malloc(sizeof(*s))); grpc_auth_metadata_processor result; s->pseudo_refcount = 1; result.state = s; @@ -189,11 +197,11 @@ static grpc_auth_metadata_processor test_processor_create(int failing) { } static void chttp2_init_server_simple_ssl_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { + grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key, test_server1_cert}; - grpc_server_credentials *ssl_creds = - grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0, NULL); + grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( + nullptr, &pem_key_cert_pair, 1, 0, nullptr); grpc_server_credentials_set_auth_metadata_processor( ssl_creds, test_processor_create(fail_server_auth_check(server_args))); chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); @@ -213,7 +221,7 @@ static grpc_end2end_test_config configs[] = { chttp2_tear_down_secure_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); diff --git a/test/core/end2end/fixtures/h2_proxy.c b/test/core/end2end/fixtures/h2_proxy.cc index 069130baf4..295654cb6a 100644 --- a/test/core/end2end/fixtures/h2_proxy.c +++ b/test/core/end2end/fixtures/h2_proxy.cc @@ -37,77 +37,82 @@ #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - grpc_end2end_proxy *proxy; + grpc_end2end_proxy* proxy; } fullstack_fixture_data; -static grpc_server *create_proxy_server(const char *port, - grpc_channel_args *server_args) { - grpc_server *s = grpc_server_create(server_args, NULL); +static grpc_server* create_proxy_server(const char* port, + grpc_channel_args* server_args) { + grpc_server* s = grpc_server_create(server_args, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(s, port)); return s; } -static grpc_channel *create_proxy_client(const char *target, - grpc_channel_args *client_args) { - return grpc_insecure_channel_create(target, client_args, NULL); +static grpc_channel* create_proxy_client(const char* target, + grpc_channel_args* client_args) { + return grpc_insecure_channel_create(target, client_args, nullptr); } static const grpc_end2end_proxy_def proxy_def = {create_proxy_server, create_proxy_client}; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); f->client = grpc_insecure_channel_create( - grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, NULL); + grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, nullptr); GPR_ASSERT(f->client); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port( f->server, grpc_end2end_proxy_get_server_port(ffd->proxy))); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); grpc_end2end_proxy_destroy(ffd->proxy); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack+proxy", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_REQUEST_PROXYING | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack+proxy", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_REQUEST_PROXYING | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 39ccb84b52..236780b8d3 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.c +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -36,9 +36,9 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/iomgr/iomgr.h" -#include "src/core/lib/support/env.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/server.h" @@ -48,78 +48,72 @@ /* chttp2 transport that is immediately available (used for testing connected_channel without a client_channel */ -static void server_setup_transport(void *ts, grpc_transport *transport) { - grpc_end2end_test_fixture *f = ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, NULL, +static void server_setup_transport(void* ts, grpc_transport* transport) { + grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { - grpc_end2end_test_fixture *f; - grpc_channel_args *client_args; + grpc_end2end_test_fixture* f; + grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, - grpc_transport *transport) { - sp_client_setup *cs = ts; +static void client_setup_transport(void* ts, grpc_transport* transport) { + sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( - grpc_channel_args *client_args, grpc_channel_args *server_args) { - grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); + grpc_channel_args* client_args, grpc_channel_args* server_args) { + grpc_endpoint_pair* sfd = + static_cast<grpc_endpoint_pair*>(gpr_malloc(sizeof(grpc_endpoint_pair))); grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); f.fixture_data = sfd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); - *sfd = grpc_iomgr_create_endpoint_pair("fixture", NULL); + *sfd = grpc_iomgr_create_endpoint_pair("fixture", nullptr); return f; } -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; +static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_transport *transport; +static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; GPR_ASSERT(!f->server); - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { +static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { gpr_free(f->fixture_data); } @@ -130,9 +124,8 @@ static grpc_end2end_test_config configs[] = { chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, }; -int main(int argc, char **argv) { +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 */ @@ -146,7 +139,6 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); grpc_init(); - grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); diff --git a/test/core/end2end/fixtures/h2_sockpair.c b/test/core/end2end/fixtures/h2_sockpair.cc index 03566ead9b..b68279fd71 100644 --- a/test/core/end2end/fixtures/h2_sockpair.c +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -42,78 +42,72 @@ /* chttp2 transport that is immediately available (used for testing connected_channel without a client_channel */ -static void server_setup_transport(void *ts, grpc_transport *transport) { - grpc_end2end_test_fixture *f = ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, NULL, +static void server_setup_transport(void* ts, grpc_transport* transport) { + grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { - grpc_end2end_test_fixture *f; - grpc_channel_args *client_args; + grpc_end2end_test_fixture* f; + grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, - grpc_transport *transport) { - sp_client_setup *cs = ts; +static void client_setup_transport(void* ts, grpc_transport* transport) { + sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( - grpc_channel_args *client_args, grpc_channel_args *server_args) { - grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); + grpc_channel_args* client_args, grpc_channel_args* server_args) { + grpc_endpoint_pair* sfd = + static_cast<grpc_endpoint_pair*>(gpr_malloc(sizeof(grpc_endpoint_pair))); grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); f.fixture_data = sfd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); - *sfd = grpc_iomgr_create_endpoint_pair("fixture", NULL); + *sfd = grpc_iomgr_create_endpoint_pair("fixture", nullptr); return f; } -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; +static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_transport *transport; +static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; GPR_ASSERT(!f->server); - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { +static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { gpr_free(f->fixture_data); } @@ -124,7 +118,7 @@ static grpc_end2end_test_config configs[] = { chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.c b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index c75a3876d5..350be138ca 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.c +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -42,88 +42,83 @@ /* chttp2 transport that is immediately available (used for testing connected_channel without a client_channel */ -static void server_setup_transport(void *ts, grpc_transport *transport) { - grpc_end2end_test_fixture *f = ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_endpoint_add_to_pollset(&exec_ctx, sfd->server, grpc_cq_pollset(f->cq)); - grpc_server_setup_transport(&exec_ctx, f->server, transport, NULL, +static void server_setup_transport(void* ts, grpc_transport* transport) { + grpc_end2end_test_fixture* f = static_cast<grpc_end2end_test_fixture*>(ts); + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq)); + grpc_server_setup_transport(f->server, transport, nullptr, grpc_server_get_channel_args(f->server)); - grpc_exec_ctx_finish(&exec_ctx); } typedef struct { - grpc_end2end_test_fixture *f; - grpc_channel_args *client_args; + grpc_end2end_test_fixture* f; + grpc_channel_args* client_args; } sp_client_setup; -static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, - grpc_transport *transport) { - sp_client_setup *cs = ts; +static void client_setup_transport(void* ts, grpc_transport* transport) { + sp_client_setup* cs = static_cast<sp_client_setup*>(ts); - cs->f->client = - grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, - GRPC_CLIENT_DIRECT_CHANNEL, transport); + cs->f->client = grpc_channel_create("socketpair-target", cs->client_args, + GRPC_CLIENT_DIRECT_CHANNEL, transport); } static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( - grpc_channel_args *client_args, grpc_channel_args *server_args) { - grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); + grpc_channel_args* client_args, grpc_channel_args* server_args) { + grpc_endpoint_pair* sfd = + static_cast<grpc_endpoint_pair*>(gpr_malloc(sizeof(grpc_endpoint_pair))); grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); f.fixture_data = sfd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); - - grpc_arg a[] = {{.key = GRPC_ARG_TCP_READ_CHUNK_SIZE, - .type = GRPC_ARG_INTEGER, - .value.integer = 1}, - {.key = GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE, - .type = GRPC_ARG_INTEGER, - .value.integer = 1}, - {.key = GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE, - .type = GRPC_ARG_INTEGER, - .value.integer = 1}}; - grpc_channel_args args = {.num_args = GPR_ARRAY_SIZE(a), .args = a}; + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); + + grpc_arg a[3]; + a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE); + a[0].type = GRPC_ARG_INTEGER; + a[0].value.integer = 1; + a[1].key = const_cast<char*>(GRPC_ARG_TCP_MIN_READ_CHUNK_SIZE); + a[1].type = GRPC_ARG_INTEGER; + a[1].value.integer = 1; + a[2].key = const_cast<char*>(GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE); + a[2].type = GRPC_ARG_INTEGER; + a[2].value.integer = 1; + grpc_channel_args args = {GPR_ARRAY_SIZE(a), a}; *sfd = grpc_iomgr_create_endpoint_pair("fixture", &args); return f; } -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; +static void chttp2_init_client_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; sp_client_setup cs; cs.client_args = client_args; cs.f = f; - transport = - grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1); - client_setup_transport(&exec_ctx, &cs, transport); + transport = grpc_create_chttp2_transport(client_args, sfd->client, true); + client_setup_transport(&cs, transport); GPR_ASSERT(f->client); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_endpoint_pair *sfd = f->fixture_data; - grpc_transport *transport; +static void chttp2_init_server_socketpair(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + grpc_core::ExecCtx exec_ctx; + grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data); + grpc_transport* transport; GPR_ASSERT(!f->server); - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); - transport = - grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0); + transport = grpc_create_chttp2_transport(server_args, sfd->server, false); server_setup_transport(f, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_transport_start_reading(transport, nullptr, nullptr); } -static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { +static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture* f) { gpr_free(f->fixture_data); } @@ -135,7 +130,7 @@ static grpc_end2end_test_config configs[] = { chttp2_tear_down_socketpair}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; g_fixture_slowdown_factor = 2; diff --git a/test/core/end2end/fixtures/h2_ssl.c b/test/core/end2end/fixtures/h2_ssl.cc index 0bac464e69..8c5c8a2f3f 100644 --- a/test/core/end2end/fixtures/h2_ssl.c +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -26,94 +26,98 @@ #include <grpc/support/log.h> #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { - char *localaddr; + char* localaddr; } fullstack_secure_fixture_data; static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; int port = grpc_pick_unused_port_or_die(); - fullstack_secure_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_secure_fixture_data)); + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>( + gpr_malloc(sizeof(fullstack_secure_fixture_data))); memset(&f, 0, sizeof(f)); gpr_join_host_port(&ffd->localaddr, "localhost", port); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -static void process_auth_failure(void *state, grpc_auth_context *ctx, - const grpc_metadata *md, size_t md_count, +static void process_auth_failure(void* state, grpc_auth_context* ctx, + const grpc_metadata* md, size_t md_count, grpc_process_auth_metadata_done_cb cb, - void *user_data) { - GPR_ASSERT(state == NULL); - cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); + void* user_data) { + GPR_ASSERT(state == nullptr); + cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr); } static void chttp2_init_client_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - grpc_channel_credentials *creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* client_args, + grpc_channel_credentials* creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); f->client = - grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); - GPR_ASSERT(f->client != NULL); + grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr); + GPR_ASSERT(f->client != nullptr); grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args, - grpc_server_credentials *server_creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* server_args, + grpc_server_credentials* server_creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(f->server); } -void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { - fullstack_secure_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } static void chttp2_init_client_simple_ssl_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_channel_credentials *ssl_creds = - grpc_ssl_credentials_create(NULL, NULL, NULL); - grpc_arg ssl_name_override = {GRPC_ARG_STRING, - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, - {"foo.test.google.fr"}}; - grpc_channel_args *new_client_args = + grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { + grpc_channel_credentials* ssl_creds = + grpc_ssl_credentials_create(nullptr, nullptr, nullptr); + grpc_arg ssl_name_override = { + GRPC_ARG_STRING, + const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), + {const_cast<char*>("foo.test.google.fr")}}; + grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } -static int fail_server_auth_check(grpc_channel_args *server_args) { +static int fail_server_auth_check(grpc_channel_args* server_args) { size_t i; - if (server_args == NULL) return 0; + if (server_args == nullptr) return 0; for (i = 0; i < server_args->num_args; i++) { if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) { @@ -124,13 +128,14 @@ static int fail_server_auth_check(grpc_channel_args *server_args) { } static void chttp2_init_server_simple_ssl_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { + grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert}; - grpc_server_credentials *ssl_creds = - grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL); + grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( + nullptr, &pem_cert_key_pair, 1, 0, nullptr); if (fail_server_auth_check(server_args)) { - grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL}; + grpc_auth_metadata_processor processor = {process_auth_failure, nullptr, + nullptr}; grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor); } chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); @@ -150,19 +155,19 @@ static grpc_end2end_test_config configs[] = { chttp2_tear_down_secure_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; - FILE *roots_file; + FILE* roots_file; size_t roots_size = strlen(test_root_cert); - char *roots_filename; + char* roots_filename; grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); /* Set the SSL roots env var. */ roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename); - GPR_ASSERT(roots_filename != NULL); - GPR_ASSERT(roots_file != NULL); + GPR_ASSERT(roots_filename != nullptr); + GPR_ASSERT(roots_file != nullptr); GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size); fclose(roots_file); gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename); diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/fixtures/h2_ssl_cert.c deleted file mode 100644 index 9b1ddadfe4..0000000000 --- a/test/core/end2end/fixtures/h2_ssl_cert.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/end2end/end2end_tests.h" - -#include <stdio.h> -#include <string.h> - -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> - -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" -#include "test/core/end2end/cq_verifier.h" -#include "test/core/end2end/data/ssl_test_data.h" -#include "test/core/util/port.h" -#include "test/core/util/test_config.h" - -extern void simple_request(grpc_end2end_test_config config); - -typedef struct fullstack_secure_fixture_data { - char *localaddr; -} fullstack_secure_fixture_data; - -static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { - grpc_end2end_test_fixture f; - int port = grpc_pick_unused_port_or_die(); - fullstack_secure_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_secure_fixture_data)); - memset(&f, 0, sizeof(f)); - - gpr_join_host_port(&ffd->localaddr, "localhost", port); - - f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); - - return f; -} - -static void process_auth_failure(void *state, grpc_auth_context *ctx, - const grpc_metadata *md, size_t md_count, - grpc_process_auth_metadata_done_cb cb, - void *user_data) { - GPR_ASSERT(state == NULL); - cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); -} - -static void chttp2_init_client_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - grpc_channel_credentials *creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; - f->client = - grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); - GPR_ASSERT(f->client != NULL); - grpc_channel_credentials_release(creds); -} - -static void chttp2_init_server_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args, - grpc_server_credentials *server_creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; - if (f->server) { - grpc_server_destroy(f->server); - } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); - GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, - server_creds)); - grpc_server_credentials_release(server_creds); - grpc_server_start(f->server); -} - -void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { - fullstack_secure_fixture_data *ffd = f->fixture_data; - gpr_free(ffd->localaddr); - gpr_free(ffd); -} - -static int fail_server_auth_check(grpc_channel_args *server_args) { - size_t i; - if (server_args == NULL) return 0; - for (i = 0; i < server_args->num_args; i++) { - if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == - 0) { - return 1; - } - } - return 0; -} - -#define SERVER_INIT_NAME(REQUEST_TYPE) \ - chttp2_init_server_simple_ssl_secure_fullstack_##REQUEST_TYPE - -#define SERVER_INIT(REQUEST_TYPE) \ - static void SERVER_INIT_NAME(REQUEST_TYPE)( \ - grpc_end2end_test_fixture * f, grpc_channel_args * server_args) { \ - grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, \ - test_server1_cert}; \ - grpc_server_credentials *ssl_creds = \ - grpc_ssl_server_credentials_create_ex( \ - test_root_cert, &pem_cert_key_pair, 1, REQUEST_TYPE, NULL); \ - if (fail_server_auth_check(server_args)) { \ - grpc_auth_metadata_processor processor = {process_auth_failure, NULL, \ - NULL}; \ - grpc_server_credentials_set_auth_metadata_processor(ssl_creds, \ - processor); \ - } \ - chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); \ - } - -SERVER_INIT(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE) -SERVER_INIT(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY) -SERVER_INIT(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY) -SERVER_INIT(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY) -SERVER_INIT(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY) - -#define CLIENT_INIT_NAME(cert_type) \ - chttp2_init_client_simple_ssl_secure_fullstack_##cert_type - -typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype; - -#define CLIENT_INIT(cert_type) \ - static void CLIENT_INIT_NAME(cert_type)(grpc_end2end_test_fixture * f, \ - grpc_channel_args * client_args) { \ - grpc_channel_credentials *ssl_creds = NULL; \ - grpc_ssl_pem_key_cert_pair self_signed_client_key_cert_pair = { \ - test_self_signed_client_key, test_self_signed_client_cert}; \ - grpc_ssl_pem_key_cert_pair signed_client_key_cert_pair = { \ - test_signed_client_key, test_signed_client_cert}; \ - grpc_ssl_pem_key_cert_pair bad_client_key_cert_pair = { \ - test_self_signed_client_key, test_signed_client_cert}; \ - grpc_ssl_pem_key_cert_pair *key_cert_pair = NULL; \ - switch (cert_type) { \ - case SELF_SIGNED: \ - key_cert_pair = &self_signed_client_key_cert_pair; \ - break; \ - case SIGNED: \ - key_cert_pair = &signed_client_key_cert_pair; \ - break; \ - case BAD_CERT_PAIR: \ - key_cert_pair = &bad_client_key_cert_pair; \ - break; \ - default: \ - break; \ - } \ - ssl_creds = \ - grpc_ssl_credentials_create(test_root_cert, key_cert_pair, NULL); \ - grpc_arg ssl_name_override = {GRPC_ARG_STRING, \ - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, \ - {"foo.test.google.fr"}}; \ - grpc_channel_args *new_client_args = \ - grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \ - chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \ - { \ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; \ - grpc_channel_args_destroy(&exec_ctx, new_client_args); \ - grpc_exec_ctx_finish(&exec_ctx); \ - } \ - } - -CLIENT_INIT(NONE) -CLIENT_INIT(SELF_SIGNED) -CLIENT_INIT(SIGNED) -CLIENT_INIT(BAD_CERT_PAIR) - -#define TEST_NAME(enum_name, cert_type, result) \ - "chttp2/ssl_" #enum_name "_" #cert_type "_" #result "_" - -typedef enum { SUCCESS, FAIL } test_result; - -#define SSL_TEST(request_type, cert_type, result) \ - { \ - {TEST_NAME(request_type, cert_type, result), \ - FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | \ - FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS | \ - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL, \ - chttp2_create_fixture_secure_fullstack, CLIENT_INIT_NAME(cert_type), \ - SERVER_INIT_NAME(request_type), chttp2_tear_down_secure_fullstack}, \ - result \ - } - -/* All test configurations */ -typedef struct grpc_end2end_test_config_wrapper { - grpc_end2end_test_config config; - test_result result; -} grpc_end2end_test_config_wrapper; - -static grpc_end2end_test_config_wrapper configs[] = { - SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NONE, SUCCESS), - SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, SELF_SIGNED, SUCCESS), - SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, SIGNED, SUCCESS), - SSL_TEST(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, BAD_CERT_PAIR, FAIL), - - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, NONE, - SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, SELF_SIGNED, - SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, SIGNED, - SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, BAD_CERT_PAIR, - FAIL), - - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY, NONE, SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY, SELF_SIGNED, FAIL), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY, SIGNED, SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY, BAD_CERT_PAIR, - FAIL), - - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, - NONE, FAIL), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, - SELF_SIGNED, SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, - SIGNED, SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, - BAD_CERT_PAIR, FAIL), - - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY, NONE, - FAIL), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY, - SELF_SIGNED, FAIL), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY, SIGNED, - SUCCESS), - SSL_TEST(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY, - BAD_CERT_PAIR, FAIL), -}; - -static void *tag(intptr_t t) { return (void *)t; } - -static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, - const char *test_name, - grpc_channel_args *client_args, - grpc_channel_args *server_args) { - grpc_end2end_test_fixture f; - gpr_log(GPR_INFO, "%s/%s", test_name, config.name); - f = config.create_fixture(client_args, server_args); - config.init_server(&f, server_args); - config.init_client(&f, client_args); - return f; -} - -static gpr_timespec n_seconds_time(int n) { - return grpc_timeout_seconds_to_deadline(n); -} - -static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } - -static void drain_cq(grpc_completion_queue *cq) { - grpc_event ev; - do { - ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL); - } while (ev.type != GRPC_QUEUE_SHUTDOWN); -} - -static void shutdown_server(grpc_end2end_test_fixture *f) { - if (!f->server) return; - grpc_server_shutdown_and_notify(f->server, f->shutdown_cq, tag(1000)); - GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000), - grpc_timeout_seconds_to_deadline(5), - NULL) - .type == GRPC_OP_COMPLETE); - grpc_server_destroy(f->server); - f->server = NULL; -} - -static void shutdown_client(grpc_end2end_test_fixture *f) { - if (!f->client) return; - grpc_channel_destroy(f->client); - f->client = NULL; -} - -static void end_test(grpc_end2end_test_fixture *f) { - shutdown_server(f); - shutdown_client(f); - - grpc_completion_queue_shutdown(f->cq); - drain_cq(f->cq); - grpc_completion_queue_destroy(f->cq); - grpc_completion_queue_destroy(f->shutdown_cq); -} - -static void simple_request_body(grpc_end2end_test_fixture f, - test_result expected_result) { - grpc_call *c; - gpr_timespec deadline = five_seconds_time(); - cq_verifier *cqv = cq_verifier_create(f.cq); - grpc_op ops[6]; - grpc_op *op; - grpc_call_error error; - - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); - c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); - GPR_ASSERT(c); - - memset(ops, 0, sizeof(ops)); - op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = NULL; - op++; - error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); - GPR_ASSERT(GRPC_CALL_OK == error); - - CQ_EXPECT_COMPLETION(cqv, tag(1), expected_result == SUCCESS); - cq_verify(cqv); - - grpc_call_unref(c); - cq_verifier_destroy(cqv); -} - -int main(int argc, char **argv) { - size_t i; - FILE *roots_file; - size_t roots_size = strlen(test_root_cert); - char *roots_filename; - - grpc_test_init(argc, argv); - grpc_end2end_tests_pre_init(); - - /* Set the SSL roots env var. */ - roots_file = - gpr_tmpfile("chttp2_simple_ssl_cert_fullstack_test", &roots_filename); - GPR_ASSERT(roots_filename != NULL); - GPR_ASSERT(roots_file != NULL); - GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size); - fclose(roots_file); - gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename); - - grpc_init(); - - for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { - grpc_end2end_test_fixture f = - begin_test(configs[i].config, "SSL_CERT_tests", NULL, NULL); - - simple_request_body(f, configs[i].result); - end_test(&f); - configs[i].config.tear_down_data(&f); - } - - grpc_shutdown(); - - /* Cleanup. */ - remove(roots_filename); - gpr_free(roots_filename); - - return 0; -} diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.c b/test/core/end2end/fixtures/h2_ssl_proxy.cc index 8bc7183510..3f0646cf0f 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.c +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -26,48 +26,48 @@ #include <grpc/support/log.h> #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/end2end/fixtures/proxy.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { - grpc_end2end_proxy *proxy; + grpc_end2end_proxy* proxy; } fullstack_secure_fixture_data; -static grpc_server *create_proxy_server(const char *port, - grpc_channel_args *server_args) { - grpc_server *s = grpc_server_create(server_args, NULL); +static grpc_server* create_proxy_server(const char* port, + grpc_channel_args* server_args) { + grpc_server* s = grpc_server_create(server_args, nullptr); grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert}; - grpc_server_credentials *ssl_creds = - grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL); + grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( + nullptr, &pem_cert_key_pair, 1, 0, nullptr); GPR_ASSERT(grpc_server_add_secure_http2_port(s, port, ssl_creds)); grpc_server_credentials_release(ssl_creds); return s; } -static grpc_channel *create_proxy_client(const char *target, - grpc_channel_args *client_args) { - grpc_channel *channel; - grpc_channel_credentials *ssl_creds = - grpc_ssl_credentials_create(NULL, NULL, NULL); - grpc_arg ssl_name_override = {GRPC_ARG_STRING, - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, - {"foo.test.google.fr"}}; - grpc_channel_args *new_client_args = +static grpc_channel* create_proxy_client(const char* target, + grpc_channel_args* client_args) { + grpc_channel* channel; + grpc_channel_credentials* ssl_creds = + grpc_ssl_credentials_create(nullptr, nullptr, nullptr); + grpc_arg ssl_name_override = { + GRPC_ARG_STRING, + const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), + {const_cast<char*>("foo.test.google.fr")}}; + grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); channel = - grpc_secure_channel_create(ssl_creds, target, new_client_args, NULL); + grpc_secure_channel_create(ssl_creds, target, new_client_args, nullptr); grpc_channel_credentials_release(ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } return channel; } @@ -76,81 +76,85 @@ static const grpc_end2end_proxy_def proxy_def = {create_proxy_server, create_proxy_client}; static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; - fullstack_secure_fixture_data *ffd = - gpr_malloc(sizeof(fullstack_secure_fixture_data)); + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>( + gpr_malloc(sizeof(fullstack_secure_fixture_data))); memset(&f, 0, sizeof(f)); ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -static void process_auth_failure(void *state, grpc_auth_context *ctx, - const grpc_metadata *md, size_t md_count, +static void process_auth_failure(void* state, grpc_auth_context* ctx, + const grpc_metadata* md, size_t md_count, grpc_process_auth_metadata_done_cb cb, - void *user_data) { - GPR_ASSERT(state == NULL); - cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); + void* user_data) { + GPR_ASSERT(state == nullptr); + cb(user_data, nullptr, 0, nullptr, 0, GRPC_STATUS_UNAUTHENTICATED, nullptr); } static void chttp2_init_client_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - grpc_channel_credentials *creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* client_args, + grpc_channel_credentials* creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); f->client = grpc_secure_channel_create( creds, grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, - NULL); - GPR_ASSERT(f->client != NULL); + nullptr); + GPR_ASSERT(f->client != nullptr); grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args, - grpc_server_credentials *server_creds) { - fullstack_secure_fixture_data *ffd = f->fixture_data; + grpc_end2end_test_fixture* f, grpc_channel_args* server_args, + grpc_server_credentials* server_creds) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_secure_http2_port( f->server, grpc_end2end_proxy_get_server_port(ffd->proxy), server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(f->server); } -void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { - fullstack_secure_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) { + fullstack_secure_fixture_data* ffd = + static_cast<fullstack_secure_fixture_data*>(f->fixture_data); grpc_end2end_proxy_destroy(ffd->proxy); gpr_free(ffd); } static void chttp2_init_client_simple_ssl_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_channel_credentials *ssl_creds = - grpc_ssl_credentials_create(NULL, NULL, NULL); - grpc_arg ssl_name_override = {GRPC_ARG_STRING, - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, - {"foo.test.google.fr"}}; - grpc_channel_args *new_client_args = + grpc_end2end_test_fixture* f, grpc_channel_args* client_args) { + grpc_channel_credentials* ssl_creds = + grpc_ssl_credentials_create(nullptr, nullptr, nullptr); + grpc_arg ssl_name_override = { + GRPC_ARG_STRING, + const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), + {const_cast<char*>("foo.test.google.fr")}}; + grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args_destroy(&exec_ctx, new_client_args); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_channel_args_destroy(new_client_args); } } -static int fail_server_auth_check(grpc_channel_args *server_args) { +static int fail_server_auth_check(grpc_channel_args* server_args) { size_t i; - if (server_args == NULL) return 0; + if (server_args == nullptr) return 0; for (i = 0; i < server_args->num_args; i++) { if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == 0) { @@ -161,13 +165,14 @@ static int fail_server_auth_check(grpc_channel_args *server_args) { } static void chttp2_init_server_simple_ssl_secure_fullstack( - grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { + grpc_end2end_test_fixture* f, grpc_channel_args* server_args) { grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, test_server1_cert}; - grpc_server_credentials *ssl_creds = - grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL); + grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( + nullptr, &pem_cert_key_pair, 1, 0, nullptr); if (fail_server_auth_check(server_args)) { - grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL}; + grpc_auth_metadata_processor processor = {process_auth_failure, nullptr, + nullptr}; grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor); } chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); @@ -188,19 +193,19 @@ static grpc_end2end_test_config configs[] = { chttp2_tear_down_secure_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; - FILE *roots_file; + FILE* roots_file; size_t roots_size = strlen(test_root_cert); - char *roots_filename; + char* roots_filename; grpc_test_init(argc, argv); grpc_end2end_tests_pre_init(); /* Set the SSL roots env var. */ roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename); - GPR_ASSERT(roots_filename != NULL); - GPR_ASSERT(roots_file != NULL); + GPR_ASSERT(roots_filename != nullptr); + GPR_ASSERT(roots_file != nullptr); GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size); fclose(roots_file); gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename); diff --git a/test/core/end2end/fixtures/h2_uds.c b/test/core/end2end/fixtures/h2_uds.cc index 05a31985e7..1944dd84a3 100644 --- a/test/core/end2end/fixtures/h2_uds.c +++ b/test/core/end2end/fixtures/h2_uds.cc @@ -33,68 +33,74 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" typedef struct fullstack_fixture_data { - char *localaddr; + char* localaddr; } fullstack_fixture_data; static int unique = 1; static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; - fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); + fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( + gpr_malloc(sizeof(fullstack_fixture_data))); memset(&f, 0, sizeof(f)); gpr_asprintf(&ffd->localaddr, "unix:/tmp/grpc_fullstack_test.%d.%d", getpid(), unique++); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - fullstack_fixture_data *ffd = f->fixture_data; - f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); +void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); + f->client = + grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); } -void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } -void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { - fullstack_fixture_data *ffd = f->fixture_data; +void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { + fullstack_fixture_data* ffd = + static_cast<fullstack_fixture_data*>(f->fixture_data); gpr_free(ffd->localaddr); gpr_free(ffd); } /* All test configurations */ static grpc_end2end_test_config configs[] = { - {"chttp2/fullstack_uds", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | - FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | - FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, + {"chttp2/fullstack_uds", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | + FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | + FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.cc index a4cfc77bcb..8ec97df3e4 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -34,6 +34,7 @@ #include <grpc/support/useful.h> #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/http/parser.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/combiner.h" @@ -49,7 +50,6 @@ #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/slice/b64.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/support/string.h" #include "test/core/util/port.h" struct grpc_end2end_http_proxy { @@ -68,6 +68,9 @@ struct grpc_end2end_http_proxy { // Connection handling // +// proxy_connection structure is only accessed in the closures which are all +// scheduled under the same combiner lock. So there is is no need for a mutex to +// protect this structure. typedef struct proxy_connection { grpc_end2end_http_proxy* proxy; @@ -78,6 +81,8 @@ typedef struct proxy_connection { grpc_pollset_set* pollset_set; + // NOTE: All the closures execute under proxy->combiner lock. Which means + // there will not be any data-races between the closures grpc_closure on_read_request_done; grpc_closure on_server_connect_done; grpc_closure on_write_response_done; @@ -86,11 +91,20 @@ typedef struct proxy_connection { grpc_closure on_server_read_done; grpc_closure on_server_write_done; + bool client_read_failed : 1; + bool client_write_failed : 1; + bool client_shutdown : 1; + bool server_read_failed : 1; + bool server_write_failed : 1; + bool server_shutdown : 1; + grpc_slice_buffer client_read_buffer; grpc_slice_buffer client_deferred_write_buffer; + bool client_is_writing; grpc_slice_buffer client_write_buffer; grpc_slice_buffer server_read_buffer; grpc_slice_buffer server_deferred_write_buffer; + bool server_is_writing; grpc_slice_buffer server_write_buffer; grpc_http_parser http_parser; @@ -102,24 +116,21 @@ static void proxy_connection_ref(proxy_connection* conn, const char* reason) { } // Helper function to destroy the proxy connection. -static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, const char* reason) { +static void proxy_connection_unref(proxy_connection* conn, const char* reason) { if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); - grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); - if (conn->server_endpoint != NULL) { - grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); + grpc_endpoint_destroy(conn->client_endpoint); + if (conn->server_endpoint != nullptr) { + grpc_endpoint_destroy(conn->server_endpoint); } - grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->client_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_read_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, - &conn->server_deferred_write_buffer); - grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); + grpc_pollset_set_destroy(conn->pollset_set); + grpc_slice_buffer_destroy_internal(&conn->client_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->client_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_read_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_deferred_write_buffer); + grpc_slice_buffer_destroy_internal(&conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); gpr_unref(&conn->proxy->users); @@ -127,30 +138,59 @@ static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, } } +enum failure_type { + SETUP_FAILED, // To be used before we start proxying. + CLIENT_READ_FAILED, + CLIENT_WRITE_FAILED, + SERVER_READ_FAILED, + SERVER_WRITE_FAILED, +}; + // Helper function to shut down the proxy connection. -// Does NOT take ownership of a reference to error. -static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, - proxy_connection* conn, bool is_client, - const char* prefix, grpc_error* error) { - const char* msg = grpc_error_string(error); - gpr_log(GPR_INFO, "%s: %s", prefix, msg); - - grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint, - GRPC_ERROR_REF(error)); - if (conn->server_endpoint != NULL) { - grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, - GRPC_ERROR_REF(error)); +static void proxy_connection_failed(proxy_connection* conn, + failure_type failure, const char* prefix, + grpc_error* error) { + gpr_log(GPR_INFO, "%s: %s", prefix, grpc_error_string(error)); + // Decide whether we should shut down the client and server. + bool shutdown_client = false; + bool shutdown_server = false; + if (failure == SETUP_FAILED) { + shutdown_client = true; + shutdown_server = true; + } else { + if ((failure == CLIENT_READ_FAILED && conn->client_write_failed) || + (failure == CLIENT_WRITE_FAILED && conn->client_read_failed) || + (failure == SERVER_READ_FAILED && !conn->client_is_writing)) { + shutdown_client = true; + } + if ((failure == SERVER_READ_FAILED && conn->server_write_failed) || + (failure == SERVER_WRITE_FAILED && conn->server_read_failed) || + (failure == CLIENT_READ_FAILED && !conn->server_is_writing)) { + shutdown_server = true; + } + } + // If we decided to shut down either one and have not yet done so, do so. + if (shutdown_client && !conn->client_shutdown) { + grpc_endpoint_shutdown(conn->client_endpoint, GRPC_ERROR_REF(error)); + conn->client_shutdown = true; } - proxy_connection_unref(exec_ctx, conn, "conn_failed"); + if (shutdown_server && !conn->server_shutdown && + (conn->server_endpoint != nullptr)) { + grpc_endpoint_shutdown(conn->server_endpoint, GRPC_ERROR_REF(error)); + conn->server_shutdown = true; + } + // Unref the connection. + proxy_connection_unref(conn, "conn_failed"); + GRPC_ERROR_UNREF(error); } // Callback for writing proxy data to the client. -static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; + conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy client write", error); + proxy_connection_failed(conn, CLIENT_WRITE_FAILED, + "HTTP proxy client write", GRPC_ERROR_REF(error)); return; } // Clear write buffer (the data we just wrote). @@ -160,22 +200,22 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, if (conn->client_deferred_write_buffer.length > 0) { grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer, &conn->client_write_buffer); - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + conn->client_is_writing = true; + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "write_done"); + proxy_connection_unref(conn, "write_done"); } } // Callback for writing proxy data to the backend server. -static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_write_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; + conn->server_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, false /* is_client */, - "HTTP proxy server write", error); + proxy_connection_failed(conn, SERVER_WRITE_FAILED, + "HTTP proxy server write", GRPC_ERROR_REF(error)); return; } // Clear write buffer (the data we just wrote). @@ -185,23 +225,22 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, if (conn->server_deferred_write_buffer.length > 0) { grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer, &conn->server_write_buffer); - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + conn->server_is_writing = true; + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn, "server_write"); + proxy_connection_unref(conn, "server_write"); } } // Callback for reading data from the client, which will be proxied to // the backend server. -static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_client_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy client read", error); + proxy_connection_failed(conn, CLIENT_READ_FAILED, "HTTP proxy client read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., server_write_buffer is @@ -210,30 +249,29 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, // the current write is finished. // // Otherwise, move the read data into the write buffer and write it. - if (conn->server_write_buffer.length > 0) { + if (conn->server_is_writing) { grpc_slice_buffer_move_into(&conn->client_read_buffer, &conn->server_deferred_write_buffer); } else { grpc_slice_buffer_move_into(&conn->client_read_buffer, &conn->server_write_buffer); proxy_connection_ref(conn, "client_read"); - grpc_endpoint_write(exec_ctx, conn->server_endpoint, - &conn->server_write_buffer, + conn->server_is_writing = true; + grpc_endpoint_write(conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); } // Callback for reading data from the backend server, which will be // proxied to the client. -static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_read_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, false /* is_client */, - "HTTP proxy server read", error); + proxy_connection_failed(conn, SERVER_READ_FAILED, "HTTP proxy server read", + GRPC_ERROR_REF(error)); return; } // If there is already a pending write (i.e., client_write_buffer is @@ -242,29 +280,29 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, // the current write is finished. // // Otherwise, move the read data into the write buffer and write it. - if (conn->client_write_buffer.length > 0) { + if (conn->client_is_writing) { grpc_slice_buffer_move_into(&conn->server_read_buffer, &conn->client_deferred_write_buffer); } else { grpc_slice_buffer_move_into(&conn->server_read_buffer, &conn->client_write_buffer); proxy_connection_ref(conn, "server_read"); - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + conn->client_is_writing = true; + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); } // Read more data. - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to write the HTTP response for the CONNECT request. -static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_write_response_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; + conn->client_is_writing = false; if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy write response", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy write response", + GRPC_ERROR_REF(error)); return; } // Clear write buffer. @@ -274,17 +312,16 @@ static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, // for the other one. proxy_connection_ref(conn, "client_read"); proxy_connection_ref(conn, "server_read"); - proxy_connection_unref(exec_ctx, conn, "write_response"); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + proxy_connection_unref(conn, "write_response"); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); - grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, + grpc_endpoint_read(conn->server_endpoint, &conn->server_read_buffer, &conn->on_server_read_done); } // Callback to connect to the backend server specified by the HTTP // CONNECT request. -static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_server_connect_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; if (error != GRPC_ERROR_NONE) { // TODO(roth): Technically, in this case, we should handle the error @@ -292,8 +329,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, // connection failed. However, for the purposes of this test code, // it's fine to pretend this is a client-side error, which will // cause the client connection to be dropped. - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy server connect", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy server connect", + GRPC_ERROR_REF(error)); return; } // We've established a connection, so send back a 200 response code to @@ -302,8 +339,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice slice = grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n"); grpc_slice_buffer_add(&conn->client_write_buffer, slice); - grpc_endpoint_write(exec_ctx, conn->client_endpoint, - &conn->client_write_buffer, + conn->client_is_writing = true; + grpc_endpoint_write(conn->client_endpoint, &conn->client_write_buffer, &conn->on_write_response_done); } @@ -312,20 +349,18 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, * Basic <base64_encoded_expected_cred> * Returns true if it matches, false otherwise */ -static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, - char* proxy_auth_header_val, +static bool proxy_auth_header_matches(char* proxy_auth_header_val, char* expected_cred) { - GPR_ASSERT(proxy_auth_header_val != NULL); - GPR_ASSERT(expected_cred != NULL); + GPR_ASSERT(proxy_auth_header_val != nullptr); + GPR_ASSERT(expected_cred != nullptr); if (strncmp(proxy_auth_header_val, "Basic ", 6) != 0) { return false; } proxy_auth_header_val += 6; - grpc_slice decoded_slice = - grpc_base64_decode(exec_ctx, proxy_auth_header_val, 0); + grpc_slice decoded_slice = grpc_base64_decode(proxy_auth_header_val, 0); const bool header_matches = grpc_slice_str_cmp(decoded_slice, expected_cred) == 0; - grpc_slice_unref_internal(exec_ctx, decoded_slice); + grpc_slice_unref_internal(decoded_slice); return header_matches; } @@ -335,24 +370,23 @@ static bool proxy_auth_header_matches(grpc_exec_ctx* exec_ctx, // the client indicating that the request failed. However, for the purposes // of this test code, it's fine to pretend this is a client-side error, // which will cause the client connection to be dropped. -static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void on_read_request_done(void* arg, grpc_error* error) { proxy_connection* conn = (proxy_connection*)arg; gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy read request", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); return; } // Read request and feed it to the parser. for (size_t i = 0; i < conn->client_read_buffer.count; ++i) { if (GRPC_SLICE_LENGTH(conn->client_read_buffer.slices[i]) > 0) { - error = grpc_http_parser_parse(&conn->http_parser, - conn->client_read_buffer.slices[i], NULL); + error = grpc_http_parser_parse( + &conn->http_parser, conn->client_read_buffer.slices[i], nullptr); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy request parse", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy request parse", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } @@ -361,8 +395,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_slice_buffer_reset_and_unref(&conn->client_read_buffer); // If we're not done reading the request, read more data. if (conn->http_parser.state != GRPC_HTTP_BODY) { - grpc_endpoint_read(exec_ctx, conn->client_endpoint, - &conn->client_read_buffer, &conn->on_read_request_done); + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, + &conn->on_read_request_done); return; } // Make sure we got a CONNECT request. @@ -372,56 +406,55 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, conn->http_request.method); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy read request", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } // If proxy auth is being used, check if the header is present and as expected const grpc_arg* proxy_auth_arg = grpc_channel_args_find( conn->proxy->channel_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS); - if (proxy_auth_arg != NULL && proxy_auth_arg->type == GRPC_ARG_STRING) { + if (proxy_auth_arg != nullptr && proxy_auth_arg->type == GRPC_ARG_STRING) { bool client_authenticated = false; for (size_t i = 0; i < conn->http_request.hdr_count; i++) { if (strcmp(conn->http_request.hdrs[i].key, "Proxy-Authorization") == 0) { client_authenticated = proxy_auth_header_matches( - exec_ctx, conn->http_request.hdrs[i].value, - proxy_auth_arg->value.string); + conn->http_request.hdrs[i].value, proxy_auth_arg->value.string); break; } } if (!client_authenticated) { const char* msg = "HTTP Connect could not verify authentication"; error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(msg); - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy read request", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy read request", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } } // Resolve address. - grpc_resolved_addresses* resolved_addresses = NULL; + grpc_resolved_addresses* resolved_addresses = nullptr; error = grpc_blocking_resolve_address(conn->http_request.path, "80", &resolved_addresses); if (error != GRPC_ERROR_NONE) { - proxy_connection_failed(exec_ctx, conn, true /* is_client */, - "HTTP proxy DNS lookup", error); + proxy_connection_failed(conn, SETUP_FAILED, "HTTP proxy DNS lookup", + GRPC_ERROR_REF(error)); GRPC_ERROR_UNREF(error); return; } GPR_ASSERT(resolved_addresses->naddrs >= 1); // Connect to requested address. // The connection callback inherits our reference to conn. - const gpr_timespec deadline = gpr_time_add( - gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(10, GPR_TIMESPAN)); - grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done, - &conn->server_endpoint, conn->pollset_set, NULL, + const grpc_millis deadline = + grpc_core::ExecCtx::Get()->Now() + 10 * GPR_MS_PER_SEC; + grpc_tcp_client_connect(&conn->on_server_connect_done, &conn->server_endpoint, + conn->pollset_set, nullptr, &resolved_addresses->addrs[0], deadline); grpc_resolved_addresses_destroy(resolved_addresses); } -static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, - grpc_endpoint* endpoint, grpc_pollset* accepting_pollset, +static void on_accept(void* arg, grpc_endpoint* endpoint, + grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { gpr_free(acceptor); grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; @@ -432,8 +465,8 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); - grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); + grpc_pollset_set_add_pollset(conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(endpoint, conn->pollset_set); GRPC_CLOSURE_INIT(&conn->on_read_request_done, on_read_request_done, conn, grpc_combiner_scheduler(conn->proxy->combiner)); GRPC_CLOSURE_INIT(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -450,13 +483,15 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_combiner_scheduler(conn->proxy->combiner)); grpc_slice_buffer_init(&conn->client_read_buffer); grpc_slice_buffer_init(&conn->client_deferred_write_buffer); + conn->client_is_writing = false; grpc_slice_buffer_init(&conn->client_write_buffer); grpc_slice_buffer_init(&conn->server_read_buffer); grpc_slice_buffer_init(&conn->server_deferred_write_buffer); + conn->server_is_writing = false; grpc_slice_buffer_init(&conn->server_write_buffer); grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST, &conn->http_request); - grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, + grpc_endpoint_read(conn->client_endpoint, &conn->client_read_buffer, &conn->on_read_request_done); } @@ -466,26 +501,23 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)arg; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; do { gpr_ref(&proxy->users); - const gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - const gpr_timespec deadline = - gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN)); - grpc_pollset_worker* worker = NULL; + grpc_pollset_worker* worker = nullptr; gpr_mu_lock(proxy->mu); GRPC_LOG_IF_ERROR( "grpc_pollset_work", - grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, now, deadline)); + grpc_pollset_work(proxy->pollset, &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC)); gpr_mu_unlock(proxy->mu); - grpc_exec_ctx_flush(&exec_ctx); + grpc_core::ExecCtx::Get()->Flush(); } while (!gpr_unref(&proxy->users)); - grpc_exec_ctx_finish(&exec_ctx); } grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( grpc_channel_args* args) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; grpc_end2end_http_proxy* proxy = (grpc_end2end_http_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); @@ -497,8 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name); // Create TCP server. proxy->channel_args = grpc_channel_args_copy(args); - grpc_error* error = grpc_tcp_server_create( - &exec_ctx, NULL, proxy->channel_args, &proxy->server); + grpc_error* error = + grpc_tcp_server_create(nullptr, proxy->channel_args, &proxy->server); GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; @@ -513,37 +545,35 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start server. proxy->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(proxy->pollset, &proxy->mu); - grpc_tcp_server_start(&exec_ctx, proxy->server, &proxy->pollset, 1, on_accept, - proxy); - grpc_exec_ctx_finish(&exec_ctx); + grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy); + // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); + GPR_ASSERT( + gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); return proxy; } -static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void destroy_pollset(void* arg, grpc_error* error) { grpc_pollset* pollset = (grpc_pollset*)arg; - grpc_pollset_destroy(exec_ctx, pollset); + grpc_pollset_destroy(pollset); gpr_free(pollset); } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { gpr_unref(&proxy->users); // Signal proxy thread to shutdown. - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_core::ExecCtx exec_ctx; gpr_thd_join(proxy->thd); - grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); - grpc_tcp_server_unref(&exec_ctx, proxy->server); + grpc_tcp_server_shutdown_listeners(proxy->server); + grpc_tcp_server_unref(proxy->server); gpr_free(proxy->proxy_name); - grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); - grpc_pollset_shutdown(&exec_ctx, proxy->pollset, + grpc_channel_args_destroy(proxy->channel_args); + grpc_pollset_shutdown(proxy->pollset, GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset, grpc_schedule_on_exec_ctx)); - GRPC_COMBINER_UNREF(&exec_ctx, proxy->combiner, "test"); + GRPC_COMBINER_UNREF(proxy->combiner, "test"); gpr_free(proxy); - grpc_exec_ctx_finish(&exec_ctx); } const char* grpc_end2end_http_proxy_get_proxy_name( diff --git a/test/core/end2end/fixtures/inproc.c b/test/core/end2end/fixtures/inproc.cc index 6f742f0293..b748fbf09a 100644 --- a/test/core/end2end/fixtures/inproc.c +++ b/test/core/end2end/fixtures/inproc.cc @@ -40,36 +40,37 @@ typedef struct inproc_fixture_data { } inproc_fixture_data; static grpc_end2end_test_fixture inproc_create_fixture( - grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_channel_args* client_args, grpc_channel_args* server_args) { grpc_end2end_test_fixture f; - inproc_fixture_data *ffd = gpr_malloc(sizeof(inproc_fixture_data)); + inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>( + gpr_malloc(sizeof(inproc_fixture_data))); memset(&f, 0, sizeof(f)); f.fixture_data = ffd; - f.cq = grpc_completion_queue_create_for_next(NULL); - f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + f.cq = grpc_completion_queue_create_for_next(nullptr); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); return f; } -void inproc_init_client(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args) { - f->client = grpc_inproc_channel_create(f->server, client_args, NULL); +void inproc_init_client(grpc_end2end_test_fixture* f, + grpc_channel_args* client_args) { + f->client = grpc_inproc_channel_create(f->server, client_args, nullptr); GPR_ASSERT(f->client); } -void inproc_init_server(grpc_end2end_test_fixture *f, - grpc_channel_args *server_args) { +void inproc_init_server(grpc_end2end_test_fixture* f, + grpc_channel_args* server_args) { if (f->server) { grpc_server_destroy(f->server); } - f->server = grpc_server_create(server_args, NULL); - grpc_server_register_completion_queue(f->server, f->cq, NULL); + f->server = grpc_server_create(server_args, nullptr); + grpc_server_register_completion_queue(f->server, f->cq, nullptr); grpc_server_start(f->server); } -void inproc_tear_down(grpc_end2end_test_fixture *f) { - inproc_fixture_data *ffd = f->fixture_data; +void inproc_tear_down(grpc_end2end_test_fixture* f) { + inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(f->fixture_data); gpr_free(ffd); } @@ -79,7 +80,7 @@ static grpc_end2end_test_config configs[] = { inproc_init_client, inproc_init_server, inproc_tear_down}, }; -int main(int argc, char **argv) { +int main(int argc, char** argv) { size_t i; grpc_test_init(argc, argv); diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.cc index 9ad862728f..b1698c804c 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.cc @@ -31,37 +31,37 @@ struct grpc_end2end_proxy { gpr_thd_id thd; - char *proxy_port; - char *server_port; - grpc_completion_queue *cq; - grpc_server *server; - grpc_channel *client; + char* proxy_port; + char* server_port; + grpc_completion_queue* cq; + grpc_server* server; + grpc_channel* client; int shutdown; /* requested call */ - grpc_call *new_call; + grpc_call* new_call; grpc_call_details new_call_details; grpc_metadata_array new_call_metadata; }; typedef struct { - void (*func)(void *arg, int success); - void *arg; + void (*func)(void* arg, int success); + void* arg; } closure; typedef struct { gpr_refcount refs; - grpc_end2end_proxy *proxy; + grpc_end2end_proxy* proxy; - grpc_call *c2p; - grpc_call *p2s; + grpc_call* c2p; + grpc_call* p2s; grpc_metadata_array c2p_initial_metadata; grpc_metadata_array p2s_initial_metadata; - grpc_byte_buffer *c2p_msg; - grpc_byte_buffer *p2s_msg; + grpc_byte_buffer* c2p_msg; + grpc_byte_buffer* p2s_msg; grpc_metadata_array p2s_trailing_metadata; grpc_status_code p2s_status; @@ -70,17 +70,17 @@ typedef struct { int c2p_server_cancelled; } proxy_call; -static void thread_main(void *arg); -static void request_call(grpc_end2end_proxy *proxy); +static void thread_main(void* arg); +static void request_call(grpc_end2end_proxy* proxy); -grpc_end2end_proxy *grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, - grpc_channel_args *client_args, - grpc_channel_args *server_args) { +grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, + grpc_channel_args* client_args, + grpc_channel_args* server_args) { gpr_thd_options opt = gpr_thd_options_default(); int proxy_port = grpc_pick_unused_port_or_die(); int server_port = grpc_pick_unused_port_or_die(); - grpc_end2end_proxy *proxy = (grpc_end2end_proxy *)gpr_malloc(sizeof(*proxy)); + grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port); @@ -89,36 +89,37 @@ grpc_end2end_proxy *grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port, proxy->server_port); - proxy->cq = grpc_completion_queue_create_for_next(NULL); + proxy->cq = grpc_completion_queue_create_for_next(nullptr); proxy->server = def->create_server(proxy->proxy_port, server_args); proxy->client = def->create_client(proxy->server_port, client_args); - grpc_server_register_completion_queue(proxy->server, proxy->cq, NULL); + grpc_server_register_completion_queue(proxy->server, proxy->cq, nullptr); grpc_server_start(proxy->server); grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); + GPR_ASSERT( + gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, &opt)); request_call(proxy); return proxy; } -static closure *new_closure(void (*func)(void *arg, int success), void *arg) { - closure *cl = (closure *)gpr_malloc(sizeof(*cl)); +static closure* new_closure(void (*func)(void* arg, int success), void* arg) { + closure* cl = (closure*)gpr_malloc(sizeof(*cl)); cl->func = func; cl->arg = arg; return cl; } -static void shutdown_complete(void *arg, int success) { - grpc_end2end_proxy *proxy = (grpc_end2end_proxy *)arg; +static void shutdown_complete(void* arg, int success) { + grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; proxy->shutdown = 1; grpc_completion_queue_shutdown(proxy->cq); } -void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) { +void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) { grpc_server_shutdown_and_notify(proxy->server, proxy->cq, new_closure(shutdown_complete, proxy)); gpr_thd_join(proxy->thd); @@ -131,7 +132,7 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) { gpr_free(proxy); } -static void unrefpc(proxy_call *pc, const char *reason) { +static void unrefpc(proxy_call* pc, const char* reason) { if (gpr_unref(&pc->refs)) { grpc_call_unref(pc->c2p); grpc_call_unref(pc->p2s); @@ -143,15 +144,15 @@ static void unrefpc(proxy_call *pc, const char *reason) { } } -static void refpc(proxy_call *pc, const char *reason) { 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 = (proxy_call *)arg; +static void on_c2p_sent_initial_metadata(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; unrefpc(pc, "on_c2p_sent_initial_metadata"); } -static void on_p2s_recv_initial_metadata(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_recv_initial_metadata(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; @@ -159,27 +160,28 @@ static void on_p2s_recv_initial_metadata(void *arg, int success) { if (!pc->proxy->shutdown) { op.op = GRPC_OP_SEND_INITIAL_METADATA; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.send_initial_metadata.count = pc->p2s_initial_metadata.count; op.data.send_initial_metadata.metadata = pc->p2s_initial_metadata.metadata; refpc(pc, "on_c2p_sent_initial_metadata"); - err = grpc_call_start_batch( - pc->c2p, &op, 1, new_closure(on_c2p_sent_initial_metadata, pc), NULL); + err = grpc_call_start_batch(pc->c2p, &op, 1, + new_closure(on_c2p_sent_initial_metadata, pc), + nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } unrefpc(pc, "on_p2s_recv_initial_metadata"); } -static void on_p2s_sent_initial_metadata(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_sent_initial_metadata(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; unrefpc(pc, "on_p2s_sent_initial_metadata"); } -static void on_c2p_recv_msg(void *arg, int success); +static void on_c2p_recv_msg(void* arg, int success); -static void on_p2s_sent_message(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_sent_message(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; @@ -187,55 +189,59 @@ static void on_p2s_sent_message(void *arg, int success) { if (!pc->proxy->shutdown && success) { op.op = GRPC_OP_RECV_MESSAGE; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.recv_message.recv_message = &pc->c2p_msg; refpc(pc, "on_c2p_recv_msg"); err = grpc_call_start_batch(pc->c2p, &op, 1, - new_closure(on_c2p_recv_msg, pc), NULL); + new_closure(on_c2p_recv_msg, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } unrefpc(pc, "on_p2s_sent_message"); } -static void on_p2s_sent_close(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_sent_close(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; unrefpc(pc, "on_p2s_sent_close"); } -static void on_c2p_recv_msg(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_c2p_recv_msg(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; if (!pc->proxy->shutdown && success) { - if (pc->c2p_msg != NULL) { + if (pc->c2p_msg != nullptr) { op.op = GRPC_OP_SEND_MESSAGE; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.send_message.send_message = pc->c2p_msg; refpc(pc, "on_p2s_sent_message"); - err = grpc_call_start_batch(pc->p2s, &op, 1, - new_closure(on_p2s_sent_message, pc), NULL); + err = grpc_call_start_batch( + pc->p2s, &op, 1, new_closure(on_p2s_sent_message, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } else { op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; refpc(pc, "on_p2s_sent_close"); err = grpc_call_start_batch(pc->p2s, &op, 1, - new_closure(on_p2s_sent_close, pc), NULL); + new_closure(on_p2s_sent_close, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } + } else { + if (pc->c2p_msg != nullptr) { + grpc_byte_buffer_destroy(pc->c2p_msg); + } } unrefpc(pc, "on_c2p_recv_msg"); } -static void on_p2s_recv_msg(void *arg, int success); +static void on_p2s_recv_msg(void* arg, int success); -static void on_c2p_sent_message(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_c2p_sent_message(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; @@ -243,30 +249,30 @@ static void on_c2p_sent_message(void *arg, int success) { if (!pc->proxy->shutdown && success) { op.op = GRPC_OP_RECV_MESSAGE; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.recv_message.recv_message = &pc->p2s_msg; refpc(pc, "on_p2s_recv_msg"); err = grpc_call_start_batch(pc->p2s, &op, 1, - new_closure(on_p2s_recv_msg, pc), NULL); + new_closure(on_p2s_recv_msg, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } unrefpc(pc, "on_c2p_sent_message"); } -static void on_p2s_recv_msg(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_recv_msg(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; if (!pc->proxy->shutdown && success && pc->p2s_msg) { op.op = GRPC_OP_SEND_MESSAGE; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.send_message.send_message = pc->p2s_msg; refpc(pc, "on_c2p_sent_message"); err = grpc_call_start_batch(pc->c2p, &op, 1, - new_closure(on_c2p_sent_message, pc), NULL); + new_closure(on_c2p_sent_message, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } else { grpc_byte_buffer_destroy(pc->p2s_msg); @@ -274,13 +280,13 @@ static void on_p2s_recv_msg(void *arg, int success) { unrefpc(pc, "on_p2s_recv_msg"); } -static void on_c2p_sent_status(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_c2p_sent_status(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; unrefpc(pc, "on_c2p_sent_status"); } -static void on_p2s_status(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_p2s_status(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; grpc_op op; grpc_call_error err; @@ -288,7 +294,7 @@ static void on_p2s_status(void *arg, int success) { GPR_ASSERT(success); op.op = GRPC_OP_SEND_STATUS_FROM_SERVER; op.flags = 0; - op.reserved = NULL; + op.reserved = nullptr; op.data.send_status_from_server.trailing_metadata_count = pc->p2s_trailing_metadata.count; op.data.send_status_from_server.trailing_metadata = @@ -297,26 +303,26 @@ static void on_p2s_status(void *arg, int success) { op.data.send_status_from_server.status_details = &pc->p2s_status_details; refpc(pc, "on_c2p_sent_status"); err = grpc_call_start_batch(pc->c2p, &op, 1, - new_closure(on_c2p_sent_status, pc), NULL); + new_closure(on_c2p_sent_status, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); } unrefpc(pc, "on_p2s_status"); } -static void on_c2p_closed(void *arg, int success) { - proxy_call *pc = (proxy_call *)arg; +static void on_c2p_closed(void* arg, int success) { + proxy_call* pc = (proxy_call*)arg; unrefpc(pc, "on_c2p_closed"); } -static void on_new_call(void *arg, int success) { - grpc_end2end_proxy *proxy = (grpc_end2end_proxy *)arg; +static void on_new_call(void* arg, int success) { + grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; grpc_call_error err; if (success) { grpc_op op; memset(&op, 0, sizeof(op)); - proxy_call *pc = (proxy_call *)gpr_malloc(sizeof(*pc)); + proxy_call* pc = (proxy_call*)gpr_malloc(sizeof(*pc)); memset(pc, 0, sizeof(*pc)); pc->proxy = proxy; GPR_SWAP(grpc_metadata_array, pc->c2p_initial_metadata, @@ -325,18 +331,19 @@ static void on_new_call(void *arg, int success) { pc->p2s = grpc_channel_create_call( proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq, proxy->new_call_details.method, &proxy->new_call_details.host, - proxy->new_call_details.deadline, NULL); + proxy->new_call_details.deadline, nullptr); gpr_ref_init(&pc->refs, 1); - op.reserved = NULL; + op.reserved = nullptr; op.op = GRPC_OP_RECV_INITIAL_METADATA; op.flags = 0; op.data.recv_initial_metadata.recv_initial_metadata = &pc->p2s_initial_metadata; refpc(pc, "on_p2s_recv_initial_metadata"); - err = grpc_call_start_batch( - pc->p2s, &op, 1, new_closure(on_p2s_recv_initial_metadata, pc), NULL); + err = grpc_call_start_batch(pc->p2s, &op, 1, + new_closure(on_p2s_recv_initial_metadata, pc), + nullptr); GPR_ASSERT(err == GRPC_CALL_OK); op.op = GRPC_OP_SEND_INITIAL_METADATA; @@ -344,8 +351,9 @@ static void on_new_call(void *arg, int success) { op.data.send_initial_metadata.count = pc->c2p_initial_metadata.count; op.data.send_initial_metadata.metadata = pc->c2p_initial_metadata.metadata; refpc(pc, "on_p2s_sent_initial_metadata"); - err = grpc_call_start_batch( - pc->p2s, &op, 1, new_closure(on_p2s_sent_initial_metadata, pc), NULL); + err = grpc_call_start_batch(pc->p2s, &op, 1, + new_closure(on_p2s_sent_initial_metadata, pc), + nullptr); GPR_ASSERT(err == GRPC_CALL_OK); op.op = GRPC_OP_RECV_MESSAGE; @@ -353,7 +361,7 @@ static void on_new_call(void *arg, int success) { op.data.recv_message.recv_message = &pc->c2p_msg; refpc(pc, "on_c2p_recv_msg"); err = grpc_call_start_batch(pc->c2p, &op, 1, - new_closure(on_c2p_recv_msg, pc), NULL); + new_closure(on_c2p_recv_msg, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); op.op = GRPC_OP_RECV_MESSAGE; @@ -361,7 +369,7 @@ static void on_new_call(void *arg, int success) { op.data.recv_message.recv_message = &pc->p2s_msg; refpc(pc, "on_p2s_recv_msg"); err = grpc_call_start_batch(pc->p2s, &op, 1, - new_closure(on_p2s_recv_msg, pc), NULL); + new_closure(on_p2s_recv_msg, pc), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; @@ -372,7 +380,7 @@ static void on_new_call(void *arg, int success) { op.data.recv_status_on_client.status_details = &pc->p2s_status_details; refpc(pc, "on_p2s_status"); err = grpc_call_start_batch(pc->p2s, &op, 1, new_closure(on_p2s_status, pc), - NULL); + nullptr); GPR_ASSERT(err == GRPC_CALL_OK); op.op = GRPC_OP_RECV_CLOSE_ON_SERVER; @@ -380,7 +388,7 @@ static void on_new_call(void *arg, int success) { op.data.recv_close_on_server.cancelled = &pc->c2p_server_cancelled; refpc(pc, "on_c2p_closed"); err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_closed, pc), - NULL); + nullptr); GPR_ASSERT(err == GRPC_CALL_OK); request_call(proxy); @@ -390,12 +398,12 @@ static void on_new_call(void *arg, int success) { unrefpc(pc, "init"); } else { - GPR_ASSERT(proxy->new_call == NULL); + GPR_ASSERT(proxy->new_call == nullptr); } } -static void request_call(grpc_end2end_proxy *proxy) { - proxy->new_call = NULL; +static void request_call(grpc_end2end_proxy* proxy) { + proxy->new_call = nullptr; GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( proxy->server, &proxy->new_call, &proxy->new_call_details, @@ -403,12 +411,12 @@ static void request_call(grpc_end2end_proxy *proxy) { proxy->cq, new_closure(on_new_call, proxy))); } -static void thread_main(void *arg) { - grpc_end2end_proxy *proxy = (grpc_end2end_proxy *)arg; - closure *cl; +static void thread_main(void* arg) { + grpc_end2end_proxy* proxy = (grpc_end2end_proxy*)arg; + closure* cl; for (;;) { grpc_event ev = grpc_completion_queue_next( - proxy->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); + proxy->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), nullptr); switch (ev.type) { case GRPC_QUEUE_TIMEOUT: gpr_log(GPR_ERROR, "Should never reach here"); @@ -416,7 +424,7 @@ static void thread_main(void *arg) { case GRPC_QUEUE_SHUTDOWN: return; case GRPC_OP_COMPLETE: - cl = (closure *)ev.tag; + cl = (closure*)ev.tag; cl->func(cl->arg, ev.success); gpr_free(cl); break; @@ -424,10 +432,10 @@ static void thread_main(void *arg) { } } -const char *grpc_end2end_proxy_get_client_target(grpc_end2end_proxy *proxy) { +const char* grpc_end2end_proxy_get_client_target(grpc_end2end_proxy* proxy) { return proxy->proxy_port; } -const char *grpc_end2end_proxy_get_server_port(grpc_end2end_proxy *proxy) { +const char* grpc_end2end_proxy_get_server_port(grpc_end2end_proxy* proxy) { return proxy->server_port; } diff --git a/test/core/end2end/fixtures/proxy.h b/test/core/end2end/fixtures/proxy.h index 89b965c903..18ad763ea7 100644 --- a/test/core/end2end/fixtures/proxy.h +++ b/test/core/end2end/fixtures/proxy.h @@ -26,18 +26,18 @@ typedef struct grpc_end2end_proxy grpc_end2end_proxy; typedef struct grpc_end2end_proxy_def { - grpc_server *(*create_server)(const char *port, - grpc_channel_args *server_args); - grpc_channel *(*create_client)(const char *target, - grpc_channel_args *client_args); + grpc_server* (*create_server)(const char* port, + grpc_channel_args* server_args); + grpc_channel* (*create_client)(const char* target, + grpc_channel_args* client_args); } grpc_end2end_proxy_def; -grpc_end2end_proxy *grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, - grpc_channel_args *client_args, - grpc_channel_args *server_args); -void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy); +grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, + grpc_channel_args* client_args, + grpc_channel_args* server_args); +void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy); -const char *grpc_end2end_proxy_get_client_target(grpc_end2end_proxy *proxy); -const char *grpc_end2end_proxy_get_server_port(grpc_end2end_proxy *proxy); +const char* grpc_end2end_proxy_get_client_target(grpc_end2end_proxy* proxy); +const char* grpc_end2end_proxy_get_server_port(grpc_end2end_proxy* proxy); #endif /* GRPC_TEST_CORE_END2END_FIXTURES_PROXY_H */ |