diff options
Diffstat (limited to 'test')
34 files changed, 373 insertions, 197 deletions
diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index d0ea79c34e..a400fb15bd 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -77,13 +77,10 @@ static void channel_func(grpc_channel_element *elem, } static void test_create_channel_stack(void) { - const grpc_channel_filter filter = { - call_func, channel_func, - - sizeof(int), call_init_func, call_destroy_func, - - sizeof(int), channel_init_func, channel_destroy_func, - }; + const grpc_channel_filter + filter = {call_func, channel_func, sizeof(int), + call_init_func, call_destroy_func, sizeof(int), + channel_init_func, channel_destroy_func, }; const grpc_channel_filter *filters = &filter; grpc_channel_stack *channel_stack; grpc_call_stack *call_stack; diff --git a/test/core/channel/metadata_buffer_test.c b/test/core/channel/metadata_buffer_test.c index d2bc30cc3c..9d7e1591f8 100644 --- a/test/core/channel/metadata_buffer_test.c +++ b/test/core/channel/metadata_buffer_test.c @@ -149,7 +149,7 @@ static void test_case(size_t key_prefix_len, size_t value_prefix_len, op.flags = i; op.data.metadata = grpc_mdelem_from_slices(mdctx, key, value); op.done_cb = do_nothing; - op.user_data = (void *)(gpr_uintptr) i; + op.user_data = (void *)(gpr_uintptr)i; grpc_metadata_buffer_queue(&buffer, &op); } diff --git a/test/core/echo/server.c b/test/core/echo/server.c index 57b083779c..6b67334248 100644 --- a/test/core/echo/server.c +++ b/test/core/echo/server.c @@ -32,6 +32,8 @@ */ #include <grpc/grpc.h> +#include <grpc/grpc_http.h> +#include <grpc/grpc_security.h> #include <signal.h> #include <stdio.h> @@ -42,10 +44,12 @@ #include "src/core/support/string.h" #include "test/core/util/test_config.h" #include <grpc/support/alloc.h> +#include <grpc/support/cmdline.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> #include <grpc/support/time.h> #include "test/core/util/port.h" +#include "test/core/end2end/data/ssl_test_data.h" static grpc_completion_queue *cq; static grpc_server *server; @@ -83,29 +87,74 @@ static void sigint_handler(int x) { got_sigint = 1; } int main(int argc, char **argv) { grpc_event *ev; - char *addr; call_state *s; + char *addr_buf = NULL; + gpr_cmdline *cl; int shutdown_started = 0; int shutdown_finished = 0; - grpc_test_init(argc, argv); + int secure = 0; + char *addr = NULL; + + char *fake_argv[1]; + +#define MAX_ARGS 4 + grpc_arg arge[MAX_ARGS]; + grpc_arg *e; + grpc_channel_args args = {0, NULL}; + + grpc_http_server_page home_page = {"/", "text/html", + "<head>\n" + "<title>Echo Server</title>\n" + "</head>\n" + "<body>\n" + "Welcome to the world of the future!\n" + "</body>\n"}; + + GPR_ASSERT(argc >= 1); + fake_argv[0] = argv[0]; + grpc_test_init(1, fake_argv); grpc_init(); srand(clock()); - - if (argc == 2) { - addr = gpr_strdup(argv[1]); - } else { - gpr_join_host_port(&addr, "::", grpc_pick_unused_port_or_die()); + memset(arge, 0, sizeof(arge)); + args.args = arge; + + cl = gpr_cmdline_create("echo server"); + gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr); + gpr_cmdline_add_flag(cl, "secure", "Run with security?", &secure); + gpr_cmdline_parse(cl, argc, argv); + gpr_cmdline_destroy(cl); + + e = &arge[args.num_args++]; + e->type = GRPC_ARG_POINTER; + e->key = GRPC_ARG_SERVE_OVER_HTTP; + e->value.pointer.p = &home_page; + + if (addr == NULL) { + gpr_join_host_port(&addr_buf, "::", grpc_pick_unused_port_or_die()); + addr = addr_buf; } gpr_log(GPR_INFO, "creating server on: %s", addr); cq = grpc_completion_queue_create(); - server = grpc_server_create(cq, NULL); - GPR_ASSERT(grpc_server_add_http2_port(server, addr)); - gpr_free(addr); + if (secure) { + 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); + server = grpc_secure_server_create(ssl_creds, cq, &args); + GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr)); + grpc_server_credentials_release(ssl_creds); + } else { + server = grpc_server_create(cq, &args); + GPR_ASSERT(grpc_server_add_http2_port(server, addr)); + } grpc_server_start(server); + gpr_free(addr_buf); + addr = addr_buf = NULL; + request_call(); signal(SIGINT, sigint_handler); diff --git a/test/core/end2end/fixtures/chttp2_fake_security.c b/test/core/end2end/fixtures/chttp2_fake_security.c index e170a55db5..38c3b22834 100644 --- a/test/core/end2end/fixtures/chttp2_fake_security.c +++ b/test/core/end2end/fixtures/chttp2_fake_security.c @@ -117,8 +117,7 @@ static grpc_end2end_test_config configs[] = { chttp2_create_fixture_secure_fullstack, chttp2_init_client_fake_secure_fullstack, chttp2_init_server_fake_secure_fullstack, - chttp2_tear_down_secure_fullstack}, -}; + chttp2_tear_down_secure_fullstack}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/fixtures/chttp2_fullstack.c b/test/core/end2end/fixtures/chttp2_fullstack.c index 86d5dd708b..82bf267ce5 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack.c +++ b/test/core/end2end/fixtures/chttp2_fullstack.c @@ -99,8 +99,7 @@ void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { static grpc_end2end_test_config configs[] = { {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, - chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, -}; + chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c index e5cdec8ea7..a70819e47e 100644 --- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c +++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c @@ -125,8 +125,7 @@ static grpc_end2end_test_config configs[] = { chttp2_create_fixture_secure_fullstack, chttp2_init_client_simple_ssl_secure_fullstack, chttp2_init_server_simple_ssl_secure_fullstack, - chttp2_tear_down_secure_fullstack}, -}; + chttp2_tear_down_secure_fullstack}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c index 8bfa465696..fb241cd460 100644 --- a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c +++ b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c @@ -99,7 +99,8 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL); + grpc_credentials *ssl_creds = + grpc_ssl_credentials_create(test_root_cert, NULL); grpc_credentials *oauth2_creds = grpc_fake_oauth2_credentials_create("Bearer aaslkfjs424535asdf", 1); grpc_credentials *ssl_oauth2_creds = @@ -132,8 +133,7 @@ static grpc_end2end_test_config configs[] = { chttp2_create_fixture_secure_fullstack, chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack, chttp2_init_server_simple_ssl_secure_fullstack, - chttp2_tear_down_secure_fullstack}, -}; + chttp2_tear_down_secure_fullstack}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/chttp2_socket_pair.c index cb5c6f7cad..b5b7cee85f 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair.c @@ -133,8 +133,7 @@ static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { static grpc_end2end_test_config configs[] = { {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair, chttp2_init_client_socketpair, chttp2_init_server_socketpair, - chttp2_tear_down_socketpair}, -}; + chttp2_tear_down_socketpair}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c index 25121683c5..2de67913d7 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c @@ -133,8 +133,7 @@ static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { static grpc_end2end_test_config configs[] = { {"chttp2/socketpair_one_byte_at_a_time", 0, chttp2_create_fixture_socketpair, chttp2_init_client_socketpair, - chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, -}; + chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, }; int main(int argc, char **argv) { size_t i; diff --git a/test/core/end2end/tests/cancel_test_helpers.h b/test/core/end2end/tests/cancel_test_helpers.h index bc6bfa9424..35c81fa792 100644 --- a/test/core/end2end/tests/cancel_test_helpers.h +++ b/test/core/end2end/tests/cancel_test_helpers.h @@ -46,7 +46,6 @@ static grpc_call_error wait_for_deadline(grpc_call *call) { static const cancellation_mode cancellation_modes[] = { {grpc_call_cancel, GRPC_STATUS_CANCELLED, NULL}, - {wait_for_deadline, GRPC_STATUS_DEADLINE_EXCEEDED, "Deadline Exceeded"}, -}; + {wait_for_deadline, GRPC_STATUS_DEADLINE_EXCEEDED, "Deadline Exceeded"}, }; #endif diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index 20f124ee9f..a177a7b2f2 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -204,7 +204,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { /* The /alpha or /beta calls started above could be invoked (but NOT both); * check this here */ /* We'll get tag 303 or 403, we want 300, 400 */ - live_call = ((int)(gpr_intptr) ev->tag) - 3; + live_call = ((int)(gpr_intptr)ev->tag) - 3; grpc_event_finish(ev); cq_expect_server_rpc_new(v_server, &s1, tag(100), diff --git a/test/core/end2end/tests/thread_stress.c b/test/core/end2end/tests/thread_stress.c index 6a3488e7dd..8fdb765951 100644 --- a/test/core/end2end/tests/thread_stress.c +++ b/test/core/end2end/tests/thread_stress.c @@ -278,11 +278,11 @@ static void run_test(grpc_end2end_test_config config, int requests_in_flight) { /* kick off threads */ for (i = 0; i < CLIENT_THREADS; i++) { gpr_event_init(&g_client_done[i]); - gpr_thd_new(&thd_id, client_thread, (void *)(gpr_intptr) i, NULL); + gpr_thd_new(&thd_id, client_thread, (void *)(gpr_intptr)i, NULL); } for (i = 0; i < SERVER_THREADS; i++) { gpr_event_init(&g_server_done[i]); - gpr_thd_new(&thd_id, server_thread, (void *)(gpr_intptr) i, NULL); + gpr_thd_new(&thd_id, server_thread, (void *)(gpr_intptr)i, NULL); } /* start requests */ diff --git a/test/core/fling/client.c b/test/core/fling/client.c index 7eb195811b..7947ffecc5 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -98,8 +98,7 @@ typedef struct { static const scenario scenarios[] = { {"ping-pong-request", init_ping_pong_request, step_ping_pong_request}, - {"ping-pong-stream", init_ping_pong_stream, step_ping_pong_stream}, -}; + {"ping-pong-stream", init_ping_pong_stream, step_ping_pong_stream}, }; int main(int argc, char **argv) { gpr_slice slice = gpr_slice_from_copied_string("x"); diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index ce9b7f4c66..a250951231 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -61,13 +61,13 @@ static void add_test(void) { /* 10 ms alarms. will expire in the current epoch */ for (i = 0; i < 10; i++) { grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(10)), - cb, (void *)(gpr_intptr) i, start); + cb, (void *)(gpr_intptr)i, start); } /* 1010 ms alarms. will expire in the next epoch */ for (i = 10; i < 20; i++) { grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(1010)), - cb, (void *)(gpr_intptr) i, start); + cb, (void *)(gpr_intptr)i, start); } /* collect alarms. Only the first batch should be ready. */ @@ -115,15 +115,15 @@ void destruction_test(void) { memset(cb_called, 0, sizeof(cb_called)); grpc_alarm_init(&alarms[0], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr) 0, gpr_time_0); + (void *)(gpr_intptr)0, gpr_time_0); grpc_alarm_init(&alarms[1], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr) 1, gpr_time_0); + (void *)(gpr_intptr)1, gpr_time_0); grpc_alarm_init(&alarms[2], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr) 2, gpr_time_0); + (void *)(gpr_intptr)2, gpr_time_0); grpc_alarm_init(&alarms[3], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr) 3, gpr_time_0); + (void *)(gpr_intptr)3, gpr_time_0); grpc_alarm_init(&alarms[4], gpr_time_from_millis(1), cb, - (void *)(gpr_intptr) 4, gpr_time_0); + (void *)(gpr_intptr)4, gpr_time_0); GPR_ASSERT(1 == grpc_alarm_check(NULL, gpr_time_from_millis(2), NULL)); GPR_ASSERT(1 == cb_called[4][1]); grpc_alarm_cancel(&alarms[0]); diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index dc5747bf57..125cde4678 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -290,7 +290,7 @@ static void shutdown_during_write_test_read_handler( if (error != GRPC_ENDPOINT_CB_OK) { grpc_endpoint_destroy(st->ep); - gpr_event_set(&st->ev, (void *)(gpr_intptr) error); + gpr_event_set(&st->ev, (void *)(gpr_intptr)error); } else { grpc_endpoint_notify_on_read( st->ep, shutdown_during_write_test_read_handler, user_data); @@ -309,7 +309,7 @@ static void shutdown_during_write_test_write_handler( gpr_log(GPR_ERROR, "shutdown_during_write_test_write_handler completed unexpectedly"); } - gpr_event_set(&st->ev, (void *)(gpr_intptr) 1); + gpr_event_set(&st->ev, (void *)(gpr_intptr)1); } static void shutdown_during_write_test(grpc_endpoint_test_config config, diff --git a/test/core/iomgr/poll_kick_test.c b/test/core/iomgr/poll_kick_posix_test.c index c30a7b9ee0..3c6d815c9d 100644 --- a/test/core/iomgr/poll_kick_test.c +++ b/test/core/iomgr/poll_kick_posix_test.c @@ -107,17 +107,23 @@ static void test_over_free(void) { } } -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - grpc_pollset_kick_global_init(); - +static void run_tests(void) { test_allocation(); test_basic_kick(); test_non_poll_kick(); test_non_kick(); test_over_free(); +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + grpc_pollset_kick_global_init(); + run_tests(); + grpc_pollset_kick_global_destroy(); + grpc_pollset_kick_global_init_fallback_fd(); + run_tests(); grpc_pollset_kick_global_destroy(); return 0; } diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c index 319ee634d6..4cc101b6b0 100644 --- a/test/core/iomgr/resolve_address_test.c +++ b/test/core/iomgr/resolve_address_test.c @@ -83,9 +83,8 @@ static void test_ipv6_with_port(void) { } static void test_ipv6_without_port(void) { - const char* const kCases[] = { - "2001:db8::1", "2001:db8::1.2.3.4", "[2001:db8::1]", - }; + const char* const kCases[] = {"2001:db8::1", "2001:db8::1.2.3.4", + "[2001:db8::1]", }; int i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; @@ -96,9 +95,7 @@ static void test_ipv6_without_port(void) { } static void test_invalid_ip_addresses(void) { - const char* const kCases[] = { - "293.283.1238.3:1", "[2001:db8::11111]:1", - }; + const char* const kCases[] = {"293.283.1238.3:1", "[2001:db8::11111]:1", }; int i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; @@ -109,9 +106,8 @@ static void test_invalid_ip_addresses(void) { } static void test_unparseable_hostports(void) { - const char* const kCases[] = { - "[", "[::1", "[::1]bad", "[1.2.3.4]", "[localhost]", "[localhost]:1", - }; + const char* const kCases[] = {"[", "[::1", "[::1]bad", + "[1.2.3.4]", "[localhost]", "[localhost]:1", }; int i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index f9212e7373..00b10f9364 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -140,7 +140,7 @@ void test_times_out(void) { /* tie up the listen buffer, which is somewhat arbitrarily sized. */ for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) { client_fd[i] = socket(AF_INET, SOCK_STREAM, 0); - grpc_set_socket_nonblocking(client_fd[i], 1); + grpc_set_socket_nonblocking(client_fd[i], 1); do { r = connect(client_fd[i], (struct sockaddr *)&addr, addr_len); } while (r == -1 && errno == EINTR); diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 182ccba3f6..24634b4700 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -484,8 +484,7 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( } static grpc_endpoint_test_config configs[] = { - {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, -}; + {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; int main(int argc, char **argv) { grpc_test_init(argc, argv); diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index 0db15d48b4..5d875025ec 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -131,8 +131,7 @@ static grpc_endpoint_test_config configs[] = { {"secure_ep/tcp_socketpair", secure_endpoint_create_fixture_tcp_socketpair_noleftover, clean_up}, {"secure_ep/tcp_socketpair_leftover", - secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up}, -}; + secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up}, }; static void verify_leftover(void *user_data, gpr_slice *slices, size_t nslices, grpc_endpoint_cb_status error) { diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 6a3c8adcc5..ca2d1dedb0 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -123,11 +123,11 @@ static void assert_log_empty(void) { /* Given log size and record size, computes the minimum usable space. */ static gpr_int32 min_usable_space(size_t log_size, size_t record_size) { gpr_int32 usable_space; - gpr_int32 num_blocks = log_size / CENSUS_LOG_MAX_RECORD_SIZE; + gpr_int32 num_blocks = GPR_MAX(log_size / CENSUS_LOG_MAX_RECORD_SIZE, + gpr_cpu_num_cores()); gpr_int32 waste_per_block = CENSUS_LOG_MAX_RECORD_SIZE % record_size; /* In the worst case, all except one core-local block is full. */ - gpr_int32 num_full_blocks = GPR_MAX(gpr_cpu_num_cores() - 2, 2); - GPR_ASSERT(num_blocks >= num_full_blocks); + gpr_int32 num_full_blocks = num_blocks - 1; usable_space = (gpr_int32)log_size - (num_full_blocks * CENSUS_LOG_MAX_RECORD_SIZE) - ((num_blocks - num_full_blocks) * waste_per_block); diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 93f9c4cc8d..540d9d1c64 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -53,12 +53,12 @@ typedef struct queue { gpr_cv non_empty; /* Signalled when length becomes non-zero. */ gpr_cv non_full; /* Signalled when length becomes non-N. */ gpr_mu mu; /* Protects all fields below. - (That is, except during initialization or - destruction, the fields below should be accessed - only by a thread that holds mu.) */ - int head; /* Index of head of queue 0..N-1. */ - int length; /* Number of valid elements in queue 0..N. */ - int elem[N]; /* elem[head .. head+length-1] are queue elements. */ + (That is, except during initialization or + destruction, the fields below should be accessed + only by a thread that holds mu.) */ + int head; /* Index of head of queue 0..N-1. */ + int length; /* Number of valid elements in queue 0..N. */ + int elem[N]; /* elem[head .. head+length-1] are queue elements. */ } queue; /* Initialize *q. */ diff --git a/test/core/surface/completion_queue_benchmark.c b/test/core/surface/completion_queue_benchmark.c index 5360d7c6c3..e1b9d0d035 100644 --- a/test/core/surface/completion_queue_benchmark.c +++ b/test/core/surface/completion_queue_benchmark.c @@ -53,23 +53,23 @@ static void producer_thread(void *arg) { test_thread_options *opt = arg; int i; - gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->start, gpr_inf_future)); for (i = 0; i < opt->iterations; i++) { grpc_cq_begin_op(opt->cc, NULL, GRPC_WRITE_ACCEPTED); - grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr) 1, NULL, NULL, - NULL, GRPC_OP_OK); + grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr)1, NULL, NULL, NULL, + GRPC_OP_OK); } - gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); } static void consumer_thread(void *arg) { test_thread_options *opt = arg; grpc_event *ev; - gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->start, gpr_inf_future)); for (;;) { @@ -78,7 +78,7 @@ static void consumer_thread(void *arg) { case GRPC_WRITE_ACCEPTED: break; case GRPC_QUEUE_SHUTDOWN: - gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); return; default: gpr_log(GPR_ERROR, "Invalid event received: %d", ev->type); @@ -112,7 +112,7 @@ double ops_per_second(int consumers, int producers, int iterations) { /* start the benchmark */ t_start = gpr_now(); - gpr_event_set(&start, (void *)(gpr_intptr) 1); + gpr_event_set(&start, (void *)(gpr_intptr)1); /* wait for producers to finish */ for (i = 0; i < producers; i++) { diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index 4bbe9cc96f..71f9cc2291 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -282,7 +282,7 @@ static void producer_thread(void *arg) { int i; gpr_log(GPR_INFO, "producer %d started", opt->id); - gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); gpr_log(GPR_INFO, "producer %d phase 1", opt->id); @@ -291,18 +291,18 @@ static void producer_thread(void *arg) { } gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id); - gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); gpr_log(GPR_INFO, "producer %d phase 2", opt->id); for (i = 0; i < TEST_THREAD_EVENTS; i++) { - grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr) 1, NULL, NULL, - NULL, GRPC_OP_OK); + grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr)1, NULL, NULL, NULL, + GRPC_OP_OK); opt->events_triggered++; } gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); - gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); } static void consumer_thread(void *arg) { @@ -310,13 +310,13 @@ static void consumer_thread(void *arg) { grpc_event *ev; gpr_log(GPR_INFO, "consumer %d started", opt->id); - gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); gpr_log(GPR_INFO, "consumer %d phase 1", opt->id); gpr_log(GPR_INFO, "consumer %d phase 1 done", opt->id); - gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr)1); GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); gpr_log(GPR_INFO, "consumer %d phase 2", opt->id); @@ -331,7 +331,7 @@ static void consumer_thread(void *arg) { break; case GRPC_QUEUE_SHUTDOWN: gpr_log(GPR_INFO, "consumer %d phase 2 done", opt->id); - gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); + gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); grpc_event_finish(ev); return; default: @@ -376,7 +376,7 @@ static void test_threading(int producers, int consumers) { /* start phase1: producers will pre-declare all operations they will complete */ gpr_log(GPR_INFO, "start phase 1"); - gpr_event_set(&phase1, (void *)(gpr_intptr) 1); + gpr_event_set(&phase1, (void *)(gpr_intptr)1); gpr_log(GPR_INFO, "wait phase 1"); for (i = 0; i < producers + consumers; i++) { @@ -386,7 +386,7 @@ static void test_threading(int producers, int consumers) { /* start phase2: operations will complete, and consumers will consume them */ gpr_log(GPR_INFO, "start phase 2"); - gpr_event_set(&phase2, (void *)(gpr_intptr) 1); + gpr_event_set(&phase2, (void *)(gpr_intptr)1); /* in parallel, we shutdown the completion channel - all events should still be consumed */ diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 12f8b35ada..3be6c366f5 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -42,7 +42,9 @@ #include "test/core/util/slice_splitter.h" #include "test/core/util/test_config.h" -typedef struct { va_list args; } test_checker; +typedef struct { + va_list args; +} test_checker; static void onhdr(void *ud, grpc_mdelem *md) { const char *ekey, *evalue; diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c index 30cd63ca67..9b4446f7f8 100644 --- a/test/core/transport/chttp2/stream_map_test.c +++ b/test/core/transport/chttp2/stream_map_test.c @@ -93,7 +93,7 @@ static void test_basic_add_find(size_t n) { grpc_chttp2_stream_map_init(&map, 8); GPR_ASSERT(0 == grpc_chttp2_stream_map_size(&map)); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr) i); + grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i); } GPR_ASSERT(n == grpc_chttp2_stream_map_size(&map)); GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 0)); @@ -148,7 +148,7 @@ static void test_delete_evens_sweep(size_t n) { grpc_chttp2_stream_map_init(&map, 8); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr) i); + grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i); } for (i = 1; i <= n; i++) { if ((i & 1) == 0) { @@ -170,7 +170,7 @@ static void test_delete_evens_incremental(size_t n) { grpc_chttp2_stream_map_init(&map, 8); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr) i); + grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i); if ((i & 1) == 0) { grpc_chttp2_stream_map_delete(&map, i); } diff --git a/test/core/transport/chttp2_transport_end2end_test.c b/test/core/transport/chttp2_transport_end2end_test.c index 8b0f9aa25b..34e3aeba38 100644 --- a/test/core/transport/chttp2_transport_end2end_test.c +++ b/test/core/transport/chttp2_transport_end2end_test.c @@ -100,8 +100,7 @@ grpc_transport_test_config fixture_configs[] = { {"chttp2_on_socketpair/medium", create_http2_transport_for_test_medium_slices}, {"chttp2_on_socketpair/large", - create_http2_transport_for_test_large_slices}, -}; + create_http2_transport_for_test_large_slices}, }; /* Driver function: run the test suite for each test configuration */ int main(int argc, char **argv) { diff --git a/test/core/transport/transport_end2end_tests.c b/test/core/transport/transport_end2end_tests.c index 8e9b4a2cc9..25276c0fca 100644 --- a/test/core/transport/transport_end2end_tests.c +++ b/test/core/transport/transport_end2end_tests.c @@ -63,7 +63,9 @@ static int g_pending_ops; typedef struct test_fixture test_fixture; /* User data passed to the transport and handed to each callback */ -typedef struct test_user_data { test_fixture *fixture; } test_user_data; +typedef struct test_user_data { + test_fixture *fixture; +} test_user_data; /* A message we expect to receive (forms a singly linked list with next) */ typedef struct expected_message { @@ -129,7 +131,7 @@ static void expect_metadata(test_stream *s, int from_client, const char *key, /* Convert some number of seconds into a gpr_timespec that many seconds in the future */ static gpr_timespec deadline_from_seconds(double deadline_seconds) { - return gpr_time_add(gpr_now(), + return gpr_time_add(gpr_now(), gpr_time_from_micros((long)(deadline_seconds * 1e6))); } @@ -589,10 +591,9 @@ static void begin_test(test_fixture *f, grpc_transport_test_config *config, f->client_transport = NULL; f->server_transport = NULL; - GPR_ASSERT(0 == - config->create_transport(setup_client_transport, f, - setup_server_transport, f, - g_metadata_context)); + GPR_ASSERT(0 == config->create_transport(setup_client_transport, f, + setup_server_transport, f, + g_metadata_context)); gpr_mu_lock(&f->mu); while (!f->client_transport || !f->server_transport) { @@ -908,9 +909,8 @@ static void test_ping(grpc_transport_test_config *config) { * Test driver */ -static const size_t interesting_message_lengths[] = { - 1, 100, 10000, 100000, 1000000, -}; +static const size_t interesting_message_lengths[] = {1, 100, 10000, + 100000, 1000000, }; void grpc_transport_end2end_tests(grpc_transport_test_config *config) { int i; diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 52008895dc..067ca0fafa 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -113,12 +113,11 @@ int grpc_pick_unused_port(void) { /* Type of port to first pick in next iteration */ int is_tcp = 1; - int try - = 0; + int try = 0; for (;;) { - int port = try - < NUM_RANDOM_PORTS_TO_PICK ? rand() % (65536 - 30000) + 30000 : 0; + int port = + try < NUM_RANDOM_PORTS_TO_PICK ? rand() % (65536 - 30000) + 30000 : 0; if (!is_port_available(&port, is_tcp)) { continue; } diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 2a18ddb72e..a0662fd05f 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -32,7 +32,9 @@ */ #include <chrono> +#include <fstream> #include <memory> +#include <sstream> #include <string> #include <thread> @@ -43,6 +45,7 @@ #include <grpc++/channel_interface.h> #include <grpc++/client_context.h> #include <grpc++/create_channel.h> +#include <grpc++/credentials.h> #include <grpc++/status.h> #include <grpc++/stream.h> #include "test/cpp/util/create_test_channel.h" @@ -51,7 +54,7 @@ #include "test/cpp/interop/messages.pb.h" DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls."); -DEFINE_bool(use_prod_roots, false, "True to use SSL roots for production GFE"); +DEFINE_bool(use_prod_roots, false, "True to use SSL roots for google"); DEFINE_int32(server_port, 0, "Server port."); DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); DEFINE_string(server_host_override, "foo.test.google.com", @@ -62,15 +65,24 @@ DEFINE_string(test_case, "large_unary", "large_unary : single request and (large) response; " "client_streaming : request streaming with single response; " "server_streaming : single request with response streaming; " - "slow_consumer : single request with response" + "slow_consumer : single request with response; " " streaming with slow client consumer; " - "half_duplex : half-duplex streaming;" - "ping_pong : full-duplex streaming;" + "half_duplex : half-duplex streaming; " + "ping_pong : full-duplex streaming; " + "service_account_creds : large_unary with service_account auth; " + "compute_engine_creds: large_unary with compute engine auth; " "all : all of above."); +DEFINE_string(default_service_account, "", + "Email of GCE default service account"); +DEFINE_string(service_account_key_file, "", + "Path to service account json key file."); +DEFINE_string(oauth_scope, "", "Scope for OAuth tokens."); using grpc::ChannelInterface; using grpc::ClientContext; using grpc::CreateTestChannel; +using grpc::Credentials; +using grpc::CredentialsFactory; using grpc::testing::ResponseParameters; using grpc::testing::SimpleRequest; using grpc::testing::SimpleResponse; @@ -91,8 +103,49 @@ const int kLargeRequestSize = 314159; const int kLargeResponseSize = 271812; } // namespace -void DoEmpty(std::shared_ptr<ChannelInterface> channel) { +grpc::string GetServiceAccountJsonKey() { + static grpc::string json_key; + if (json_key.empty()) { + std::ifstream json_key_file(FLAGS_service_account_key_file); + std::stringstream key_stream; + key_stream << json_key_file.rdbuf(); + json_key = key_stream.str(); + } + return json_key; +} + +std::shared_ptr<ChannelInterface> CreateChannelForTestCase( + const grpc::string& test_case) { + GPR_ASSERT(FLAGS_server_port); + const int host_port_buf_size = 1024; + char host_port[host_port_buf_size]; + snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), + FLAGS_server_port); + + if (test_case == "service_account_creds") { + std::unique_ptr<Credentials> creds; + GPR_ASSERT(FLAGS_enable_ssl); + grpc::string json_key = GetServiceAccountJsonKey(); + creds = CredentialsFactory::ServiceAccountCredentials( + json_key, FLAGS_oauth_scope, std::chrono::hours(1)); + return CreateTestChannel(host_port, FLAGS_server_host_override, + FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); + } else if (test_case == "compute_engine_creds") { + std::unique_ptr<Credentials> creds; + GPR_ASSERT(FLAGS_enable_ssl); + creds = CredentialsFactory::ComputeEngineCredentials(); + return CreateTestChannel(host_port, FLAGS_server_host_override, + FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); + } else { + return CreateTestChannel(host_port, FLAGS_server_host_override, + FLAGS_enable_ssl, FLAGS_use_prod_roots); + } +} + +void DoEmpty() { gpr_log(GPR_INFO, "Sending an empty rpc..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("empty_unary"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::testing::Empty request = grpc::testing::Empty::default_instance(); @@ -105,30 +158,79 @@ void DoEmpty(std::shared_ptr<ChannelInterface> channel) { gpr_log(GPR_INFO, "Empty rpc done."); } -void DoLargeUnary(std::shared_ptr<ChannelInterface> channel) { - gpr_log(GPR_INFO, "Sending a large unary rpc..."); +// Shared code to set large payload, make rpc and check response payload. +void PerformLargeUnary(std::shared_ptr<ChannelInterface> channel, + SimpleRequest* request, SimpleResponse* response) { std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); - SimpleRequest request; - SimpleResponse response; ClientContext context; - request.set_response_type(grpc::testing::PayloadType::COMPRESSABLE); - request.set_response_size(kLargeResponseSize); + request->set_response_type(grpc::testing::PayloadType::COMPRESSABLE); + request->set_response_size(kLargeResponseSize); grpc::string payload(kLargeRequestSize, '\0'); - request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); + request->mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); - grpc::Status s = stub->UnaryCall(&context, request, &response); + grpc::Status s = stub->UnaryCall(&context, *request, response); GPR_ASSERT(s.IsOk()); - GPR_ASSERT(response.payload().type() == + GPR_ASSERT(response->payload().type() == grpc::testing::PayloadType::COMPRESSABLE); - GPR_ASSERT(response.payload().body() == + GPR_ASSERT(response->payload().body() == grpc::string(kLargeResponseSize, '\0')); +} + +void DoComputeEngineCreds() { + gpr_log(GPR_INFO, + "Sending a large unary rpc with compute engine credentials ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("compute_engine_creds"); + SimpleRequest request; + SimpleResponse response; + request.set_fill_username(true); + request.set_fill_oauth_scope(true); + PerformLargeUnary(channel, &request, &response); + gpr_log(GPR_INFO, "Got username %s", response.username().c_str()); + gpr_log(GPR_INFO, "Got oauth_scope %s", response.oauth_scope().c_str()); + GPR_ASSERT(!response.username().empty()); + GPR_ASSERT(response.username() == FLAGS_default_service_account); + GPR_ASSERT(!response.oauth_scope().empty()); + GPR_ASSERT( + FLAGS_oauth_scope.find(response.oauth_scope()) != grpc::string::npos); + gpr_log(GPR_INFO, "Large unary with compute engine creds done."); +} + +void DoServiceAccountCreds() { + gpr_log(GPR_INFO, + "Sending a large unary rpc with service account credentials ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("service_account_creds"); + SimpleRequest request; + SimpleResponse response; + request.set_fill_username(true); + request.set_fill_oauth_scope(true); + PerformLargeUnary(channel, &request, &response); + GPR_ASSERT(!response.username().empty()); + GPR_ASSERT(!response.oauth_scope().empty()); + grpc::string json_key = GetServiceAccountJsonKey(); + GPR_ASSERT(json_key.find(response.username()) != grpc::string::npos); + GPR_ASSERT(FLAGS_oauth_scope.find(response.oauth_scope()) != + grpc::string::npos); + gpr_log(GPR_INFO, "Large unary with service account creds done."); +} + +void DoLargeUnary() { + gpr_log(GPR_INFO, "Sending a large unary rpc..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("large_unary"); + SimpleRequest request; + SimpleResponse response; + PerformLargeUnary(channel, &request, &response); gpr_log(GPR_INFO, "Large unary done."); } -void DoRequestStreaming(std::shared_ptr<ChannelInterface> channel) { +void DoRequestStreaming() { gpr_log(GPR_INFO, "Sending request steaming rpc ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("client_streaming"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::ClientContext context; @@ -153,8 +255,10 @@ void DoRequestStreaming(std::shared_ptr<ChannelInterface> channel) { gpr_log(GPR_INFO, "Request streaming done."); } -void DoResponseStreaming(std::shared_ptr<ChannelInterface> channel) { +void DoResponseStreaming() { gpr_log(GPR_INFO, "Receiving response steaming rpc ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("server_streaming"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::ClientContext context; @@ -180,9 +284,10 @@ void DoResponseStreaming(std::shared_ptr<ChannelInterface> channel) { gpr_log(GPR_INFO, "Response streaming done."); } -void DoResponseStreamingWithSlowConsumer( - std::shared_ptr<ChannelInterface> channel) { +void DoResponseStreamingWithSlowConsumer() { gpr_log(GPR_INFO, "Receiving response steaming rpc with slow consumer ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("slow_consumer"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::ClientContext context; @@ -212,8 +317,10 @@ void DoResponseStreamingWithSlowConsumer( gpr_log(GPR_INFO, "Response streaming done."); } -void DoHalfDuplex(std::shared_ptr<ChannelInterface> channel) { +void DoHalfDuplex() { gpr_log(GPR_INFO, "Sending half-duplex streaming rpc ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("half_duplex"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::ClientContext context; @@ -243,8 +350,10 @@ void DoHalfDuplex(std::shared_ptr<ChannelInterface> channel) { gpr_log(GPR_INFO, "Half-duplex streaming rpc done."); } -void DoPingPong(std::shared_ptr<ChannelInterface> channel) { +void DoPingPong() { gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc ..."); + std::shared_ptr<ChannelInterface> channel = + CreateChannelForTestCase("ping_pong"); std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel)); grpc::ClientContext context; @@ -279,46 +388,45 @@ int main(int argc, char** argv) { google::ParseCommandLineFlags(&argc, &argv, true); - GPR_ASSERT(FLAGS_server_port); - const int host_port_buf_size = 1024; - char host_port[host_port_buf_size]; - snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), - FLAGS_server_port); - - std::shared_ptr<ChannelInterface> channel( - CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_enable_ssl, - FLAGS_use_prod_roots)); - if (FLAGS_test_case == "empty_unary") { - DoEmpty(channel); + DoEmpty(); } else if (FLAGS_test_case == "large_unary") { - DoLargeUnary(channel); + DoLargeUnary(); } else if (FLAGS_test_case == "client_streaming") { - DoRequestStreaming(channel); + DoRequestStreaming(); } else if (FLAGS_test_case == "server_streaming") { - DoResponseStreaming(channel); + DoResponseStreaming(); } else if (FLAGS_test_case == "slow_consumer") { - DoResponseStreamingWithSlowConsumer(channel); + DoResponseStreamingWithSlowConsumer(); } else if (FLAGS_test_case == "half_duplex") { - DoHalfDuplex(channel); + DoHalfDuplex(); } else if (FLAGS_test_case == "ping_pong") { - DoPingPong(channel); + DoPingPong(); + } else if (FLAGS_test_case == "service_account_creds") { + DoServiceAccountCreds(); + } else if (FLAGS_test_case == "compute_engine_creds") { + DoComputeEngineCreds(); } else if (FLAGS_test_case == "all") { - DoEmpty(channel); - DoLargeUnary(channel); - DoRequestStreaming(channel); - DoResponseStreaming(channel); - DoHalfDuplex(channel); - DoPingPong(channel); + DoEmpty(); + DoLargeUnary(); + DoRequestStreaming(); + DoResponseStreaming(); + DoHalfDuplex(); + DoPingPong(); + // service_account_creds can only run with ssl. + if (FLAGS_enable_ssl) { + DoServiceAccountCreds(); + } + // compute_engine_creds only runs in GCE. } else { gpr_log( GPR_ERROR, "Unsupported test case %s. Valid options are all|empty_unary|" - "large_unary|client_streaming|server_streaming|half_duplex|ping_pong", + "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" + "service_account_creds|compute_engine_creds", FLAGS_test_case.c_str()); } - channel.reset(); grpc_shutdown(); return 0; } diff --git a/test/cpp/interop/messages.proto b/test/cpp/interop/messages.proto index 29db0dd8b1..1d95154cf4 100644 --- a/test/cpp/interop/messages.proto +++ b/test/cpp/interop/messages.proto @@ -36,6 +36,12 @@ message SimpleRequest { // Optional input payload sent along with the request. optional Payload payload = 3; + + // Whether SimpleResponse should include username. + optional bool fill_username = 4; + + // Whether SimpleResponse should include OAuth scope. + optional bool fill_oauth_scope = 5; } // Unary response, as configured by the request. @@ -44,7 +50,9 @@ message SimpleResponse { optional Payload payload = 1; // The user the request came from, for verifying authentication was // successful when the client expected it. - optional int64 effective_gaia_user_id = 2; + optional string username = 2; + // OAuth scope. + optional string oauth_scope = 3; } // Client-streaming request. diff --git a/test/cpp/qps/client.cc b/test/cpp/qps/client.cc index 450373ecf8..affc4926bf 100644 --- a/test/cpp/qps/client.cc +++ b/test/cpp/qps/client.cc @@ -134,33 +134,37 @@ void RunTest(const int client_threads, const int client_channels, GPR_ASSERT(hist != NULL); thread_stats[i] = hist; - threads.push_back(std::thread( - [hist, client_threads, client_channels, num_rpcs, payload_size, - &channels](int channel_num) { - SimpleRequest request; - SimpleResponse response; - request.set_response_type(grpc::testing::PayloadType::COMPRESSABLE); - request.set_response_size(payload_size); - - for (int j = 0; j < num_rpcs; j++) { - TestService::Stub *stub = channels[channel_num].get_stub(); - double start = now(); - grpc::ClientContext context; - grpc::Status s = stub->UnaryCall(&context, request, &response); - gpr_histogram_add(hist, now() - start); - - GPR_ASSERT((s.code() == grpc::StatusCode::OK) && - (response.payload().type() == - grpc::testing::PayloadType::COMPRESSABLE) && - (response.payload().body().length() == - static_cast<size_t>(payload_size))); - - // Now do runtime round-robin assignment of the next channel number - channel_num += client_threads; - channel_num %= client_channels; - } - }, - i % client_channels)); + threads.push_back( + std::thread([hist, client_threads, client_channels, num_rpcs, + payload_size, &channels](int channel_num) { + SimpleRequest request; + SimpleResponse response; + request.set_response_type( + grpc::testing::PayloadType::COMPRESSABLE); + request.set_response_size(payload_size); + + for (int j = 0; j < num_rpcs; j++) { + TestService::Stub *stub = + channels[channel_num].get_stub(); + double start = now(); + grpc::ClientContext context; + grpc::Status s = + stub->UnaryCall(&context, request, &response); + gpr_histogram_add(hist, now() - start); + + GPR_ASSERT((s.code() == grpc::StatusCode::OK) && + (response.payload().type() == + grpc::testing::PayloadType::COMPRESSABLE) && + (response.payload().body().length() == + static_cast<size_t>(payload_size))); + + // Now do runtime round-robin assignment of the next + // channel number + channel_num += client_threads; + channel_num %= client_channels; + } + }, + i % client_channels)); } gpr_histogram *hist = gpr_histogram_create(0.01, 60e9); diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc index 68f6244a53..a521162bea 100644 --- a/test/cpp/util/create_test_channel.cc +++ b/test/cpp/util/create_test_channel.cc @@ -44,22 +44,26 @@ namespace grpc { // create channel. Otherwise, connect to server and override hostname if // override_hostname is provided. // When ssl is not enabled, override_hostname is ignored. -// Set use_prod_root to true to use the SSL root for production GFE. Otherwise, -// root for test SSL cert will be used. +// Set use_prod_root to true to use the SSL root for connecting to google. +// Otherwise, root for test SSL cert will be used. +// creds will be used to create a channel when enable_ssl is true. // Use examples: -// CreateTestChannel("1.1.1.1:12345", "override.hostname.com", true, false); -// CreateTestChannel("test.google.com:443", "", true, true); -// CreateTestChannel("", "test.google.com:443", true, true); // same as above +// CreateTestChannel( +// "1.1.1.1:12345", "override.hostname.com", true, false, creds); +// CreateTestChannel("test.google.com:443", "", true, true, creds); +// same as above +// CreateTestChannel("", "test.google.com:443", true, true, creds); std::shared_ptr<ChannelInterface> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots) { + bool enable_ssl, bool use_prod_roots, + const std::unique_ptr<Credentials>& creds) { ChannelArguments channel_args; if (enable_ssl) { const char* roots_certs = use_prod_roots ? prod_roots_certs : test_root_cert; SslCredentialsOptions ssl_opts = {roots_certs, "", ""}; - std::unique_ptr<Credentials> creds = + std::unique_ptr<Credentials> channel_creds = CredentialsFactory::SslCredentials(ssl_opts); if (!server.empty() && !override_hostname.empty()) { @@ -67,12 +71,23 @@ std::shared_ptr<ChannelInterface> CreateTestChannel( } const grpc::string& connect_to = server.empty() ? override_hostname : server; - return CreateChannel(connect_to, creds, channel_args); + if (creds.get()) { + channel_creds = + CredentialsFactory::ComposeCredentials(creds, channel_creds); + } + return CreateChannel(connect_to, channel_creds, channel_args); } else { return CreateChannel(server, channel_args); } } +std::shared_ptr<ChannelInterface> CreateTestChannel( + const grpc::string& server, const grpc::string& override_hostname, + bool enable_ssl, bool use_prod_roots) { + return CreateTestChannel(server, override_hostname, enable_ssl, + use_prod_roots, std::unique_ptr<Credentials>()); +} + // Shortcut for end2end and interop tests. std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server, bool enable_ssl) { diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h index 17b519ecb0..4e326559bf 100644 --- a/test/cpp/util/create_test_channel.h +++ b/test/cpp/util/create_test_channel.h @@ -37,14 +37,11 @@ #include <memory> #include <grpc++/config.h> +#include <grpc++/credentials.h> namespace grpc { class ChannelInterface; -std::shared_ptr<ChannelInterface> CreateTestChannel( - const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl); - std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server, bool enable_ssl); @@ -52,6 +49,11 @@ std::shared_ptr<ChannelInterface> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, bool enable_ssl, bool use_prod_roots); +std::shared_ptr<ChannelInterface> CreateTestChannel( + const grpc::string& server, const grpc::string& override_hostname, + bool enable_ssl, bool use_prod_roots, + const std::unique_ptr<Credentials>& creds); + } // namespace grpc #endif // __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_ |