diff options
author | 2018-01-19 12:20:15 -0800 | |
---|---|---|
committer | 2018-01-19 12:20:15 -0800 | |
commit | fb061c329ac5086b62619b118191574f3fd27a79 (patch) | |
tree | 6a855770d7218425a2cd53bc378800c30d6c8525 /test | |
parent | 032e9b32dc5978a042bdda5c3031ae6cbd928973 (diff) | |
parent | 9813858908da2e7deaa58d91f4030e6881e364e3 (diff) |
Merge remote-tracking branch 'upstream/master' into fix-stream-compression-config-interface
Diffstat (limited to 'test')
134 files changed, 1529 insertions, 534 deletions
diff --git a/test/core/backoff/BUILD b/test/core/backoff/BUILD index 4cd7acf066..6fbd6542d4 100644 --- a/test/core/backoff/BUILD +++ b/test/core/backoff/BUILD @@ -26,11 +26,14 @@ package( grpc_cc_test( name = "backoff_test", srcs = ["backoff_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ - "//:grpc", - "//test/core/util:grpc_test_util", "//:gpr", + "//:grpc", "//test/core/util:gpr_test_util", + "//test/core/util:grpc_test_util", ], ) diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index d3115fe1dd..2e61243831 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -18,137 +18,131 @@ #include "src/core/lib/backoff/backoff.h" -#include <grpc/grpc.h> +#include <algorithm> + #include <grpc/support/log.h> #include <grpc/support/useful.h> +#include <gtest/gtest.h> #include "test/core/util/test_config.h" -static void test_constant_backoff(void) { - grpc_backoff backoff; +namespace grpc { +namespace testing { +namespace { + +using grpc_core::BackOff; + +TEST(BackOffTest, ConstantBackOff) { const grpc_millis initial_backoff = 200; const double multiplier = 1.0; const double jitter = 0.0; - const grpc_millis min_connect_timeout = 100; const grpc_millis max_backoff = 1000; - grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, - min_connect_timeout, max_backoff); grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); + BackOff::Options options; + options.set_initial_backoff(initial_backoff) + .set_multiplier(multiplier) + .set_jitter(jitter) + .set_max_backoff(max_backoff); + BackOff backoff(options); + + grpc_millis next_attempt_start_time = backoff.NextAttemptTime(); + EXPECT_EQ(next_attempt_start_time - grpc_core::ExecCtx::Get()->Now(), + initial_backoff); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); + next_attempt_start_time = backoff.NextAttemptTime(); + EXPECT_EQ(next_attempt_start_time - grpc_core::ExecCtx::Get()->Now(), + initial_backoff); } } -static void test_min_connect(void) { - grpc_backoff backoff; +TEST(BackOffTest, MinConnect) { const grpc_millis initial_backoff = 100; const double multiplier = 1.0; const double jitter = 0.0; - const grpc_millis min_connect_timeout = 200; const grpc_millis max_backoff = 1000; - grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, - min_connect_timeout, max_backoff); grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next = grpc_backoff_begin(&backoff); - // Because the min_connect_timeout > initial_backoff, current_deadline is used - // as the deadline for the current attempt. - GPR_ASSERT(next.current_deadline - grpc_core::ExecCtx::Get()->Now() == - min_connect_timeout); - // ... while, if the current attempt fails, the next one will happen after - // initial_backoff. - GPR_ASSERT(next.next_attempt_start_time - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); + BackOff::Options options; + options.set_initial_backoff(initial_backoff) + .set_multiplier(multiplier) + .set_jitter(jitter) + .set_max_backoff(max_backoff); + BackOff backoff(options); + grpc_millis next = backoff.NextAttemptTime(); + EXPECT_EQ(next - grpc_core::ExecCtx::Get()->Now(), initial_backoff); } -static void test_no_jitter_backoff(void) { - grpc_backoff backoff; +TEST(BackOffTest, NoJitterBackOff) { const grpc_millis initial_backoff = 2; const double multiplier = 2.0; const double jitter = 0.0; - const grpc_millis min_connect_timeout = 1; const grpc_millis max_backoff = 513; - grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, - min_connect_timeout, max_backoff); + BackOff::Options options; + options.set_initial_backoff(initial_backoff) + .set_multiplier(multiplier) + .set_jitter(jitter) + .set_max_backoff(max_backoff); + BackOff backoff(options); // x_1 = 2 // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 ) grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx::Get()->TestOnlySetNow(0); - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == - next_deadlines.next_attempt_start_time); - GPR_ASSERT(next_deadlines.current_deadline == 2); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 6); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 14); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 30); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 62); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 126); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 254); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 510); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 1022); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); + grpc_millis next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 2); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 6); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 14); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 30); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 62); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 126); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 254); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 510); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 1022); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); // Hit the maximum timeout. From this point onwards, retries will increase // only by max timeout. - GPR_ASSERT(next_deadlines.current_deadline == 1535); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 2048); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); - next_deadlines = grpc_backoff_step(&backoff); - GPR_ASSERT(next_deadlines.current_deadline == 2561); + EXPECT_EQ(next, 1535); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 2048); + grpc_core::ExecCtx::Get()->TestOnlySetNow(next); + next = backoff.NextAttemptTime(); + EXPECT_EQ(next, 2561); } -static void test_jitter_backoff(void) { +TEST(BackOffTest, JitterBackOff) { const grpc_millis initial_backoff = 500; grpc_millis current_backoff = initial_backoff; const grpc_millis max_backoff = 1000; - const grpc_millis min_connect_timeout = 100; const double multiplier = 1.0; const double jitter = 0.1; - grpc_backoff backoff; - grpc_backoff_init(&backoff, initial_backoff, multiplier, jitter, - min_connect_timeout, max_backoff); + BackOff::Options options; + options.set_initial_backoff(initial_backoff) + .set_multiplier(multiplier) + .set_jitter(jitter) + .set_max_backoff(max_backoff); + BackOff backoff(options); - backoff.rng_state = 0; // force consistent PRNG + backoff.SetRandomSeed(0); // force consistent PRNG grpc_core::ExecCtx exec_ctx; - grpc_backoff_result next_deadlines = grpc_backoff_begin(&backoff); - GPR_ASSERT(next_deadlines.current_deadline - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); - GPR_ASSERT(next_deadlines.next_attempt_start_time - - grpc_core::ExecCtx::Get()->Now() == - initial_backoff); + grpc_millis next = backoff.NextAttemptTime(); + EXPECT_EQ(next - grpc_core::ExecCtx::Get()->Now(), initial_backoff); grpc_millis expected_next_lower_bound = (grpc_millis)((double)current_backoff * (1 - jitter)); @@ -156,33 +150,27 @@ static void test_jitter_backoff(void) { (grpc_millis)((double)current_backoff * (1 + jitter)); for (int i = 0; i < 10000; i++) { - next_deadlines = grpc_backoff_step(&backoff); + next = backoff.NextAttemptTime(); // next-now must be within (jitter*100)% of the current backoff (which // increases by * multiplier up to max_backoff). - const grpc_millis timeout_millis = - next_deadlines.current_deadline - grpc_core::ExecCtx::Get()->Now(); - GPR_ASSERT(timeout_millis >= expected_next_lower_bound); - GPR_ASSERT(timeout_millis <= expected_next_upper_bound); - current_backoff = GPR_MIN( + const grpc_millis timeout_millis = next - grpc_core::ExecCtx::Get()->Now(); + EXPECT_GE(timeout_millis, expected_next_lower_bound); + EXPECT_LE(timeout_millis, expected_next_upper_bound); + current_backoff = std::min( (grpc_millis)((double)current_backoff * multiplier), max_backoff); expected_next_lower_bound = (grpc_millis)((double)current_backoff * (1 - jitter)); expected_next_upper_bound = (grpc_millis)((double)current_backoff * (1 + jitter)); - grpc_core::ExecCtx::Get()->TestOnlySetNow(next_deadlines.current_deadline); } } +} // namespace +} // namespace testing +} // namespace grpc + int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_init(); - gpr_time_init(); - - test_constant_backoff(); - test_min_connect(); - test_no_jitter_backoff(); - test_jitter_backoff(); - - grpc_shutdown(); - return 0; + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 4c1642aa5d..dd8d88170e 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -28,10 +28,10 @@ #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/channel_stack.h" +#include "src/core/lib/gpr/murmur_hash.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/endpoint_pair.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/support/murmur_hash.h" -#include "src/core/lib/support/string.h" #include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/server.h" diff --git a/test/core/bad_client/tests/large_metadata.cc b/test/core/bad_client/tests/large_metadata.cc index 1ce0f28967..ff3e9eb932 100644 --- a/test/core/bad_client/tests/large_metadata.cc +++ b/test/core/bad_client/tests/large_metadata.cc @@ -22,7 +22,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/string_util.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" diff --git a/test/core/bad_ssl/bad_ssl_test.cc b/test/core/bad_ssl/bad_ssl_test.cc index 0e74a62f19..8a7960b5ed 100644 --- a/test/core/bad_ssl/bad_ssl_test.cc +++ b/test/core/bad_ssl/bad_ssl_test.cc @@ -26,8 +26,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index 3495f603e4..f02c8180f2 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -35,7 +35,7 @@ #include <string.h> #include "src/core/lib/channel/channel_stack_builder.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_stack_type.h" #include "src/core/lib/transport/transport_impl.h" diff --git a/test/core/client_channel/lb_policies_test.cc b/test/core/client_channel/lb_policies_test.cc index 847ea0066b..716c63b9d0 100644 --- a/test/core/client_channel/lb_policies_test.cc +++ b/test/core/client_channel/lb_policies_test.cc @@ -30,7 +30,7 @@ #include "src/core/ext/filters/client_channel/lb_policy_registry.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack.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/end2end/cq_verifier.h" diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index 4d16a77924..07ee133ee3 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -63,8 +63,10 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, on_resolution); GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); - grpc_uri_destroy(uri); + /* Flush ExecCtx to avoid stack-use-after-scope on on_res_arg which is + * accessed in the closure on_resolution_cb */ + grpc_core::ExecCtx::Get()->Flush(); } static void test_fails(grpc_resolver_factory* factory, const char* string) { diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 9934af84f2..bab32e0cc5 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -25,8 +25,8 @@ #include <grpc/support/log.h> #include <grpc/support/useful.h> +#include "src/core/lib/gpr/murmur_hash.h" #include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/support/murmur_hash.h" #include "test/core/util/slice_splitter.h" #include "test/core/util/test_config.h" diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 93809ac37a..a8e5e291c8 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -31,10 +31,10 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/end2end/cq_verifier.cc b/test/core/end2end/cq_verifier.cc index 8686f4e7b7..7bf8ae0f6e 100644 --- a/test/core/end2end/cq_verifier.cc +++ b/test/core/end2end/cq_verifier.cc @@ -29,7 +29,7 @@ #include <grpc/support/string_util.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/surface/event_string.h" #define ROOT_EXPECTATION 1000 diff --git a/test/core/end2end/dualstack_socket_test.cc b/test/core/end2end/dualstack_socket_test.cc index 2ba1c17c2c..bb30547cd2 100644 --- a/test/core/end2end/dualstack_socket_test.cc +++ b/test/core/end2end/dualstack_socket_test.cc @@ -29,12 +29,12 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" #include "test/core/end2end/cq_verifier.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -43,14 +43,11 @@ static void* tag(intptr_t i) { return (void*)i; } -static gpr_timespec ms_from_now(int ms) { - return grpc_timeout_milliseconds_to_deadline(ms); -} - static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; do { - ev = grpc_completion_queue_next(cq, ms_from_now(5000), nullptr); + ev = grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(5000), nullptr); } while (ev.type != GRPC_QUEUE_SHUTDOWN); } @@ -165,11 +162,11 @@ void test_connect(const char* server_host, const char* client_host, int port, if (expect_ok) { /* Normal deadline, shouldn't be reached. */ - deadline = ms_from_now(60000); + deadline = grpc_timeout_milliseconds_to_deadline(60000); } else { /* Give up faster when failure is expected. BUG: Setting this to 1000 reveals a memory leak (b/18608927). */ - deadline = ms_from_now(1500); + deadline = grpc_timeout_milliseconds_to_deadline(3000); } /* Send a trivial request. */ diff --git a/test/core/end2end/end2end_nosec_tests.cc b/test/core/end2end/end2end_nosec_tests.cc index 3236feea56..6318550ad8 100644 --- a/test/core/end2end/end2end_nosec_tests.cc +++ b/test/core/end2end/end2end_nosec_tests.cc @@ -68,6 +68,8 @@ extern void filter_causes_close(grpc_end2end_test_config config); extern void filter_causes_close_pre_init(void); extern void filter_latency(grpc_end2end_test_config config); extern void filter_latency_pre_init(void); +extern void filter_status_code(grpc_end2end_test_config config); +extern void filter_status_code_pre_init(void); extern void graceful_server_shutdown(grpc_end2end_test_config config); extern void graceful_server_shutdown_pre_init(void); extern void high_initial_seqno(grpc_end2end_test_config config); @@ -170,6 +172,7 @@ void grpc_end2end_tests_pre_init(void) { filter_call_init_fails_pre_init(); filter_causes_close_pre_init(); filter_latency_pre_init(); + filter_status_code_pre_init(); graceful_server_shutdown_pre_init(); high_initial_seqno_pre_init(); hpack_size_pre_init(); @@ -237,6 +240,7 @@ void grpc_end2end_tests(int argc, char **argv, filter_call_init_fails(config); filter_causes_close(config); filter_latency(config); + filter_status_code(config); graceful_server_shutdown(config); high_initial_seqno(config); hpack_size(config); @@ -356,6 +360,10 @@ void grpc_end2end_tests(int argc, char **argv, filter_latency(config); continue; } + if (0 == strcmp("filter_status_code", argv[i])) { + filter_status_code(config); + continue; + } if (0 == strcmp("graceful_server_shutdown", argv[i])) { graceful_server_shutdown(config); continue; diff --git a/test/core/end2end/end2end_tests.cc b/test/core/end2end/end2end_tests.cc index ca9443b642..9d8dfd6723 100644 --- a/test/core/end2end/end2end_tests.cc +++ b/test/core/end2end/end2end_tests.cc @@ -70,6 +70,8 @@ extern void filter_causes_close(grpc_end2end_test_config config); extern void filter_causes_close_pre_init(void); extern void filter_latency(grpc_end2end_test_config config); extern void filter_latency_pre_init(void); +extern void filter_status_code(grpc_end2end_test_config config); +extern void filter_status_code_pre_init(void); extern void graceful_server_shutdown(grpc_end2end_test_config config); extern void graceful_server_shutdown_pre_init(void); extern void high_initial_seqno(grpc_end2end_test_config config); @@ -173,6 +175,7 @@ void grpc_end2end_tests_pre_init(void) { filter_call_init_fails_pre_init(); filter_causes_close_pre_init(); filter_latency_pre_init(); + filter_status_code_pre_init(); graceful_server_shutdown_pre_init(); high_initial_seqno_pre_init(); hpack_size_pre_init(); @@ -241,6 +244,7 @@ void grpc_end2end_tests(int argc, char **argv, filter_call_init_fails(config); filter_causes_close(config); filter_latency(config); + filter_status_code(config); graceful_server_shutdown(config); high_initial_seqno(config); hpack_size(config); @@ -364,6 +368,10 @@ void grpc_end2end_tests(int argc, char **argv, filter_latency(config); continue; } + if (0 == strcmp("filter_status_code", argv[i])) { + filter_status_code(config); + continue; + } if (0 == strcmp("graceful_server_shutdown", argv[i])) { graceful_server_shutdown(config); continue; diff --git a/test/core/end2end/fixtures/h2_full+trace.cc b/test/core/end2end/fixtures/h2_full+trace.cc index a49de96009..7104fbc581 100644 --- a/test/core/end2end/fixtures/h2_full+trace.cc +++ b/test/core/end2end/fixtures/h2_full+trace.cc @@ -35,7 +35,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/util/port.h" diff --git a/test/core/end2end/fixtures/h2_http_proxy.cc b/test/core/end2end/fixtures/h2_http_proxy.cc index 099367d91b..e8e81f0930 100644 --- a/test/core/end2end/fixtures/h2_http_proxy.cc +++ 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" diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 9807e929af..236780b8d3 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ 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" diff --git a/test/core/end2end/fixtures/h2_ssl.cc b/test/core/end2end/fixtures/h2_ssl.cc index 9a0680c40e..8c5c8a2f3f 100644 --- a/test/core/end2end/fixtures/h2_ssl.cc +++ b/test/core/end2end/fixtures/h2_ssl.cc @@ -26,10 +26,10 @@ #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" diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.cc b/test/core/end2end/fixtures/h2_ssl_proxy.cc index 5ddbdefc8c..3f0646cf0f 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.cc +++ b/test/core/end2end/fixtures/h2_ssl_proxy.cc @@ -26,10 +26,10 @@ #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" diff --git a/test/core/end2end/fixtures/h2_uds.cc b/test/core/end2end/fixtures/h2_uds.cc index 28f0a50e15..1944dd84a3 100644 --- a/test/core/end2end/fixtures/h2_uds.cc +++ b/test/core/end2end/fixtures/h2_uds.cc @@ -33,7 +33,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/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" diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 137f7c9fa3..8ec97df3e4 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ 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 { diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 967a6d560f..14c155502a 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -28,13 +28,13 @@ #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer_manager.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/support/env.h" #include "src/core/lib/surface/server.h" #include "src/core/lib/transport/metadata.h" #include "test/core/end2end/data/ssl_test_data.h" @@ -280,7 +280,12 @@ static grpc_channel_credentials* read_ssl_channel_creds(input_stream* inp) { return creds; } -static grpc_call_credentials* read_call_creds(input_stream* inp) { +static grpc_call_credentials* read_call_creds(input_stream* inp, int depth) { + if (depth > 64) { + // prevent creating infinitely deep call creds + end(inp); + return nullptr; + } switch (next_byte(inp)) { default: end(inp); @@ -288,8 +293,8 @@ static grpc_call_credentials* read_call_creds(input_stream* inp) { case 0: return nullptr; case 1: { - grpc_call_credentials* c1 = read_call_creds(inp); - grpc_call_credentials* c2 = read_call_creds(inp); + grpc_call_credentials* c1 = read_call_creds(inp, depth + 1); + grpc_call_credentials* c2 = read_call_creds(inp, depth + 1); if (c1 != nullptr && c2 != nullptr) { grpc_call_credentials* out = grpc_composite_call_credentials_create(c1, c2, nullptr); @@ -338,7 +343,7 @@ static grpc_channel_credentials* read_channel_creds(input_stream* inp) { break; case 1: { grpc_channel_credentials* c1 = read_channel_creds(inp); - grpc_call_credentials* c2 = read_call_creds(inp); + grpc_call_credentials* c2 = read_call_creds(inp, 0); if (c1 != nullptr && c2 != nullptr) { grpc_channel_credentials* out = grpc_composite_channel_credentials_create(c1, c2, nullptr); diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/fuzz-input-d2ab5 b/test/core/end2end/fuzzers/api_fuzzer_corpus/fuzz-input-d2ab5 Binary files differnew file mode 100644 index 0000000000..1745798b68 --- /dev/null +++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/fuzz-input-d2ab5 diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 7c8e7f420a..e7cf97b2d0 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -101,6 +101,7 @@ END2END_TESTS = { 'filter_causes_close': default_test_options._replace(cpu_cost=LOWCPU), 'filter_call_init_fails': default_test_options, 'filter_latency': default_test_options._replace(cpu_cost=LOWCPU), + 'filter_status_code': default_test_options._replace(cpu_cost=LOWCPU), 'graceful_server_shutdown': default_test_options._replace(cpu_cost=LOWCPU,exclude_inproc=True), 'hpack_size': default_test_options._replace(proxyable=False, traceable=False, diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index b9a42bdb88..1d759e1ecb 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -146,6 +146,7 @@ END2END_TESTS = { 'trailing_metadata': test_options(), 'authority_not_supported': test_options(), 'filter_latency': test_options(), + 'filter_status_code': test_options(), 'workaround_cronet_compression': test_options(), 'write_buffering': test_options(needs_write_buffering=True), 'write_buffering_at_end': test_options(needs_write_buffering=True), diff --git a/test/core/end2end/h2_ssl_cert_test.cc b/test/core/end2end/h2_ssl_cert_test.cc index d50d1f4d81..3383d6d5d1 100644 --- a/test/core/end2end/h2_ssl_cert_test.cc +++ b/test/core/end2end/h2_ssl_cert_test.cc @@ -26,10 +26,10 @@ #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/cq_verifier.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" diff --git a/test/core/end2end/tests/bad_hostname.cc b/test/core/end2end/tests/bad_hostname.cc index 97ef62b5e3..85e9ba1307 100644 --- a/test/core/end2end/tests/bad_hostname.cc +++ b/test/core/end2end/tests/bad_hostname.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/call_creds.cc b/test/core/end2end/tests/call_creds.cc index e1c868232c..c5ea101c53 100644 --- a/test/core/end2end/tests/call_creds.cc +++ b/test/core/end2end/tests/call_creds.cc @@ -27,8 +27,8 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/support/string.h" #include "test/core/end2end/cq_verifier.h" static const char iam_token[] = "token"; diff --git a/test/core/end2end/tests/cancel_with_status.cc b/test/core/end2end/tests/cancel_with_status.cc index c867751d53..7937fd161f 100644 --- a/test/core/end2end/tests/cancel_with_status.cc +++ b/test/core/end2end/tests/cancel_with_status.cc @@ -28,7 +28,7 @@ #include <grpc/support/string_util.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/default_host.cc b/test/core/end2end/tests/default_host.cc index 85f92b0ab0..7c94420540 100644 --- a/test/core/end2end/tests/default_host.cc +++ b/test/core/end2end/tests/default_host.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/empty_batch.cc b/test/core/end2end/tests/empty_batch.cc index b249c141de..c41e65ddd2 100644 --- a/test/core/end2end/tests/empty_batch.cc +++ b/test/core/end2end/tests/empty_batch.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/filter_status_code.cc b/test/core/end2end/tests/filter_status_code.cc new file mode 100644 index 0000000000..61c658b95a --- /dev/null +++ b/test/core/end2end/tests/filter_status_code.cc @@ -0,0 +1,378 @@ +/* + * + * Copyright 2017 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 <limits.h> +#include <stdbool.h> +#include <stdio.h> +#include <string.h> + +#include <grpc/byte_buffer.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> +#include <grpc/support/useful.h> + +#include "src/core/lib/channel/channel_stack_builder.h" +#include "src/core/lib/surface/call.h" +#include "src/core/lib/surface/channel_init.h" +#include "test/core/end2end/cq_verifier.h" + +static bool g_enable_filter = false; +static gpr_mu g_mu; +static grpc_call_stack* g_client_call_stack; +static grpc_call_stack* g_server_call_stack; +static bool g_client_code_recv; +static bool g_server_code_recv; +static gpr_cv g_client_code_cv; +static gpr_cv g_server_code_cv; +static grpc_status_code g_client_status_code; +static grpc_status_code g_server_status_code; + +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, "Running test: %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_from_now(int n) { + return grpc_timeout_seconds_to_deadline(n); +} + +static gpr_timespec five_seconds_from_now(void) { + return n_seconds_from_now(5); +} + +static void drain_cq(grpc_completion_queue* cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr); + } 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), + nullptr) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = nullptr; +} + +static void shutdown_client(grpc_end2end_test_fixture* f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = nullptr; +} + +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); +} + +// Simple request via a server filter that saves the reported status code. +static void test_request(grpc_end2end_test_config config) { + grpc_call* c; + grpc_call* s; + grpc_end2end_test_fixture f = + begin_test(config, "filter_status_code", nullptr, nullptr); + cq_verifier* cqv = cq_verifier_create(f.cq); + grpc_op ops[6]; + grpc_op* op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_call_details call_details; + grpc_status_code status; + grpc_call_error error; + grpc_slice details; + int was_cancelled = 2; + + gpr_mu_lock(&g_mu); + g_client_call_stack = nullptr; + g_server_call_stack = nullptr; + g_client_status_code = GRPC_STATUS_OK; + g_server_status_code = GRPC_STATUS_OK; + gpr_mu_unlock(&g_mu); + + gpr_timespec deadline = five_seconds_from_now(); + c = grpc_channel_create_call( + f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr", config), deadline, nullptr); + GPR_ASSERT(c); + gpr_mu_lock(&g_mu); + g_client_call_stack = grpc_call_get_call_stack(c); + gpr_mu_unlock(&g_mu); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->data.send_initial_metadata.metadata = nullptr; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->flags = 0; + op->reserved = nullptr; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + GPR_ASSERT(GRPC_CALL_OK == error); + + error = + grpc_server_request_call(f.server, &s, &call_details, + &request_metadata_recv, f.cq, f.cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + gpr_mu_lock(&g_mu); + g_server_call_stack = grpc_call_get_call_stack(s); + gpr_mu_unlock(&g_mu); + + 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 = nullptr; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; + grpc_slice status_string = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_string; + op->flags = 0; + op->reserved = nullptr; + op++; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op->reserved = nullptr; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(102), 1); + CQ_EXPECT_COMPLETION(cqv, tag(1), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + + grpc_slice_unref(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + + grpc_call_unref(s); + grpc_call_unref(c); + + cq_verifier_destroy(cqv); + + end_test(&f); + config.tear_down_data(&f); + + // Perform checks after test tear-down + // Guards against the case that there's outstanding channel-related work on a + // call prior to verification + gpr_mu_lock(&g_mu); + if (!g_client_code_recv) { + GPR_ASSERT(gpr_cv_wait(&g_client_code_cv, &g_mu, + grpc_timeout_seconds_to_deadline(3)) == 0); + } + if (!g_server_code_recv) { + GPR_ASSERT(gpr_cv_wait(&g_server_code_cv, &g_mu, + grpc_timeout_seconds_to_deadline(3)) == 0); + } + GPR_ASSERT(g_client_status_code == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT(g_server_status_code == GRPC_STATUS_UNIMPLEMENTED); + gpr_mu_unlock(&g_mu); +} + +/******************************************************************************* + * Test status_code filter + */ + +typedef struct final_status_data { + grpc_call_stack* call; +} final_status_data; + +static grpc_error* init_call_elem(grpc_call_element* elem, + const grpc_call_element_args* args) { + final_status_data* data = (final_status_data*)elem->call_data; + data->call = args->call_stack; + return GRPC_ERROR_NONE; +} + +static void client_destroy_call_elem(grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + final_status_data* data = (final_status_data*)elem->call_data; + gpr_mu_lock(&g_mu); + // Some fixtures, like proxies, will spawn intermidiate calls + // We only want the results from our explicit calls + if (data->call == g_client_call_stack) { + g_client_status_code = final_info->final_status; + g_client_code_recv = true; + gpr_cv_signal(&g_client_code_cv); + } + gpr_mu_unlock(&g_mu); +} + +static void server_destroy_call_elem(grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + final_status_data* data = (final_status_data*)elem->call_data; + gpr_mu_lock(&g_mu); + // Some fixtures, like proxies, will spawn intermidiate calls + // We only want the results from our explicit calls + if (data->call == g_server_call_stack) { + g_server_status_code = final_info->final_status; + g_server_code_recv = true; + gpr_cv_signal(&g_server_code_cv); + } + gpr_mu_unlock(&g_mu); +} + +static grpc_error* init_channel_elem(grpc_channel_element* elem, + grpc_channel_element_args* args) { + return GRPC_ERROR_NONE; +} + +static void destroy_channel_elem(grpc_channel_element* elem) {} + +static const grpc_channel_filter test_client_filter = { + grpc_call_next_op, + grpc_channel_next_op, + sizeof(final_status_data), + init_call_elem, + grpc_call_stack_ignore_set_pollset_or_pollset_set, + client_destroy_call_elem, + 0, + init_channel_elem, + destroy_channel_elem, + grpc_channel_next_get_info, + "client_filter_status_code"}; + +static const grpc_channel_filter test_server_filter = { + grpc_call_next_op, + grpc_channel_next_op, + sizeof(final_status_data), + init_call_elem, + grpc_call_stack_ignore_set_pollset_or_pollset_set, + server_destroy_call_elem, + 0, + init_channel_elem, + destroy_channel_elem, + grpc_channel_next_get_info, + "server_filter_status_code"}; + +/******************************************************************************* + * Registration + */ + +static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) { + grpc_channel_filter* filter = (grpc_channel_filter*)arg; + if (g_enable_filter) { + // Want to add the filter as close to the end as possible, to make + // sure that all of the filters work well together. However, we + // can't add it at the very end, because the + // connected_channel/client_channel filter must be the last one. + // So we add it right before the last one. + grpc_channel_stack_builder_iterator* it = + grpc_channel_stack_builder_create_iterator_at_last(builder); + GPR_ASSERT(grpc_channel_stack_builder_move_prev(it)); + const bool retval = grpc_channel_stack_builder_add_filter_before( + it, filter, nullptr, nullptr); + grpc_channel_stack_builder_iterator_destroy(it); + return retval; + } else { + return true; + } +} + +static void init_plugin(void) { + gpr_mu_init(&g_mu); + gpr_cv_init(&g_client_code_cv); + gpr_cv_init(&g_server_code_cv); + g_client_code_recv = false; + g_server_code_recv = false; + + grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, + maybe_add_filter, + (void*)&test_client_filter); + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, + maybe_add_filter, + (void*)&test_client_filter); + grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, + maybe_add_filter, + (void*)&test_server_filter); +} + +static void destroy_plugin(void) { + gpr_cv_destroy(&g_client_code_cv); + gpr_cv_destroy(&g_server_code_cv); + gpr_mu_destroy(&g_mu); +} + +void filter_status_code(grpc_end2end_test_config config) { + g_enable_filter = true; + test_request(config); + g_enable_filter = false; +} + +void filter_status_code_pre_init(void) { + grpc_register_plugin(init_plugin, destroy_plugin); +} diff --git a/test/core/end2end/tests/high_initial_seqno.cc b/test/core/end2end/tests/high_initial_seqno.cc index d390a954e5..d4d4f5a817 100644 --- a/test/core/end2end/tests/high_initial_seqno.cc +++ b/test/core/end2end/tests/high_initial_seqno.cc @@ -29,7 +29,7 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/hpack_size.cc b/test/core/end2end/tests/hpack_size.cc index 7ac5fefa22..0d6ec01e36 100644 --- a/test/core/end2end/tests/hpack_size.cc +++ b/test/core/end2end/tests/hpack_size.cc @@ -29,7 +29,7 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/idempotent_request.cc b/test/core/end2end/tests/idempotent_request.cc index e39975382a..7487e4d83d 100644 --- a/test/core/end2end/tests/idempotent_request.cc +++ b/test/core/end2end/tests/idempotent_request.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/keepalive_timeout.cc b/test/core/end2end/tests/keepalive_timeout.cc index 822565510f..6482b86825 100644 --- a/test/core/end2end/tests/keepalive_timeout.cc +++ b/test/core/end2end/tests/keepalive_timeout.cc @@ -28,8 +28,8 @@ #include <grpc/support/useful.h> #include "src/core/ext/transport/chttp2/transport/frame_ping.h" #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/support/env.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/negative_deadline.cc b/test/core/end2end/tests/negative_deadline.cc index b793964b48..b752bf9482 100644 --- a/test/core/end2end/tests/negative_deadline.cc +++ b/test/core/end2end/tests/negative_deadline.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/no_logging.cc b/test/core/end2end/tests/no_logging.cc index bf8651221a..d89918bd3e 100644 --- a/test/core/end2end/tests/no_logging.cc +++ b/test/core/end2end/tests/no_logging.cc @@ -28,8 +28,8 @@ #include <grpc/support/string_util.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/error.h" -#include "src/core/lib/support/string.h" #include "test/core/end2end/cq_verifier.h" enum { TIMEOUT = 200000 }; diff --git a/test/core/end2end/tests/proxy_auth.cc b/test/core/end2end/tests/proxy_auth.cc index e4b91ab879..495151b592 100644 --- a/test/core/end2end/tests/proxy_auth.cc +++ b/test/core/end2end/tests/proxy_auth.cc @@ -32,7 +32,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/registered_call.cc b/test/core/end2end/tests/registered_call.cc index 440d817cf1..cefa89db4d 100644 --- a/test/core/end2end/tests/registered_call.cc +++ b/test/core/end2end/tests/registered_call.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/server_finishes_request.cc b/test/core/end2end/tests/server_finishes_request.cc index 46b874b569..743b3aeb91 100644 --- a/test/core/end2end/tests/server_finishes_request.cc +++ b/test/core/end2end/tests/server_finishes_request.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index 7eb7467981..ae93f79c9d 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -28,7 +28,7 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> #include "src/core/lib/debug/stats.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/end2end/cq_verifier.h" static void* tag(intptr_t t) { return (void*)t; } diff --git a/test/core/fling/client.cc b/test/core/fling/client.cc index 69fb6dc7c7..28e62e0e83 100644 --- a/test/core/fling/client.cc +++ b/test/core/fling/client.cc @@ -186,8 +186,10 @@ int main(int argc, char** argv) { } if (!sc.name) { fprintf(stderr, "unsupported scenario '%s'. Valid are:", scenario_name); + fflush(stderr); for (i = 0; i < GPR_ARRAY_SIZE(scenarios); i++) { fprintf(stderr, " %s", scenarios[i].name); + fflush(stderr); } return 1; } diff --git a/test/core/fling/fling_stream_test.cc b/test/core/fling/fling_stream_test.cc index b476f2e128..b5a5ce816e 100644 --- a/test/core/fling/fling_stream_test.cc +++ b/test/core/fling/fling_stream_test.cc @@ -23,7 +23,7 @@ #include <grpc/support/host_port.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/port.h" int main(int argc, char** argv) { diff --git a/test/core/fling/fling_test.cc b/test/core/fling/fling_test.cc index 0e8b3c1028..3792e45c42 100644 --- a/test/core/fling/fling_test.cc +++ b/test/core/fling/fling_test.cc @@ -23,7 +23,7 @@ #include <grpc/support/host_port.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/port.h" int main(int argc, const char** argv) { diff --git a/test/core/gpr++/BUILD b/test/core/gpr++/BUILD new file mode 100644 index 0000000000..93324a378b --- /dev/null +++ b/test/core/gpr++/BUILD @@ -0,0 +1,95 @@ +# Copyright 2016 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. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary", "grpc_package") + +licenses(["notice"]) # Apache v2 + +grpc_package(name = "test/core/gpr++") + +grpc_cc_test( + name = "manual_constructor_test", + srcs = ["manual_constructor_test.cc"], + language = "C++", + deps = [ + "//:gpr", + "//test/core/util:gpr_test_util", + ], +) + +grpc_cc_test( + name = "memory_test", + srcs = ["memory_test.cc"], + external_deps = [ + "gtest", + ], + language = "C++", + deps = [ + "//:grpc", + "//test/core/util:gpr_test_util", + ], +) + +grpc_cc_test( + name = "inlined_vector_test", + srcs = ["inlined_vector_test.cc"], + external_deps = [ + "gtest", + ], + language = "C++", + deps = [ + "//:grpc", + "//test/core/util:gpr_test_util", + ], +) + +grpc_cc_test( + name = "orphanable_test", + srcs = ["orphanable_test.cc"], + language = "C++", + deps = [ + "//:orphanable", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], +) + +grpc_cc_test( + name = "ref_counted_test", + srcs = ["ref_counted_test.cc"], + language = "C++", + deps = [ + "//:ref_counted", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], +) + +grpc_cc_test( + name = "ref_counted_ptr_test", + srcs = ["ref_counted_ptr_test.cc"], + language = "C++", + deps = [ + "//:ref_counted", + "//:ref_counted_ptr", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], +) diff --git a/test/core/gpr++/inlined_vector_test.cc b/test/core/gpr++/inlined_vector_test.cc new file mode 100644 index 0000000000..09d5453a56 --- /dev/null +++ b/test/core/gpr++/inlined_vector_test.cc @@ -0,0 +1,74 @@ +/* + * + * Copyright 2017 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 "src/core/lib/gpr++/inlined_vector.h" +#include <gtest/gtest.h> +#include "src/core/lib/gpr++/memory.h" +#include "test/core/util/test_config.h" + +namespace grpc_core { +namespace testing { + +TEST(InlinedVectorTest, CreateAndIterate) { + const int kNumElements = 9; + InlinedVector<int, 2> v; + for (int i = 0; i < kNumElements; ++i) { + v.push_back(i); + } + EXPECT_EQ(static_cast<size_t>(kNumElements), v.size()); + for (int i = 0; i < kNumElements; ++i) { + EXPECT_EQ(i, v[i]); + } +} + +TEST(InlinedVectorTest, ValuesAreInlined) { + const int kNumElements = 5; + InlinedVector<int, 10> v; + for (int i = 0; i < kNumElements; ++i) { + v.push_back(i); + } + EXPECT_EQ(static_cast<size_t>(kNumElements), v.size()); + for (int i = 0; i < kNumElements; ++i) { + EXPECT_EQ(i, v[i]); + } +} + +TEST(InlinedVectorTest, PushBackWithMove) { + InlinedVector<UniquePtr<int>, 1> v; + UniquePtr<int> i = MakeUnique<int>(3); + v.push_back(std::move(i)); + EXPECT_EQ(nullptr, i.get()); + EXPECT_EQ(1UL, v.size()); + EXPECT_EQ(3, *v[0]); +} + +TEST(InlinedVectorTest, EmplaceBack) { + InlinedVector<UniquePtr<int>, 1> v; + v.emplace_back(New<int>(3)); + EXPECT_EQ(1UL, v.size()); + EXPECT_EQ(3, *v[0]); +} + +} // namespace testing +} // namespace grpc_core + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/core/support/manual_constructor_test.cc b/test/core/gpr++/manual_constructor_test.cc index 714f8b21a0..e049b793f6 100644 --- a/test/core/support/manual_constructor_test.cc +++ b/test/core/gpr++/manual_constructor_test.cc @@ -18,7 +18,7 @@ /* Test of gpr synchronization support. */ -#include "src/core/lib/support/manual_constructor.h" +#include "src/core/lib/gpr++/manual_constructor.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> @@ -26,7 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include <cstring> -#include "src/core/lib/support/abstract.h" +#include "src/core/lib/gpr++/abstract.h" #include "test/core/util/test_config.h" class A { diff --git a/test/core/support/memory_test.cc b/test/core/gpr++/memory_test.cc index 79ab631a78..3553e119e3 100644 --- a/test/core/support/memory_test.cc +++ b/test/core/gpr++/memory_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/support/memory.h" +#include "src/core/lib/gpr++/memory.h" #include <gtest/gtest.h> #include "test/core/util/test_config.h" diff --git a/test/core/gpr++/orphanable_test.cc b/test/core/gpr++/orphanable_test.cc new file mode 100644 index 0000000000..4513d25da1 --- /dev/null +++ b/test/core/gpr++/orphanable_test.cc @@ -0,0 +1,114 @@ +/* + * + * Copyright 2017 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 "src/core/lib/gpr++/orphanable.h" + +#include <gtest/gtest.h> + +#include "src/core/lib/gpr++/memory.h" +#include "test/core/util/test_config.h" + +namespace grpc_core { +namespace testing { +namespace { + +class Foo : public Orphanable { + public: + Foo() : Foo(0) {} + explicit Foo(int value) : value_(value) {} + void Orphan() override { Delete(this); } + int value() const { return value_; } + + private: + int value_; +}; + +TEST(Orphanable, Basic) { + Foo* foo = New<Foo>(); + foo->Orphan(); +} + +TEST(OrphanablePtr, Basic) { + OrphanablePtr<Foo> foo(New<Foo>()); + EXPECT_EQ(0, foo->value()); +} + +TEST(MakeOrphanable, DefaultConstructor) { + auto foo = MakeOrphanable<Foo>(); + EXPECT_EQ(0, foo->value()); +} + +TEST(MakeOrphanable, WithParameters) { + auto foo = MakeOrphanable<Foo>(5); + EXPECT_EQ(5, foo->value()); +} + +class Bar : public InternallyRefCounted { + public: + Bar() : Bar(0) {} + explicit Bar(int value) : value_(value) {} + void Orphan() override { Unref(); } + int value() const { return value_; } + + void StartWork() { Ref(); } + void FinishWork() { Unref(); } + + private: + int value_; +}; + +TEST(OrphanablePtr, InternallyRefCounted) { + auto bar = MakeOrphanable<Bar>(); + bar->StartWork(); + bar->FinishWork(); +} + +// Note: We use DebugOnlyTraceFlag instead of TraceFlag to ensure that +// things build properly in both debug and non-debug cases. +DebugOnlyTraceFlag baz_tracer(true, "baz"); + +class Baz : public InternallyRefCountedWithTracing { + public: + Baz() : Baz(0) {} + explicit Baz(int value) + : InternallyRefCountedWithTracing(&baz_tracer), value_(value) {} + void Orphan() override { Unref(); } + int value() const { return value_; } + + void StartWork() { Ref(DEBUG_LOCATION, "work"); } + void FinishWork() { Unref(DEBUG_LOCATION, "work"); } + + private: + int value_; +}; + +TEST(OrphanablePtr, InternallyRefCountedWithTracing) { + auto baz = MakeOrphanable<Baz>(); + baz->StartWork(); + baz->FinishWork(); +} + +} // namespace +} // namespace testing +} // namespace grpc_core + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/core/support/ref_counted_ptr_test.cc b/test/core/gpr++/ref_counted_ptr_test.cc index 1830edc4e5..e897b2859c 100644 --- a/test/core/support/ref_counted_ptr_test.cc +++ b/test/core/gpr++/ref_counted_ptr_test.cc @@ -16,14 +16,14 @@ * */ -#include "src/core/lib/support/ref_counted_ptr.h" +#include "src/core/lib/gpr++/ref_counted_ptr.h" #include <gtest/gtest.h> #include <grpc/support/log.h> -#include "src/core/lib/support/memory.h" -#include "src/core/lib/support/ref_counted.h" +#include "src/core/lib/gpr++/memory.h" +#include "src/core/lib/gpr++/ref_counted.h" #include "test/core/util/test_config.h" namespace grpc_core { @@ -138,6 +138,19 @@ TEST(RefCountedPtr, DerefernceOperators) { foo_ref.value(); } +TEST(RefCountedPtr, EqualityOperators) { + RefCountedPtr<Foo> foo(New<Foo>()); + RefCountedPtr<Foo> bar = foo; + RefCountedPtr<Foo> empty; + // Test equality between RefCountedPtrs. + EXPECT_EQ(foo, bar); + EXPECT_NE(foo, empty); + // Test equality with bare pointers. + EXPECT_EQ(foo, foo.get()); + EXPECT_EQ(empty, nullptr); + EXPECT_NE(foo, nullptr); +} + TEST(MakeRefCounted, NoArgs) { RefCountedPtr<Foo> foo = MakeRefCounted<Foo>(); EXPECT_EQ(0, foo->value()); diff --git a/test/core/support/ref_counted_test.cc b/test/core/gpr++/ref_counted_test.cc index be9b6ff7c2..568ec51c64 100644 --- a/test/core/support/ref_counted_test.cc +++ b/test/core/gpr++/ref_counted_test.cc @@ -16,11 +16,11 @@ * */ -#include "src/core/lib/support/ref_counted.h" +#include "src/core/lib/gpr++/ref_counted.h" #include <gtest/gtest.h> -#include "src/core/lib/support/memory.h" +#include "src/core/lib/gpr++/memory.h" #include "test/core/util/test_config.h" namespace grpc_core { @@ -44,7 +44,9 @@ TEST(RefCounted, ExtraRef) { foo->Unref(); } -TraceFlag foo_tracer(true, "foo"); +// Note: We use DebugOnlyTraceFlag instead of TraceFlag to ensure that +// things build properly in both debug and non-debug cases. +DebugOnlyTraceFlag foo_tracer(true, "foo"); class FooWithTracing : public RefCountedWithTracing { public: diff --git a/test/core/support/BUILD b/test/core/gpr/BUILD index 4372b49b54..1be1036d04 100644 --- a/test/core/support/BUILD +++ b/test/core/gpr/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_c licenses(["notice"]) # Apache v2 -grpc_package(name = "test/core/support") +grpc_package(name = "test/core/gpr") grpc_cc_test( name = "alloc_test", @@ -119,16 +119,6 @@ grpc_cc_test( ) grpc_cc_test( - name = "manual_constructor_test", - srcs = ["manual_constructor_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//test/core/util:gpr_test_util", - ], -) - -grpc_cc_test( name = "spinlock_test", srcs = ["spinlock_test.cc"], language = "C++", @@ -187,56 +177,3 @@ grpc_cc_test( "//test/core/util:gpr_test_util", ], ) - -grpc_cc_test( - name = "memory_test", - srcs = ["memory_test.cc"], - external_deps = [ - "gtest", - ], - language = "C++", - deps = [ - "//:grpc", - "//test/core/util:gpr_test_util", - ], -) - -grpc_cc_test( - name = "vector_test", - srcs = ["vector_test.cc"], - external_deps = [ - "gtest", - ], - language = "C++", - deps = [ - "//:grpc", - "//test/core/util:gpr_test_util", - ], -) - -grpc_cc_test( - name = "ref_counted_test", - srcs = ["ref_counted_test.cc"], - language = "C++", - deps = [ - "//:ref_counted", - "//test/core/util:gpr_test_util", - ], - external_deps = [ - "gtest", - ], -) - -grpc_cc_test( - name = "ref_counted_ptr_test", - srcs = ["ref_counted_ptr_test.cc"], - language = "C++", - deps = [ - "//:ref_counted", - "//:ref_counted_ptr", - "//test/core/util:gpr_test_util", - ], - external_deps = [ - "gtest", - ], -) diff --git a/test/core/support/alloc_test.cc b/test/core/gpr/alloc_test.cc index 6074c6e6e7..6074c6e6e7 100644 --- a/test/core/support/alloc_test.cc +++ b/test/core/gpr/alloc_test.cc diff --git a/test/core/support/arena_test.cc b/test/core/gpr/arena_test.cc index ada0f43854..59ea04c0ed 100644 --- a/test/core/support/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/support/arena.h" +#include "src/core/lib/gpr/arena.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -27,7 +27,7 @@ #include <inttypes.h> #include <string.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" static void test_noop(void) { gpr_arena_destroy(gpr_arena_create(1)); } diff --git a/test/core/support/avl_test.cc b/test/core/gpr/avl_test.cc index 345db557b9..345db557b9 100644 --- a/test/core/support/avl_test.cc +++ b/test/core/gpr/avl_test.cc diff --git a/test/core/support/cmdline_test.cc b/test/core/gpr/cmdline_test.cc index 172efda8a0..172efda8a0 100644 --- a/test/core/support/cmdline_test.cc +++ b/test/core/gpr/cmdline_test.cc diff --git a/test/core/support/cpu_test.cc b/test/core/gpr/cpu_test.cc index 334c4318e1..87cdc0fb50 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/gpr/cpu_test.cc @@ -119,13 +119,16 @@ static void cpu_test(void) { } gpr_mu_unlock(&ct.mu); fprintf(stderr, "Saw cores ["); + fflush(stderr); for (i = 0; i < ct.ncores; i++) { if (ct.used[i]) { fprintf(stderr, "%d,", i); + fflush(stderr); cores_seen++; } } fprintf(stderr, "] (%d/%d)\n", cores_seen, ct.ncores); + fflush(stderr); gpr_free(ct.used); } diff --git a/test/core/support/env_test.cc b/test/core/gpr/env_test.cc index b12c04d06f..3f4b493239 100644 --- a/test/core/support/env_test.cc +++ b/test/core/gpr/env_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/support/host_port_test.cc b/test/core/gpr/host_port_test.cc index 42dd56524f..42dd56524f 100644 --- a/test/core/support/host_port_test.cc +++ b/test/core/gpr/host_port_test.cc diff --git a/test/core/support/log_test.cc b/test/core/gpr/log_test.cc index 7dba35c13e..839ff0aef9 100644 --- a/test/core/support/log_test.cc +++ b/test/core/gpr/log_test.cc @@ -21,7 +21,7 @@ #include <stdbool.h> #include <string.h> -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "test/core/util/test_config.h" static bool log_func_reached = false; diff --git a/test/core/support/mpscq_test.cc b/test/core/gpr/mpscq_test.cc index 1b83f7d5be..5a8177543c 100644 --- a/test/core/support/mpscq_test.cc +++ b/test/core/gpr/mpscq_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/support/mpscq.h" +#include "src/core/lib/gpr/mpscq.h" #include <stdlib.h> diff --git a/test/core/support/murmur_hash_test.cc b/test/core/gpr/murmur_hash_test.cc index 461c728951..d920dd3f95 100644 --- a/test/core/support/murmur_hash_test.cc +++ b/test/core/gpr/murmur_hash_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/support/murmur_hash.h" +#include "src/core/lib/gpr/murmur_hash.h" #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include "test/core/util/test_config.h" diff --git a/test/core/support/spinlock_test.cc b/test/core/gpr/spinlock_test.cc index 58d5fcd42b..77e3dfbede 100644 --- a/test/core/support/spinlock_test.cc +++ b/test/core/gpr/spinlock_test.cc @@ -18,7 +18,7 @@ /* Test of gpr synchronization support. */ -#include "src/core/lib/support/spinlock.h" +#include "src/core/lib/gpr/spinlock.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> @@ -95,15 +95,18 @@ static void test(const char* name, void (*body)(void* m), int timeout_s, gpr_timespec deadline = gpr_time_add( start, gpr_time_from_micros((int64_t)timeout_s * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); + fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { if (iterations < INT64_MAX / 2) iterations <<= 1; fprintf(stderr, " %ld", (long)iterations); + fflush(stderr); m = test_new(10, iterations, incr_step); test_create_threads(m, body); test_wait(m); if (m->counter != m->thread_count * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", (long)m->counter, m->thread_count, (long)m->iterations); + fflush(stderr); GPR_ASSERT(0); } test_destroy(m); @@ -111,6 +114,7 @@ static void test(const char* name, void (*body)(void* m), int timeout_s, time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec, (int)time_taken.tv_nsec); + fflush(stderr); } /* Increment m->counter on each iteration; then mark thread as done. */ diff --git a/test/core/support/string_test.cc b/test/core/gpr/string_test.cc index fd7f7cde59..57068eb2c9 100644 --- a/test/core/support/string_test.cc +++ b/test/core/gpr/string_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include <limits.h> #include <stddef.h> diff --git a/test/core/support/sync_test.cc b/test/core/gpr/sync_test.cc index fb7ec44754..768f96d093 100644 --- a/test/core/support/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -231,16 +231,17 @@ static void mark_thread_done(struct test* m) { */ static void test(const char* name, void (*body)(void* m), void (*extra)(void* m), int timeout_s, int incr_step) { - int64_t iterations = 1024; + int64_t iterations = 256; struct test* m; gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add( start, gpr_time_from_micros((int64_t)timeout_s * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); + fflush(stderr); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { - iterations <<= 1; fprintf(stderr, " %ld", (long)iterations); + fflush(stderr); m = test_new(10, iterations, incr_step); if (extra != nullptr) { gpr_thd_id id; @@ -252,13 +253,16 @@ static void test(const char* name, void (*body)(void* m), if (m->counter != m->threads * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", (long)m->counter, m->threads, (long)m->iterations); + fflush(stderr); GPR_ASSERT(0); } test_destroy(m); + iterations <<= 1; } time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec, (int)time_taken.tv_nsec); + fflush(stderr); } /* Increment m->counter on each iteration; then mark thread as done. */ diff --git a/test/core/support/thd_test.cc b/test/core/gpr/thd_test.cc index b755bf18f3..b755bf18f3 100644 --- a/test/core/support/thd_test.cc +++ b/test/core/gpr/thd_test.cc diff --git a/test/core/support/time_test.cc b/test/core/gpr/time_test.cc index 608169274f..b2b4dce58e 100644 --- a/test/core/support/time_test.cc +++ b/test/core/gpr/time_test.cc @@ -66,21 +66,28 @@ static void test_values(void) { x = gpr_inf_future(GPR_CLOCK_REALTIME); fprintf(stderr, "far future "); + fflush(stderr); i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(x.tv_sec == INT64_MAX); fprintf(stderr, "far future "); + fflush(stderr); ts_to_s(x, &to_fp, stderr); fprintf(stderr, "\n"); + fflush(stderr); x = gpr_inf_past(GPR_CLOCK_REALTIME); fprintf(stderr, "far past "); + fflush(stderr); i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); + fflush(stderr); GPR_ASSERT(x.tv_sec == INT64_MIN); fprintf(stderr, "far past "); + fflush(stderr); ts_to_s(x, &to_fp, stderr); fprintf(stderr, "\n"); + fflush(stderr); for (i = 1; i != 1000 * 1000 * 1000; i *= 10) { x = gpr_time_from_micros(i, GPR_TIMESPAN); @@ -135,15 +142,19 @@ static void test_add_sub(void) { if (gpr_time_cmp(gpr_time_from_micros(sum * k, GPR_TIMESPAN), sumt) != 0) { fprintf(stderr, "i %d j %d sum %d sumt ", i, j, sum); + fflush(stderr); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); + fflush(stderr); GPR_ASSERT(0); } if (gpr_time_cmp(gpr_time_from_micros(diff * k, GPR_TIMESPAN), difft) != 0) { fprintf(stderr, "i %d j %d diff %d diff ", i, j, diff); + fflush(stderr); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); + fflush(stderr); GPR_ASSERT(0); } } diff --git a/test/core/support/tls_test.cc b/test/core/gpr/tls_test.cc index 743b10f090..743b10f090 100644 --- a/test/core/support/tls_test.cc +++ b/test/core/gpr/tls_test.cc diff --git a/test/core/support/useful_test.cc b/test/core/gpr/useful_test.cc index 2f86010d77..2f86010d77 100644 --- a/test/core/support/useful_test.cc +++ b/test/core/gpr/useful_test.cc diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index e767e01f21..262470300e 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -18,7 +18,7 @@ #include "src/core/lib/iomgr/port.h" /* This test only relevant on linux systems where epoll() is available */ -#ifdef GRPC_LINUX_EPOLL +#ifdef GRPC_LINUX_EPOLL_CREATE1 #include "src/core/lib/iomgr/ev_epollsig_linux.h" #include "src/core/lib/iomgr/ev_posix.h" @@ -319,6 +319,6 @@ int main(int argc, char** argv) { grpc_shutdown(); return 0; } -#else /* defined(GRPC_LINUX_EPOLL) */ +#else /* defined(GRPC_LINUX_EPOLL_CREATE1) */ int main(int argc, char** argv) { return 0; } -#endif /* !defined(GRPC_LINUX_EPOLL) */ +#endif /* !defined(GRPC_LINUX_EPOLL_CREATE1) */ diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index aaa14010f8..4866e350d5 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -43,7 +43,7 @@ int main(int argc, char** argv) { grpc_resource_quota_create("fd_conservation_posix_test"); for (i = 0; i < 100; i++) { - p = grpc_iomgr_create_endpoint_pair("test", NULL); + p = grpc_iomgr_create_endpoint_pair("test", nullptr); grpc_endpoint_destroy(p.client); grpc_endpoint_destroy(p.server); grpc_core::ExecCtx::Get()->Flush(); diff --git a/test/core/iomgr/load_file_test.cc b/test/core/iomgr/load_file_test.cc index 797d0ef1a4..38c8710535 100644 --- a/test/core/iomgr/load_file_test.cc +++ b/test/core/iomgr/load_file_test.cc @@ -24,9 +24,9 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/iomgr/load_file.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" #include "test/core/util/test_config.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/iomgr/pollset_set_test.cc b/test/core/iomgr/pollset_set_test.cc index f27079134b..7d2f59bed4 100644 --- a/test/core/iomgr/pollset_set_test.cc +++ b/test/core/iomgr/pollset_set_test.cc @@ -18,7 +18,7 @@ #include "src/core/lib/iomgr/port.h" /* This test only relevant on linux systems where epoll is available */ -#ifdef GRPC_LINUX_EPOLL +#ifdef GRPC_LINUX_EPOLL_CREATE1 #include <errno.h> #include <string.h> @@ -443,6 +443,6 @@ int main(int argc, char** argv) { grpc_shutdown(); return 0; } -#else /* defined(GRPC_LINUX_EPOLL) */ +#else /* defined(GRPC_LINUX_EPOLL_CREATE1) */ int main(int argc, char** argv) { return 0; } -#endif /* !defined(GRPC_LINUX_EPOLL) */ +#endif /* !defined(GRPC_LINUX_EPOLL_CREATE1) */ diff --git a/test/core/iomgr/resource_quota_test.cc b/test/core/iomgr/resource_quota_test.cc index ae26f72701..07682d2630 100644 --- a/test/core/iomgr/resource_quota_test.cc +++ b/test/core/iomgr/resource_quota_test.cc @@ -118,7 +118,7 @@ static void test_instant_alloc_then_free(void) { grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); + grpc_resource_user_alloc(usr, 1024, nullptr); } { grpc_core::ExecCtx exec_ctx; @@ -136,7 +136,7 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); + grpc_resource_user_alloc(usr, 1024, nullptr); grpc_resource_user_free(usr, 1024); } grpc_resource_quota_unref(q); @@ -565,7 +565,7 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_user* usr = grpc_resource_user_create(q, "usr"); { grpc_core::ExecCtx exec_ctx; - grpc_resource_user_alloc(usr, 1024, NULL); + grpc_resource_user_alloc(usr, 1024, nullptr); } { grpc_core::ExecCtx exec_ctx; @@ -608,8 +608,8 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(gpr_event_wait(&allocated, - grpc_timeout_seconds_to_deadline(5)) != NULL); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( + 5)) != nullptr); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); @@ -667,8 +667,8 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { grpc_core::ExecCtx exec_ctx; grpc_resource_user_alloc(usr, 1024, set_event(&allocated)); grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(gpr_event_wait(&allocated, - grpc_timeout_seconds_to_deadline(5)) != NULL); + GPR_ASSERT(gpr_event_wait(&allocated, grpc_timeout_seconds_to_deadline( + 5)) != nullptr); GPR_ASSERT(gpr_event_wait(&reclaimer_done, grpc_timeout_seconds_to_deadline(5)) != nullptr); diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 0deb534abd..09f0283013 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -49,8 +49,14 @@ static int g_number_of_reads = 0; static int g_number_of_writes = 0; static int g_number_of_bytes_read = 0; static int g_number_of_orphan_calls = 0; +static int g_number_of_starts = 0; -static bool on_read(grpc_fd* emfd, void* user_data) { +int rcv_buf_size = 1024; +int snd_buf_size = 1024; + +static void on_start(grpc_fd* emfd, void* user_data) { g_number_of_starts++; } + +static bool on_read(grpc_fd* emfd) { char read_buffer[512]; ssize_t byte_count; @@ -129,21 +135,41 @@ static test_socket_factory* test_socket_factory_create(void) { return factory; } +static void destroy_pollset(void* p, grpc_error* error) { + grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); +} + +static void shutdown_and_destroy_pollset() { + gpr_mu_lock(g_mu); + auto closure = GRPC_CLOSURE_CREATE(destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, closure); + gpr_mu_unlock(g_mu); + /* Flush exec_ctx to run |destroyed| */ + grpc_core::ExecCtx::Get()->Flush(); +} + static void test_no_op(void) { + grpc_pollset_init(g_pollset, &g_mu); grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); + LOG_TEST("test_no_op"); grpc_udp_server_destroy(s, nullptr); + shutdown_and_destroy_pollset(); } static void test_no_op_with_start(void) { + grpc_pollset_init(g_pollset, &g_mu); grpc_core::ExecCtx exec_ctx; grpc_udp_server* s = grpc_udp_server_create(nullptr); LOG_TEST("test_no_op_with_start"); grpc_udp_server_start(s, nullptr, 0, nullptr); grpc_udp_server_destroy(s, nullptr); + shutdown_and_destroy_pollset(); } static void test_no_op_with_port(void) { + grpc_pollset_init(g_pollset, &g_mu); g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; @@ -154,16 +180,19 @@ static void test_no_op_with_port(void) { memset(&resolved_addr, 0, sizeof(resolved_addr)); resolved_addr.len = sizeof(struct sockaddr_in); addr->sin_family = AF_INET; - GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, + GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, + snd_buf_size, on_start, on_read, on_write, on_fd_orphaned)); grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); + shutdown_and_destroy_pollset(); } static void test_no_op_with_port_and_socket_factory(void) { + grpc_pollset_init(g_pollset, &g_mu); g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; @@ -182,7 +211,8 @@ static void test_no_op_with_port_and_socket_factory(void) { memset(&resolved_addr, 0, sizeof(resolved_addr)); resolved_addr.len = sizeof(struct sockaddr_in); addr->sin_family = AF_INET; - GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, + GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, + snd_buf_size, on_start, on_read, on_write, on_fd_orphaned)); GPR_ASSERT(socket_factory->number_of_socket_calls == 1); GPR_ASSERT(socket_factory->number_of_bind_calls == 1); @@ -193,9 +223,11 @@ static void test_no_op_with_port_and_socket_factory(void) { /* The server had a single FD, which should have been orphaned. */ GPR_ASSERT(g_number_of_orphan_calls == 1); + shutdown_and_destroy_pollset(); } static void test_no_op_with_port_and_start(void) { + grpc_pollset_init(g_pollset, &g_mu); g_number_of_orphan_calls = 0; grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; @@ -206,19 +238,22 @@ static void test_no_op_with_port_and_start(void) { memset(&resolved_addr, 0, sizeof(resolved_addr)); resolved_addr.len = sizeof(struct sockaddr_in); addr->sin_family = AF_INET; - GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, + GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, + snd_buf_size, on_start, on_read, on_write, on_fd_orphaned)); grpc_udp_server_start(s, nullptr, 0, nullptr); - + GPR_ASSERT(g_number_of_starts == 1); grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ GPR_ASSERT(g_number_of_orphan_calls == 1); + shutdown_and_destroy_pollset(); } static void test_receive(int number_of_clients) { + grpc_pollset_init(g_pollset, &g_mu); grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; struct sockaddr_storage* addr = (struct sockaddr_storage*)resolved_addr.addr; @@ -236,7 +271,8 @@ static void test_receive(int number_of_clients) { memset(&resolved_addr, 0, sizeof(resolved_addr)); resolved_addr.len = sizeof(struct sockaddr_storage); addr->ss_family = AF_INET; - GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write, + GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, + snd_buf_size, on_start, on_read, on_write, on_fd_orphaned)); svrfd = grpc_udp_server_get_fd(s, 0); @@ -281,20 +317,15 @@ static void test_receive(int number_of_clients) { /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ GPR_ASSERT(g_number_of_orphan_calls == 1); -} - -static void destroy_pollset(void* p, grpc_error* error) { - grpc_pollset_destroy(static_cast<grpc_pollset*>(p)); + shutdown_and_destroy_pollset(); } int main(int argc, char** argv) { - grpc_closure destroyed; grpc_test_init(argc, argv); grpc_init(); { grpc_core::ExecCtx exec_ctx; g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); test_no_op(); test_no_op_with_start(); @@ -304,10 +335,6 @@ int main(int argc, char** argv) { test_receive(1); test_receive(10); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - grpc_core::ExecCtx::Get()->Flush(); gpr_free(g_pollset); } grpc_shutdown(); diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index d4e05bd7ef..c092a8f3bf 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -27,9 +27,9 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_posix.h" -#include "src/core/lib/support/env.h" typedef struct poll_args { struct pollfd* fds; diff --git a/test/core/json/json_test.cc b/test/core/json/json_test.cc index 18b9c55ee7..902f1cd90e 100644 --- a/test/core/json/json_test.cc +++ b/test/core/json/json_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/useful.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/json/json.h" -#include "src/core/lib/support/string.h" #include "test/core/util/test_config.h" diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc index eb90067970..ca841434aa 100644 --- a/test/core/memory_usage/client.cc +++ b/test/core/memory_usage/client.cc @@ -28,8 +28,8 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/memory_counters.h" #include "test/core/util/test_config.h" diff --git a/test/core/memory_usage/memory_usage_test.cc b/test/core/memory_usage/memory_usage_test.cc index 58e31c9531..fb6d290130 100644 --- a/test/core/memory_usage/memory_usage_test.cc +++ b/test/core/memory_usage/memory_usage_test.cc @@ -23,7 +23,7 @@ #include <grpc/support/host_port.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/port.h" int main(int argc, char** argv) { diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 96b0745f52..fb982a10fd 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -535,6 +535,7 @@ void print_usage(char* argv0) { fprintf(stderr, " tcp: fds are endpoints of a TCP connection\n"); fprintf(stderr, " socketpair: fds come from socketpair()\n"); fprintf(stderr, " pipe: fds come from pipe()\n"); + fflush(stderr); } typedef struct test_strategy { @@ -565,6 +566,7 @@ int create_socket(const char* socket_type, fd_pair* client_fds, create_sockets_pipe(client_fds, server_fds); } else { fprintf(stderr, "Invalid socket type %s\n", socket_type); + fflush(stderr); return -1; } return 0; @@ -657,6 +659,7 @@ int main(int argc, char** argv) { } if (msg_size <= 0) { fprintf(stderr, "msg_size must be > 0\n"); + fflush(stderr); print_usage(argv[0]); return -1; } @@ -668,6 +671,7 @@ int main(int argc, char** argv) { } if (strategy == nullptr) { fprintf(stderr, "Invalid read strategy %s\n", read_strategy); + fflush(stderr); return -1; } diff --git a/test/core/security/auth_context_test.cc b/test/core/security/auth_context_test.cc index d8e41326c0..58f0d8e1c2 100644 --- a/test/core/security/auth_context_test.cc +++ b/test/core/security/auth_context_test.cc @@ -18,8 +18,8 @@ #include <string.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/security/context/security_context.h" -#include "src/core/lib/support/string.h" #include "test/core/util/test_config.h" #include <grpc/support/log.h> diff --git a/test/core/security/create_jwt.cc b/test/core/security/create_jwt.cc index 867a8ba575..56ae9c891c 100644 --- a/test/core/security/create_jwt.cc +++ b/test/core/security/create_jwt.cc @@ -39,6 +39,7 @@ void create_jwt(const char* json_key_file_path, const char* service_url, grpc_slice_unref(json_key_data); if (!grpc_auth_json_key_is_valid(&key)) { fprintf(stderr, "Could not parse json key.\n"); + fflush(stderr); exit(1); } jwt = grpc_jwt_encode_and_sign( @@ -47,6 +48,7 @@ void create_jwt(const char* json_key_file_path, const char* service_url, grpc_auth_json_key_destruct(&key); if (jwt == nullptr) { fprintf(stderr, "Could not create JWT.\n"); + fflush(stderr); exit(1); } fprintf(stdout, "%s\n", jwt); @@ -72,16 +74,19 @@ int main(int argc, char** argv) { if (json_key_file_path == nullptr) { fprintf(stderr, "Missing --json_key option.\n"); + fflush(stderr); exit(1); } if (scope != nullptr) { if (service_url != nullptr) { fprintf(stderr, "Options --scope and --service_url are mutually exclusive.\n"); + fflush(stderr); exit(1); } } else if (service_url == nullptr) { fprintf(stderr, "Need one of --service_url or --scope options.\n"); + fflush(stderr); exit(1); } diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index ecc61928f5..90310469aa 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -31,6 +31,9 @@ #include <grpc/support/string_util.h> #include <grpc/support/time.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/http/httpcli.h" #include "src/core/lib/security/credentials/composite/composite_credentials.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" @@ -38,9 +41,6 @@ #include "src/core/lib/security/credentials/jwt/jwt_credentials.h" #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h" #include "src/core/lib/security/transport/auth_filters.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/util/test_config.h" /* -- Mock channel credentials. -- */ diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc index b3742f58a8..a90f997bda 100644 --- a/test/core/security/print_google_default_creds_token.cc +++ b/test/core/security/print_google_default_creds_token.cc @@ -27,10 +27,10 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/security/credentials/composite/composite_credentials.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" typedef struct { gpr_mu* mu; @@ -45,6 +45,7 @@ static void on_metadata_response(void* arg, grpc_error* error) { synchronizer* sync = static_cast<synchronizer*>(arg); if (error != GRPC_ERROR_NONE) { fprintf(stderr, "Fetching token failed: %s\n", grpc_error_string(error)); + fflush(stderr); } else { char* token; GPR_ASSERT(sync->md_array.size == 1); @@ -81,6 +82,7 @@ int main(int argc, char** argv) { creds = grpc_google_default_credentials_create(); if (creds == nullptr) { fprintf(stderr, "\nCould not find default credentials.\n\n"); + fflush(stderr); result = 1; goto end; } diff --git a/test/core/security/security_connector_test.cc b/test/core/security/security_connector_test.cc index 9a68e176db..6eaef2bf49 100644 --- a/test/core/security/security_connector_test.cc +++ b/test/core/security/security_connector_test.cc @@ -25,12 +25,12 @@ #include <grpc/support/string_util.h> #include <grpc/support/useful.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/context/security_context.h" #include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" #include "test/core/util/test_config.h" diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc index e039970c67..5d32ce0cdb 100644 --- a/test/core/security/verify_jwt.cc +++ b/test/core/security/verify_jwt.cc @@ -39,6 +39,7 @@ typedef struct { static void print_usage_and_exit(gpr_cmdline* cl, const char* argv0) { char* usage = gpr_cmdline_usage_string(cl, argv0); fprintf(stderr, "%s", usage); + fflush(stderr); gpr_free(usage); gpr_cmdline_destroy(cl); exit(1); @@ -62,6 +63,7 @@ static void on_jwt_verification_done(void* user_data, GPR_ASSERT(claims == nullptr); fprintf(stderr, "Verification failed with error %s\n", grpc_jwt_verifier_status_to_string(status)); + fflush(stderr); } gpr_mu_lock(sync->mu); diff --git a/test/core/slice/percent_encoding_test.cc b/test/core/slice/percent_encoding_test.cc index 11f3995f98..e8d04fcc83 100644 --- a/test/core/slice/percent_encoding_test.cc +++ b/test/core/slice/percent_encoding_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" #include "test/core/util/test_config.h" #define TEST_VECTOR(raw, encoded, dict) \ diff --git a/test/core/slice/slice_string_helpers_test.cc b/test/core/slice/slice_string_helpers_test.cc index ceb36ff438..1e38f8daca 100644 --- a/test/core/slice/slice_string_helpers_test.cc +++ b/test/core/slice/slice_string_helpers_test.cc @@ -28,7 +28,7 @@ #include <grpc/support/string_util.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/support/vector_test.cc b/test/core/support/vector_test.cc deleted file mode 100644 index aad9f3be90..0000000000 --- a/test/core/support/vector_test.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Copyright 2017 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 "src/core/lib/support/vector.h" -#include <gtest/gtest.h> -#include "test/core/util/test_config.h" - -namespace grpc_core { -namespace testing { - -TEST(InlinedVectorTest, CreateAndIterate) { - InlinedVector<int, 1> v{1, 2, 3}; - int sum = 0; - for (auto i : v) { - sum += i; - } - EXPECT_EQ(6, sum); -} - -} // namespace testing -} // namespace grpc_core - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/core/surface/alarm_test.cc b/test/core/surface/alarm_test.cc index 8950603b41..67fc6833a5 100644 --- a/test/core/surface/alarm_test.cc +++ b/test/core/surface/alarm_test.cc @@ -34,8 +34,15 @@ static void* create_test_tag(void) { static void shutdown_and_destroy(grpc_completion_queue* cc) { grpc_event ev; grpc_completion_queue_shutdown(cc); - ev = - grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), nullptr); + /* By the time grpc_completion_queue_shutdown runs, the cq's internal + pending event counter might not have been updated yet by a previous + cq_end_op_for_next (which releases a completed event first and only later + updates the pending event counter), so we can't rely on a no-polling + cq_next to never return GRPC_QUEUE_TIMEOUT. Using a deadline in the future + solves the problem. See https://github.com/grpc/grpc/issues/13693. + */ + ev = grpc_completion_queue_next(cc, grpc_timeout_seconds_to_deadline(2), + nullptr); GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); grpc_completion_queue_destroy(cc); } diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index 22f6e21796..f4de5d7d8a 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -30,7 +30,6 @@ #include <grpc/impl/codegen/byte_buffer_reader.h> #include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/connectivity_state.h> -#include <grpc/impl/codegen/exec_ctx_fwd.h> #include <grpc/impl/codegen/fork.h> #include <grpc/impl/codegen/gpr_slice.h> #include <grpc/impl/codegen/gpr_types.h> diff --git a/test/core/transport/bdp_estimator_test.cc b/test/core/transport/bdp_estimator_test.cc index 445823b628..3afcad7f17 100644 --- a/test/core/transport/bdp_estimator_test.cc +++ b/test/core/transport/bdp_estimator_test.cc @@ -25,8 +25,8 @@ #include <grpc/support/useful.h> #include <gtest/gtest.h> #include <limits.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/timer_manager.h" -#include "src/core/lib/support/string.h" #include "test/core/util/test_config.h" extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type); diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 6d70a4261b..283eebbacf 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -24,9 +24,9 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" static int all_ok = 1; diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 44f5de8a50..bd62b0e479 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -26,8 +26,8 @@ #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" static int all_ok = 1; diff --git a/test/core/transport/chttp2/hpack_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc index d2dbd4a798..a40bd643ec 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.cc +++ b/test/core/transport/chttp2/hpack_encoder_test.cc @@ -26,9 +26,9 @@ #include <grpc/support/string_util.h> #include "src/core/ext/transport/chttp2/transport/hpack_parser.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/string.h" #include "src/core/lib/transport/metadata.h" #include "test/core/util/parse_hexstring.h" #include "test/core/util/slice_splitter.h" diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc index 3f3cb2ee9d..e316cf63a0 100644 --- a/test/core/transport/chttp2/hpack_table_test.cc +++ b/test/core/transport/chttp2/hpack_table_test.cc @@ -26,7 +26,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc index 08473c72b6..d7d6ee7508 100644 --- a/test/core/transport/chttp2/settings_timeout_test.cc +++ b/test/core/transport/chttp2/settings_timeout_test.cc @@ -21,6 +21,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> +#include <functional> #include <memory> #include <thread> diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index 5c52ae8d5f..7d943fd5c7 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -27,8 +27,8 @@ #include <grpc/support/string_util.h> #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" diff --git a/test/core/transport/pid_controller_test.cc b/test/core/transport/pid_controller_test.cc index 081d03472a..1a499c2fb7 100644 --- a/test/core/transport/pid_controller_test.cc +++ b/test/core/transport/pid_controller_test.cc @@ -26,7 +26,7 @@ #include <grpc/support/string_util.h> #include <grpc/support/useful.h> #include <gtest/gtest.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" namespace grpc_core { diff --git a/test/core/transport/timeout_encoding_test.cc b/test/core/transport/timeout_encoding_test.cc index 0930bc836d..e94be138dd 100644 --- a/test/core/transport/timeout_encoding_test.cc +++ b/test/core/transport/timeout_encoding_test.cc @@ -25,8 +25,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/murmur_hash.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/murmur_hash.h" +#include "src/core/lib/gpr/string.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) diff --git a/test/core/tsi/transport_security_test.cc b/test/core/tsi/transport_security_test.cc index c788ad96ad..42e17df25d 100644 --- a/test/core/tsi/transport_security_test.cc +++ b/test/core/tsi/transport_security_test.cc @@ -27,7 +27,7 @@ #include <openssl/crypto.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" #include "test/core/util/test_config.h" diff --git a/test/core/util/debugger_macros.cc b/test/core/util/debugger_macros.cc index f1e4ffd3af..bb96fc7054 100644 --- a/test/core/util/debugger_macros.cc +++ b/test/core/util/debugger_macros.cc @@ -39,6 +39,7 @@ grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { grpc_subchannel_call* scc = grpc_client_channel_get_subchannel_call(el); if (scc == nullptr) { fprintf(stderr, "No subchannel-call"); + fflush(stderr); return nullptr; } cs = grpc_subchannel_call_get_call_stack(scc); @@ -46,6 +47,7 @@ grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { return grpc_connected_channel_get_stream(el); } else { fprintf(stderr, "Unrecognized filter: %s", el->filter->name); + fflush(stderr); return nullptr; } } diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index 9ebb52d83e..6b410440c2 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -27,8 +27,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" int64_t g_fixture_slowdown_factor = 1; int64_t g_poller_slowdown_factor = 1; diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index e829d5278b..80d1583333 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -19,6 +19,7 @@ #include <atomic> #include <memory> #include <mutex> +#include <random> #include <sstream> #include <thread> @@ -104,8 +105,8 @@ class BalancerServiceImpl : public LoadBalancer::Service { for (size_t i = 0; i < num_drop_entry; ++i) { random_backend_indices.push_back(-1); } - std::random_shuffle(random_backend_indices.begin(), - random_backend_indices.end()); + std::shuffle(random_backend_indices.begin(), random_backend_indices.end(), + std::mt19937(std::random_device()())); // Build the response according to the random list generated above. LoadBalanceResponse response; for (int index : random_backend_indices) { @@ -149,7 +150,8 @@ class ClientChannelStressTest { addresses.emplace_back(AddressData{balancer_server.port_, true, ""}); } } - std::random_shuffle(addresses.begin(), addresses.end()); + std::shuffle(addresses.begin(), addresses.end(), + std::mt19937(std::random_device()())); SetNextResolution(addresses); std::this_thread::sleep_for(wait_duration); } diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 6cc81e3398..1388dbc650 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -14,7 +14,7 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package", "grpc_cc_binary", "grpc_sh_test") grpc_package(name = "test/cpp/codegen") @@ -55,14 +55,10 @@ grpc_cc_test( ], ) -grpc_cc_test( +grpc_cc_binary( name = "golden_file_test", + testonly = True, srcs = ["golden_file_test.cc"], - args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/"], - data = [ - ":compiler_test_golden", - "//src/proto/grpc/testing:_compiler_test_proto_grpc_codegen", - ], deps = [ "//:grpc++", "//src/proto/grpc/testing:compiler_test_proto", @@ -73,3 +69,14 @@ grpc_cc_test( "gflags", ], ) + +grpc_sh_test( + name = "run_golden_file_test", + srcs = ["run_golden_file_test.sh"], + data = [ + ":golden_file_test", + ":compiler_test_golden", + ":compiler_test_mock_golden", + "//src/proto/grpc/testing:_compiler_test_proto_grpc_codegen", + ], +) diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index 14880982b5..7e4d15a7c9 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -22,6 +22,13 @@ #include <gflags/gflags.h> #include <gtest/gtest.h> +// In some distros, gflags is in the namespace google, and in some others, +// in gflags. This hack is enabling us to find both. +namespace google {} +namespace gflags {} +using namespace google; +using namespace gflags; + DEFINE_string( generated_file_path, "", "path to the directory containing generated files compiler_test.grpc.pb.h" @@ -60,7 +67,7 @@ TEST(GoldenMockFileTest, TestGeneratedMockFile) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_generated_file_path.empty()) { FLAGS_generated_file_path = "gens/src/proto/grpc/testing/"; } diff --git a/test/cpp/codegen/run_golden_file_test.sh b/test/cpp/codegen/run_golden_file_test.sh new file mode 100755 index 0000000000..cdfaa96a1c --- /dev/null +++ b/test/cpp/codegen/run_golden_file_test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Copyright 2017 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. + +set -ex + +GENERATED_FILES_PATH="$TEST_SRCDIR/../../../../../genfiles/src/proto/grpc/testing/" +test/cpp/codegen/golden_file_test --generated_file_path="$GENERATED_FILES_PATH" diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index b29a13d4fb..8894c68b95 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -14,27 +14,33 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package", "grpc_cc_binary") -grpc_package(name = "test/cpp/end2end", visibility = "public") # Allows external users to implement end2end tests. +grpc_package( + name = "test/cpp/end2end", + visibility = "public", +) # Allows external users to implement end2end tests. grpc_cc_library( name = "test_service_impl", testonly = True, srcs = ["test_service_impl.cc"], hdrs = ["test_service_impl.h"], + external_deps = [ + "gtest", + ], deps = [ "//src/proto/grpc/testing:echo_proto", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "async_end2end_test", srcs = ["async_end2end_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -47,14 +53,17 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "client_crash_test", srcs = ["client_crash_test.cc"], + data = [ + ":client_crash_test_server", + ], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -66,14 +75,16 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) -grpc_cc_test( +grpc_cc_binary( name = "client_crash_test_server", + testonly = True, srcs = ["client_crash_test_server.cc"], + external_deps = [ + "gflags", + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -85,16 +96,15 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gflags", - "gtest", - ], ) grpc_cc_library( name = "end2end_test_lib", - srcs = ["end2end_test.cc"], testonly = True, + srcs = ["end2end_test.cc"], + external_deps = [ + "gtest", + ], deps = [ ":test_service_impl", "//:gpr", @@ -107,40 +117,58 @@ grpc_cc_library( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "end2end_test", deps = [ - ":end2end_test_lib" + ":end2end_test_lib", ], ) grpc_cc_test( - name = "filter_end2end_test", - srcs = ["filter_end2end_test.cc"], + name = "exception_test", + srcs = ["exception_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", "//:grpc++", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", - "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], +) + +grpc_cc_test( + name = "filter_end2end_test", + srcs = ["filter_end2end_test.cc"], external_deps = [ "gtest", ], + deps = [ + "//:gpr", + "//:grpc", + "//:grpc++", + "//src/proto/grpc/testing:echo_messages_proto", + "//src/proto/grpc/testing:echo_proto", + "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//test/core/util:gpr_test_util", + "//test/core/util:grpc_test_util", + "//test/cpp/util:test_util", + ], ) grpc_cc_test( name = "generic_end2end_test", srcs = ["generic_end2end_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -152,14 +180,14 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "hybrid_end2end_test", srcs = ["hybrid_end2end_test.cc"], + external_deps = [ + "gtest", + ], deps = [ ":test_service_impl", "//:gpr", @@ -172,14 +200,15 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "mock_test", srcs = ["mock_test.cc"], + external_deps = [ + "gmock", + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -192,15 +221,14 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gmock", - "gtest", - ], ) grpc_cc_test( name = "client_lb_end2end_test", srcs = ["client_lb_end2end_test.cc"], + external_deps = [ + "gtest", + ], deps = [ ":test_service_impl", "//:gpr", @@ -213,37 +241,38 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "grpclb_end2end_test", srcs = ["grpclb_end2end_test.cc"], + external_deps = [ + "gmock", + "gtest", + ], deps = [ ":test_service_impl", "//:gpr", "//:grpc", "//:grpc++", + "//:grpc_resolver_fake", "//src/proto/grpc/lb/v1:load_balancer_proto", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", - "//:grpc_resolver_fake", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gmock", - "gtest", - ], ) grpc_cc_test( name = "proto_server_reflection_test", srcs = ["proto_server_reflection_test.cc"], + external_deps = [ + "gtest", + "gflags", + ], deps = [ ":test_service_impl", "//:gpr", @@ -258,15 +287,14 @@ grpc_cc_test( "//test/cpp/util:grpc++_proto_reflection_desc_db", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - "gflags", - ], ) grpc_cc_test( name = "server_builder_plugin_test", srcs = ["server_builder_plugin_test.cc"], + external_deps = [ + "gtest", + ], deps = [ ":test_service_impl", "//:gpr", @@ -279,14 +307,17 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "server_crash_test", srcs = ["server_crash_test.cc"], + data = [ + ":server_crash_test_client", + ], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -298,14 +329,16 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) -grpc_cc_test( +grpc_cc_binary( name = "server_crash_test_client", + testonly = True, srcs = ["server_crash_test_client.cc"], + external_deps = [ + "gflags", + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -317,15 +350,14 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gflags", - "gtest", - ], ) grpc_cc_test( name = "shutdown_test", srcs = ["shutdown_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -337,14 +369,14 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "streaming_throughput_test", srcs = ["streaming_throughput_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -356,14 +388,14 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "thread_stress_test", srcs = ["thread_stress_test.cc"], + external_deps = [ + "gtest", + ], deps = [ "//:gpr", "//:grpc", @@ -375,7 +407,4 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - external_deps = [ - "gtest", - ], ) diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 1ea087e706..44cd81a6a4 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -34,8 +34,8 @@ #include <grpc/support/time.h> #include <grpc/support/tls.h> +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/port.h" -#include "src/core/lib/support/env.h" #include "src/proto/grpc/health/v1/health.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index e83a6e675e..328ad86061 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -19,6 +19,7 @@ #include <algorithm> #include <memory> #include <mutex> +#include <random> #include <thread> #include <grpc++/channel.h> @@ -28,6 +29,7 @@ #include <grpc++/server_builder.h> #include <grpc/grpc.h> #include <grpc/support/alloc.h> +#include <grpc/support/atm.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/thd.h> @@ -35,7 +37,8 @@ #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/ext/filters/client_channel/subchannel_index.h" -#include "src/core/lib/support/env.h" +#include "src/core/lib/backoff/backoff.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -48,10 +51,33 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; +// defined in tcp_client_posix.c +extern void (*grpc_tcp_client_connect_impl)( + grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, grpc_millis deadline); + +const auto original_tcp_connect_fn = grpc_tcp_client_connect_impl; + namespace grpc { namespace testing { namespace { +gpr_atm g_connection_delay_ms; + +void tcp_client_connect_with_delay(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { + const int delay_ms = gpr_atm_acq_load(&g_connection_delay_ms); + if (delay_ms > 0) { + gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(delay_ms)); + } + original_tcp_connect_fn(closure, ep, interested_parties, channel_args, addr, + deadline + delay_ms); +} + // Subclass of TestServiceImpl that increments a request counter for // every call to the Echo RPC. class MyTestServiceImpl : public TestServiceImpl { @@ -136,22 +162,22 @@ class ClientLbEnd2endTest : public ::testing::Test { grpc_lb_addresses_destroy(addresses); } - void ResetStub(const grpc::string& lb_policy_name = "") { - ChannelArguments args; + std::vector<int> GetServersPorts() { + std::vector<int> ports; + for (const auto& server : servers_) ports.push_back(server->port_); + return ports; + } + + void ResetStub(const std::vector<int>& ports, + const grpc::string& lb_policy_name, + ChannelArguments args = ChannelArguments()) { if (lb_policy_name.size() > 0) { args.SetLoadBalancingPolicyName(lb_policy_name); } // else, default to pick first args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, response_generator_); - args.SetInt("grpc.testing.fixed_reconnect_backoff_ms", 2000); - std::ostringstream uri; - uri << "fake:///"; - for (size_t i = 0; i < servers_.size() - 1; ++i) { - uri << "127.0.0.1:" << servers_[i]->port_ << ","; - } - uri << "127.0.0.1:" << servers_[servers_.size() - 1]->port_; channel_ = - CreateCustomChannel(uri.str(), InsecureChannelCredentials(), args); + CreateCustomChannel("fake:///", InsecureChannelCredentials(), args); stub_ = grpc::testing::EchoTestService::NewStub(channel_); } @@ -266,7 +292,7 @@ TEST_F(ClientLbEnd2endTest, PickFirst) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub(); // implicit pick first + ResetStub(GetServersPorts(), ""); // test that pick first is the default. std::vector<int> ports; for (size_t i = 0; i < servers_.size(); ++i) { ports.emplace_back(servers_[i]->port_); @@ -290,11 +316,63 @@ TEST_F(ClientLbEnd2endTest, PickFirst) { EXPECT_EQ("pick_first", channel_->GetLoadBalancingPolicyName()); } +TEST_F(ClientLbEnd2endTest, PickFirstBackOffInitialReconnect) { + ChannelArguments args; + constexpr int kInitialBackOffMs = 100; + args.SetInt(GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS, kInitialBackOffMs); + const std::vector<int> ports = {grpc_pick_unused_port_or_die()}; + const gpr_timespec t0 = gpr_now(GPR_CLOCK_MONOTONIC); + ResetStub(ports, "pick_first", args); + SetNextResolution(ports); + // The channel won't become connected (there's no server). + ASSERT_FALSE(channel_->WaitForConnected( + grpc_timeout_milliseconds_to_deadline(kInitialBackOffMs * 2))); + // Bring up a server on the chosen port. + StartServers(1, ports); + // Now it will. + ASSERT_TRUE(channel_->WaitForConnected( + grpc_timeout_milliseconds_to_deadline(kInitialBackOffMs * 2))); + const gpr_timespec t1 = gpr_now(GPR_CLOCK_MONOTONIC); + const grpc_millis waited_ms = gpr_time_to_millis(gpr_time_sub(t1, t0)); + gpr_log(GPR_DEBUG, "Waited %ld milliseconds", waited_ms); + // We should have waited at least kInitialBackOffMs. We substract one to + // account for test and precision accuracy drift. + EXPECT_GE(waited_ms, kInitialBackOffMs - 1); + // But not much more. + EXPECT_GT( + gpr_time_cmp( + grpc_timeout_milliseconds_to_deadline(kInitialBackOffMs * 1.10), t1), + 0); +} + +TEST_F(ClientLbEnd2endTest, PickFirstBackOffMinReconnect) { + ChannelArguments args; + constexpr int kMinReconnectBackOffMs = 1000; + args.SetInt(GRPC_ARG_MIN_RECONNECT_BACKOFF_MS, kMinReconnectBackOffMs); + const std::vector<int> ports = {grpc_pick_unused_port_or_die()}; + ResetStub(ports, "pick_first", args); + SetNextResolution(ports); + // Make connection delay a 10% longer than it's willing to in order to make + // sure we are hitting the codepath that waits for the min reconnect backoff. + gpr_atm_rel_store(&g_connection_delay_ms, kMinReconnectBackOffMs * 1.10); + grpc_tcp_client_connect_impl = tcp_client_connect_with_delay; + const gpr_timespec t0 = gpr_now(GPR_CLOCK_MONOTONIC); + channel_->WaitForConnected( + grpc_timeout_milliseconds_to_deadline(kMinReconnectBackOffMs * 2)); + const gpr_timespec t1 = gpr_now(GPR_CLOCK_MONOTONIC); + const grpc_millis waited_ms = gpr_time_to_millis(gpr_time_sub(t1, t0)); + gpr_log(GPR_DEBUG, "Waited %ld ms", waited_ms); + // We should have waited at least kMinReconnectBackOffMs. We substract one to + // account for test and precision accuracy drift. + EXPECT_GE(waited_ms, kMinReconnectBackOffMs - 1); + gpr_atm_rel_store(&g_connection_delay_ms, 0); +} + TEST_F(ClientLbEnd2endTest, PickFirstUpdates) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub(); // implicit pick first + ResetStub(GetServersPorts(), "pick_first"); std::vector<int> ports; // Perform one RPC against the first server. @@ -340,7 +418,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdateSuperset) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub(); // implicit pick first + ResetStub(GetServersPorts(), "pick_first"); std::vector<int> ports; // Perform one RPC against the first server. @@ -370,7 +448,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstManyUpdates) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub(); // implicit pick first + ResetStub(GetServersPorts(), "pick_first"); std::vector<int> ports; for (size_t i = 0; i < servers_.size(); ++i) { ports.emplace_back(servers_[i]->port_); @@ -379,7 +457,8 @@ TEST_F(ClientLbEnd2endTest, PickFirstManyUpdates) { grpc_subchannel_index_test_only_set_force_creation(force_creation); gpr_log(GPR_INFO, "Force subchannel creation: %d", force_creation); for (size_t i = 0; i < 1000; ++i) { - std::random_shuffle(ports.begin(), ports.end()); + std::shuffle(ports.begin(), ports.end(), + std::mt19937(std::random_device()())); SetNextResolution(ports); if (i % 10 == 0) CheckRpcSendOk(); } @@ -392,7 +471,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobin) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub("round_robin"); + ResetStub(GetServersPorts(), "round_robin"); std::vector<int> ports; for (const auto& server : servers_) { ports.emplace_back(server->port_); @@ -423,7 +502,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub("round_robin"); + ResetStub(GetServersPorts(), "round_robin"); std::vector<int> ports; // Start with a single server. @@ -506,7 +585,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { TEST_F(ClientLbEnd2endTest, RoundRobinUpdateInError) { const int kNumServers = 3; StartServers(kNumServers); - ResetStub("round_robin"); + ResetStub(GetServersPorts(), "round_robin"); std::vector<int> ports; // Start with a single server. @@ -538,13 +617,14 @@ TEST_F(ClientLbEnd2endTest, RoundRobinManyUpdates) { // Start servers and send one RPC per server. const int kNumServers = 3; StartServers(kNumServers); - ResetStub("round_robin"); + ResetStub(GetServersPorts(), "round_robin"); std::vector<int> ports; for (size_t i = 0; i < servers_.size(); ++i) { ports.emplace_back(servers_[i]->port_); } for (size_t i = 0; i < 1000; ++i) { - std::random_shuffle(ports.begin(), ports.end()); + std::shuffle(ports.begin(), ports.end(), + std::mt19937(std::random_device()())); SetNextResolution(ports); if (i % 10 == 0) CheckRpcSendOk(); } @@ -565,7 +645,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinReresolve) { ports.push_back(grpc_pick_unused_port_or_die()); } StartServers(kNumServers, ports); - ResetStub("round_robin"); + ResetStub(GetServersPorts(), "round_robin"); SetNextResolution(ports); // Send a number of RPCs, which succeed. for (size_t i = 0; i < 100; ++i) { @@ -596,6 +676,42 @@ TEST_F(ClientLbEnd2endTest, RoundRobinReresolve) { GPR_ASSERT(gpr_time_cmp(deadline, now) > 0); } +TEST_F(ClientLbEnd2endTest, RoundRobinSingleReconnect) { + const int kNumServers = 3; + StartServers(kNumServers); + const auto ports = GetServersPorts(); + ResetStub(ports, "round_robin"); + SetNextResolution(ports); + for (size_t i = 0; i < kNumServers; ++i) WaitForServer(i); + for (size_t i = 0; i < servers_.size(); ++i) { + CheckRpcSendOk(); + EXPECT_EQ(1, servers_[i]->service_.request_count()) << "for backend #" << i; + } + // One request should have gone to each server. + for (size_t i = 0; i < servers_.size(); ++i) { + EXPECT_EQ(1, servers_[i]->service_.request_count()); + } + const auto pre_death = servers_[0]->service_.request_count(); + // Kill the first server. + servers_[0]->Shutdown(true); + // Client request still succeed. May need retrying if RR had returned a pick + // before noticing the change in the server's connectivity. + while (!SendRpc()) + ; // Retry until success. + // Send a bunch of RPCs that should succeed. + for (int i = 0; i < 10 * kNumServers; ++i) CheckRpcSendOk(); + const auto post_death = servers_[0]->service_.request_count(); + // No requests have gone to the deceased server. + EXPECT_EQ(pre_death, post_death); + // Bring the first server back up. + servers_[0].reset(new ServerData(server_host_, ports[0])); + // Requests should start arriving at the first server either right away (if + // the server managed to start before the RR policy retried the subchannel) or + // after the subchannel retry delay otherwise (RR's subchannel retried before + // the server was fully back up). + WaitForServer(0); +} + } // namespace } // namespace testing } // namespace grpc diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index dc0f6e1051..730bdf1e7e 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -35,8 +35,8 @@ #include <grpc/support/thd.h> #include <grpc/support/time.h> +#include "src/core/lib/gpr/env.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/support/env.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -1609,7 +1609,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginKeyFailure) { Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); - EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); + EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); } TEST_P(SecureEnd2endTest, AuthMetadataPluginValueFailure) { @@ -1626,7 +1626,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginValueFailure) { Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); - EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); + EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); } TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginFailure) { @@ -1644,7 +1644,7 @@ TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginFailure) { Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); - EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); + EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); EXPECT_EQ(s.error_message(), grpc::string("Getting metadata from plugin failed with error: ") + kTestCredsPluginErrorMsg); @@ -1705,7 +1705,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginFailure) { Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); - EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); + EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); EXPECT_EQ(s.error_message(), grpc::string("Getting metadata from plugin failed with error: ") + kTestCredsPluginErrorMsg); diff --git a/test/cpp/end2end/exception_test.cc b/test/cpp/end2end/exception_test.cc new file mode 100644 index 0000000000..76272ad08a --- /dev/null +++ b/test/cpp/end2end/exception_test.cc @@ -0,0 +1,119 @@ +/* + * + * Copyright 2017 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 <exception> +#include <memory> + +#include <grpc++/channel.h> +#include <grpc++/client_context.h> +#include <grpc++/server.h> +#include <grpc++/server_builder.h> +#include <grpc++/server_context.h> +#include <grpc/impl/codegen/port_platform.h> + +#include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "test/core/util/test_config.h" + +#include <gtest/gtest.h> + +namespace grpc { +namespace testing { + +const char* kErrorMessage = "This service caused an exception"; + +#if GRPC_ALLOW_EXCEPTIONS +class ExceptingServiceImpl : public ::grpc::testing::EchoTestService::Service { + public: + Status Echo(ServerContext* server_context, const EchoRequest* request, + EchoResponse* response) override { + throw - 1; + } + Status RequestStream(ServerContext* context, + ServerReader<EchoRequest>* reader, + EchoResponse* response) override { + throw ServiceException(); + } + + private: + class ServiceException final : public std::exception { + public: + ServiceException() {} + + private: + const char* what() const noexcept override { return kErrorMessage; } + }; +}; + +class ExceptionTest : public ::testing::Test { + protected: + ExceptionTest() {} + + void SetUp() override { + ServerBuilder builder; + builder.RegisterService(&service_); + server_ = builder.BuildAndStart(); + } + + void TearDown() override { server_->Shutdown(); } + + void ResetStub() { + channel_ = server_->InProcessChannel(ChannelArguments()); + stub_ = grpc::testing::EchoTestService::NewStub(channel_); + } + + std::shared_ptr<Channel> channel_; + std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; + std::unique_ptr<Server> server_; + ExceptingServiceImpl service_; +}; + +TEST_F(ExceptionTest, Unary) { + ResetStub(); + EchoRequest request; + EchoResponse response; + request.set_message("test"); + ClientContext context; + + Status s = stub_->Echo(&context, request, &response); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(s.error_code(), StatusCode::UNKNOWN); +} + +TEST_F(ExceptionTest, RequestStream) { + ResetStub(); + EchoResponse response; + ClientContext context; + + auto stream = stub_->RequestStream(&context, &response); + stream->WritesDone(); + Status s = stream->Finish(); + + EXPECT_FALSE(s.ok()); + EXPECT_EQ(s.error_code(), StatusCode::UNKNOWN); +} + +#endif // GRPC_ALLOW_EXCEPTIONS + +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index d4ee6b429f..815dfd0c4f 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -34,8 +34,8 @@ #include <grpc/support/time.h> #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/support/env.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 61f4111e3b..175ecea2b3 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -43,7 +43,6 @@ #include <iostream> -using namespace std; using ::testing::AtLeast; using ::testing::DoAll; using ::testing::Invoke; @@ -57,6 +56,7 @@ using grpc::testing::EchoResponse; using grpc::testing::EchoTestService; using grpc::testing::MockClientReaderWriter; using std::chrono::system_clock; +using std::vector; namespace grpc { namespace testing { diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc index 14ba7c96cc..9119102f7a 100644 --- a/test/cpp/end2end/shutdown_test.cc +++ b/test/cpp/end2end/shutdown_test.cc @@ -28,7 +28,7 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 38b65fbc78..d241594af1 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -40,11 +40,11 @@ #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack.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/iomgr/sockaddr.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/support/tmpfile.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 716fb96382..8958b9884d 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -27,7 +27,7 @@ #include <grpc/support/log.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" #include "test/cpp/util/test_config.h" diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index 2de7abcf17..7a9e3ced6a 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -30,7 +30,7 @@ #include "src/proto/grpc/testing/test.grpc.pb.h" #include "test/cpp/interop/http2_client.h" -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/test_config.h" diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 24c6b3f188..6b59584353 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -122,7 +122,8 @@ InteropClient::InteropClient(std::shared_ptr<Channel> channel, : serviceStub_(channel, new_stub_every_test_case), do_not_abort_on_transient_failures_(do_not_abort_on_transient_failures) {} -bool InteropClient::AssertStatusOk(const Status& s) { +bool InteropClient::AssertStatusOk(const Status& s, + const grpc::string& optional_debug_string) { if (s.ok()) { return true; } @@ -131,17 +132,21 @@ bool InteropClient::AssertStatusOk(const Status& s) { // already checked for s.ok() above). So, the following will call abort() // (unless s.error_code() corresponds to a transient failure and // 'do_not_abort_on_transient_failures' is true) - return AssertStatusCode(s, StatusCode::OK); + return AssertStatusCode(s, StatusCode::OK, optional_debug_string); } -bool InteropClient::AssertStatusCode(const Status& s, - StatusCode expected_code) { +bool InteropClient::AssertStatusCode( + const Status& s, StatusCode expected_code, + const grpc::string& optional_debug_string) { if (s.error_code() == expected_code) { return true; } - gpr_log(GPR_ERROR, "Error status code: %d (expected: %d), message: %s", - s.error_code(), expected_code, s.error_message().c_str()); + gpr_log(GPR_ERROR, + "Error status code: %d (expected: %d), message: %s," + " debug string: %s", + s.error_code(), expected_code, s.error_message().c_str(), + optional_debug_string.c_str()); // In case of transient transient/retryable failures (like a broken // connection) we may or may not abort (see TransientFailureOrAbort()) @@ -161,7 +166,7 @@ bool InteropClient::DoEmpty() { Status s = serviceStub_.Get()->EmptyCall(&context, request, &response); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -191,7 +196,7 @@ bool InteropClient::PerformLargeUnary(SimpleRequest* request, } Status s = serviceStub_.Get()->UnaryCall(&context, *request, response); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -241,7 +246,7 @@ bool InteropClient::DoOauth2AuthToken(const grpc::string& username, Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -269,7 +274,7 @@ bool InteropClient::DoPerRpcCreds(const grpc::string& json_key) { Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -412,7 +417,7 @@ bool InteropClient::DoRequestStreaming() { GPR_ASSERT(stream->WritesDone()); Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -451,7 +456,7 @@ bool InteropClient::DoResponseStreaming() { } Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -516,7 +521,7 @@ bool InteropClient::DoClientCompressedStreaming() { GPR_ASSERT(stream->WritesDone()); s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -578,7 +583,7 @@ bool InteropClient::DoServerCompressedStreaming() { } Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } return true; @@ -619,7 +624,7 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() { } Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -666,7 +671,7 @@ bool InteropClient::DoHalfDuplex() { } Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -710,7 +715,7 @@ bool InteropClient::DoPingPong() { GPR_ASSERT(!stream->Read(&response)); Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -732,7 +737,8 @@ bool InteropClient::DoCancelAfterBegin() { context.TryCancel(); Status s = stream->Finish(); - if (!AssertStatusCode(s, StatusCode::CANCELLED)) { + if (!AssertStatusCode(s, StatusCode::CANCELLED, + context.debug_error_string())) { return false; } @@ -790,7 +796,8 @@ bool InteropClient::DoTimeoutOnSleepingServer() { stream->Write(request); Status s = stream->Finish(); - if (!AssertStatusCode(s, StatusCode::DEADLINE_EXCEEDED)) { + if (!AssertStatusCode(s, StatusCode::DEADLINE_EXCEEDED, + context.debug_error_string())) { return false; } @@ -810,7 +817,7 @@ bool InteropClient::DoEmptyStream() { GPR_ASSERT(stream->Read(&response) == false); Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -833,7 +840,8 @@ bool InteropClient::DoStatusWithMessage() { requested_status->set_code(test_code); requested_status->set_message(test_msg); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { + if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN, + context.debug_error_string())) { return false; } GPR_ASSERT(s.error_message() == test_msg); @@ -853,7 +861,8 @@ bool InteropClient::DoStatusWithMessage() { while (stream->Read(&streaming_response)) ; s = stream->Finish(); - if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { + if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN, + context.debug_error_string())) { return false; } GPR_ASSERT(s.error_message() == test_msg); @@ -880,7 +889,7 @@ bool InteropClient::DoCacheableUnary() { context1.AddMetadata("x-user-ip", "1.2.3.4"); Status s1 = serviceStub_.Get()->CacheableUnaryCall(&context1, request, &response1); - if (!AssertStatusOk(s1)) { + if (!AssertStatusOk(s1, context1.debug_error_string())) { return false; } gpr_log(GPR_DEBUG, "response 1 payload: %s", @@ -893,7 +902,7 @@ bool InteropClient::DoCacheableUnary() { context2.AddMetadata("x-user-ip", "1.2.3.4"); Status s2 = serviceStub_.Get()->CacheableUnaryCall(&context2, request, &response2); - if (!AssertStatusOk(s2)) { + if (!AssertStatusOk(s2, context2.debug_error_string())) { return false; } gpr_log(GPR_DEBUG, "response 2 payload: %s", @@ -915,7 +924,7 @@ bool InteropClient::DoCacheableUnary() { context3.AddMetadata("x-user-ip", "1.2.3.4"); Status s3 = serviceStub_.Get()->CacheableUnaryCall(&context3, request1, &response3); - if (!AssertStatusOk(s3)) { + if (!AssertStatusOk(s3, context3.debug_error_string())) { return false; } gpr_log(GPR_DEBUG, "response 3 payload: %s", @@ -946,7 +955,7 @@ bool InteropClient::DoCustomMetadata() { request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -997,7 +1006,7 @@ bool InteropClient::DoCustomMetadata() { GPR_ASSERT(!stream->Read(&response)); Status s = stream->Finish(); - if (!AssertStatusOk(s)) { + if (!AssertStatusOk(s, context.debug_error_string())) { return false; } @@ -1028,7 +1037,8 @@ bool InteropClient::DoUnimplementedService() { Status s = stub->UnimplementedCall(&context, request, &response); - if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { + if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED, + context.debug_error_string())) { return false; } @@ -1046,7 +1056,8 @@ bool InteropClient::DoUnimplementedMethod() { Status s = serviceStub_.Get()->UnimplementedCall(&context, request, &response); - if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { + if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED, + context.debug_error_string())) { return false; } diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 57e8ba63f5..b8bb134c20 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -103,8 +103,10 @@ class InteropClient { /// Run \a custom_check_fn as an additional check. bool PerformLargeUnary(SimpleRequest* request, SimpleResponse* response, CheckerFn custom_checks_fn); - bool AssertStatusOk(const Status& s); - bool AssertStatusCode(const Status& s, StatusCode expected_code); + bool AssertStatusOk(const Status& s, + const grpc::string& optional_debug_string); + bool AssertStatusCode(const Status& s, StatusCode expected_code, + const grpc::string& optional_debug_string); bool TransientFailureOrAbort(); ServiceStub serviceStub_; diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 30bd8bfef8..7cfdb2f9e9 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -31,7 +31,7 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/lib/support/string.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/transport/byte_stream.h" #include "src/proto/grpc/testing/empty.pb.h" #include "src/proto/grpc/testing/messages.pb.h" diff --git a/test/cpp/interop/interop_test.cc b/test/cpp/interop/interop_test.cc index 1bf0d8d10f..563b7abb5e 100644 --- a/test/cpp/interop/interop_test.cc +++ b/test/cpp/interop/interop_test.cc @@ -37,8 +37,8 @@ #include "test/core/util/port.h" #include "test/cpp/util/test_config.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/socket_utils_posix.h" -#include "src/core/lib/support/string.h" DEFINE_string(extra_server_flags, "", "Extra flags to pass to server."); diff --git a/test/cpp/microbenchmarks/bm_arena.cc b/test/cpp/microbenchmarks/bm_arena.cc index 5b7c611919..69c8c1c029 100644 --- a/test/cpp/microbenchmarks/bm_arena.cc +++ b/test/cpp/microbenchmarks/bm_arena.cc @@ -18,7 +18,7 @@ /* Benchmark arenas */ -#include "src/core/lib/support/arena.h" +#include "src/core/lib/gpr/arena.h" #include "test/cpp/microbenchmarks/helpers.h" #include "third_party/benchmark/include/benchmark/benchmark.h" diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index 4d5a82c3f6..6d88faecc0 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -22,10 +22,10 @@ #include <grpc/grpc.h> #include <sstream> +#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/support/spinlock.h" #include "test/cpp/microbenchmarks/helpers.h" diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 3481d9d1aa..8b5523f01a 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -37,13 +37,13 @@ #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/ext/filters/client_channel/resolver_registry.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/iomgr/combiner.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/sockaddr_utils.h" -#include "src/core/lib/support/env.h" -#include "src/core/lib/support/string.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/naming/resolver_component_tests_runner_invoker.cc b/test/cpp/naming/resolver_component_tests_runner_invoker.cc index 0beb27de1b..65f11243fe 100644 --- a/test/cpp/naming/resolver_component_tests_runner_invoker.cc +++ b/test/cpp/naming/resolver_component_tests_runner_invoker.cc @@ -32,7 +32,7 @@ #include "test/cpp/util/subprocess.h" #include "test/cpp/util/test_config.h" -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "test/core/util/port.h" DEFINE_bool( diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 22d039d4b7..2f765a6d1e 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -31,8 +31,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> +#include "src/core/lib/gpr/env.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/support/env.h" #include "src/proto/grpc/testing/services.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 1ef8f65b0b..bd40d0a5a2 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -101,24 +101,26 @@ print yaml.dump({ } for scenario_json in scenario_config.CXXLanguage().scenarios() if 'inproc' in scenario_json.get('CATEGORIES', []) - ] + [ - { - 'name': 'json_run_localhost', - 'shortname': 'json_run_localhost:%s_low_thread_count' % scenario_json['name'], - 'args': ['--scenarios_json', _scenario_json_string(scenario_json, True)], - 'ci_platforms': ['linux'], - 'platforms': ['linux'], - 'flaky': False, - 'language': 'c++', - 'boringssl': True, - 'defaults': 'boringssl', - 'cpu_cost': guess_cpu(scenario_json, True), - 'exclude_configs': sorted(c for c in configs_from_yaml if c not in ('tsan', 'asan')), - 'timeout_seconds': 10*60, - 'excluded_poll_engines': scenario_json.get('EXCLUDED_POLL_ENGINES', []), - 'auto_timeout_scaling': False - } - for scenario_json in scenario_config.CXXLanguage().scenarios() - if 'scalable' in scenario_json.get('CATEGORIES', []) ] + # Disabled until https://github.com/grpc/grpc/issues/13122 is resolved. + # + [ + # { + # 'name': 'json_run_localhost', + # 'shortname': 'json_run_localhost:%s_low_thread_count' % scenario_json['name'], + # 'args': ['--scenarios_json', _scenario_json_string(scenario_json, True)], + # 'ci_platforms': ['linux'], + # 'platforms': ['linux'], + # 'flaky': False, + # 'language': 'c++', + # 'boringssl': True, + # 'defaults': 'boringssl', + # 'cpu_cost': guess_cpu(scenario_json, True), + # 'exclude_configs': sorted(c for c in configs_from_yaml if c not in ('tsan', 'asan')), + # 'timeout_seconds': 10*60, + # 'excluded_poll_engines': scenario_json.get('EXCLUDED_POLL_ENGINES', []), + # 'auto_timeout_scaling': False + # } + # for scenario_json in scenario_config.CXXLanguage().scenarios() + # if 'scalable' in scenario_json.get('CATEGORIES', []) + # ] }) diff --git a/test/cpp/qps/json_run_localhost.cc b/test/cpp/qps/json_run_localhost.cc index db8b2a3943..948c3088e6 100644 --- a/test/cpp/qps/json_run_localhost.cc +++ b/test/cpp/qps/json_run_localhost.cc @@ -26,7 +26,7 @@ #include <grpc/support/log.h> -#include "src/core/lib/support/env.h" +#include "src/core/lib/gpr/env.h" #include "test/core/util/port.h" #include "test/cpp/util/subprocess.h" diff --git a/test/cpp/util/cli_credentials.cc b/test/cpp/util/cli_credentials.cc index f1f43f8ae0..aa4eafb756 100644 --- a/test/cpp/util/cli_credentials.cc +++ b/test/cpp/util/cli_credentials.cc @@ -22,27 +22,43 @@ DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls."); DEFINE_bool(use_auth, false, "Whether to create default google credentials."); +DEFINE_string( + access_token, "", + "The access token that will be sent to the server to authenticate RPCs."); namespace grpc { namespace testing { std::shared_ptr<grpc::ChannelCredentials> CliCredentials::GetCredentials() const { - if (!FLAGS_enable_ssl) { - return grpc::InsecureChannelCredentials(); - } else { + if (!FLAGS_access_token.empty()) { if (FLAGS_use_auth) { - return grpc::GoogleDefaultCredentials(); - } else { - return grpc::SslCredentials(grpc::SslCredentialsOptions()); + fprintf(stderr, + "warning: use_auth is ignored when access_token is provided."); } + + return grpc::CompositeChannelCredentials( + grpc::SslCredentials(grpc::SslCredentialsOptions()), + grpc::AccessTokenCredentials(FLAGS_access_token)); + } + + if (FLAGS_use_auth) { + return grpc::GoogleDefaultCredentials(); } + + if (FLAGS_enable_ssl) { + return grpc::SslCredentials(grpc::SslCredentialsOptions()); + } + + return grpc::InsecureChannelCredentials(); } const grpc::string CliCredentials::GetCredentialUsage() const { return " --enable_ssl ; Set whether to use tls\n" " --use_auth ; Set whether to create default google" - " credentials\n"; + " credentials\n" + " --access_token ; Set the access token in metadata," + " overrides --use_auth\n"; } } // namespace testing } // namespace grpc diff --git a/test/distrib/cpp/run_distrib_test_cmake.bat b/test/distrib/cpp/run_distrib_test_cmake.bat index 047846b0f1..f920768ae3 100644 --- a/test/distrib/cpp/run_distrib_test_cmake.bat +++ b/test/distrib/cpp/run_distrib_test_cmake.bat @@ -58,13 +58,13 @@ cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOP cmake --build . --config Release --target install || goto :error cd ../.. -# Build helloworld example using cmake +@rem Build helloworld example using cmake cd examples/cpp/helloworld mkdir cmake cd cmake mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ../.. || goto :error +cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include ../.. || goto :error cmake --build . --config Release || goto :error cd ../../../../.. diff --git a/test/distrib/ruby/distribtest.gemspec b/test/distrib/ruby/distribtest.gemspec index d72892f46c..f11f5218d5 100644 --- a/test/distrib/ruby/distribtest.gemspec +++ b/test/distrib/ruby/distribtest.gemspec @@ -14,6 +14,8 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.add_dependency 'grpc', '>=0' + s.add_dependency 'public_suffix', '< 3.0' + s.add_dependency 'jwt', '< 2.0' s.add_development_dependency 'bundler', '~> 1.7' end diff --git a/test/distrib/ruby/run_distrib_test.sh b/test/distrib/ruby/run_distrib_test.sh index 0c214e38f2..d74f4cd76d 100755 --- a/test/distrib/ruby/run_distrib_test.sh +++ b/test/distrib/ruby/run_distrib_test.sh @@ -17,10 +17,16 @@ set -ex cd $(dirname $0) +ARCH=$1 +PLATFORM=$2 # Create an indexed local gem source with gRPC gems to test GEM_SOURCE=../../../gem_source mkdir -p ${GEM_SOURCE}/gems -cp -r $EXTERNAL_GIT_ROOT/input_artifacts/*.gem ${GEM_SOURCE}/gems +cp $EXTERNAL_GIT_ROOT/input_artifacts/grpc-*$ARCH-$PLATFORM.gem ${GEM_SOURCE}/gems +if [[ "$(ls ${GEM_SOURCE}/gems | grep grpc | wc -l)" != 1 ]]; then + echo "Sanity check failed. Copied over more than one grpc gem into the gem source directory." + exit 1 +fi; gem install builder gem generate_index --directory ${GEM_SOURCE} |