diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index 7e4d15a7c9e..bfd36494941 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -37,8 +37,8 @@ DEFINE_string( const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden"; const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden"; -void run_test(std::basic_string generated_file, - std::basic_string golden_file) { +void run_test(const std::basic_string& generated_file, + const std::basic_string& golden_file) { std::ifstream generated(generated_file); std::ifstream golden(golden_file); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 87bba2263fa..3d31c9d8100 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -891,7 +891,7 @@ TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) { cq_.get(), tag(2)); Verifier().Expect(2, true).Verify(cq_.get()); EXPECT_EQ(send_request.message(), recv_request.message()); - auto client_initial_metadata = srv_ctx.client_metadata(); + const auto& client_initial_metadata = srv_ctx.client_metadata(); EXPECT_EQ(meta1.second, ToString(client_initial_metadata.find(meta1.first)->second)); EXPECT_EQ(meta2.second, @@ -937,7 +937,7 @@ TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) { srv_ctx.AddInitialMetadata(meta2.first, meta2.second); response_writer.SendInitialMetadata(tag(3)); Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); - auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); + const auto& server_initial_metadata = cli_ctx.GetServerInitialMetadata(); EXPECT_EQ(meta1.second, ToString(server_initial_metadata.find(meta1.first)->second)); EXPECT_EQ(meta2.second, @@ -990,7 +990,7 @@ TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) { EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.ok()); - auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); + const auto& server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); EXPECT_EQ(meta1.second, ToString(server_trailing_metadata.find(meta1.first)->second)); EXPECT_EQ(meta2.second, @@ -1038,7 +1038,7 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) { cq_.get(), tag(2)); Verifier().Expect(2, true).Verify(cq_.get()); EXPECT_EQ(send_request.message(), recv_request.message()); - auto client_initial_metadata = srv_ctx.client_metadata(); + const auto& client_initial_metadata = srv_ctx.client_metadata(); EXPECT_EQ(meta1.second, ToString(client_initial_metadata.find(meta1.first)->second)); EXPECT_EQ(meta2.second, @@ -1049,7 +1049,7 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) { srv_ctx.AddInitialMetadata(meta4.first, meta4.second); response_writer.SendInitialMetadata(tag(3)); Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); - auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); + const auto& server_initial_metadata = cli_ctx.GetServerInitialMetadata(); EXPECT_EQ(meta3.second, ToString(server_initial_metadata.find(meta3.first)->second)); EXPECT_EQ(meta4.second, @@ -1066,7 +1066,7 @@ TEST_P(AsyncEnd2endTest, MetadataRpc) { EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.ok()); - auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); + const auto& server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); EXPECT_EQ(meta5.second, ToString(server_trailing_metadata.find(meta5.first)->second)); EXPECT_EQ(meta6.second, @@ -1144,7 +1144,7 @@ TEST_P(AsyncEnd2endTest, ServerCheckDone) { TEST_P(AsyncEnd2endTest, UnimplementedRpc) { ChannelArguments args; - auto channel_creds = GetCredentialsProvider()->GetChannelCredentials( + const auto& channel_creds = GetCredentialsProvider()->GetChannelCredentials( GetParam().credentials_type, &args); std::shared_ptr channel = !(GetParam().inproc) diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index 543f1592650..bc7f0f5edba 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -42,16 +42,16 @@ const int kLargeRequestSize = 271828; const int kLargeResponseSize = 314159; } // namespace -Http2Client::ServiceStub::ServiceStub(std::shared_ptr channel) - : channel_(channel) { +Http2Client::ServiceStub::ServiceStub(const std::shared_ptr& channel) + : channel_(std::move(channel)) { stub_ = TestService::NewStub(channel); } TestService::Stub* Http2Client::ServiceStub::Get() { return stub_.get(); } -Http2Client::Http2Client(std::shared_ptr channel) +Http2Client::Http2Client(const std::shared_ptr& channel) : serviceStub_(channel), - channel_(channel), + channel_(std::move(channel)), defaultRequest_(BuildDefaultRequest()) {} bool Http2Client::AssertStatusCode(const Status& s, StatusCode expected_code) { @@ -140,7 +140,8 @@ bool Http2Client::DoPing() { return true; } -void Http2Client::MaxStreamsWorker(std::shared_ptr channel) { +void Http2Client::MaxStreamsWorker( + const std::shared_ptr& channel) { SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::OK); GPR_ASSERT(response.payload().body() == diff --git a/test/cpp/interop/http2_client.h b/test/cpp/interop/http2_client.h index 2bcfdd69dbb..269d3b32e27 100644 --- a/test/cpp/interop/http2_client.h +++ b/test/cpp/interop/http2_client.h @@ -31,7 +31,7 @@ namespace testing { class Http2Client { public: - explicit Http2Client(std::shared_ptr channel); + explicit Http2Client(const std::shared_ptr& channel); ~Http2Client() {} bool DoRstAfterHeader(); @@ -44,7 +44,7 @@ class Http2Client { private: class ServiceStub { public: - ServiceStub(std::shared_ptr channel); + ServiceStub(const std::shared_ptr& channel); TestService::Stub* Get(); @@ -53,7 +53,7 @@ class Http2Client { std::shared_ptr channel_; }; - void MaxStreamsWorker(std::shared_ptr channel); + void MaxStreamsWorker(const std::shared_ptr& channel); bool AssertStatusCode(const Status& s, StatusCode expected_code); Status SendUnaryCall(SimpleResponse* response); SimpleRequest BuildDefaultRequest(); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index aaaa21de5bf..fce99a1697b 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -113,11 +113,11 @@ void InteropClient::ServiceStub::Reset( } } -void InteropClient::Reset(std::shared_ptr channel) { +void InteropClient::Reset(const std::shared_ptr& channel) { serviceStub_.Reset(std::move(channel)); } -InteropClient::InteropClient(std::shared_ptr channel, +InteropClient::InteropClient(const std::shared_ptr& channel, bool new_stub_every_test_case, bool do_not_abort_on_transient_failures) : serviceStub_(std::move(channel), new_stub_every_test_case), diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index a146212ff68..480eb3f4b62 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -40,12 +40,12 @@ class InteropClient { /// created for every test case /// If do_not_abort_on_transient_failures is true, abort() is not called in /// case of transient failures (like connection failures) - explicit InteropClient(std::shared_ptr channel, + explicit InteropClient(const std::shared_ptr& channel, bool new_stub_every_test_case, bool do_not_abort_on_transient_failures); ~InteropClient() {} - void Reset(std::shared_ptr channel); + void Reset(const std::shared_ptr& channel); bool DoEmpty(); bool DoLargeUnary(); diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index f55d624b21c..6570bbf9696 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -317,25 +317,25 @@ class TestServiceImpl : public TestService::Service { }; void grpc::testing::interop::RunServer( - std::shared_ptr creds) { + const std::shared_ptr& creds) { RunServer(creds, FLAGS_port, nullptr, nullptr); } void grpc::testing::interop::RunServer( - std::shared_ptr creds, + const std::shared_ptr& creds, std::unique_ptr>> server_options) { RunServer(creds, FLAGS_port, nullptr, std::move(server_options)); } void grpc::testing::interop::RunServer( - std::shared_ptr creds, const int port, + const std::shared_ptr& creds, const int port, ServerStartedCondition* server_started_condition) { RunServer(creds, port, server_started_condition, nullptr); } void grpc::testing::interop::RunServer( - std::shared_ptr creds, const int port, + const std::shared_ptr& creds, const int port, ServerStartedCondition* server_started_condition, std::unique_ptr>> server_options) { diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index 265874df707..1bfbf8e474d 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -63,7 +63,7 @@ struct ServerStartedCondition { /// Run gRPC interop server using port FLAGS_port. /// /// \param creds The credentials associated with the server. -void RunServer(std::shared_ptr creds); +void RunServer(const std::shared_ptr& creds); /// Run gRPC interop server. /// @@ -71,7 +71,7 @@ void RunServer(std::shared_ptr creds); /// \param port Port to use for the server. /// \param server_started_condition (optional) Struct holding mutex, condition /// variable, and condition used to notify when the server has started. -void RunServer(std::shared_ptr creds, int port, +void RunServer(const std::shared_ptr& creds, int port, ServerStartedCondition* server_started_condition); /// Run gRPC interop server. @@ -79,7 +79,7 @@ void RunServer(std::shared_ptr creds, int port, /// \param creds The credentials associated with the server. /// \param server_options List of options to set when building the server. void RunServer( - std::shared_ptr creds, + const std::shared_ptr& creds, std::unique_ptr>> server_options); @@ -91,7 +91,7 @@ void RunServer( /// \param server_started_condition (optional) Struct holding mutex, condition // variable, and condition used to notify when the server has started. void RunServer( - std::shared_ptr creds, const int port, + const std::shared_ptr& creds, const int port, ServerStartedCondition* server_started_condition, std::unique_ptr>> server_options); diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 07ddfd30eee..6ac548120ca 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -90,7 +90,7 @@ namespace { class GrpcLBAddress final { public: GrpcLBAddress(std::string address, bool is_balancer) - : is_balancer(is_balancer), address(address) {} + : is_balancer(is_balancer), address(std::move(address)) {} bool operator==(const GrpcLBAddress& other) const { return this->is_balancer == other.is_balancer && @@ -109,7 +109,7 @@ vector ParseExpectedAddrs(std::string expected_addrs) { std::vector out; while (expected_addrs.size() != 0) { // get the next , (v4 or v6) - size_t next_comma = expected_addrs.find(","); + size_t next_comma = expected_addrs.find(','); if (next_comma == std::string::npos) { gpr_log(GPR_ERROR, "Missing ','. Expected_addrs arg should be a semicolon-separated " @@ -120,7 +120,7 @@ vector ParseExpectedAddrs(std::string expected_addrs) { std::string next_addr = expected_addrs.substr(0, next_comma); expected_addrs = expected_addrs.substr(next_comma + 1, std::string::npos); // get the next is_balancer 'bool' associated with this address - size_t next_semicolon = expected_addrs.find(";"); + size_t next_semicolon = expected_addrs.find(';'); bool is_balancer = gpr_is_true(expected_addrs.substr(0, next_semicolon).c_str()); out.emplace_back(GrpcLBAddress(next_addr, is_balancer)); diff --git a/test/cpp/naming/resolver_component_tests_runner_invoker.cc b/test/cpp/naming/resolver_component_tests_runner_invoker.cc index 45c1029caa2..68be00a67d6 100644 --- a/test/cpp/naming/resolver_component_tests_runner_invoker.cc +++ b/test/cpp/naming/resolver_component_tests_runner_invoker.cc @@ -99,21 +99,21 @@ namespace grpc { namespace testing { -void InvokeResolverComponentTestsRunner(std::string test_runner_bin_path, - std::string test_bin_path, - std::string dns_server_bin_path, - std::string records_config_path, - std::string dns_resolver_bin_path, - std::string tcp_connect_bin_path) { +void InvokeResolverComponentTestsRunner( + std::string test_runner_bin_path, const std::string& test_bin_path, + const std::string& dns_server_bin_path, + const std::string& records_config_path, + const std::string& dns_resolver_bin_path, + const std::string& tcp_connect_bin_path) { int dns_server_port = grpc_pick_unused_port_or_die(); - SubProcess* test_driver = - new SubProcess({test_runner_bin_path, "--test_bin_path=" + test_bin_path, - "--dns_server_bin_path=" + dns_server_bin_path, - "--records_config_path=" + records_config_path, - "--dns_server_port=" + std::to_string(dns_server_port), - "--dns_resolver_bin_path=" + dns_resolver_bin_path, - "--tcp_connect_bin_path=" + tcp_connect_bin_path}); + SubProcess* test_driver = new SubProcess( + {std::move(test_runner_bin_path), "--test_bin_path=" + test_bin_path, + "--dns_server_bin_path=" + dns_server_bin_path, + "--records_config_path=" + records_config_path, + "--dns_server_port=" + std::to_string(dns_server_port), + "--dns_resolver_bin_path=" + dns_resolver_bin_path, + "--tcp_connect_bin_path=" + tcp_connect_bin_path}); gpr_mu test_driver_mu; gpr_mu_init(&test_driver_mu); gpr_cv test_driver_cv; diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 31ae6ca1fbe..9d58ea8882a 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -450,7 +450,7 @@ class ClientImpl : public Client { private: void set_channel_args(const ClientConfig& config, ChannelArguments* args) { - for (auto channel_arg : config.channel_args()) { + for (const auto& channel_arg : config.channel_args()) { if (channel_arg.value_case() == ChannelArg::kStrValue) { args->SetString(channel_arg.name(), channel_arg.str_value()); } else if (channel_arg.value_case() == ChannelArg::kIntValue) { diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index e6dbb7e0765..bad24cf04a2 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -299,7 +299,7 @@ class AsyncClient : public ClientImpl { }; static std::unique_ptr BenchmarkStubCreator( - std::shared_ptr ch) { + const std::shared_ptr& ch) { return BenchmarkService::NewStub(ch); } @@ -314,7 +314,7 @@ class AsyncUnaryClient final ~AsyncUnaryClient() override {} private: - static void CheckDone(grpc::Status s, SimpleResponse* response, + static void CheckDone(const grpc::Status& s, SimpleResponse* response, HistogramEntry* entry) { entry->set_status(s.error_code()); } @@ -498,7 +498,7 @@ class AsyncStreamingPingPongClient final ~AsyncStreamingPingPongClient() override {} private: - static void CheckDone(grpc::Status s, SimpleResponse* response) {} + static void CheckDone(const grpc::Status& s, SimpleResponse* response) {} static std::unique_ptr< grpc::ClientAsyncReaderWriter> PrepareReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx, @@ -630,7 +630,7 @@ class AsyncStreamingFromClientClient final ~AsyncStreamingFromClientClient() override {} private: - static void CheckDone(grpc::Status s, SimpleResponse* response) {} + static void CheckDone(const grpc::Status& s, SimpleResponse* response) {} static std::unique_ptr> PrepareReq( BenchmarkService::Stub* stub, grpc::ClientContext* ctx, SimpleResponse* resp, CompletionQueue* cq) { @@ -745,7 +745,7 @@ class AsyncStreamingFromServerClient final ~AsyncStreamingFromServerClient() override {} private: - static void CheckDone(grpc::Status s, SimpleResponse* response) {} + static void CheckDone(const grpc::Status& s, SimpleResponse* response) {} static std::unique_ptr> PrepareReq( BenchmarkService::Stub* stub, grpc::ClientContext* ctx, const SimpleRequest& req, CompletionQueue* cq) { @@ -895,7 +895,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { }; static std::unique_ptr GenericStubCreator( - std::shared_ptr ch) { + const std::shared_ptr& ch) { return std::unique_ptr(new grpc::GenericStub(ch)); } @@ -911,7 +911,7 @@ class GenericAsyncStreamingClient final ~GenericAsyncStreamingClient() override {} private: - static void CheckDone(grpc::Status s, ByteBuffer* response) {} + static void CheckDone(const grpc::Status& s, ByteBuffer* response) {} static std::unique_ptr PrepareReq( grpc::GenericStub* stub, grpc::ClientContext* ctx, const grpc::string& method_name, CompletionQueue* cq) { diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index 3a60c57e1d1..668d9abf5ca 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -44,7 +44,7 @@ namespace grpc { namespace testing { static std::unique_ptr BenchmarkStubCreator( - std::shared_ptr ch) { + const std::shared_ptr& ch) { return BenchmarkService::NewStub(ch); } diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index ecf5860b93a..cabbd518437 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -217,7 +217,6 @@ std::unique_ptr RunScenario( // To be added to the result, containing the final configuration used for // client and config (including host, etc.) ClientConfig result_client_config; - const ServerConfig& result_server_config = initial_server_config; // Get client, server lists; ignore if inproc test auto workers = (!run_inproc) ? get_workers("QPS_WORKERS") : deque();