diff options
Diffstat (limited to 'test/cpp')
24 files changed, 443 insertions, 180 deletions
diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index 1443eb2f68..60d3215265 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -33,12 +33,58 @@ #include <grpc++/support/channel_arguments.h> +#include <grpc++/grpc++.h> #include <grpc/grpc.h> +#include <grpc/support/useful.h> #include <gtest/gtest.h> +#include "src/core/lib/iomgr/socket_mutator.h" namespace grpc { namespace testing { +namespace { + +// A simple grpc_socket_mutator to be used to test SetSocketMutator +class TestSocketMutator : public grpc_socket_mutator { + public: + TestSocketMutator(); + + bool MutateFd(int fd) { + // Do nothing on the fd + return true; + } +}; + +// +// C API for TestSocketMutator +// + +bool test_mutator_mutate_fd(int fd, grpc_socket_mutator* mutator) { + TestSocketMutator* tsm = (TestSocketMutator*)mutator; + return tsm->MutateFd(fd); +} + +int test_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b) { + return GPR_ICMP(a, b); +} + +void test_mutator_destroy(grpc_socket_mutator* mutator) { + TestSocketMutator* tsm = (TestSocketMutator*)mutator; + delete tsm; +} + +grpc_socket_mutator_vtable test_mutator_vtable = { + test_mutator_mutate_fd, test_mutator_compare, test_mutator_destroy}; + +// +// TestSocketMutator implementation +// + +TestSocketMutator::TestSocketMutator() { + grpc_socket_mutator_init(this, &test_mutator_vtable); +} +} + class ChannelArgumentsTest : public ::testing::Test { protected: ChannelArgumentsTest() @@ -53,7 +99,7 @@ class ChannelArgumentsTest : public ::testing::Test { grpc::string GetDefaultUserAgentPrefix() { std::ostringstream user_agent_prefix; - user_agent_prefix << "grpc-c++/" << grpc_version_string(); + user_agent_prefix << "grpc-c++/" << Version(); return user_agent_prefix.str(); } @@ -165,6 +211,26 @@ TEST_F(ChannelArgumentsTest, SetPointer) { EXPECT_TRUE(HasArg(arg0)); } +TEST_F(ChannelArgumentsTest, SetSocketMutator) { + VerifyDefaultChannelArgs(); + grpc_arg arg0, arg1; + TestSocketMutator* mutator0 = new TestSocketMutator(); + TestSocketMutator* mutator1 = new TestSocketMutator(); + arg0 = grpc_socket_mutator_to_arg(mutator0); + arg1 = grpc_socket_mutator_to_arg(mutator1); + + channel_args_.SetSocketMutator(mutator0); + EXPECT_TRUE(HasArg(arg0)); + + channel_args_.SetSocketMutator(mutator1); + EXPECT_TRUE(HasArg(arg1)); + // arg0 is replaced by arg1 + EXPECT_FALSE(HasArg(arg0)); + + // arg0 is destroyed by grpc_socket_mutator_to_arg(mutator1) + arg1.value.pointer.vtable->destroy(arg1.value.pointer.p); +} + TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { VerifyDefaultChannelArgs(); grpc::string prefix("prefix"); diff --git a/test/cpp/common/channel_filter_test.cc b/test/cpp/common/channel_filter_test.cc new file mode 100644 index 0000000000..600a953d82 --- /dev/null +++ b/test/cpp/common/channel_filter_test.cc @@ -0,0 +1,70 @@ +// +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#include "src/cpp/common/channel_filter.h" + +#include <limits.h> + +#include <grpc/grpc.h> +#include <gtest/gtest.h> + +namespace grpc { +namespace testing { + +class MyChannelData : public ChannelData { + public: + MyChannelData(const grpc_channel_args& args, const char* peer) + : ChannelData(args, peer) {} +}; + +class MyCallData : public CallData { + public: + explicit MyCallData(const ChannelData& channel_data) + : CallData(channel_data) {} +}; + +// This test ensures that when we make changes to the filter API in +// C-core, we don't accidentally break the C++ filter API. +TEST(ChannelFilterTest, RegisterChannelFilter) { + grpc::RegisterChannelFilter<MyChannelData, MyCallData>( + "myfilter", GRPC_CLIENT_CHANNEL, INT_MAX, nullptr); +} + +// TODO(roth): When we have time, add tests for all methods of the +// filter API. + +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 3845582d5d..8e385d100c 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -352,15 +352,13 @@ void ServerWait(Server* server, int* notify) { } TEST_P(AsyncEnd2endTest, WaitAndShutdownTest) { int notify = 0; - std::thread* wait_thread = - new std::thread(&ServerWait, server_.get(), ¬ify); + std::thread wait_thread(&ServerWait, server_.get(), ¬ify); ResetStub(); SendRpc(1); EXPECT_EQ(0, notify); server_->Shutdown(); - wait_thread->join(); + wait_thread.join(); EXPECT_EQ(1, notify); - delete wait_thread; } TEST_P(AsyncEnd2endTest, ShutdownThenWait) { @@ -991,7 +989,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { expected_server_cq_result = false; } - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; auto verif = Verifier(GetParam().disable_blocking); @@ -1027,7 +1025,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { } } - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; } @@ -1112,7 +1110,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { expected_cq_result = false; } - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; auto verif = Verifier(GetParam().disable_blocking); @@ -1150,7 +1148,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { } } - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; } @@ -1252,7 +1250,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { expected_cq_result = false; } - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; auto verif = Verifier(GetParam().disable_blocking); @@ -1332,7 +1330,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 8); } - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 4b8749884f..9bb892c694 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -656,25 +656,23 @@ TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) { TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { ResetStub(); - std::vector<std::thread*> threads; + std::vector<std::thread> threads; for (int i = 0; i < 10; ++i) { - threads.push_back(new std::thread(SendRpc, stub_.get(), 10, true)); + threads.emplace_back(SendRpc, stub_.get(), 10, true); } for (int i = 0; i < 10; ++i) { - threads[i]->join(); - delete threads[i]; + threads[i].join(); } } TEST_P(End2endTest, MultipleRpcs) { ResetStub(); - std::vector<std::thread*> threads; + std::vector<std::thread> threads; for (int i = 0; i < 10; ++i) { - threads.push_back(new std::thread(SendRpc, stub_.get(), 10, false)); + threads.emplace_back(SendRpc, stub_.get(), 10, false); } for (int i = 0; i < 10; ++i) { - threads[i]->join(); - delete threads[i]; + threads[i].join(); } } @@ -1058,13 +1056,12 @@ TEST_P(ProxyEnd2endTest, SimpleRpcWithEmptyMessages) { TEST_P(ProxyEnd2endTest, MultipleRpcs) { ResetStub(); - std::vector<std::thread*> threads; + std::vector<std::thread> threads; for (int i = 0; i < 10; ++i) { - threads.push_back(new std::thread(SendRpc, stub_.get(), 10, false)); + threads.emplace_back(SendRpc, stub_.get(), 10, false); } for (int i = 0; i < 10; ++i) { - threads[i]->join(); - delete threads[i]; + threads[i].join(); } } diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index 2de344efd5..001047778d 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -194,7 +194,7 @@ Status TestServiceImpl::RequestStream(ServerContext* context, return Status::CANCELLED; } - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; if (server_try_cancel == CANCEL_DURING_PROCESSING) { server_try_cancel_thd = new std::thread(&TestServiceImpl::ServerTryCancel, this, context); @@ -212,7 +212,7 @@ Status TestServiceImpl::RequestStream(ServerContext* context, } gpr_log(GPR_INFO, "Read: %d messages", num_msgs_read); - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; return Status::CANCELLED; @@ -248,7 +248,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context, } EchoResponse response; - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; if (server_try_cancel == CANCEL_DURING_PROCESSING) { server_try_cancel_thd = new std::thread(&TestServiceImpl::ServerTryCancel, this, context); @@ -259,7 +259,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context, writer->Write(response); } - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; return Status::CANCELLED; @@ -295,7 +295,7 @@ Status TestServiceImpl::BidiStream( return Status::CANCELLED; } - std::thread* server_try_cancel_thd = NULL; + std::thread* server_try_cancel_thd = nullptr; if (server_try_cancel == CANCEL_DURING_PROCESSING) { server_try_cancel_thd = new std::thread(&TestServiceImpl::ServerTryCancel, this, context); @@ -307,7 +307,7 @@ Status TestServiceImpl::BidiStream( stream->Write(response); } - if (server_try_cancel_thd != NULL) { + if (server_try_cancel_thd != nullptr) { server_try_cancel_thd->join(); delete server_try_cancel_thd; return Status::CANCELLED; diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index fe5a219eed..d353f9894b 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -232,19 +232,19 @@ class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> { class CommonStressTestAsyncServer : public CommonStressTest<grpc::testing::EchoTestService::AsyncService> { public: + CommonStressTestAsyncServer() : contexts_(kNumAsyncServerThreads * 100) {} void SetUp() override { shutting_down_ = false; ServerBuilder builder; SetUpStart(&builder, &service_); cq_ = builder.AddCompletionQueue(); SetUpEnd(&builder); - contexts_ = new Context[kNumAsyncServerThreads * 100]; for (int i = 0; i < kNumAsyncServerThreads * 100; i++) { RefreshContext(i); } for (int i = 0; i < kNumAsyncServerThreads; i++) { - server_threads_.push_back( - new std::thread(&CommonStressTestAsyncServer::ProcessRpcs, this)); + server_threads_.emplace_back(&CommonStressTestAsyncServer::ProcessRpcs, + this); } } void TearDown() override { @@ -256,8 +256,7 @@ class CommonStressTestAsyncServer } for (int i = 0; i < kNumAsyncServerThreads; i++) { - server_threads_[i]->join(); - delete server_threads_[i]; + server_threads_[i].join(); } void* ignored_tag; @@ -265,7 +264,6 @@ class CommonStressTestAsyncServer while (cq_->Next(&ignored_tag, &ignored_ok)) ; TearDownEnd(); - delete[] contexts_; } private: @@ -311,12 +309,13 @@ class CommonStressTestAsyncServer response_writer; EchoRequest recv_request; enum { READY, DONE } state; - } * contexts_; + }; + std::vector<Context> contexts_; ::grpc::testing::EchoTestService::AsyncService service_; std::unique_ptr<ServerCompletionQueue> cq_; bool shutting_down_; std::mutex mu_; - std::vector<std::thread*> server_threads_; + std::vector<std::thread> server_threads_; }; template <class Common> @@ -353,14 +352,12 @@ typedef ::testing::Types<CommonStressTestSyncServer, TYPED_TEST_CASE(End2endTest, CommonTypes); TYPED_TEST(End2endTest, ThreadStress) { this->common_.ResetStub(); - std::vector<std::thread*> threads; + std::vector<std::thread> threads; for (int i = 0; i < kNumThreads; ++i) { - threads.push_back( - new std::thread(SendRpc, this->common_.GetStub(), kNumRpcs)); + threads.emplace_back(SendRpc, this->common_.GetStub(), kNumRpcs); } for (int i = 0; i < kNumThreads; ++i) { - threads[i]->join(); - delete threads[i]; + threads[i].join(); } } @@ -442,26 +439,24 @@ class AsyncClientEnd2endTest : public ::testing::Test { TYPED_TEST_CASE(AsyncClientEnd2endTest, CommonTypes); TYPED_TEST(AsyncClientEnd2endTest, ThreadStress) { this->common_.ResetStub(); - std::vector<std::thread *> send_threads, completion_threads; + std::vector<std::thread> send_threads, completion_threads; for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { - completion_threads.push_back(new std::thread( + completion_threads.emplace_back( &AsyncClientEnd2endTest_ThreadStress_Test<TypeParam>::AsyncCompleteRpc, - this)); + this); } for (int i = 0; i < kNumAsyncSendThreads; ++i) { - send_threads.push_back(new std::thread( + send_threads.emplace_back( &AsyncClientEnd2endTest_ThreadStress_Test<TypeParam>::AsyncSendRpc, - this, kNumRpcs)); + this, kNumRpcs); } for (int i = 0; i < kNumAsyncSendThreads; ++i) { - send_threads[i]->join(); - delete send_threads[i]; + send_threads[i].join(); } this->Wait(); for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { - completion_threads[i]->join(); - delete completion_threads[i]; + completion_threads[i].join(); } } diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index e67189c69e..191d729a9e 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -71,12 +71,12 @@ TEST_F(GrpclbTest, CreateRequest) { const grpc::string service_name = "AServiceName"; LoadBalanceRequest request; grpc_grpclb_request* c_req = grpc_grpclb_request_create(service_name.c_str()); - gpr_slice slice = grpc_grpclb_request_encode(c_req); - const int num_bytes_written = GPR_SLICE_LENGTH(slice); + grpc_slice slice = grpc_grpclb_request_encode(c_req); + const int num_bytes_written = GRPC_SLICE_LENGTH(slice); EXPECT_GT(num_bytes_written, 0); - request.ParseFromArray(GPR_SLICE_START_PTR(slice), num_bytes_written); + request.ParseFromArray(GRPC_SLICE_START_PTR(slice), num_bytes_written); EXPECT_EQ(request.initial_request().name(), service_name); - gpr_slice_unref(slice); + grpc_slice_unref(slice); grpc_grpclb_request_destroy(c_req); } @@ -88,15 +88,15 @@ TEST_F(GrpclbTest, ParseInitialResponse) { client_stats_report_interval->set_seconds(123); client_stats_report_interval->set_nanos(456); const grpc::string encoded_response = response.SerializeAsString(); - gpr_slice encoded_slice = - gpr_slice_from_copied_string(encoded_response.c_str()); + grpc_slice encoded_slice = + grpc_slice_from_copied_string(encoded_response.c_str()); grpc_grpclb_initial_response* c_initial_response = grpc_grpclb_initial_response_parse(encoded_slice); EXPECT_FALSE(c_initial_response->has_load_balancer_delegate); EXPECT_EQ(c_initial_response->client_stats_report_interval.seconds, 123); EXPECT_EQ(c_initial_response->client_stats_report_interval.nanos, 456); - gpr_slice_unref(encoded_slice); + grpc_slice_unref(encoded_slice); grpc_grpclb_initial_response_destroy(c_initial_response); } @@ -116,7 +116,7 @@ TEST_F(GrpclbTest, ParseResponseServerList) { expiration_interval->set_nanos(999); const grpc::string encoded_response = response.SerializeAsString(); - const gpr_slice encoded_slice = gpr_slice_from_copied_buffer( + const grpc_slice encoded_slice = grpc_slice_from_copied_buffer( encoded_response.data(), encoded_response.size()); grpc_grpclb_serverlist* c_serverlist = grpc_grpclb_response_parse_serverlist(encoded_slice); @@ -137,7 +137,7 @@ TEST_F(GrpclbTest, ParseResponseServerList) { EXPECT_TRUE(c_serverlist->expiration_interval.has_nanos); EXPECT_EQ(c_serverlist->expiration_interval.nanos, 999); - gpr_slice_unref(encoded_slice); + grpc_slice_unref(encoded_slice); grpc_grpclb_destroy_serverlist(c_serverlist); } diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 70d50ec2fa..175786332b 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -121,7 +121,7 @@ typedef struct test_fixture { static void *tag(intptr_t t) { return (void *)t; } -static gpr_slice build_response_payload_slice( +static grpc_slice build_response_payload_slice( const char *host, int *ports, size_t nports, int64_t expiration_interval_secs, int32_t expiration_interval_nanos) { // server_list { @@ -159,7 +159,7 @@ static gpr_slice build_response_payload_slice( server->set_load_balance_token(token_data); } const grpc::string &enc_resp = response.SerializeAsString(); - return gpr_slice_from_copied_buffer(enc_resp.data(), enc_resp.size()); + return grpc_slice_from_copied_buffer(enc_resp.data(), enc_resp.size()); } static void drain_cq(grpc_completion_queue *cq) { @@ -221,17 +221,17 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, // validate initial request. grpc_byte_buffer_reader bbr; grpc_byte_buffer_reader_init(&bbr, request_payload_recv); - gpr_slice request_payload_slice = grpc_byte_buffer_reader_readall(&bbr); + grpc_slice request_payload_slice = grpc_byte_buffer_reader_readall(&bbr); grpc::lb::v1::LoadBalanceRequest request; - request.ParseFromArray(GPR_SLICE_START_PTR(request_payload_slice), - GPR_SLICE_LENGTH(request_payload_slice)); + request.ParseFromArray(GRPC_SLICE_START_PTR(request_payload_slice), + GRPC_SLICE_LENGTH(request_payload_slice)); GPR_ASSERT(request.has_initial_request()); GPR_ASSERT(request.initial_request().name() == sf->servers_hostport); - gpr_slice_unref(request_payload_slice); + grpc_slice_unref(request_payload_slice); grpc_byte_buffer_reader_destroy(&bbr); grpc_byte_buffer_destroy(request_payload_recv); - gpr_slice response_payload_slice; + grpc_slice response_payload_slice; op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; @@ -275,7 +275,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, sf->servers_hostport, i); grpc_byte_buffer_destroy(response_payload); - gpr_slice_unref(response_payload_slice); + grpc_slice_unref(response_payload_slice); } gpr_log(GPR_INFO, "LB Server[%s] shutting down", sf->servers_hostport); @@ -365,7 +365,7 @@ static void start_backend_server(server_fixture *sf) { gpr_log(GPR_INFO, "Server[%s] after tag 101", sf->servers_hostport); bool exit = false; - gpr_slice response_payload_slice = gpr_slice_from_copied_string(PAYLOAD); + grpc_slice response_payload_slice = grpc_slice_from_copied_string(PAYLOAD); while (!exit) { op = ops; op->op = GRPC_OP_RECV_MESSAGE; @@ -424,7 +424,7 @@ static void start_backend_server(server_fixture *sf) { ++sf->num_calls_serviced; gpr_log(GPR_INFO, "Server[%s] OUT OF THE LOOP", sf->servers_hostport); - gpr_slice_unref(response_payload_slice); + grpc_slice_unref(response_payload_slice); op = ops; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; @@ -466,7 +466,8 @@ static void perform_request(client_fixture *cf) { int i; memset(ops, 0, sizeof(ops)); - gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); + grpc_slice request_payload_slice = + grpc_slice_from_copied_string("hello world"); c = grpc_channel_create_call(cf->client, NULL, GRPC_PROPAGATE_DEFAULTS, cf->cq, "/foo", "foo.test.google.fr:1234", @@ -525,7 +526,7 @@ static void perform_request(client_fixture *cf) { grpc_byte_buffer_destroy(response_payload_recv); } - gpr_slice_unref(request_payload_slice); + grpc_slice_unref(request_payload_slice); op = ops; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index a8d125ad28..fdd78ebb89 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -103,7 +103,7 @@ class ClientRequestCreator<ByteBuffer> { if (payload_config.has_bytebuf_params()) { std::unique_ptr<char[]> buf( new char[payload_config.bytebuf_params().req_size()]); - gpr_slice s = gpr_slice_from_copied_buffer( + grpc_slice s = grpc_slice_from_copied_buffer( buf.get(), payload_config.bytebuf_params().req_size()); Slice slice(s, Slice::STEAL_REF); *req = ByteBuffer(&slice, 1); @@ -163,10 +163,9 @@ class Client { MaybeStartRequests(); - // avoid std::vector for old compilers that expect a copy constructor if (reset) { - Histogram* to_merge = new Histogram[threads_.size()]; - StatusHistogram* to_merge_status = new StatusHistogram[threads_.size()]; + std::vector<Histogram> to_merge(threads_.size()); + std::vector<StatusHistogram> to_merge_status(threads_.size()); for (size_t i = 0; i < threads_.size(); i++) { threads_[i]->BeginSwap(&to_merge[i], &to_merge_status[i]); @@ -177,8 +176,6 @@ class Client { latencies.Merge(to_merge[i]); MergeStatusHistogram(to_merge_status[i], &statuses); } - delete[] to_merge; - delete[] to_merge_status; timer_result = timer->Mark(); } else { // merge snapshots of each thread histogram diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 2ec6a5a23b..4032039ea1 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -177,7 +177,6 @@ class AsyncClient : public ClientImpl<StubType, RequestType> { shutdown_state_.emplace_back(new PerThreadShutdownState()); } - using namespace std::placeholders; int t = 0; for (int ch = 0; ch < config.client_channels(); ch++) { for (int i = 0; i < config.outstanding_rpcs_per_channel(); i++) { diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index a88a24d89c..b1e61865e7 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -138,10 +138,9 @@ class SynchronousUnaryClient final : public SynchronousClient { class SynchronousStreamingClient final : public SynchronousClient { public: SynchronousStreamingClient(const ClientConfig& config) - : SynchronousClient(config) { - context_ = new grpc::ClientContext[num_threads_]; - stream_ = new std::unique_ptr< - grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>[num_threads_]; + : SynchronousClient(config), + context_(num_threads_), + stream_(num_threads_) { for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) { auto* stub = channels_[thread_idx % channels_.size()].get_stub(); stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]); @@ -161,8 +160,6 @@ class SynchronousStreamingClient final : public SynchronousClient { } } } - delete[] stream_; - delete[] context_; } bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override { @@ -182,8 +179,9 @@ class SynchronousStreamingClient final : public SynchronousClient { private: // These are both conceptually std::vector but cannot be for old compilers // that expect contained classes to support copy constructors - grpc::ClientContext* context_; - std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>* + std::vector<grpc::ClientContext> context_; + std::vector< + std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>> stream_; }; diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index a440341ccf..ea0b38e8ad 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -125,6 +125,8 @@ static double UserTime(ClientStats s) { return s.time_user(); } static double ServerWallTime(ServerStats s) { return s.time_elapsed(); } static double ServerSystemTime(ServerStats s) { return s.time_system(); } static double ServerUserTime(ServerStats s) { return s.time_user(); } +static double ServerTotalCpuTime(ServerStats s) { return s.total_cpu_time(); } +static double ServerIdleCpuTime(ServerStats s) { return s.idle_cpu_time(); } static int Cores(int n) { return n; } // Postprocess ScenarioResult and populate result summary. @@ -149,6 +151,7 @@ static void postprocess_scenario_result(ScenarioResult* result) { sum(result->server_stats(), ServerWallTime); auto server_user_time = 100.0 * sum(result->server_stats(), ServerUserTime) / sum(result->server_stats(), ServerWallTime); + auto client_system_time = 100.0 * sum(result->client_stats(), SystemTime) / sum(result->client_stats(), WallTime); auto client_user_time = 100.0 * sum(result->client_stats(), UserTime) / @@ -159,6 +162,18 @@ static void postprocess_scenario_result(ScenarioResult* result) { result->mutable_summary()->set_client_system_time(client_system_time); result->mutable_summary()->set_client_user_time(client_user_time); + // For Non-linux platform, get_cpu_usage() is not implemented. Thus, + // ServerTotalCpuTime and ServerIdleCpuTime are both 0. + if (average(result->server_stats(), ServerTotalCpuTime) == 0) { + result->mutable_summary()->set_server_cpu_usage(0); + } else { + auto server_cpu_usage = + 100 - + 100 * average(result->server_stats(), ServerIdleCpuTime) / + average(result->server_stats(), ServerTotalCpuTime); + result->mutable_summary()->set_server_cpu_usage(server_cpu_usage); + } + if (result->request_results_size() > 0) { int64_t successes = 0; int64_t failures = 0; @@ -177,30 +192,6 @@ static void postprocess_scenario_result(ScenarioResult* result) { } } -// Namespace for classes and functions used only in RunScenario -// Using this rather than local definitions to workaround gcc-4.4 limitations -// regarding using templates without linkage -namespace runsc { - -// ClientContext allocator -static ClientContext* AllocContext(list<ClientContext>* contexts) { - contexts->emplace_back(); - auto context = &contexts->back(); - context->set_wait_for_ready(true); - return context; -} - -struct ServerData { - unique_ptr<WorkerService::Stub> stub; - unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; -}; - -struct ClientData { - unique_ptr<WorkerService::Stub> stub; - unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; -}; -} // namespace runsc - std::unique_ptr<ScenarioResult> RunScenario( const ClientConfig& initial_client_config, size_t num_clients, const ServerConfig& initial_server_config, size_t num_servers, @@ -210,6 +201,12 @@ std::unique_ptr<ScenarioResult> RunScenario( // ClientContext allocations (all are destroyed at scope exit) list<ClientContext> contexts; + auto alloc_context = [](list<ClientContext>* contexts) { + contexts->emplace_back(); + auto context = &contexts->back(); + context->set_wait_for_ready(true); + return context; + }; // To be added to the result, containing the final configuration used for // client and config (including host, etc.) @@ -262,10 +259,11 @@ std::unique_ptr<ScenarioResult> RunScenario( workers.resize(num_clients + num_servers); // Start servers - using runsc::ServerData; - // servers is array rather than std::vector to avoid gcc-4.4 issues - // where class contained in std::vector must have a copy constructor - auto* servers = new ServerData[num_servers]; + struct ServerData { + unique_ptr<WorkerService::Stub> stub; + unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; + }; + std::vector<ServerData> servers(num_servers); for (size_t i = 0; i < num_servers; i++) { gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")", workers[i].c_str(), i); @@ -309,8 +307,7 @@ std::unique_ptr<ScenarioResult> RunScenario( ServerArgs args; *args.mutable_setup() = server_config; - servers[i].stream = - servers[i].stub->RunServer(runsc::AllocContext(&contexts)); + servers[i].stream = servers[i].stub->RunServer(alloc_context(&contexts)); if (!servers[i].stream->Write(args)) { gpr_log(GPR_ERROR, "Could not write args to server %zu", i); } @@ -328,10 +325,11 @@ std::unique_ptr<ScenarioResult> RunScenario( // Targets are all set by now result_client_config = client_config; // Start clients - using runsc::ClientData; - // clients is array rather than std::vector to avoid gcc-4.4 issues - // where class contained in std::vector must have a copy constructor - auto* clients = new ClientData[num_clients]; + struct ClientData { + unique_ptr<WorkerService::Stub> stub; + unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; + }; + std::vector<ClientData> clients(num_clients); size_t channels_allocated = 0; for (size_t i = 0; i < num_clients; i++) { const auto& worker = workers[i + num_servers]; @@ -380,8 +378,7 @@ std::unique_ptr<ScenarioResult> RunScenario( ClientArgs args; *args.mutable_setup() = per_client_config; - clients[i].stream = - clients[i].stub->RunClient(runsc::AllocContext(&contexts)); + clients[i].stream = clients[i].stub->RunClient(alloc_context(&contexts)); if (!clients[i].stream->Write(args)) { gpr_log(GPR_ERROR, "Could not write args to client %zu", i); } @@ -501,7 +498,6 @@ std::unique_ptr<ScenarioResult> RunScenario( s.error_message().c_str()); } } - delete[] clients; merged_latencies.FillProto(result->mutable_latencies()); for (std::unordered_map<int, int64_t>::iterator it = merged_statuses.begin(); @@ -544,8 +540,6 @@ std::unique_ptr<ScenarioResult> RunScenario( } } - delete[] servers; - postprocess_scenario_result(result.get()); return result; } diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index 1524ebbc38..31b5917fb7 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -49,10 +49,111 @@ DEFINE_string(scenarios_file, "", DEFINE_string(scenarios_json, "", "JSON string containing an array of Scenario objects"); DEFINE_bool(quit, false, "Quit the workers"); +DEFINE_string(search_param, "", + "The parameter, whose value is to be searched for to achieve " + "targeted cpu load. For now, we have 'offered_load'. Later, " + "'num_channels', 'num_outstanding_requests', etc. shall be " + "added."); +DEFINE_double( + initial_search_value, 0.0, + "initial parameter value to start the search with (i.e. lower bound)"); +DEFINE_double(targeted_cpu_load, 70.0, + "Targeted cpu load (unit: %, range [0,100])"); +DEFINE_double(stride, 1, + "Defines each stride of the search. The larger the stride is, " + "the coarser the result will be, but will also be faster."); +DEFINE_double(error_tolerance, 0.01, + "Defines threshold for stopping the search. When current search " + "range is narrower than the error_tolerance computed range, we " + "stop the search."); namespace grpc { namespace testing { +static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario, + bool* success) { + std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n"; + auto result = + RunScenario(scenario.client_config(), scenario.num_clients(), + scenario.server_config(), scenario.num_servers(), + scenario.warmup_seconds(), scenario.benchmark_seconds(), + scenario.spawn_local_worker_count()); + + // Amend the result with scenario config. Eventually we should adjust + // RunScenario contract so we don't need to touch the result here. + result->mutable_scenario()->CopyFrom(scenario); + + GetReporter()->ReportQPS(*result); + GetReporter()->ReportQPSPerCore(*result); + GetReporter()->ReportLatency(*result); + GetReporter()->ReportTimes(*result); + GetReporter()->ReportCpuUsage(*result); + + for (int i = 0; *success && i < result->client_success_size(); i++) { + *success = result->client_success(i); + } + for (int i = 0; *success && i < result->server_success_size(); i++) { + *success = result->server_success(i); + } + + return result; +} + +static double GetCpuLoad(Scenario* scenario, double offered_load, + bool* success) { + scenario->mutable_client_config() + ->mutable_load_params() + ->mutable_poisson() + ->set_offered_load(offered_load); + auto result = RunAndReport(*scenario, success); + return result->summary().server_cpu_usage(); +} + +static double BinarySearch(Scenario* scenario, double targeted_cpu_load, + double low, double high, bool* success) { + while (low <= high * (1 - FLAGS_error_tolerance)) { + double mid = low + (high - low) / 2; + double current_cpu_load = GetCpuLoad(scenario, mid, success); + gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", mid); + if (!*success) { + gpr_log(GPR_ERROR, "Client/Server Failure"); + break; + } + if (targeted_cpu_load <= current_cpu_load) { + high = mid - FLAGS_stride; + } else { + low = mid + FLAGS_stride; + } + } + + return low; +} + +static double SearchOfferedLoad(double initial_offered_load, + double targeted_cpu_load, Scenario* scenario, + bool* success) { + std::cerr << "RUNNING SCENARIO: " << scenario->name() << "\n"; + double current_offered_load = initial_offered_load; + double current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); + if (current_cpu_load > targeted_cpu_load) { + gpr_log(GPR_ERROR, "Initial offered load too high"); + return -1; + } + + while (*success && (current_cpu_load < targeted_cpu_load)) { + current_offered_load *= 2; + current_cpu_load = GetCpuLoad(scenario, current_offered_load, success); + gpr_log(GPR_DEBUG, "Binary Search: current_offered_load %.0f", + current_offered_load); + } + + double targeted_offered_load = + BinarySearch(scenario, targeted_cpu_load, current_offered_load / 2, + current_offered_load, success); + + return targeted_offered_load; +} + static bool QpsDriver() { grpc::string json; @@ -68,11 +169,11 @@ static bool QpsDriver() { if (scfile) { // Read the json data from disk - FILE *json_file = fopen(FLAGS_scenarios_file.c_str(), "r"); + FILE* json_file = fopen(FLAGS_scenarios_file.c_str(), "r"); GPR_ASSERT(json_file != NULL); fseek(json_file, 0, SEEK_END); long len = ftell(json_file); - char *data = new char[len]; + char* data = new char[len]; fseek(json_file, 0, SEEK_SET); GPR_ASSERT(len == (long)fread(data, 1, len, json_file)); fclose(json_file); @@ -93,28 +194,19 @@ static bool QpsDriver() { GPR_ASSERT(scenarios.scenarios_size() > 0); for (int i = 0; i < scenarios.scenarios_size(); i++) { - const Scenario &scenario = scenarios.scenarios(i); - std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n"; - auto result = - RunScenario(scenario.client_config(), scenario.num_clients(), - scenario.server_config(), scenario.num_servers(), - scenario.warmup_seconds(), scenario.benchmark_seconds(), - scenario.spawn_local_worker_count()); - - // Amend the result with scenario config. Eventually we should adjust - // RunScenario contract so we don't need to touch the result here. - result->mutable_scenario()->CopyFrom(scenario); - - GetReporter()->ReportQPS(*result); - GetReporter()->ReportQPSPerCore(*result); - GetReporter()->ReportLatency(*result); - GetReporter()->ReportTimes(*result); - - for (int i = 0; success && i < result->client_success_size(); i++) { - success = result->client_success(i); - } - for (int i = 0; success && i < result->server_success_size(); i++) { - success = result->server_success(i); + if (FLAGS_search_param == "") { + const Scenario& scenario = scenarios.scenarios(i); + RunAndReport(scenario, &success); + } else { + if (FLAGS_search_param == "offered_load") { + Scenario* scenario = scenarios.mutable_scenarios(i); + double targeted_offered_load = + SearchOfferedLoad(FLAGS_initial_search_value, + FLAGS_targeted_cpu_load, scenario, &success); + gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load); + } else { + gpr_log(GPR_ERROR, "Unimplemented search param"); + } } } return success; @@ -123,7 +215,7 @@ static bool QpsDriver() { } // namespace testing } // namespace grpc -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); bool ok = grpc::testing::QpsDriver(); diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 41617e968a..7f84816421 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -71,6 +71,12 @@ void CompositeReporter::ReportTimes(const ScenarioResult& result) { } } +void CompositeReporter::ReportCpuUsage(const ScenarioResult& result) { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportCpuUsage(result); + } +} + void GprLogReporter::ReportQPS(const ScenarioResult& result) { gpr_log(GPR_INFO, "QPS: %.1f", result.summary().qps()); if (result.summary().failed_requests_per_second() > 0) { @@ -107,6 +113,11 @@ void GprLogReporter::ReportTimes(const ScenarioResult& result) { result.summary().client_user_time()); } +void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) { + gpr_log(GPR_INFO, "Server CPU usage: %.2f%%", + result.summary().server_cpu_usage()); +} + void JsonReporter::ReportQPS(const ScenarioResult& result) { grpc::string json_string = SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult"); @@ -127,5 +138,9 @@ void JsonReporter::ReportTimes(const ScenarioResult& result) { // NOP - all reporting is handled by ReportQPS. } +void JsonReporter::ReportCpuUsage(const ScenarioResult& result) { + // NOP - all reporting is handled by ReportQPS. +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index 9dc259e95a..faf87ff060 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -70,6 +70,9 @@ class Reporter { /** Reports system and user time for client and server systems. */ virtual void ReportTimes(const ScenarioResult& result) = 0; + /** Reports server cpu usage. */ + virtual void ReportCpuUsage(const ScenarioResult& result) = 0; + private: const string name_; }; @@ -86,6 +89,7 @@ class CompositeReporter : public Reporter { void ReportQPSPerCore(const ScenarioResult& result) override; void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; + void ReportCpuUsage(const ScenarioResult& result) override; private: std::vector<std::unique_ptr<Reporter> > reporters_; @@ -101,6 +105,7 @@ class GprLogReporter : public Reporter { void ReportQPSPerCore(const ScenarioResult& result) override; void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; + void ReportCpuUsage(const ScenarioResult& result) override; }; /** Dumps the report to a JSON file. */ @@ -114,6 +119,7 @@ class JsonReporter : public Reporter { void ReportQPSPerCore(const ScenarioResult& result) override; void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; + void ReportCpuUsage(const ScenarioResult& result) override; const string report_file_; }; diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index e8bc396696..c3d18e5789 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -75,6 +75,8 @@ class Server { stats.set_time_elapsed(timer_result.wall); stats.set_time_system(timer_result.system); stats.set_time_user(timer_result.user); + stats.set_total_cpu_time(timer_result.total_cpu_time); + stats.set_idle_cpu_time(timer_result.idle_cpu_time); return stats; } diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index f556fbdfa1..b3a06aeaf5 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -376,7 +376,7 @@ static Status ProcessGenericRPC(const PayloadConfig &payload_config, ByteBuffer *response) { int resp_size = payload_config.bytebuf_params().resp_size(); std::unique_ptr<char[]> buf(new char[resp_size]); - gpr_slice s = gpr_slice_from_copied_buffer(buf.get(), resp_size); + grpc_slice s = grpc_slice_from_copied_buffer(buf.get(), resp_size); Slice slice(s, Slice::STEAL_REF); *response = ByteBuffer(&slice, 1); return Status::OK; diff --git a/test/cpp/qps/usage_timer.cc b/test/cpp/qps/usage_timer.cc index ff595b2ba0..c6697fbdfd 100644 --- a/test/cpp/qps/usage_timer.cc +++ b/test/cpp/qps/usage_timer.cc @@ -33,10 +33,14 @@ #include "test/cpp/qps/usage_timer.h" +#include <fstream> +#include <sstream> +#include <string> + +#include <grpc/support/log.h> #include <grpc/support/time.h> #include <sys/resource.h> #include <sys/time.h> - UsageTimer::UsageTimer() : start_(Sample()) {} double UsageTimer::Now() { @@ -48,6 +52,27 @@ static double time_double(struct timeval* tv) { return tv->tv_sec + 1e-6 * tv->tv_usec; } +static void get_cpu_usage(unsigned long long* total_cpu_time, + unsigned long long* idle_cpu_time) { +#ifdef __linux__ + std::ifstream proc_stat("/proc/stat"); + proc_stat.ignore(5); + std::string cpu_time_str; + std::string first_line; + std::getline(proc_stat, first_line); + std::stringstream first_line_s(first_line); + for (int i = 0; i < 10; ++i) { + std::getline(first_line_s, cpu_time_str, ' '); + *total_cpu_time += std::stol(cpu_time_str); + if (i == 3) { + *idle_cpu_time = std::stol(cpu_time_str); + } + } +#else + gpr_log(GPR_INFO, "get_cpu_usage(): Non-linux platform is not supported."); +#endif +} + UsageTimer::Result UsageTimer::Sample() { struct rusage usage; struct timeval tv; @@ -58,6 +83,9 @@ UsageTimer::Result UsageTimer::Sample() { r.wall = time_double(&tv); r.user = time_double(&usage.ru_utime); r.system = time_double(&usage.ru_stime); + r.total_cpu_time = 0; + r.idle_cpu_time = 0; + get_cpu_usage(&r.total_cpu_time, &r.idle_cpu_time); return r; } @@ -67,5 +95,8 @@ UsageTimer::Result UsageTimer::Mark() const { r.wall = s.wall - start_.wall; r.user = s.user - start_.user; r.system = s.system - start_.system; + r.total_cpu_time = s.total_cpu_time - start_.total_cpu_time; + r.idle_cpu_time = s.idle_cpu_time - start_.idle_cpu_time; + return r; } diff --git a/test/cpp/qps/usage_timer.h b/test/cpp/qps/usage_timer.h index 8343cd6653..0fc1b47996 100644 --- a/test/cpp/qps/usage_timer.h +++ b/test/cpp/qps/usage_timer.h @@ -42,6 +42,8 @@ class UsageTimer { double wall; double user; double system; + unsigned long long total_cpu_time; + unsigned long long idle_cpu_time; }; Result Mark() const; diff --git a/test/cpp/util/byte_buffer_proto_helper.cc b/test/cpp/util/byte_buffer_proto_helper.cc index d625d6f3f4..ab5ca261e6 100644 --- a/test/cpp/util/byte_buffer_proto_helper.cc +++ b/test/cpp/util/byte_buffer_proto_helper.cc @@ -51,7 +51,7 @@ std::unique_ptr<ByteBuffer> SerializeToByteBuffer( grpc::protobuf::Message* message) { grpc::string buf; message->SerializeToString(&buf); - gpr_slice s = gpr_slice_from_copied_string(buf.c_str()); + grpc_slice s = grpc_slice_from_copied_string(buf.c_str()); Slice slice(s, Slice::STEAL_REF); return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1)); } diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc index 2089a62011..470ce0cbf4 100644 --- a/test/cpp/util/byte_buffer_test.cc +++ b/test/cpp/util/byte_buffer_test.cc @@ -37,7 +37,7 @@ #include <vector> #include <grpc++/support/slice.h> -#include <grpc/support/slice.h> +#include <grpc/slice.h> #include <gtest/gtest.h> namespace grpc { @@ -49,14 +49,14 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world"; class ByteBufferTest : public ::testing::Test {}; TEST_F(ByteBufferTest, CreateFromSingleSlice) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); Slice s(hello, Slice::STEAL_REF); ByteBuffer buffer(&s, 1); } TEST_F(ByteBufferTest, CreateFromVector) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); - gpr_slice world = gpr_slice_from_copied_string(kContent2); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); + grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF)); @@ -64,15 +64,15 @@ TEST_F(ByteBufferTest, CreateFromVector) { } TEST_F(ByteBufferTest, Clear) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); Slice s(hello, Slice::STEAL_REF); ByteBuffer buffer(&s, 1); buffer.Clear(); } TEST_F(ByteBufferTest, Length) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); - gpr_slice world = gpr_slice_from_copied_string(kContent2); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); + grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF)); @@ -80,12 +80,12 @@ TEST_F(ByteBufferTest, Length) { EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); } -bool SliceEqual(const Slice& a, gpr_slice b) { - if (a.size() != GPR_SLICE_LENGTH(b)) { +bool SliceEqual(const Slice& a, grpc_slice b) { + if (a.size() != GRPC_SLICE_LENGTH(b)) { return false; } for (size_t i = 0; i < a.size(); i++) { - if (a.begin()[i] != GPR_SLICE_START_PTR(b)[i]) { + if (a.begin()[i] != GRPC_SLICE_START_PTR(b)[i]) { return false; } } @@ -93,8 +93,8 @@ bool SliceEqual(const Slice& a, gpr_slice b) { } TEST_F(ByteBufferTest, Dump) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); - gpr_slice world = gpr_slice_from_copied_string(kContent2); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); + grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF)); @@ -106,8 +106,8 @@ TEST_F(ByteBufferTest, Dump) { } TEST_F(ByteBufferTest, SerializationMakesCopy) { - gpr_slice hello = gpr_slice_from_copied_string(kContent1); - gpr_slice world = gpr_slice_from_copied_string(kContent2); + grpc_slice hello = grpc_slice_from_copied_string(kContent1); + grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF)); diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index 1edffbe08e..a02a8b2ee2 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -41,8 +41,8 @@ #include <grpc++/generic/generic_stub.h> #include <grpc++/support/byte_buffer.h> #include <grpc/grpc.h> +#include <grpc/slice.h> #include <grpc/support/log.h> -#include <grpc/support/slice.h> namespace grpc { namespace testing { @@ -72,7 +72,7 @@ Status CliCall::Call(std::shared_ptr<grpc::Channel> channel, cq.Next(&got_tag, &ok); GPR_ASSERT(ok); - gpr_slice s = gpr_slice_from_copied_string(request.c_str()); + grpc_slice s = grpc_slice_from_copied_string(request.c_str()); grpc::Slice req_slice(s, grpc::Slice::STEAL_REF); grpc::ByteBuffer send_buffer(&req_slice, 1); call->Write(send_buffer, tag(2)); diff --git a/test/cpp/util/config_grpc_cli.h b/test/cpp/util/config_grpc_cli.h index ea8231aa26..ac1e3044b7 100644 --- a/test/cpp/util/config_grpc_cli.h +++ b/test/cpp/util/config_grpc_cli.h @@ -77,7 +77,7 @@ namespace compiler { typedef GRPC_CUSTOM_DISKSOURCETREE DiskSourceTree; typedef GRPC_CUSTOM_IMPORTER Importer; typedef GRPC_CUSTOM_MULTIFILEERRORCOLLECTOR MultiFileErrorCollector; -} // namespace importer +} // namespace compiler } // namespace protobuf } // namespace grpc diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc index 45799ae157..8926fb7d5a 100644 --- a/test/cpp/util/slice_test.cc +++ b/test/cpp/util/slice_test.cc @@ -33,7 +33,7 @@ #include <grpc++/support/slice.h> -#include <grpc/support/slice.h> +#include <grpc/slice.h> #include <gtest/gtest.h> namespace grpc { @@ -51,15 +51,15 @@ class SliceTest : public ::testing::Test { }; TEST_F(SliceTest, Steal) { - gpr_slice s = gpr_slice_from_copied_string(kContent); + grpc_slice s = grpc_slice_from_copied_string(kContent); Slice spp(s, Slice::STEAL_REF); CheckSlice(spp, kContent); } TEST_F(SliceTest, Add) { - gpr_slice s = gpr_slice_from_copied_string(kContent); + grpc_slice s = grpc_slice_from_copied_string(kContent); Slice spp(s, Slice::ADD_REF); - gpr_slice_unref(s); + grpc_slice_unref(s); CheckSlice(spp, kContent); } @@ -69,13 +69,13 @@ TEST_F(SliceTest, Empty) { } TEST_F(SliceTest, Cslice) { - gpr_slice s = gpr_slice_from_copied_string(kContent); + grpc_slice s = grpc_slice_from_copied_string(kContent); Slice spp(s, Slice::STEAL_REF); CheckSlice(spp, kContent); - gpr_slice c_slice = spp.c_slice(); - EXPECT_EQ(GPR_SLICE_START_PTR(s), GPR_SLICE_START_PTR(c_slice)); - EXPECT_EQ(GPR_SLICE_END_PTR(s), GPR_SLICE_END_PTR(c_slice)); - gpr_slice_unref(c_slice); + grpc_slice c_slice = spp.c_slice(); + EXPECT_EQ(GRPC_SLICE_START_PTR(s), GRPC_SLICE_START_PTR(c_slice)); + EXPECT_EQ(GRPC_SLICE_END_PTR(s), GRPC_SLICE_END_PTR(c_slice)); + grpc_slice_unref(c_slice); } } // namespace |