From 1383895b7660357298c652e8ccfd45a0190d70e8 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 15:43:07 -0700 Subject: [PATCH 01/43] Initial commit: Auto-generate GMOCK code for client stub. --- Makefile | 10 +- build.yaml | 1 + include/grpc++/test/mock_stream.h | 128 +++++++++++++++++++++ src/compiler/cpp_generator.cc | 184 ++++++++++++++++++++++++++++++ src/compiler/cpp_generator.h | 12 ++ src/compiler/cpp_plugin.cc | 10 ++ test/cpp/end2end/mock_test.cc | 142 +++++++---------------- third_party/googletest | 2 +- 8 files changed, 382 insertions(+), 107 deletions(-) create mode 100644 include/grpc++/test/mock_stream.h diff --git a/Makefile b/Makefile index bfc43aab28e..68fb09b3e4a 100644 --- a/Makefile +++ b/Makefile @@ -401,8 +401,12 @@ AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little USE_BUILT_PROTOC = false endif -GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc +GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc GTEST_LIB += -lgflags + +#GMOCK_LIB = -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock -Ithird_party/googletest/googlemock/src/gmock-all.cc +#GMOCK_LIB += -lgflags + ifeq ($(V),1) E = @: Q = @@ -776,7 +780,7 @@ PROTOBUF_PKG_CONFIG = false PC_REQUIRES_GRPCXX = PC_LIBS_GRPCXX = -CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS) +CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS) PROTOC_PLUGINS_ALL = $(BINDIR)/$(CONFIG)/grpc_cpp_plugin $(BINDIR)/$(CONFIG)/grpc_csharp_plugin $(BINDIR)/$(CONFIG)/grpc_node_plugin $(BINDIR)/$(CONFIG)/grpc_objective_c_plugin $(BINDIR)/$(CONFIG)/grpc_php_plugin $(BINDIR)/$(CONFIG)/grpc_python_plugin $(BINDIR)/$(CONFIG)/grpc_ruby_plugin PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG) @@ -14835,7 +14839,7 @@ else $(BINDIR)/$(CONFIG)/mock_test: $(PROTOBUF_DEP) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test + $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test endif diff --git a/build.yaml b/build.yaml index 6e590f4ca6b..5f0358dd2d7 100644 --- a/build.yaml +++ b/build.yaml @@ -934,6 +934,7 @@ filegroups: language: c++ public_headers: - include/grpc++/test/server_context_test_spouse.h + - include/grpc++/test/mock_stream.h deps: - grpc++ - name: thrift_util diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h new file mode 100644 index 00000000000..f99a1b1128b --- /dev/null +++ b/include/grpc++/test/mock_stream.h @@ -0,0 +1,128 @@ +#ifndef NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ +#define NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ + +#include + +#include +#include +#include +#include +#include + +namespace grpc { +namespace testing { + +template +class MockClientReader : public ClientReaderInterface { + public: + MockClientReader() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // ClientReaderInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); +}; + +template +class MockClientWriter : public ClientWriterInterface { + public: + MockClientWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + + // ClientWriterInterface + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientReaderWriter : public ClientReaderWriterInterface { + public: + MockClientReaderWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); + + // ClientReaderWriterInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientAsyncResponseReader + : public ClientAsyncResponseReaderInterface { + public: + MockClientAsyncResponseReader() = default; + + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD3_T(Finish, void(R*, Status*, void*)); +}; + +template +class MockClientAsyncReader : public ClientAsyncReaderInterface { + public: + MockClientAsyncReader() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); +}; + +template +class MockClientAsyncWriter : public ClientAsyncWriterInterface { + public: + MockClientAsyncWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // ClientAsyncWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +template +class MockClientAsyncReaderWriter + : public ClientAsyncReaderWriterInterface { + public: + MockClientAsyncReaderWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); + + // ClientAsyncReaderWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +} // namespace testing +} // namespace grpc + +#endif // NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 2908b639f39..b47fc717461 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1375,4 +1375,188 @@ grpc::string GetSourceEpilogue(File *file, const Parameters & /*params*/) { return temp; } +// TODO(mmukhi): Make sure we need parameters or not. +grpc::string GetMockPrologue(File *file, const Parameters & ) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + vars["filename"] = file->filename(); + vars["filename_base"] = file->filename_without_ext(); + vars["message_header_ext"] = file->message_header_ext(); + vars["service_header_ext"] = file->service_header_ext(); + + printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); + printer->Print(vars, + "// If you make any local change, they will be lost.\n"); + printer->Print(vars, "// source: $filename$\n\n"); + + printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n"); + printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n"); + printer->Print(vars, file->additional_headers().c_str()); + printer->Print(vars, "\n"); + } + return output; +} + +// TODO(mmukhi): Add client-stream and completion-queue headers. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + static const char *headers_strs[] = { + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/sync_stream.h", + "gmock/gmock.h", + }; + std::vector headers(headers_strs, array_end(headers_strs)); + PrintIncludes(printer.get(), headers, params); + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for(auto part = parts.begin(); part != parts.end(); part++) { + vars["part"] = *part; + printer->Print(vars, "namespace $part$ {\n"); + } + } + + printer->Print(vars, "\n"); + } + return output; +} + +void PrintMockClientMethods( + Printer *printer, const Method *method, + std::map *vars) { + (*vars)["Method"] = method->name(); + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + + if (method->NoStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " + "const $Request$& request, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq));\n"); + } else if (method->ClientOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->ServerOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->BidiStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD1($Method$Raw, " + "::grpc::ClientReaderWriterInterface< $Request$, $Response$>*" + "(::grpc::ClientContext* context));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncReaderWriterInterface<$Request$, $Response$>*" + "(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, " + "void* tag));\n"); + } +} + +void PrintMockService(Printer *printer, + const Service *service, + std::map *vars) { + (*vars)["Service"] = service->name(); + + printer->Print(service->GetLeadingComments().c_str()); + printer->Print(*vars, + "class Mock$Service$Stub : public $Service$::StubInterface {\n" + " public:\n"); + printer->Indent(); + printer->Print(*vars, + "Mock$Service$Stub(){}\n" + "~Mock$Service$Stub(){}\n"); + for (int i = 0; i < service->method_count(); ++i) { + printer->Print(service->method(i)->GetLeadingComments().c_str()); + PrintMockClientMethods(printer, service->method(i).get(), vars); + printer->Print(service->method(i)->GetTrailingComments().c_str()); + } + printer->Outdent(); + printer->Print("};\n"); + +} + +grpc::string GetMockServices(File *file, + const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + // Package string is empty or ends with a dot. It is used to fully qualify + // method names. + vars["Package"] = file->package(); + if (!file->package().empty()) { + vars["Package"].append("."); + } + + if(!params.services_namespace.empty()) { + vars["services_namespace"] = params.services_namespace; + printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); + } + + for (int i =0; i < file->service_count(); i++) { + PrintMockService(printer.get(), file->service(i).get(), &vars); + printer->Print("\n"); + } + + if (!params.services_namespace.empty()) { + printer->Print(vars, "} // namespace $services_namespace$\n\n"); + } + } + return output; +} + +grpc::string GetMockEpilogue(File *file, const Parameters &) { + grpc::string temp; + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for (auto part = parts.begin(); part != parts.end(); part++){ + temp.append("} // namespace "); + temp.append(*part); + temp.append("\n"); + } + temp.append("\n"); + } + + return temp; +} + } // namespace grpc_cpp_generator diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index d0343e9978b..50ac9258401 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -152,6 +152,18 @@ grpc::string GetSourceServices(File *file, const Parameters ¶ms); // Return the epilogue of the generated source file. grpc::string GetSourceEpilogue(File *file, const Parameters ¶ms); +// Return the prologue of the generated mock file. +grpc::string GetMockPrologue(File *file, const Parameters ¶ms); + +// Return the includes needed for generated mock file. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms); + +// Return the services for generated mock file. +grpc::string GetMockServices(File* file, const Parameters ¶ms); + +// Return the epilogue of generated mock file. +grpc::string GetMockEpilogue(File* file, const Parameters ¶ms); + } // namespace grpc_cpp_generator #endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index 38f8f738ed9..c16246e47c8 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -245,6 +245,16 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); + grpc::string mock_code = + grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockServices(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockEpilogue(&pbfile, generator_parameters); + std::unique_ptr mock_output( + context->Open(file_name + "_mock.grpc.pb.h")); + grpc::protobuf::io::CodedOutputStream mock_coded_out(mock_output.get()); + mock_coded_out.WriteRaw(mock_code.data(), mock_code.size()); + return true; } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index fdb2732e503..16c04032ab1 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -1,5 +1,5 @@ /* - * +* * Copyright 2015, Google Inc. * All rights reserved. * @@ -45,121 +45,37 @@ #include #include #include +#include + +#include #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "src/proto/grpc/testing/echo_mock.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include + +using namespace std; using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using grpc::testing::EchoTestService; +using grpc::testing::MockClientReaderWriter; using std::chrono::system_clock; +using ::testing::AtLeast; +using ::testing::SetArgPointee; +using ::testing::SaveArg; +using ::testing::_; +using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArg; +using ::testing::DoAll; namespace grpc { namespace testing { namespace { -template -class MockClientReaderWriter final : public ClientReaderWriterInterface { - public: - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(R* msg) override { return true; } - bool Write(const W& msg) override { return true; } - bool WritesDone() override { return true; } - Status Finish() override { return Status::OK; } -}; -template <> -class MockClientReaderWriter final - : public ClientReaderWriterInterface { - public: - MockClientReaderWriter() : writes_done_(false) {} - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(EchoResponse* msg) override { - if (writes_done_) return false; - msg->set_message(last_message_); - return true; - } - - bool Write(const EchoRequest& msg, WriteOptions options) override { - gpr_log(GPR_INFO, "mock recv msg %s", msg.message().c_str()); - last_message_ = msg.message(); - return true; - } - bool WritesDone() override { - writes_done_ = true; - return true; - } - Status Finish() override { return Status::OK; } - - private: - bool writes_done_; - grpc::string last_message_; -}; - -// Mocked stub. -class MockStub : public EchoTestService::StubInterface { - public: - MockStub() {} - ~MockStub() {} - Status Echo(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - response->set_message(request.message()); - return Status::OK; - } - Status Unimplemented(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - return Status::OK; - } - - private: - ClientAsyncResponseReaderInterface* AsyncEchoRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } - ClientWriterInterface* RequestStreamRaw( - ClientContext* context, EchoResponse* response) override { - return nullptr; - } - ClientAsyncWriterInterface* AsyncRequestStreamRaw( - ClientContext* context, EchoResponse* response, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderInterface* ResponseStreamRaw( - ClientContext* context, const EchoRequest& request) override { - return nullptr; - } - ClientAsyncReaderInterface* AsyncResponseStreamRaw( - ClientContext* context, const EchoRequest& request, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderWriterInterface* BidiStreamRaw( - ClientContext* context) override { - return new MockClientReaderWriter(); - } - ClientAsyncReaderWriterInterface* - AsyncBidiStreamRaw(ClientContext* context, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientAsyncResponseReaderInterface* AsyncUnimplementedRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } -}; - class FakeClient { public: explicit FakeClient(EchoTestService::StubInterface* stub) : stub_(stub) {} @@ -267,16 +183,36 @@ TEST_F(MockTest, SimpleRpc) { ResetStub(); FakeClient client(stub_.get()); client.DoEcho(); - MockStub stub; + MockEchoTestServiceStub stub; + EchoResponse resp; + resp.set_message("hello world"); + EXPECT_CALL(stub, Echo(_, _, _)).Times(AtLeast(1)).WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); client.ResetStub(&stub); client.DoEcho(); } +ACTION_P(copy, msg) { + arg0->set_message(msg->message()); +} + TEST_F(MockTest, BidiStream) { ResetStub(); FakeClient client(stub_.get()); client.DoBidiStream(); - MockStub stub; + MockEchoTestServiceStub stub; + auto rw = new MockClientReaderWriter(); + EchoRequest msg; + + EXPECT_CALL(*rw, Write(_, _)).Times(3).WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); + EXPECT_CALL(*rw, Read(_)). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*rw, WritesDone()); + EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, BidiStreamRaw(_)).WillOnce(Return(rw)); client.ResetStub(&stub); client.DoBidiStream(); } diff --git a/third_party/googletest b/third_party/googletest index c99458533a9..aa148eb2b7f 160000 --- a/third_party/googletest +++ b/third_party/googletest @@ -1 +1 @@ -Subproject commit c99458533a9b4c743ed51537e25989ea55944908 +Subproject commit aa148eb2b7f70ede0eb10de34b6254826bfb34f4 From c0ae1be4c87d9821a53a703633a53cd93f31a625 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 17:49:23 -0700 Subject: [PATCH 02/43] Added tests for uni-directional streaming RPCs. --- include/grpc++/test/mock_stream.h | 2 +- test/cpp/end2end/mock_test.cc | 137 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index f99a1b1128b..1b1a7351855 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -37,7 +37,7 @@ class MockClientWriter : public ClientWriterInterface { MOCK_METHOD0_T(Finish, Status()); // WriterInterface - MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); // ClientWriterInterface MOCK_METHOD0_T(WritesDone, bool()); diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 16c04032ab1..b7968ce2306 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -90,6 +90,55 @@ class FakeClient { EXPECT_TRUE(s.ok()); } + void DoRequestStream() { + EchoRequest request; + EchoResponse response; + + ClientContext context; + grpc::string msg("hello"); + grpc::string exp(msg); + + std::unique_ptr> + cstream = stub_->RequestStream(&context, &response); + + request.set_message(msg); + EXPECT_TRUE(cstream->Write(request)); + + msg = ", world"; + request.set_message(msg); + exp.append(msg); + EXPECT_TRUE(cstream->Write(request)); + + cstream->WritesDone(); + Status s = cstream->Finish(); + + EXPECT_EQ(exp, response.message()); + EXPECT_TRUE(s.ok()); + } + + void DoResponseStream() { + EchoRequest request; + EchoResponse response; + request.set_message("hello world"); + + ClientContext context; + std::unique_ptr> + cstream = stub_->ResponseStream(&context, request); + + grpc::string exp = ""; + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message() + " "); + + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message()); + + EXPECT_FALSE(cstream->Read(&response)); + EXPECT_EQ(request.message(), exp); + + Status s = cstream->Finish(); + EXPECT_TRUE(s.ok()); + } + void DoBidiStream() { EchoRequest request; EchoResponse response; @@ -135,6 +184,31 @@ class TestServiceImpl : public EchoTestService::Service { return Status::OK; } + Status RequestStream(ServerContext* context, + ServerReader* reader, + EchoResponse* response) { + EchoRequest request; + grpc::string resp(""); + while (reader->Read(&request)) { + gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); + resp.append(request.message()); + } + response->set_message(resp); + return Status::OK; + } + + Status ResponseStream(ServerContext* context, + const EchoRequest* request, + ServerWriter* writer) { + EchoResponse response; + vector tokens = split(request->message()); + for (grpc::string token : tokens) { + response.set_message(token); + writer->Write(response); + } + return Status::OK; + } + Status BidiStream( ServerContext* context, ServerReaderWriter* stream) override { @@ -147,6 +221,26 @@ class TestServiceImpl : public EchoTestService::Service { } return Status::OK; } + private: + const vector split(const grpc::string& input) { + grpc::string buff(""); + vector result; + + for (auto n:input) { + if (n != ' ') { + buff += n; + continue; + } + if (buff == "") + continue; + result.push_back(buff); + buff = ""; + } + if (buff != "") + result.push_back(buff); + + return result; + } }; class MockTest : public ::testing::Test { @@ -191,6 +285,49 @@ TEST_F(MockTest, SimpleRpc) { client.DoEcho(); } +TEST_F(MockTest, ClientStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoRequestStream(); + + MockEchoTestServiceStub stub; + auto w = new MockClientWriter(); + EchoResponse resp; + resp.set_message("hello, world"); + + EXPECT_CALL(*w, Write(_, _)).Times(2).WillRepeatedly(Return(true)); + EXPECT_CALL(*w, WritesDone()); + EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, RequestStreamRaw(_, _)).WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); + client.ResetStub(&stub); + client.DoRequestStream(); +} + +TEST_F(MockTest, ServerStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoResponseStream(); + + MockEchoTestServiceStub stub; + auto r = new MockClientReader(); + EchoResponse resp1; + resp1.set_message("hello"); + EchoResponse resp2; + resp2.set_message("world"); + + EXPECT_CALL(*r, Read(_)). + WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))). + WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r)); + + client.ResetStub(&stub); + client.DoResponseStream(); +} + ACTION_P(copy, msg) { arg0->set_message(msg->message()); } From 31d92d42ff8493fc0a9eb419ff662e4e5244096b Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 15:43:07 -0700 Subject: [PATCH 03/43] Initial commit: Auto-generate GMOCK code for client stub. --- Makefile | 7 +- build.yaml | 1 + include/grpc++/test/mock_stream.h | 128 +++++++++++++++++++++ src/compiler/cpp_generator.cc | 184 ++++++++++++++++++++++++++++++ src/compiler/cpp_generator.h | 12 ++ src/compiler/cpp_plugin.cc | 10 ++ test/cpp/end2end/mock_test.cc | 142 +++++++---------------- 7 files changed, 378 insertions(+), 106 deletions(-) create mode 100644 include/grpc++/test/mock_stream.h diff --git a/Makefile b/Makefile index 02840b3c26c..4d12b95238b 100644 --- a/Makefile +++ b/Makefile @@ -409,8 +409,9 @@ AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little USE_BUILT_PROTOC = false endif -GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc +GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc GTEST_LIB += -lgflags + ifeq ($(V),1) E = @: Q = @@ -784,7 +785,7 @@ PROTOBUF_PKG_CONFIG = false PC_REQUIRES_GRPCXX = PC_LIBS_GRPCXX = -CPPFLAGS := -Ithird_party/googletest/googletest/include $(CPPFLAGS) +CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS) PROTOC_PLUGINS_ALL = $(BINDIR)/$(CONFIG)/grpc_cpp_plugin $(BINDIR)/$(CONFIG)/grpc_csharp_plugin $(BINDIR)/$(CONFIG)/grpc_node_plugin $(BINDIR)/$(CONFIG)/grpc_objective_c_plugin $(BINDIR)/$(CONFIG)/grpc_php_plugin $(BINDIR)/$(CONFIG)/grpc_python_plugin $(BINDIR)/$(CONFIG)/grpc_ruby_plugin PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG) @@ -15198,7 +15199,7 @@ else $(BINDIR)/$(CONFIG)/mock_test: $(PROTOBUF_DEP) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test + $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test endif diff --git a/build.yaml b/build.yaml index 414950cd6fc..d4b50b25992 100644 --- a/build.yaml +++ b/build.yaml @@ -949,6 +949,7 @@ filegroups: language: c++ public_headers: - include/grpc++/test/server_context_test_spouse.h + - include/grpc++/test/mock_stream.h deps: - grpc++ - name: thrift_util diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h new file mode 100644 index 00000000000..f99a1b1128b --- /dev/null +++ b/include/grpc++/test/mock_stream.h @@ -0,0 +1,128 @@ +#ifndef NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ +#define NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ + +#include + +#include +#include +#include +#include +#include + +namespace grpc { +namespace testing { + +template +class MockClientReader : public ClientReaderInterface { + public: + MockClientReader() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // ClientReaderInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); +}; + +template +class MockClientWriter : public ClientWriterInterface { + public: + MockClientWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + + // ClientWriterInterface + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientReaderWriter : public ClientReaderWriterInterface { + public: + MockClientReaderWriter() = default; + + // ClientStreamingInterface + MOCK_METHOD0_T(Finish, Status()); + + // ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + // WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); + + // ClientReaderWriterInterface + MOCK_METHOD0_T(WaitForInitialMetadata, void()); + MOCK_METHOD0_T(WritesDone, bool()); +}; + +template +class MockClientAsyncResponseReader + : public ClientAsyncResponseReaderInterface { + public: + MockClientAsyncResponseReader() = default; + + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD3_T(Finish, void(R*, Status*, void*)); +}; + +template +class MockClientAsyncReader : public ClientAsyncReaderInterface { + public: + MockClientAsyncReader() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); +}; + +template +class MockClientAsyncWriter : public ClientAsyncWriterInterface { + public: + MockClientAsyncWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // ClientAsyncWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +template +class MockClientAsyncReaderWriter + : public ClientAsyncReaderWriterInterface { + public: + MockClientAsyncReaderWriter() = default; + + // ClientAsyncStreamingInterface + MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); + MOCK_METHOD2_T(Finish, void(Status*, void*)); + + // AsyncWriterInterface + MOCK_METHOD2_T(Write, void(const W&, void*)); + + // AsyncReaderInterface + MOCK_METHOD2_T(Read, void(R*, void*)); + + // ClientAsyncReaderWriterInterface + MOCK_METHOD1_T(WritesDone, void(void*)); +}; + +} // namespace testing +} // namespace grpc + +#endif // NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index c01e830cd68..400627ecca7 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1407,4 +1407,188 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, return temp; } +// TODO(mmukhi): Make sure we need parameters or not. +grpc::string GetMockPrologue(File *file, const Parameters & ) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + vars["filename"] = file->filename(); + vars["filename_base"] = file->filename_without_ext(); + vars["message_header_ext"] = file->message_header_ext(); + vars["service_header_ext"] = file->service_header_ext(); + + printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); + printer->Print(vars, + "// If you make any local change, they will be lost.\n"); + printer->Print(vars, "// source: $filename$\n\n"); + + printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n"); + printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n"); + printer->Print(vars, file->additional_headers().c_str()); + printer->Print(vars, "\n"); + } + return output; +} + +// TODO(mmukhi): Add client-stream and completion-queue headers. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + + static const char *headers_strs[] = { + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/sync_stream.h", + "gmock/gmock.h", + }; + std::vector headers(headers_strs, array_end(headers_strs)); + PrintIncludes(printer.get(), headers, params); + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for(auto part = parts.begin(); part != parts.end(); part++) { + vars["part"] = *part; + printer->Print(vars, "namespace $part$ {\n"); + } + } + + printer->Print(vars, "\n"); + } + return output; +} + +void PrintMockClientMethods( + Printer *printer, const Method *method, + std::map *vars) { + (*vars)["Method"] = method->name(); + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + + if (method->NoStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " + "const $Request$& request, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq));\n"); + } else if (method->ClientOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->ServerOnlyStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD2($Method$Raw, " + "::grpc::ClientReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request));\n"); + printer->Print( + *vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq, void* tag));\n"); + } else if (method->BidiStreaming()) { + printer->Print( + *vars, + "MOCK_METHOD1($Method$Raw, " + "::grpc::ClientReaderWriterInterface< $Request$, $Response$>*" + "(::grpc::ClientContext* context));\n"); + printer->Print( + *vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncReaderWriterInterface<$Request$, $Response$>*" + "(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, " + "void* tag));\n"); + } +} + +void PrintMockService(Printer *printer, + const Service *service, + std::map *vars) { + (*vars)["Service"] = service->name(); + + printer->Print(service->GetLeadingComments().c_str()); + printer->Print(*vars, + "class Mock$Service$Stub : public $Service$::StubInterface {\n" + " public:\n"); + printer->Indent(); + printer->Print(*vars, + "Mock$Service$Stub(){}\n" + "~Mock$Service$Stub(){}\n"); + for (int i = 0; i < service->method_count(); ++i) { + printer->Print(service->method(i)->GetLeadingComments().c_str()); + PrintMockClientMethods(printer, service->method(i).get(), vars); + printer->Print(service->method(i)->GetTrailingComments().c_str()); + } + printer->Outdent(); + printer->Print("};\n"); + +} + +grpc::string GetMockServices(File *file, + const Parameters ¶ms) { + grpc::string output; + { + // Scope the output stream so it closes and finalizes output to the string. + auto printer = file->CreatePrinter(&output); + std::map vars; + // Package string is empty or ends with a dot. It is used to fully qualify + // method names. + vars["Package"] = file->package(); + if (!file->package().empty()) { + vars["Package"].append("."); + } + + if(!params.services_namespace.empty()) { + vars["services_namespace"] = params.services_namespace; + printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); + } + + for (int i =0; i < file->service_count(); i++) { + PrintMockService(printer.get(), file->service(i).get(), &vars); + printer->Print("\n"); + } + + if (!params.services_namespace.empty()) { + printer->Print(vars, "} // namespace $services_namespace$\n\n"); + } + } + return output; +} + +grpc::string GetMockEpilogue(File *file, const Parameters &) { + grpc::string temp; + + if (!file->package().empty()) { + std::vector parts = file->package_parts(); + + for (auto part = parts.begin(); part != parts.end(); part++){ + temp.append("} // namespace "); + temp.append(*part); + temp.append("\n"); + } + temp.append("\n"); + } + + return temp; +} + } // namespace grpc_cpp_generator diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index 69fd8a93e93..55432203d3e 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -99,6 +99,18 @@ grpc::string GetSourceServices(grpc_generator::File *file, grpc::string GetSourceEpilogue(grpc_generator::File *file, const Parameters ¶ms); +// Return the prologue of the generated mock file. +grpc::string GetMockPrologue(File *file, const Parameters ¶ms); + +// Return the includes needed for generated mock file. +grpc::string GetMockIncludes(File *file, const Parameters ¶ms); + +// Return the services for generated mock file. +grpc::string GetMockServices(File* file, const Parameters ¶ms); + +// Return the epilogue of generated mock file. +grpc::string GetMockEpilogue(File* file, const Parameters ¶ms); + } // namespace grpc_cpp_generator #endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index 4ee05ee0370..a0986d92cee 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -114,6 +114,16 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); + grpc::string mock_code = + grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockServices(&pbfile, generator_parameters) + + grpc_cpp_generator::GetMockEpilogue(&pbfile, generator_parameters); + std::unique_ptr mock_output( + context->Open(file_name + "_mock.grpc.pb.h")); + grpc::protobuf::io::CodedOutputStream mock_coded_out(mock_output.get()); + mock_coded_out.WriteRaw(mock_code.data(), mock_code.size()); + return true; } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index fdb2732e503..16c04032ab1 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -1,5 +1,5 @@ /* - * +* * Copyright 2015, Google Inc. * All rights reserved. * @@ -45,121 +45,37 @@ #include #include #include +#include + +#include #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "src/proto/grpc/testing/echo_mock.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include + +using namespace std; using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using grpc::testing::EchoTestService; +using grpc::testing::MockClientReaderWriter; using std::chrono::system_clock; +using ::testing::AtLeast; +using ::testing::SetArgPointee; +using ::testing::SaveArg; +using ::testing::_; +using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArg; +using ::testing::DoAll; namespace grpc { namespace testing { namespace { -template -class MockClientReaderWriter final : public ClientReaderWriterInterface { - public: - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(R* msg) override { return true; } - bool Write(const W& msg) override { return true; } - bool WritesDone() override { return true; } - Status Finish() override { return Status::OK; } -}; -template <> -class MockClientReaderWriter final - : public ClientReaderWriterInterface { - public: - MockClientReaderWriter() : writes_done_(false) {} - void WaitForInitialMetadata() override {} - bool NextMessageSize(uint32_t* sz) override { - *sz = UINT_MAX; - return true; - } - bool Read(EchoResponse* msg) override { - if (writes_done_) return false; - msg->set_message(last_message_); - return true; - } - - bool Write(const EchoRequest& msg, WriteOptions options) override { - gpr_log(GPR_INFO, "mock recv msg %s", msg.message().c_str()); - last_message_ = msg.message(); - return true; - } - bool WritesDone() override { - writes_done_ = true; - return true; - } - Status Finish() override { return Status::OK; } - - private: - bool writes_done_; - grpc::string last_message_; -}; - -// Mocked stub. -class MockStub : public EchoTestService::StubInterface { - public: - MockStub() {} - ~MockStub() {} - Status Echo(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - response->set_message(request.message()); - return Status::OK; - } - Status Unimplemented(ClientContext* context, const EchoRequest& request, - EchoResponse* response) override { - return Status::OK; - } - - private: - ClientAsyncResponseReaderInterface* AsyncEchoRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } - ClientWriterInterface* RequestStreamRaw( - ClientContext* context, EchoResponse* response) override { - return nullptr; - } - ClientAsyncWriterInterface* AsyncRequestStreamRaw( - ClientContext* context, EchoResponse* response, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderInterface* ResponseStreamRaw( - ClientContext* context, const EchoRequest& request) override { - return nullptr; - } - ClientAsyncReaderInterface* AsyncResponseStreamRaw( - ClientContext* context, const EchoRequest& request, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientReaderWriterInterface* BidiStreamRaw( - ClientContext* context) override { - return new MockClientReaderWriter(); - } - ClientAsyncReaderWriterInterface* - AsyncBidiStreamRaw(ClientContext* context, CompletionQueue* cq, - void* tag) override { - return nullptr; - } - ClientAsyncResponseReaderInterface* AsyncUnimplementedRaw( - ClientContext* context, const EchoRequest& request, - CompletionQueue* cq) override { - return nullptr; - } -}; - class FakeClient { public: explicit FakeClient(EchoTestService::StubInterface* stub) : stub_(stub) {} @@ -267,16 +183,36 @@ TEST_F(MockTest, SimpleRpc) { ResetStub(); FakeClient client(stub_.get()); client.DoEcho(); - MockStub stub; + MockEchoTestServiceStub stub; + EchoResponse resp; + resp.set_message("hello world"); + EXPECT_CALL(stub, Echo(_, _, _)).Times(AtLeast(1)).WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); client.ResetStub(&stub); client.DoEcho(); } +ACTION_P(copy, msg) { + arg0->set_message(msg->message()); +} + TEST_F(MockTest, BidiStream) { ResetStub(); FakeClient client(stub_.get()); client.DoBidiStream(); - MockStub stub; + MockEchoTestServiceStub stub; + auto rw = new MockClientReaderWriter(); + EchoRequest msg; + + EXPECT_CALL(*rw, Write(_, _)).Times(3).WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); + EXPECT_CALL(*rw, Read(_)). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*rw, WritesDone()); + EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, BidiStreamRaw(_)).WillOnce(Return(rw)); client.ResetStub(&stub); client.DoBidiStream(); } From e536eeb6d060f5b39269a240c1ec7ddacc358484 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 17:49:23 -0700 Subject: [PATCH 04/43] Added tests for uni-directional streaming RPCs. --- include/grpc++/test/mock_stream.h | 2 +- test/cpp/end2end/mock_test.cc | 137 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index f99a1b1128b..1b1a7351855 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -37,7 +37,7 @@ class MockClientWriter : public ClientWriterInterface { MOCK_METHOD0_T(Finish, Status()); // WriterInterface - MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions&)); + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); // ClientWriterInterface MOCK_METHOD0_T(WritesDone, bool()); diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 16c04032ab1..b7968ce2306 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -90,6 +90,55 @@ class FakeClient { EXPECT_TRUE(s.ok()); } + void DoRequestStream() { + EchoRequest request; + EchoResponse response; + + ClientContext context; + grpc::string msg("hello"); + grpc::string exp(msg); + + std::unique_ptr> + cstream = stub_->RequestStream(&context, &response); + + request.set_message(msg); + EXPECT_TRUE(cstream->Write(request)); + + msg = ", world"; + request.set_message(msg); + exp.append(msg); + EXPECT_TRUE(cstream->Write(request)); + + cstream->WritesDone(); + Status s = cstream->Finish(); + + EXPECT_EQ(exp, response.message()); + EXPECT_TRUE(s.ok()); + } + + void DoResponseStream() { + EchoRequest request; + EchoResponse response; + request.set_message("hello world"); + + ClientContext context; + std::unique_ptr> + cstream = stub_->ResponseStream(&context, request); + + grpc::string exp = ""; + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message() + " "); + + EXPECT_TRUE(cstream->Read(&response)); + exp.append(response.message()); + + EXPECT_FALSE(cstream->Read(&response)); + EXPECT_EQ(request.message(), exp); + + Status s = cstream->Finish(); + EXPECT_TRUE(s.ok()); + } + void DoBidiStream() { EchoRequest request; EchoResponse response; @@ -135,6 +184,31 @@ class TestServiceImpl : public EchoTestService::Service { return Status::OK; } + Status RequestStream(ServerContext* context, + ServerReader* reader, + EchoResponse* response) { + EchoRequest request; + grpc::string resp(""); + while (reader->Read(&request)) { + gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); + resp.append(request.message()); + } + response->set_message(resp); + return Status::OK; + } + + Status ResponseStream(ServerContext* context, + const EchoRequest* request, + ServerWriter* writer) { + EchoResponse response; + vector tokens = split(request->message()); + for (grpc::string token : tokens) { + response.set_message(token); + writer->Write(response); + } + return Status::OK; + } + Status BidiStream( ServerContext* context, ServerReaderWriter* stream) override { @@ -147,6 +221,26 @@ class TestServiceImpl : public EchoTestService::Service { } return Status::OK; } + private: + const vector split(const grpc::string& input) { + grpc::string buff(""); + vector result; + + for (auto n:input) { + if (n != ' ') { + buff += n; + continue; + } + if (buff == "") + continue; + result.push_back(buff); + buff = ""; + } + if (buff != "") + result.push_back(buff); + + return result; + } }; class MockTest : public ::testing::Test { @@ -191,6 +285,49 @@ TEST_F(MockTest, SimpleRpc) { client.DoEcho(); } +TEST_F(MockTest, ClientStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoRequestStream(); + + MockEchoTestServiceStub stub; + auto w = new MockClientWriter(); + EchoResponse resp; + resp.set_message("hello, world"); + + EXPECT_CALL(*w, Write(_, _)).Times(2).WillRepeatedly(Return(true)); + EXPECT_CALL(*w, WritesDone()); + EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, RequestStreamRaw(_, _)).WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); + client.ResetStub(&stub); + client.DoRequestStream(); +} + +TEST_F(MockTest, ServerStream) { + ResetStub(); + FakeClient client(stub_.get()); + client.DoResponseStream(); + + MockEchoTestServiceStub stub; + auto r = new MockClientReader(); + EchoResponse resp1; + resp1.set_message("hello"); + EchoResponse resp2; + resp2.set_message("world"); + + EXPECT_CALL(*r, Read(_)). + WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))). + WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))). + WillOnce(Return(false)); + EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK)); + + EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r)); + + client.ResetStub(&stub); + client.DoResponseStream(); +} + ACTION_P(copy, msg) { arg0->set_message(msg->message()); } From 29bc253d25e9aa7d932ae70b752447a3264339b0 Mon Sep 17 00:00:00 2001 From: Zoltan Kuscsik Date: Thu, 13 Apr 2017 16:41:25 +0200 Subject: [PATCH 05/43] core: fix duplicated definition Refactor remove() function name to avoid duplicated function definition when building on latest AOSP. stdio in Bionic also defines remove(). --- src/core/lib/support/avl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/lib/support/avl.c b/src/core/lib/support/avl.c index acf8fd5a552..d8440001536 100644 --- a/src/core/lib/support/avl.c +++ b/src/core/lib/support/avl.c @@ -247,7 +247,7 @@ static gpr_avl_node *in_order_tail(gpr_avl_node *node) { return node; } -static gpr_avl_node *remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, +static gpr_avl_node *_remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, void *key) { long cmp; if (node == NULL) { @@ -263,27 +263,27 @@ static gpr_avl_node *remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, gpr_avl_node *h = in_order_head(node->right); return rebalance(vtable, vtable->copy_key(h->key), vtable->copy_value(h->value), ref_node(node->left), - remove(vtable, node->right, h->key)); + _remove(vtable, node->right, h->key)); } else { gpr_avl_node *h = in_order_tail(node->left); return rebalance( vtable, vtable->copy_key(h->key), vtable->copy_value(h->value), - remove(vtable, node->left, h->key), ref_node(node->right)); + _remove(vtable, node->left, h->key), ref_node(node->right)); } } else if (cmp > 0) { return rebalance(vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), - remove(vtable, node->left, key), ref_node(node->right)); + _remove(vtable, node->left, key), ref_node(node->right)); } else { return rebalance(vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), ref_node(node->left), - remove(vtable, node->right, key)); + _remove(vtable, node->right, key)); } } gpr_avl gpr_avl_remove(gpr_avl avl, void *key) { gpr_avl_node *old_root = avl.root; - avl.root = remove(avl.vtable, avl.root, key); + avl.root = _remove(avl.vtable, avl.root, key); assert_invariants(avl.root); unref_node(avl.vtable, old_root); return avl; From 529e4c53854e89f22f66defd766a95ca0a96b0b6 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 13:28:16 -0700 Subject: [PATCH 06/43] update according to new changes in cpp code --- src/compiler/cpp_generator.cc | 32 ++++++++++++++++---------------- src/compiler/cpp_generator.h | 24 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 400627ecca7..c13577ce52c 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1408,7 +1408,7 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, } // TODO(mmukhi): Make sure we need parameters or not. -grpc::string GetMockPrologue(File *file, const Parameters & ) { +grpc::string GetMockPrologue(grpc_generator::File *file, const Parameters & /*params*/ ) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1417,8 +1417,8 @@ grpc::string GetMockPrologue(File *file, const Parameters & ) { vars["filename"] = file->filename(); vars["filename_base"] = file->filename_without_ext(); - vars["message_header_ext"] = file->message_header_ext(); - vars["service_header_ext"] = file->service_header_ext(); + vars["message_header_ext"] = message_header_ext(); + vars["service_header_ext"] = service_header_ext(); printer->Print(vars, "// Generated by the gRPC C++ plugin.\n"); printer->Print(vars, @@ -1434,7 +1434,7 @@ grpc::string GetMockPrologue(File *file, const Parameters & ) { } // TODO(mmukhi): Add client-stream and completion-queue headers. -grpc::string GetMockIncludes(File *file, const Parameters ¶ms) { +grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1463,9 +1463,9 @@ grpc::string GetMockIncludes(File *file, const Parameters ¶ms) { return output; } -void PrintMockClientMethods( - Printer *printer, const Method *method, - std::map *vars) { +void PrintMockClientMethods(grpc_generator::Printer *printer, + const grpc_generator::Method *method, + std::map *vars) { (*vars)["Method"] = method->name(); (*vars)["Request"] = method->input_type_name(); (*vars)["Response"] = method->output_type_name(); @@ -1481,7 +1481,7 @@ void PrintMockClientMethods( "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" "(::grpc::ClientContext* context, const $Request$& request, " "::grpc::CompletionQueue* cq));\n"); - } else if (method->ClientOnlyStreaming()) { + } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " @@ -1493,7 +1493,7 @@ void PrintMockClientMethods( "::grpc::ClientAsyncWriterInterface< $Request$>*" "(::grpc::ClientContext* context, $Response$* response, " "::grpc::CompletionQueue* cq, void* tag));\n"); - } else if (method->ServerOnlyStreaming()) { + } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " @@ -1520,12 +1520,12 @@ void PrintMockClientMethods( } } -void PrintMockService(Printer *printer, - const Service *service, +void PrintMockService(grpc_generator::Printer *printer, + const grpc_generator::Service *service, std::map *vars) { (*vars)["Service"] = service->name(); - printer->Print(service->GetLeadingComments().c_str()); + printer->Print(service->GetLeadingComments("//").c_str()); printer->Print(*vars, "class Mock$Service$Stub : public $Service$::StubInterface {\n" " public:\n"); @@ -1534,16 +1534,16 @@ void PrintMockService(Printer *printer, "Mock$Service$Stub(){}\n" "~Mock$Service$Stub(){}\n"); for (int i = 0; i < service->method_count(); ++i) { - printer->Print(service->method(i)->GetLeadingComments().c_str()); + printer->Print(service->method(i)->GetLeadingComments("//").c_str()); PrintMockClientMethods(printer, service->method(i).get(), vars); - printer->Print(service->method(i)->GetTrailingComments().c_str()); + printer->Print(service->method(i)->GetTrailingComments("//").c_str()); } printer->Outdent(); printer->Print("};\n"); } -grpc::string GetMockServices(File *file, +grpc::string GetMockServices(grpc_generator::File *file, const Parameters ¶ms) { grpc::string output; { @@ -1574,7 +1574,7 @@ grpc::string GetMockServices(File *file, return output; } -grpc::string GetMockEpilogue(File *file, const Parameters &) { +grpc::string GetMockEpilogue(grpc_generator::File *file, const Parameters & /*params*/) { grpc::string temp; if (!file->package().empty()) { diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index c59310f0536..cd672d120d5 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -100,28 +100,36 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, const Parameters ¶ms); // Return the prologue of the generated mock file. -grpc::string GetMockPrologue(File *file, const Parameters ¶ms); +grpc::string GetMockPrologue(grpc_generator::File *file, + const Parameters ¶ms); // Return the includes needed for generated mock file. -grpc::string GetMockIncludes(File *file, const Parameters ¶ms); +grpc::string GetMockIncludes(grpc_generator::File *file, + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(File* file, const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File* file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(File* file, const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File* file, + const Parameters ¶ms); // Return the prologue of the generated mock file. -grpc::string GetMockPrologue(File *file, const Parameters ¶ms); +grpc::string GetMockPrologue(grpc_generator::File *file, + const Parameters ¶ms); // Return the includes needed for generated mock file. -grpc::string GetMockIncludes(File *file, const Parameters ¶ms); +grpc::string GetMockIncludes(grpc_generator::File *file, + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(File* file, const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File* file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(File* file, const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File* file, + const Parameters ¶ms); } // namespace grpc_cpp_generator From 13d85d499a1f7a3a48066511dd9db856f7671e2d Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 13:41:51 -0700 Subject: [PATCH 07/43] rectify issues --- .gitmodules | 7 +++++++ third_party/googletest | 1 + third_party/protobuf | 1 + 3 files changed, 9 insertions(+) create mode 160000 third_party/googletest create mode 160000 third_party/protobuf diff --git a/.gitmodules b/.gitmodules index c9af37c5ab0..0f003693e43 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,16 @@ [submodule "third_party/zlib"] path = third_party/zlib url = https://github.com/madler/zlib +[submodule "third_party/protobuf"] + path = third_party/protobuf + url = https://github.com/google/protobuf.git + branch = 3.0.x [submodule "third_party/gflags"] path = third_party/gflags url = https://github.com/gflags/gflags.git +[submodule "third_party/googletest"] + path = third_party/googletest + url = https://github.com/google/googletest.git [submodule "third_party/boringssl"] path = third_party/boringssl url = https://github.com/google/boringssl.git diff --git a/third_party/googletest b/third_party/googletest new file mode 160000 index 00000000000..ec44c6c1675 --- /dev/null +++ b/third_party/googletest @@ -0,0 +1 @@ +Subproject commit ec44c6c1675c25b9827aacd08c02433cccde7780 diff --git a/third_party/protobuf b/third_party/protobuf new file mode 160000 index 00000000000..4a0dd03e52e --- /dev/null +++ b/third_party/protobuf @@ -0,0 +1 @@ +Subproject commit 4a0dd03e52e09332c8fd0f8f26a8e0ae9f911182 From 2814b5148e9f902ef2893da34cc7a81106668e9a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 14:45:26 -0700 Subject: [PATCH 08/43] formatting --- Makefile | 2 +- include/grpc++/test/mock_stream.h | 2 +- src/compiler/cpp_generator.cc | 60 +++++++++++++++---------------- src/compiler/cpp_generator.h | 26 +++++++------- src/compiler/cpp_plugin.cc | 11 ++++++ test/cpp/end2end/mock_test.cc | 59 +++++++++++++++--------------- 6 files changed, 86 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index e931d0d13c0..4f9184f4a4c 100644 --- a/Makefile +++ b/Makefile @@ -2331,7 +2331,7 @@ $(GENDIR)/src/proto/grpc/testing/echo.pb.cc: src/proto/grpc/testing/echo.proto $ $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc: src/proto/grpc/testing/echo.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=generate_mock_code=true:$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif ifeq ($(NO_PROTOC),true) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index 1b1a7351855..e1dbd5ae3f4 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -3,11 +3,11 @@ #include +#include #include #include #include #include -#include namespace grpc { namespace testing { diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index c13577ce52c..d64f8c95322 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1408,7 +1408,8 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, } // TODO(mmukhi): Make sure we need parameters or not. -grpc::string GetMockPrologue(grpc_generator::File *file, const Parameters & /*params*/ ) { +grpc::string GetMockPrologue(grpc_generator::File *file, + const Parameters & /*params*/) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1434,7 +1435,8 @@ grpc::string GetMockPrologue(grpc_generator::File *file, const Parameters & /*pa } // TODO(mmukhi): Add client-stream and completion-queue headers. -grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶ms) { +grpc::string GetMockIncludes(grpc_generator::File *file, + const Parameters ¶ms) { grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -1442,9 +1444,8 @@ grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶m std::map vars; static const char *headers_strs[] = { - "grpc++/impl/codegen/async_stream.h", - "grpc++/impl/codegen/sync_stream.h", - "gmock/gmock.h", + "grpc++/impl/codegen/async_stream.h", + "grpc++/impl/codegen/sync_stream.h", "gmock/gmock.h", }; std::vector headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params); @@ -1452,7 +1453,7 @@ grpc::string GetMockIncludes(grpc_generator::File *file, const Parameters ¶m if (!file->package().empty()) { std::vector parts = file->package_parts(); - for(auto part = parts.begin(); part != parts.end(); part++) { + for (auto part = parts.begin(); part != parts.end(); part++) { vars["part"] = *part; printer->Print(vars, "namespace $part$ {\n"); } @@ -1475,36 +1476,33 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, *vars, "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response));\n"); - printer->Print( - *vars, - "MOCK_METHOD3(Async$Method$Raw, " - "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" - "(::grpc::ClientContext* context, const $Request$& request, " - "::grpc::CompletionQueue* cq));\n"); + printer->Print(*vars, + "MOCK_METHOD3(Async$Method$Raw, " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq));\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientWriterInterface< $Request$>*" "(::grpc::ClientContext* context, $Response$* response));\n"); - printer->Print( - *vars, - "MOCK_METHOD4(Async$Method$Raw, " - "::grpc::ClientAsyncWriterInterface< $Request$>*" - "(::grpc::ClientContext* context, $Response$* response, " - "::grpc::CompletionQueue* cq, void* tag));\n"); + printer->Print(*vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncWriterInterface< $Request$>*" + "(::grpc::ClientContext* context, $Response$* response, " + "::grpc::CompletionQueue* cq, void* tag));\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, "MOCK_METHOD2($Method$Raw, " "::grpc::ClientReaderInterface< $Response$>*" "(::grpc::ClientContext* context, const $Request$& request));\n"); - printer->Print( - *vars, - "MOCK_METHOD4(Async$Method$Raw, " - "::grpc::ClientAsyncReaderInterface< $Response$>*" - "(::grpc::ClientContext* context, const $Request$& request, " - "::grpc::CompletionQueue* cq, void* tag));\n"); + printer->Print(*vars, + "MOCK_METHOD4(Async$Method$Raw, " + "::grpc::ClientAsyncReaderInterface< $Response$>*" + "(::grpc::ClientContext* context, const $Request$& request, " + "::grpc::CompletionQueue* cq, void* tag));\n"); } else if (method->BidiStreaming()) { printer->Print( *vars, @@ -1521,8 +1519,8 @@ void PrintMockClientMethods(grpc_generator::Printer *printer, } void PrintMockService(grpc_generator::Printer *printer, - const grpc_generator::Service *service, - std::map *vars) { + const grpc_generator::Service *service, + std::map *vars) { (*vars)["Service"] = service->name(); printer->Print(service->GetLeadingComments("//").c_str()); @@ -1540,7 +1538,6 @@ void PrintMockService(grpc_generator::Printer *printer, } printer->Outdent(); printer->Print("};\n"); - } grpc::string GetMockServices(grpc_generator::File *file, @@ -1557,12 +1554,12 @@ grpc::string GetMockServices(grpc_generator::File *file, vars["Package"].append("."); } - if(!params.services_namespace.empty()) { + if (!params.services_namespace.empty()) { vars["services_namespace"] = params.services_namespace; printer->Print(vars, "\nnamespace $services_namespace$ {\n\n"); } - for (int i =0; i < file->service_count(); i++) { + for (int i = 0; i < file->service_count(); i++) { PrintMockService(printer.get(), file->service(i).get(), &vars); printer->Print("\n"); } @@ -1574,13 +1571,14 @@ grpc::string GetMockServices(grpc_generator::File *file, return output; } -grpc::string GetMockEpilogue(grpc_generator::File *file, const Parameters & /*params*/) { +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters & /*params*/) { grpc::string temp; if (!file->package().empty()) { std::vector parts = file->package_parts(); - for (auto part = parts.begin(); part != parts.end(); part++){ + for (auto part = parts.begin(); part != parts.end(); part++) { temp.append("} // namespace "); temp.append(*part); temp.append("\n"); diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h index cd672d120d5..6119ebe2896 100644 --- a/src/compiler/cpp_generator.h +++ b/src/compiler/cpp_generator.h @@ -65,6 +65,8 @@ struct Parameters { bool use_system_headers; // Prefix to any grpc include grpc::string grpc_search_path; + // Generate GMOCK code to facilitate unit testing. + bool generate_mock_code; }; // Return the prologue of the generated header file. @@ -101,35 +103,35 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file, // Return the prologue of the generated mock file. grpc::string GetMockPrologue(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the includes needed for generated mock file. grpc::string GetMockIncludes(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File *file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters ¶ms); // Return the prologue of the generated mock file. grpc::string GetMockPrologue(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the includes needed for generated mock file. grpc::string GetMockIncludes(grpc_generator::File *file, - const Parameters ¶ms); + const Parameters ¶ms); // Return the services for generated mock file. -grpc::string GetMockServices(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockServices(grpc_generator::File *file, + const Parameters ¶ms); // Return the epilogue of generated mock file. -grpc::string GetMockEpilogue(grpc_generator::File* file, - const Parameters ¶ms); +grpc::string GetMockEpilogue(grpc_generator::File *file, + const Parameters ¶ms); } // namespace grpc_cpp_generator diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index a0986d92cee..35f1bf3e93c 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -62,6 +62,7 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc_cpp_generator::Parameters generator_parameters; generator_parameters.use_system_headers = true; + generator_parameters.generate_mock_code = false; ProtoBufFile pbfile(file); @@ -85,6 +86,13 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { } } else if (param[0] == "grpc_search_path") { generator_parameters.grpc_search_path = param[1]; + } else if (param[0] == "generate_mock_code") { + if (param[1] == "true") { + generator_parameters.generate_mock_code = true; + } else if (param[1] != "false") { + *error = grpc::string("Invalid parameter: ") + *parameter_string; + return false; + } } else { *error = grpc::string("Unknown parameter: ") + *parameter_string; return false; @@ -114,6 +122,9 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { grpc::protobuf::io::CodedOutputStream source_coded_out(source_output.get()); source_coded_out.WriteRaw(source_code.data(), source_code.size()); + if (!generator_parameters.generate_mock_code) { + return true; + } grpc::string mock_code = grpc_cpp_generator::GetMockPrologue(&pbfile, generator_parameters) + grpc_cpp_generator::GetMockIncludes(&pbfile, generator_parameters) + diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index b7968ce2306..9c040a0cc37 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -1,5 +1,5 @@ /* -* + * * Copyright 2015, Google Inc. * All rights reserved. * @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include #include -#include #include @@ -55,7 +55,7 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -#include +#include using namespace std; using grpc::testing::EchoRequest; @@ -98,8 +98,8 @@ class FakeClient { grpc::string msg("hello"); grpc::string exp(msg); - std::unique_ptr> - cstream = stub_->RequestStream(&context, &response); + std::unique_ptr> cstream = + stub_->RequestStream(&context, &response); request.set_message(msg); EXPECT_TRUE(cstream->Write(request)); @@ -122,8 +122,8 @@ class FakeClient { request.set_message("hello world"); ClientContext context; - std::unique_ptr> - cstream = stub_->ResponseStream(&context, request); + std::unique_ptr> cstream = + stub_->ResponseStream(&context, request); grpc::string exp = ""; EXPECT_TRUE(cstream->Read(&response)); @@ -197,8 +197,7 @@ class TestServiceImpl : public EchoTestService::Service { return Status::OK; } - Status ResponseStream(ServerContext* context, - const EchoRequest* request, + Status ResponseStream(ServerContext* context, const EchoRequest* request, ServerWriter* writer) { EchoResponse response; vector tokens = split(request->message()); @@ -221,23 +220,22 @@ class TestServiceImpl : public EchoTestService::Service { } return Status::OK; } + private: const vector split(const grpc::string& input) { grpc::string buff(""); vector result; - for (auto n:input) { + for (auto n : input) { if (n != ' ') { buff += n; continue; } - if (buff == "") - continue; + if (buff == "") continue; result.push_back(buff); buff = ""; } - if (buff != "") - result.push_back(buff); + if (buff != "") result.push_back(buff); return result; } @@ -280,7 +278,9 @@ TEST_F(MockTest, SimpleRpc) { MockEchoTestServiceStub stub; EchoResponse resp; resp.set_message("hello world"); - EXPECT_CALL(stub, Echo(_, _, _)).Times(AtLeast(1)).WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); + EXPECT_CALL(stub, Echo(_, _, _)) + .Times(AtLeast(1)) + .WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK))); client.ResetStub(&stub); client.DoEcho(); } @@ -299,7 +299,8 @@ TEST_F(MockTest, ClientStream) { EXPECT_CALL(*w, WritesDone()); EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK)); - EXPECT_CALL(stub, RequestStreamRaw(_, _)).WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); + EXPECT_CALL(stub, RequestStreamRaw(_, _)) + .WillOnce(DoAll(SetArgPointee<1>(resp), Return(w))); client.ResetStub(&stub); client.DoRequestStream(); } @@ -316,10 +317,10 @@ TEST_F(MockTest, ServerStream) { EchoResponse resp2; resp2.set_message("world"); - EXPECT_CALL(*r, Read(_)). - WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))). - WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))). - WillOnce(Return(false)); + EXPECT_CALL(*r, Read(_)) + .WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true))) + .WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true))) + .WillOnce(Return(false)); EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK)); EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r)); @@ -328,9 +329,7 @@ TEST_F(MockTest, ServerStream) { client.DoResponseStream(); } -ACTION_P(copy, msg) { - arg0->set_message(msg->message()); -} +ACTION_P(copy, msg) { arg0->set_message(msg->message()); } TEST_F(MockTest, BidiStream) { ResetStub(); @@ -340,12 +339,14 @@ TEST_F(MockTest, BidiStream) { auto rw = new MockClientReaderWriter(); EchoRequest msg; - EXPECT_CALL(*rw, Write(_, _)).Times(3).WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); - EXPECT_CALL(*rw, Read(_)). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))). - WillOnce(Return(false)); + EXPECT_CALL(*rw, Write(_, _)) + .Times(3) + .WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true))); + EXPECT_CALL(*rw, Read(_)) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true))) + .WillOnce(Return(false)); EXPECT_CALL(*rw, WritesDone()); EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK)); From b32e89eb8b3bd1a7b11ff50d0d7c57f92bb91c57 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 14:55:06 -0700 Subject: [PATCH 09/43] added todo --- include/grpc++/test/mock_stream.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index e1dbd5ae3f4..c26ddecb705 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -63,6 +63,8 @@ class MockClientReaderWriter : public ClientReaderWriterInterface { MOCK_METHOD0_T(WritesDone, bool()); }; +// TODO: We do not support mocking an async RPC for now. + template class MockClientAsyncResponseReader : public ClientAsyncResponseReaderInterface { From 443a75dd2282ff442fcd217f1b254ebe8a0f4355 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Fri, 14 Apr 2017 15:33:55 -0700 Subject: [PATCH 10/43] 1. Added golden file test. 2. Added support for mock. 3. Sanity fix. --- Makefile | 2 +- bazel/cc_grpc_library.bzl | 4 +- bazel/generate_cc.bzl | 9 +++- bazel/grpc_build_system.bzl | 3 +- build.yaml | 2 +- src/proto/grpc/testing/BUILD | 2 + test/cpp/codegen/BUILD | 2 +- test/cpp/codegen/compiler_test_mock_golden | 49 ++++++++++++++++++++++ test/cpp/codegen/golden_file_test.cc | 29 +++++++++---- test/cpp/end2end/mock_test.cc | 4 +- 10 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 test/cpp/codegen/compiler_test_mock_golden diff --git a/Makefile b/Makefile index 4f9184f4a4c..bfd31b0236f 100644 --- a/Makefile +++ b/Makefile @@ -2286,7 +2286,7 @@ $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc: src/proto/grpc/testing/com $(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.cc: src/proto/grpc/testing/compiler_test.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=generate_mock_code=true:$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif ifeq ($(NO_PROTOC),true) diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl index ab1add476e1..03a092192f8 100644 --- a/bazel/cc_grpc_library.bzl +++ b/bazel/cc_grpc_library.bzl @@ -2,7 +2,7 @@ load("//:bazel/generate_cc.bzl", "generate_cc") -def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_external = False, **kwargs): +def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mock, use_external = False, **kwargs): """Generates C++ grpc classes from a .proto file. Assumes the generated classes will be used in cc_api_version = 2. @@ -17,6 +17,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa "@submodule_protobuf//:well_known_protos" use_external: When True the grpc deps are prefixed with //external. This allows grpc to be used as a dependency in other bazel projects. + generate_mock: When true GMOCk code for client stub is generated. **kwargs: rest of arguments, e.g., compatible_with and visibility. """ if len(srcs) > 1: @@ -54,6 +55,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa srcs = [proto_target], plugin = plugin, well_known_protos = well_known_protos, + generate_mock = generate_mock, **kwargs ) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index f3961f0a419..7dd2c0486b0 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -23,7 +23,10 @@ def generate_cc_impl(ctx): arguments = [] if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] - arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] + arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags)] + if ctx.attr.generate_mock: + arguments += [",generate_mock_code=true"] + arguments += [":" + dir_out] additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] @@ -71,6 +74,10 @@ generate_cc = rule( "well_known_protos" : attr.label( mandatory = False, ), + "generate_mock" : attr.bool( + default = False, + mandatory = False, + ), "_protoc": attr.label( default = Label("//external:protocol_compiler"), executable = True, diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 8b524bd0e52..b49ad3aa597 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -59,7 +59,7 @@ def grpc_proto_plugin(name, srcs = [], deps = []): load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None, - has_services = True, use_external = False): + has_services = True, use_external = False, generate_mock = False): cc_grpc_library( name = name, srcs = srcs, @@ -67,5 +67,6 @@ def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None, well_known_protos = well_known_protos, proto_only = not has_services, use_external = use_external, + generate_mock = generate_mock, ) diff --git a/build.yaml b/build.yaml index 15a08397792..8fd1b7bad4d 100644 --- a/build.yaml +++ b/build.yaml @@ -3630,7 +3630,7 @@ targets: - grpc - gpr args: - - --generated_file_path=gens/src/proto/grpc/testing/compiler_test.grpc.pb.h + - --generated_file_path=gens/src/proto/grpc/testing - name: grpc_cli build: test run: false diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 6f3422e4d16..805988c3372 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -36,6 +36,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_proto_library") grpc_proto_library( name = "compiler_test_proto", srcs = ["compiler_test.proto"], + generate_mock = True, ) grpc_proto_library( @@ -55,6 +56,7 @@ grpc_proto_library( name = "echo_proto", srcs = ["echo.proto"], deps = ["echo_messages_proto"], + generate_mock = True, ) grpc_proto_library( diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 14d5733da2c..43d133fc342 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -62,7 +62,7 @@ cc_test( cc_test( name = "golden_file_test", srcs = ["golden_file_test.cc"], - args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.h"], + args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/"], data = [ ":compiler_test_golden", "//src/proto/grpc/testing:_compiler_test_proto_grpc_codegen", diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden new file mode 100644 index 00000000000..ced61aeb94f --- /dev/null +++ b/test/cpp/codegen/compiler_test_mock_golden @@ -0,0 +1,49 @@ +// Generated by the gRPC C++ plugin. +// If you make any local change, they will be lost. +// source: src/proto/grpc/testing/compiler_test.proto + +#include "src/proto/grpc/testing/compiler_test.pb.h" +#include "src/proto/grpc/testing/compiler_test.grpc.pb.h" + +#include +#include +#include +namespace grpc { +namespace testing { + +// ServiceA detached comment 1 +// +// ServiceA detached comment 2 +// +// ServiceA leading comment 1 +class MockServiceAStub : public ServiceA::StubInterface { + public: + MockServiceAStub(){} + ~MockServiceAStub(){} + // MethodA1 leading comment 1 + MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); + MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); + // MethodA1 trailing comment 1 + // MethodA2 detached leading comment 1 + // + // Method A2 leading comment 1 + // Method A2 leading comment 2 + MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response)); + MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag)); + // MethodA2 trailing comment 1 +}; + +// ServiceB leading comment 1 +class MockServiceBStub : public ServiceB::StubInterface { + public: + MockServiceBStub(){} + ~MockServiceBStub(){} + // MethodB1 leading comment 1 + MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); + MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); + // MethodB1 trailing comment 1 +}; + +} // namespace grpc +} // namespace testing + diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index 158a4d933c9..dd09471fdb8 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -37,16 +37,18 @@ #include #include -DEFINE_string(generated_file_path, "", - "path to the generated compiler_test.grpc.pb.h file"); +DEFINE_string( + generated_file_path, "", + "path to the directory containing generated files compiler_test.grpc.pb.h" + "and compiler_test_mock.grpc.pb.h"); const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden"; +const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden"; -TEST(GoldenFileTest, TestGeneratedFile) { - ASSERT_FALSE(FLAGS_generated_file_path.empty()); - - std::ifstream generated(FLAGS_generated_file_path); - std::ifstream golden(kGoldenFilePath); +void run_test(std::basic_string generated_file, + std::basic_string golden_file) { + std::ifstream generated(generated_file); + std::ifstream golden(golden_file); ASSERT_TRUE(generated.good()); ASSERT_TRUE(golden.good()); @@ -61,8 +63,21 @@ TEST(GoldenFileTest, TestGeneratedFile) { golden.close(); } +TEST(GoldenFileTest, TestGeneratedFile) { + run_test(FLAGS_generated_file_path + "compiler_test.grpc.pb.h", + kGoldenFilePath); +} + +TEST(GoldenMockFileTest, TestGeneratedMockFile) { + run_test(FLAGS_generated_file_path + "compiler_test_mock.grpc.pb.h", + kMockGoldenFilePath); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); ::google::ParseCommandLineFlags(&argc, &argv, true); + if (FLAGS_generated_file_path.empty()) return 1; + if (FLAGS_generated_file_path.back() != '/') + FLAGS_generated_file_path.append("/"); return RUN_ALL_TESTS(); } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 9c040a0cc37..7e330063ed3 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -186,7 +186,7 @@ class TestServiceImpl : public EchoTestService::Service { Status RequestStream(ServerContext* context, ServerReader* reader, - EchoResponse* response) { + EchoResponse* response) override { EchoRequest request; grpc::string resp(""); while (reader->Read(&request)) { @@ -198,7 +198,7 @@ class TestServiceImpl : public EchoTestService::Service { } Status ResponseStream(ServerContext* context, const EchoRequest* request, - ServerWriter* writer) { + ServerWriter* writer) override { EchoResponse response; vector tokens = split(request->message()); for (grpc::string token : tokens) { From c5eee16814254cc94883ac5e43a3604f8172c020 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Fri, 14 Apr 2017 17:02:26 -0700 Subject: [PATCH 11/43] more sanity fixes --- include/grpc++/test/mock_stream.h | 39 +++++++++++++++++-- .../generated/sources_and_headers.json | 5 ++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index c26ddecb705..679fea81bd1 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -1,5 +1,38 @@ -#ifndef NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ -#define NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_TEST_MOCK_STREAM_H +#define GRPCXX_TEST_MOCK_STREAM_H #include @@ -127,4 +160,4 @@ class MockClientAsyncReaderWriter } // namespace testing } // namespace grpc -#endif // NET_GRPC_PUBLIC_INCLUDE_TEST_MOCK_STREAM_H_ +#endif // GRPCXX_TEST_MOCK_STREAM_H diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index f5653d6f9ef..c0199961742 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3394,7 +3394,10 @@ "grpc++_test_util", "grpc_test_util" ], - "headers": [], + "headers": [ + "include/grpc++/test/mock_stream.h", + "src/proto/grpc/testing/echo_mock.grpc.pb.h" + ], "is_filegroup": false, "language": "c++", "name": "mock_test", From a68829023c4d20767938a9e2156bab1fe83b082a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Fri, 14 Apr 2017 17:37:46 -0700 Subject: [PATCH 12/43] more sanity trying to fix some sanity nope that didn't work fixing test failiures added debug code more trail and error more trial and error cleaning debug code --- CMakeLists.txt | 1 + bazel/generate_cc.bzl | 6 +++--- build.yaml | 6 ++++-- test/cpp/codegen/golden_file_test.cc | 4 +++- tools/run_tests/generated/sources_and_headers.json | 3 +++ tools/run_tests/generated/tests.json | 2 +- .../vcxproj/test/golden_file_test/golden_file_test.vcxproj | 2 ++ 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3db20d4203..4c23d28b905 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10082,6 +10082,7 @@ add_executable(golden_file_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test_mock.grpc.pb.h test/cpp/codegen/golden_file_test.cc third_party/googletest/googletest/src/gtest-all.cc ) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 7dd2c0486b0..dac76f67f17 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -23,10 +23,10 @@ def generate_cc_impl(ctx): arguments = [] if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] - arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags)] + gen_mock = "" if ctx.attr.generate_mock: - arguments += [",generate_mock_code=true"] - arguments += [":" + dir_out] + gen_mock = ",generate_mock_code=true" + arguments += ["--PLUGIN_out=" + gen_mock + ",".join(ctx.attr.flags) + ":" + dir_out] additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] diff --git a/build.yaml b/build.yaml index 8fd1b7bad4d..52ff98c64b2 100644 --- a/build.yaml +++ b/build.yaml @@ -948,8 +948,8 @@ filegroups: - name: grpc++_test language: c++ public_headers: - - include/grpc++/test/server_context_test_spouse.h - include/grpc++/test/mock_stream.h + - include/grpc++/test/server_context_test_spouse.h deps: - grpc++ - name: thrift_util @@ -3630,7 +3630,7 @@ targets: - grpc - gpr args: - - --generated_file_path=gens/src/proto/grpc/testing + - --generated_file_path=gens/src/proto/grpc/testing/ - name: grpc_cli build: test run: false @@ -3891,6 +3891,8 @@ targets: gtest: true build: test language: c++ + headers: + - include/grpc++/test/mock_stream.h src: - test/cpp/end2end/mock_test.cc deps: diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc index dd09471fdb8..7789ac738b9 100644 --- a/test/cpp/codegen/golden_file_test.cc +++ b/test/cpp/codegen/golden_file_test.cc @@ -76,7 +76,9 @@ TEST(GoldenMockFileTest, TestGeneratedMockFile) { int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); ::google::ParseCommandLineFlags(&argc, &argv, true); - if (FLAGS_generated_file_path.empty()) return 1; + if (FLAGS_generated_file_path.empty()) { + FLAGS_generated_file_path = "gens/src/proto/grpc/testing/"; + } if (FLAGS_generated_file_path.back() != '/') FLAGS_generated_file_path.append("/"); return RUN_ALL_TESTS(); diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index c0199961742..fa28af7f7b8 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3031,6 +3031,7 @@ ], "headers": [ "src/proto/grpc/testing/compiler_test.grpc.pb.h", + "src/proto/grpc/testing/compiler_test_mock.grpc.pb.h", "src/proto/grpc/testing/compiler_test.pb.h" ], "is_filegroup": false, @@ -8933,12 +8934,14 @@ "grpc++" ], "headers": [ + "include/grpc++/test/mock_stream.h", "include/grpc++/test/server_context_test_spouse.h" ], "is_filegroup": true, "language": "c++", "name": "grpc++_test", "src": [ + "include/grpc++/test/mock_stream.h", "include/grpc++/test/server_context_test_spouse.h" ], "third_party": false, diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a08caf30d36..408b38f844e 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3263,7 +3263,7 @@ }, { "args": [ - "--generated_file_path=gens/src/proto/grpc/testing/compiler_test.grpc.pb.h" + "--generated_file_path=gens/src/proto/grpc/testing/" ], "ci_platforms": [ "linux", diff --git a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj index e9802773d8d..7deebd17286 100644 --- a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj +++ b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj @@ -168,6 +168,8 @@ + + From 459da91519078f0ab46206febcc22d5d223c3781 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sun, 16 Apr 2017 20:44:04 -0700 Subject: [PATCH 13/43] fixing bug --- bazel/generate_cc.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index dac76f67f17..72fc6093f80 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -23,10 +23,10 @@ def generate_cc_impl(ctx): arguments = [] if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] - gen_mock = "" + flags = list(ctx.attr.flags) if ctx.attr.generate_mock: - gen_mock = ",generate_mock_code=true" - arguments += ["--PLUGIN_out=" + gen_mock + ",".join(ctx.attr.flags) + ":" + dir_out] + flags.append("generate_mock_code=true") + arguments += ["--PLUGIN_out=" + ",".join(flags) + ":" + dir_out] additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] From f9283768950985e34fe91891e9852de8cb81f884 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sun, 16 Apr 2017 21:06:11 -0700 Subject: [PATCH 14/43] updated gtest.BUILD to include gmock --- third_party/gtest.BUILD | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/third_party/gtest.BUILD b/third_party/gtest.BUILD index 52c9ca2ba7c..b70f2c51bcf 100644 --- a/third_party/gtest.BUILD +++ b/third_party/gtest.BUILD @@ -2,11 +2,14 @@ cc_library( name = "gtest", srcs = [ "googletest/src/gtest-all.cc", + "googlemock/src/gmock-all.cc" ], - hdrs = glob(["googletest/include/**/*.h", "googletest/src/*.cc", "googletest/src/*.h"]), + hdrs = glob(["googletest/include/**/*.h", "googletest/src/*.cc", "googletest/src/*.h", "googlemock/include/**/*.h", "googlemock/src/*.cc", "googlemock/src/*.h"]), includes = [ "googletest", "googletest/include", + "googlemock", + "googlemock/include", ], linkstatic = 1, visibility = [ From 78f12e5c760486f4297e1b6ddbac772d6e942eac Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sun, 16 Apr 2017 21:24:16 -0700 Subject: [PATCH 15/43] Add _mock files to output list of generate_cc.bzl --- bazel/generate_cc.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 72fc6093f80..d979b762282 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -12,6 +12,8 @@ def generate_cc_impl(ctx): if ctx.executable.plugin: outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos] outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos] + if ctx.attr.generate_mock: + outs += [proto.basename[:-len(".proto")] + "_mock.grpc.pb.h" for proto in protos] else: outs += [proto.basename[:-len(".proto")] + ".pb.h" for proto in protos] outs += [proto.basename[:-len(".proto")] + ".pb.cc" for proto in protos] From 32da70d9afb4c73608c0e885fe03ae964d246911 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 10:50:14 -0700 Subject: [PATCH 16/43] more trial and error for sanity --- CMakeLists.txt | 3 +++ tools/run_tests/generated/sources_and_headers.json | 1 + vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c23d28b905..b87430d50cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3157,6 +3157,7 @@ add_library(grpc++_test_util ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc_mock.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.h @@ -10431,6 +10432,7 @@ add_executable(grpc_tool_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_mock.grpc.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h @@ -11511,6 +11513,7 @@ add_executable(server_builder_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_mock.grpc.pb.h test/cpp/server/server_builder_test.cc third_party/googletest/googletest/src/gtest-all.cc ) diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fa28af7f7b8..449e2ebda89 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -5930,6 +5930,7 @@ "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h", "src/proto/grpc/testing/duplicate/echo_duplicate.pb.h", "src/proto/grpc/testing/echo.grpc.pb.h", + "src/proto/grpc/testing/echo_mock.grpc.pb.h", "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", "src/proto/grpc/testing/echo_messages.pb.h", diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index c060f98b34a..fa224a70912 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -234,6 +234,8 @@ + + From 980e9805c38c16856964cbfc9b06f31c6fd948af Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 11:27:36 -0700 Subject: [PATCH 17/43] more trial and error --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b87430d50cc..d3db20d4203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3157,7 +3157,6 @@ add_library(grpc++_test_util ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc_mock.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.h @@ -10083,7 +10082,6 @@ add_executable(golden_file_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test.grpc.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/compiler_test_mock.grpc.pb.h test/cpp/codegen/golden_file_test.cc third_party/googletest/googletest/src/gtest-all.cc ) @@ -10432,7 +10430,6 @@ add_executable(grpc_tool_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_mock.grpc.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h @@ -11513,7 +11510,6 @@ add_executable(server_builder_test ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_mock.grpc.pb.h test/cpp/server/server_builder_test.cc third_party/googletest/googletest/src/gtest-all.cc ) From fb059a2782c33bbbefc65b4c6ee4ef6087cbcf3a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 14:40:00 -0700 Subject: [PATCH 18/43] discovered generate_projects.sh script! --- Makefile | 22 ++++++++++++++++--- templates/Makefile.template | 15 +++++++++---- .../generated/sources_and_headers.json | 6 ++--- .../grpc++_test_util/grpc++_test_util.vcxproj | 2 -- .../golden_file_test/golden_file_test.vcxproj | 2 -- .../vcxproj/test/mock_test/mock_test.vcxproj | 3 +++ .../test/mock_test/mock_test.vcxproj.filters | 14 ++++++++++++ 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index bfd31b0236f..c3a8e7e4172 100644 --- a/Makefile +++ b/Makefile @@ -411,7 +411,6 @@ endif GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc GTEST_LIB += -lgflags - ifeq ($(V),1) E = @: Q = @@ -903,7 +902,6 @@ openssl_dep_message: @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo "doesn't have it, or your compiler can't build BoringSSL." @echo @echo "Please consult INSTALL to get more information." @echo @@ -2218,6 +2216,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc: src/proto/grpc/health/v1/health.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2233,6 +2232,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/lb/v1/load_balancer.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/lb/v1/load_balancer.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/lb/v1/load_balancer.pb.cc: src/proto/grpc/lb/v1/load_balancer.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2248,6 +2248,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.pb.cc: src/proto/grpc/reflection/v1alpha/reflection.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2263,6 +2264,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/status/status.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/status/status.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/status/status.pb.cc: src/proto/grpc/status/status.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2278,6 +2280,8 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.cc: protoc_dep_error else + + $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc: src/proto/grpc/testing/compiler_test.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2293,6 +2297,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/control.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/control.pb.cc: src/proto/grpc/testing/control.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2308,6 +2313,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc: src/proto/grpc/testing/duplicate/echo_duplicate.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2323,6 +2329,8 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/echo.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc: protoc_dep_error else + + $(GENDIR)/src/proto/grpc/testing/echo.pb.cc: src/proto/grpc/testing/echo.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2338,6 +2346,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc: src/proto/grpc/testing/echo_messages.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2353,6 +2362,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/empty.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/empty.pb.cc: src/proto/grpc/testing/empty.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2368,6 +2378,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/messages.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/messages.pb.cc: src/proto/grpc/testing/messages.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2383,6 +2394,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc: src/proto/grpc/testing/metrics.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2398,6 +2410,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc: src/proto/grpc/testing/payloads.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2413,6 +2426,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/services.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/services.pb.cc: src/proto/grpc/testing/services.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2428,6 +2442,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/stats.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/stats.pb.cc: src/proto/grpc/testing/stats.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -2443,6 +2458,7 @@ ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/testing/test.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc: protoc_dep_error else + $(GENDIR)/src/proto/grpc/testing/test.pb.cc: src/proto/grpc/testing/test.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -15353,7 +15369,7 @@ else $(BINDIR)/$(CONFIG)/mock_test: $(PROTOBUF_DEP) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test + $(Q) $(LDXX) $(LDFLAGS) $(MOCK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/mock_test endif diff --git a/templates/Makefile.template b/templates/Makefile.template index 8f61a8b9907..84afcdb354e 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -311,7 +311,7 @@ USE_BUILT_PROTOC = false endif - GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc + GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc GTEST_LIB += -lgflags ifeq ($(V),1) E = @: @@ -716,7 +716,7 @@ PC_REQUIRES_GRPCXX = PC_LIBS_GRPCXX = - CPPFLAGS := -Ithird_party/googletest/googletest/include $(CPPFLAGS) + CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS) PROTOC_PLUGINS_ALL =\ % for tgt in targets: @@ -846,7 +846,6 @@ @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo "doesn't have it, or your compiler can't build BoringSSL." @echo @echo "Please consult INSTALL to get more information." @echo @@ -1240,6 +1239,14 @@ $(GENDIR)/${p}.pb.cc: protoc_dep_error $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error else + <% + pluginflags="" + %> + % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]: + <% + pluginflags="generate_mock_code=true:" + %> + % endif $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc' % q for q in proto_deps.get(p, []))} $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` @@ -1248,7 +1255,7 @@ $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc $(GENDIR)/%s.grpc.pb.cc' % (q,q) for q in proto_deps.get(p, []))} $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif % endfor diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 449e2ebda89..236229fe743 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3031,7 +3031,6 @@ ], "headers": [ "src/proto/grpc/testing/compiler_test.grpc.pb.h", - "src/proto/grpc/testing/compiler_test_mock.grpc.pb.h", "src/proto/grpc/testing/compiler_test.pb.h" ], "is_filegroup": false, @@ -3396,13 +3395,13 @@ "grpc_test_util" ], "headers": [ - "include/grpc++/test/mock_stream.h", - "src/proto/grpc/testing/echo_mock.grpc.pb.h" + "include/grpc++/test/mock_stream.h" ], "is_filegroup": false, "language": "c++", "name": "mock_test", "src": [ + "include/grpc++/test/mock_stream.h", "test/cpp/end2end/mock_test.cc" ], "third_party": false, @@ -5930,7 +5929,6 @@ "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h", "src/proto/grpc/testing/duplicate/echo_duplicate.pb.h", "src/proto/grpc/testing/echo.grpc.pb.h", - "src/proto/grpc/testing/echo_mock.grpc.pb.h", "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", "src/proto/grpc/testing/echo_messages.pb.h", diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index fa224a70912..c060f98b34a 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -234,8 +234,6 @@ - - diff --git a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj index 7deebd17286..e9802773d8d 100644 --- a/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj +++ b/vsprojects/vcxproj/test/golden_file_test/golden_file_test.vcxproj @@ -168,8 +168,6 @@ - - diff --git a/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj b/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj index 8c840fd5be9..bc1cae59117 100644 --- a/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj +++ b/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj @@ -159,6 +159,9 @@ + + + diff --git a/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj.filters b/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj.filters index 1b3b773b08f..6db61c9037b 100644 --- a/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/mock_test/mock_test.vcxproj.filters @@ -5,8 +5,22 @@ test\cpp\end2end + + + include\grpc++\test + + + + {b827d6d2-cfa5-2dd4-6ebc-afcccd5e8e0c} + + + {28289e8f-b68e-b9f5-7680-c15d77b574a5} + + + {4a7b43be-c730-6221-d190-e394521f9ae7} + {69c257a2-3e4c-a86e-ce0d-1a97b237d294} From b28ddaf9a96ebf000a47c056fde9ad41f25f0165 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 15:38:02 -0700 Subject: [PATCH 19/43] trial and error --- build.yaml | 1 + tools/run_tests/generated/sources_and_headers.json | 2 ++ vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj | 1 + .../vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters | 3 +++ 4 files changed, 7 insertions(+) diff --git a/build.yaml b/build.yaml index 52ff98c64b2..4b3dd51e236 100644 --- a/build.yaml +++ b/build.yaml @@ -1227,6 +1227,7 @@ libs: build: private language: c++ headers: + - src/proto/grpc/testing/echo_mock.grpc.pb.h - test/cpp/end2end/test_service_impl.h - test/cpp/util/byte_buffer_proto_helper.h - test/cpp/util/create_test_channel.h diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 236229fe743..14c8f67c12d 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -5932,6 +5932,7 @@ "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", "src/proto/grpc/testing/echo_messages.pb.h", + "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.h", "test/cpp/util/create_test_channel.h", @@ -5943,6 +5944,7 @@ "language": "c++", "name": "grpc++_test_util", "src": [ + "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.cc", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.cc", diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index c060f98b34a..814b61a7bf1 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -202,6 +202,7 @@ + diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters index 0623e421b21..721388e769a 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters @@ -197,6 +197,9 @@ + + src\proto\grpc\testing + test\cpp\end2end From a0cabfcad7f47422399bff91385bb0a760c1990d Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 15:43:11 -0700 Subject: [PATCH 20/43] trial and error --- build.yaml | 1 - .../sources_and_headers.json.template | 2 +- .../generated/sources_and_headers.json | 76 +++++++++++++++---- .../grpc++_test_util/grpc++_test_util.vcxproj | 1 - .../grpc++_test_util.vcxproj.filters | 3 - 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/build.yaml b/build.yaml index 4b3dd51e236..52ff98c64b2 100644 --- a/build.yaml +++ b/build.yaml @@ -1227,7 +1227,6 @@ libs: build: private language: c++ headers: - - src/proto/grpc/testing/echo_mock.grpc.pb.h - test/cpp/end2end/test_service_impl.h - test/cpp/util/byte_buffer_proto_helper.h - test/cpp/util/create_test_channel.h diff --git a/templates/tools/run_tests/generated/sources_and_headers.json.template b/templates/tools/run_tests/generated/sources_and_headers.json.template index 1c5c9747d65..c7dc3c837d1 100644 --- a/templates/tools/run_tests/generated/sources_and_headers.json.template +++ b/templates/tools/run_tests/generated/sources_and_headers.json.template @@ -9,7 +9,7 @@ for f in src: name, ext = os.path.splitext(f) if ext == '.proto': - out.extend(fmt % name for fmt in ['%s.grpc.pb.h', '%s.pb.h']) + out.extend(fmt % name for fmt in ['%s.grpc.pb.h', '%s.pb.h', '%s_mock.grpc.pb.h']) return out def all_targets(targets, libs, filegroups): diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 14c8f67c12d..c3f7f588445 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -2820,14 +2820,19 @@ "headers": [ "src/proto/grpc/testing/control.grpc.pb.h", "src/proto/grpc/testing/control.pb.h", + "src/proto/grpc/testing/control_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/payloads.grpc.pb.h", "src/proto/grpc/testing/payloads.pb.h", + "src/proto/grpc/testing/payloads_mock.grpc.pb.h", "src/proto/grpc/testing/services.grpc.pb.h", "src/proto/grpc/testing/services.pb.h", + "src/proto/grpc/testing/services_mock.grpc.pb.h", "src/proto/grpc/testing/stats.grpc.pb.h", - "src/proto/grpc/testing/stats.pb.h" + "src/proto/grpc/testing/stats.pb.h", + "src/proto/grpc/testing/stats_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -2846,14 +2851,19 @@ "headers": [ "src/proto/grpc/testing/control.grpc.pb.h", "src/proto/grpc/testing/control.pb.h", + "src/proto/grpc/testing/control_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/payloads.grpc.pb.h", "src/proto/grpc/testing/payloads.pb.h", + "src/proto/grpc/testing/payloads_mock.grpc.pb.h", "src/proto/grpc/testing/services.grpc.pb.h", "src/proto/grpc/testing/services.pb.h", + "src/proto/grpc/testing/services_mock.grpc.pb.h", "src/proto/grpc/testing/stats.grpc.pb.h", - "src/proto/grpc/testing/stats.pb.h" + "src/proto/grpc/testing/stats.pb.h", + "src/proto/grpc/testing/stats_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -2974,7 +2984,8 @@ ], "headers": [ "src/proto/grpc/testing/echo_messages.grpc.pb.h", - "src/proto/grpc/testing/echo_messages.pb.h" + "src/proto/grpc/testing/echo_messages.pb.h", + "src/proto/grpc/testing/echo_messages_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3031,7 +3042,8 @@ ], "headers": [ "src/proto/grpc/testing/compiler_test.grpc.pb.h", - "src/proto/grpc/testing/compiler_test.pb.h" + "src/proto/grpc/testing/compiler_test.pb.h", + "src/proto/grpc/testing/compiler_test_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3176,7 +3188,9 @@ "src/proto/grpc/testing/echo.grpc.pb.h", "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", - "src/proto/grpc/testing/echo_messages.pb.h" + "src/proto/grpc/testing/echo_messages.pb.h", + "src/proto/grpc/testing/echo_messages_mock.grpc.pb.h", + "src/proto/grpc/testing/echo_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3196,7 +3210,8 @@ ], "headers": [ "src/proto/grpc/lb/v1/load_balancer.grpc.pb.h", - "src/proto/grpc/lb/v1/load_balancer.pb.h" + "src/proto/grpc/lb/v1/load_balancer.pb.h", + "src/proto/grpc/lb/v1/load_balancer_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3218,7 +3233,8 @@ ], "headers": [ "src/proto/grpc/lb/v1/load_balancer.grpc.pb.h", - "src/proto/grpc/lb/v1/load_balancer.pb.h" + "src/proto/grpc/lb/v1/load_balancer.pb.h", + "src/proto/grpc/lb/v1/load_balancer_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3373,6 +3389,7 @@ "headers": [ "src/proto/grpc/testing/metrics.grpc.pb.h", "src/proto/grpc/testing/metrics.pb.h", + "src/proto/grpc/testing/metrics_mock.grpc.pb.h", "test/cpp/util/metrics_server.h" ], "is_filegroup": false, @@ -3560,10 +3577,13 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", - "src/proto/grpc/testing/test.pb.h" + "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3589,10 +3609,13 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", - "src/proto/grpc/testing/test.pb.h" + "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3693,7 +3716,9 @@ "src/proto/grpc/testing/echo.grpc.pb.h", "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", - "src/proto/grpc/testing/echo_messages.pb.h" + "src/proto/grpc/testing/echo_messages.pb.h", + "src/proto/grpc/testing/echo_messages_mock.grpc.pb.h", + "src/proto/grpc/testing/echo_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -3830,12 +3855,16 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/metrics.grpc.pb.h", "src/proto/grpc/testing/metrics.pb.h", + "src/proto/grpc/testing/metrics_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h", "test/cpp/interop/client_helper.h", "test/cpp/interop/interop_client.h", "test/cpp/interop/stress_interop_client.h", @@ -5846,7 +5875,8 @@ "headers": [ "include/grpc++/support/error_details.h", "src/proto/grpc/status/status.grpc.pb.h", - "src/proto/grpc/status/status.pb.h" + "src/proto/grpc/status/status.pb.h", + "src/proto/grpc/status/status_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -5926,12 +5956,15 @@ "headers": [ "src/proto/grpc/health/v1/health.grpc.pb.h", "src/proto/grpc/health/v1/health.pb.h", + "src/proto/grpc/health/v1/health_mock.grpc.pb.h", "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h", "src/proto/grpc/testing/duplicate/echo_duplicate.pb.h", + "src/proto/grpc/testing/duplicate/echo_duplicate_mock.grpc.pb.h", "src/proto/grpc/testing/echo.grpc.pb.h", "src/proto/grpc/testing/echo.pb.h", "src/proto/grpc/testing/echo_messages.grpc.pb.h", "src/proto/grpc/testing/echo_messages.pb.h", + "src/proto/grpc/testing/echo_messages_mock.grpc.pb.h", "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.h", @@ -5944,7 +5977,6 @@ "language": "c++", "name": "grpc++_test_util", "src": [ - "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.cc", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.cc", @@ -6113,10 +6145,13 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h", "test/cpp/interop/http2_client.h" ], "is_filegroup": false, @@ -6140,6 +6175,7 @@ "headers": [ "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "test/cpp/interop/client_helper.h" ], "is_filegroup": false, @@ -6166,10 +6202,13 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h", "test/cpp/interop/interop_client.h" ], "is_filegroup": false, @@ -6218,10 +6257,13 @@ "headers": [ "src/proto/grpc/testing/empty.grpc.pb.h", "src/proto/grpc/testing/empty.pb.h", + "src/proto/grpc/testing/empty_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/test.grpc.pb.h", - "src/proto/grpc/testing/test.pb.h" + "src/proto/grpc/testing/test.pb.h", + "src/proto/grpc/testing/test_mock.grpc.pb.h" ], "is_filegroup": false, "language": "c++", @@ -6255,14 +6297,19 @@ "headers": [ "src/proto/grpc/testing/control.grpc.pb.h", "src/proto/grpc/testing/control.pb.h", + "src/proto/grpc/testing/control_mock.grpc.pb.h", "src/proto/grpc/testing/messages.grpc.pb.h", "src/proto/grpc/testing/messages.pb.h", + "src/proto/grpc/testing/messages_mock.grpc.pb.h", "src/proto/grpc/testing/payloads.grpc.pb.h", "src/proto/grpc/testing/payloads.pb.h", + "src/proto/grpc/testing/payloads_mock.grpc.pb.h", "src/proto/grpc/testing/services.grpc.pb.h", "src/proto/grpc/testing/services.pb.h", + "src/proto/grpc/testing/services_mock.grpc.pb.h", "src/proto/grpc/testing/stats.grpc.pb.h", "src/proto/grpc/testing/stats.pb.h", + "src/proto/grpc/testing/stats_mock.grpc.pb.h", "test/cpp/qps/benchmark_config.h", "test/cpp/qps/client.h", "test/cpp/qps/driver.h", @@ -8921,7 +8968,8 @@ "deps": [], "headers": [ "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h", - "src/proto/grpc/reflection/v1alpha/reflection.pb.h" + "src/proto/grpc/reflection/v1alpha/reflection.pb.h", + "src/proto/grpc/reflection/v1alpha/reflection_mock.grpc.pb.h" ], "is_filegroup": true, "language": "c++", diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index 814b61a7bf1..c060f98b34a 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -202,7 +202,6 @@ - diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters index 721388e769a..0623e421b21 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters @@ -197,9 +197,6 @@ - - src\proto\grpc\testing - test\cpp\end2end From ea07b60401054e1a6bb5ce8c92ae28e8c4996287 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 17:05:49 -0700 Subject: [PATCH 21/43] Post-review update --- include/grpc++/test/mock_stream.h | 2 +- src/compiler/cpp_generator.cc | 6 - src/proto/grpc/testing/compiler_test.proto | 8 ++ test/cpp/codegen/compiler_test_golden | 144 ++++++++++++++++++++- test/cpp/codegen/compiler_test_mock_golden | 23 +--- 5 files changed, 154 insertions(+), 29 deletions(-) diff --git a/include/grpc++/test/mock_stream.h b/include/grpc++/test/mock_stream.h index 679fea81bd1..f2de9472d6b 100644 --- a/include/grpc++/test/mock_stream.h +++ b/include/grpc++/test/mock_stream.h @@ -1,6 +1,6 @@ /* * - * Copyright 2016, Google Inc. + * Copyright 2017, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d64f8c95322..d01f4ab899b 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1523,18 +1523,12 @@ void PrintMockService(grpc_generator::Printer *printer, std::map *vars) { (*vars)["Service"] = service->name(); - printer->Print(service->GetLeadingComments("//").c_str()); printer->Print(*vars, "class Mock$Service$Stub : public $Service$::StubInterface {\n" " public:\n"); printer->Indent(); - printer->Print(*vars, - "Mock$Service$Stub(){}\n" - "~Mock$Service$Stub(){}\n"); for (int i = 0; i < service->method_count(); ++i) { - printer->Print(service->method(i)->GetLeadingComments("//").c_str()); PrintMockClientMethods(printer, service->method(i).get(), vars); - printer->Print(service->method(i)->GetTrailingComments("//").c_str()); } printer->Outdent(); printer->Print("};\n"); diff --git a/src/proto/grpc/testing/compiler_test.proto b/src/proto/grpc/testing/compiler_test.proto index 085e8ae59f7..24735522e03 100644 --- a/src/proto/grpc/testing/compiler_test.proto +++ b/src/proto/grpc/testing/compiler_test.proto @@ -59,6 +59,14 @@ service ServiceA { // Method A2 leading comment 2 rpc MethodA2(stream Request) returns (Response); // MethodA2 trailing comment 1 + + // Method A3 leading comment 1 + rpc MethodA3(Request) returns (stream Response); + // Method A3 trailing comment 1 + + // Method A4 leading comment 1 + rpc MethodA4(stream Request) returns (stream Response); + // Method A4 trailing comment 1 } // Ignored ServiceA trailing comment 1 diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index fd26a17ac11..8e3ae32a494 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -89,10 +89,30 @@ class ServiceA final { return std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag)); } // MethodA2 trailing comment 1 + // Method A3 leading comment 1 + std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) { + return std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>>(MethodA3Raw(context, request)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag)); + } + // Method A3 trailing comment 1 + // Method A4 leading comment 1 + std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag)); + } + // Method A4 trailing comment 1 private: virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientWriterInterface< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) = 0; virtual ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) = 0; + virtual ::grpc::ClientReaderInterface< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) = 0; + virtual ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) = 0; + virtual ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) = 0; + virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0; }; class Stub final : public StubInterface { public: @@ -107,14 +127,32 @@ class ServiceA final { std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>> AsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) { return std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag)); } + std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) { + return std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>>(MethodA3Raw(context, request)); + } + std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag)); + } + std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag)); + } private: std::shared_ptr< ::grpc::ChannelInterface> channel_; ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientWriter< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) override; ::grpc::ClientAsyncWriter< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) override; + ::grpc::ClientReader< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) override; + ::grpc::ClientAsyncReader< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) override; + ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) override; + ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) override; const ::grpc::RpcMethod rpcmethod_MethodA1_; const ::grpc::RpcMethod rpcmethod_MethodA2_; + const ::grpc::RpcMethod rpcmethod_MethodA3_; + const ::grpc::RpcMethod rpcmethod_MethodA4_; }; static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); @@ -131,6 +169,12 @@ class ServiceA final { // Method A2 leading comment 2 virtual ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response); // MethodA2 trailing comment 1 + // Method A3 leading comment 1 + virtual ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer); + // Method A3 trailing comment 1 + // Method A4 leading comment 1 + virtual ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream); + // Method A4 trailing comment 1 }; template class WithAsyncMethod_MethodA1 : public BaseClass { @@ -172,7 +216,47 @@ class ServiceA final { ::grpc::Service::RequestAsyncClientStreaming(1, context, reader, new_call_cq, notification_cq, tag); } }; - typedef WithAsyncMethod_MethodA1 > AsyncService; + template + class WithAsyncMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_MethodA3() { + ::grpc::Service::MarkMethodAsync(2); + } + ~WithAsyncMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA3(::grpc::ServerContext* context, ::grpc::testing::Request* request, ::grpc::ServerAsyncWriter< ::grpc::testing::Response>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncServerStreaming(2, context, request, writer, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_MethodA4 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_MethodA4() { + ::grpc::Service::MarkMethodAsync(3); + } + ~WithAsyncMethod_MethodA4() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA4(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncBidiStreaming(3, context, stream, new_call_cq, notification_cq, tag); + } + }; + typedef WithAsyncMethod_MethodA1 > > > AsyncService; template class WithGenericMethod_MethodA1 : public BaseClass { private: @@ -208,6 +292,40 @@ class ServiceA final { } }; template + class WithGenericMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_MethodA3() { + ::grpc::Service::MarkMethodGeneric(2); + } + ~WithGenericMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_MethodA4 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_MethodA4() { + ::grpc::Service::MarkMethodGeneric(3); + } + ~WithGenericMethod_MethodA4() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template class WithStreamedUnaryMethod_MethodA1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} @@ -228,8 +346,28 @@ class ServiceA final { virtual ::grpc::Status StreamedMethodA1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0; }; typedef WithStreamedUnaryMethod_MethodA1 StreamedUnaryService; - typedef Service SplitStreamedService; - typedef WithStreamedUnaryMethod_MethodA1 StreamedService; + template + class WithSplitStreamingMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithSplitStreamingMethod_MethodA3() { + ::grpc::Service::MarkMethodStreamed(2, + new ::grpc::SplitServerStreamingHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithSplitStreamingMethod_MethodA3::StreamedMethodA3, this, std::placeholders::_1, std::placeholders::_2))); + } + ~WithSplitStreamingMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable regular version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + // replace default version of method with split streamed + virtual ::grpc::Status StreamedMethodA3(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_split_streamer) = 0; + }; + typedef WithSplitStreamingMethod_MethodA3 SplitStreamedService; + typedef WithStreamedUnaryMethod_MethodA1 > StreamedService; }; // ServiceB leading comment 1 diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden index ced61aeb94f..8e4b4d59112 100644 --- a/test/cpp/codegen/compiler_test_mock_golden +++ b/test/cpp/codegen/compiler_test_mock_golden @@ -11,37 +11,22 @@ namespace grpc { namespace testing { -// ServiceA detached comment 1 -// -// ServiceA detached comment 2 -// -// ServiceA leading comment 1 class MockServiceAStub : public ServiceA::StubInterface { public: - MockServiceAStub(){} - ~MockServiceAStub(){} - // MethodA1 leading comment 1 MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); - // MethodA1 trailing comment 1 - // MethodA2 detached leading comment 1 - // - // Method A2 leading comment 1 - // Method A2 leading comment 2 MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response)); MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag)); - // MethodA2 trailing comment 1 + MOCK_METHOD2(MethodA3Raw, ::grpc::ClientReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request)); + MOCK_METHOD4(AsyncMethodA3Raw, ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag)); + MOCK_METHOD1(MethodA4Raw, ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context)); + MOCK_METHOD3(AsyncMethodA4Raw, ::grpc::ClientAsyncReaderWriterInterface<::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag)); }; -// ServiceB leading comment 1 class MockServiceBStub : public ServiceB::StubInterface { public: - MockServiceBStub(){} - ~MockServiceBStub(){} - // MethodB1 leading comment 1 MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response)); MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq)); - // MethodB1 trailing comment 1 }; } // namespace grpc From af3d2bc997bc2adc76fe82258851df30da7a9d35 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 17:21:43 -0700 Subject: [PATCH 22/43] Readding the line mistakenly deleted. --- Makefile | 3 ++- templates/Makefile.template | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c3a8e7e4172..b0e122e6bd1 100644 --- a/Makefile +++ b/Makefile @@ -902,7 +902,8 @@ openssl_dep_message: @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo + @echo "doesn't have it, or your compiler can't build BoringSSL." + @echo @echo "Please consult INSTALL to get more information." @echo @echo "If you need information about why these tests failed, run:" diff --git a/templates/Makefile.template b/templates/Makefile.template index 84afcdb354e..6c6a8e05932 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -846,7 +846,8 @@ @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo + @echo "doesn't have it, or your compiler can't build BoringSSL." + @echo @echo "Please consult INSTALL to get more information." @echo @echo "If you need information about why these tests failed, run:" From 1bcb976a3a8b1da416a2766fb012335d52086c00 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 17:58:16 -0700 Subject: [PATCH 23/43] Tab/space problem with Makefile.template --- Makefile | 4 ++-- templates/Makefile.template | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b0e122e6bd1..c6592e8e1af 100644 --- a/Makefile +++ b/Makefile @@ -902,8 +902,8 @@ openssl_dep_message: @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo "doesn't have it, or your compiler can't build BoringSSL." - @echo + @echo "doesn't have it, or your compiler can't build BoringSSL." + @echo @echo "Please consult INSTALL to get more information." @echo @echo "If you need information about why these tests failed, run:" diff --git a/templates/Makefile.template b/templates/Makefile.template index 6c6a8e05932..b8beaec11e8 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -846,8 +846,8 @@ @echo @echo "The target you are trying to run requires an OpenSSL implementation." @echo "Your system doesn't have one, and either the third_party directory" - @echo "doesn't have it, or your compiler can't build BoringSSL." - @echo + @echo "doesn't have it, or your compiler can't build BoringSSL." + @echo @echo "Please consult INSTALL to get more information." @echo @echo "If you need information about why these tests failed, run:" From fefd2f2d8b57386f3bef3128c075c06e605c48c0 Mon Sep 17 00:00:00 2001 From: Dan Zhang Date: Fri, 21 Apr 2017 12:28:48 -0400 Subject: [PATCH 24/43] Add make udp_server shutdown_fd() protected by mutex lock. --- src/core/lib/iomgr/udp_server.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/core/lib/iomgr/udp_server.c b/src/core/lib/iomgr/udp_server.c index ca283d034f9..af70746064e 100644 --- a/src/core/lib/iomgr/udp_server.c +++ b/src/core/lib/iomgr/udp_server.c @@ -92,6 +92,11 @@ struct grpc_udp_listener { struct grpc_udp_listener *next; }; +struct shutdown_fd_args { + grpc_fd *fd; + gpr_mu *server_mu; +}; + /* the overall server */ struct grpc_udp_server { gpr_mu mu; @@ -151,8 +156,13 @@ grpc_udp_server *grpc_udp_server_create(const grpc_channel_args *args) { return s; } -static void shutdown_fd(grpc_exec_ctx *exec_ctx, void *fd, grpc_error *error) { - grpc_fd_shutdown(exec_ctx, (grpc_fd *)fd, GRPC_ERROR_REF(error)); +static void shutdown_fd(grpc_exec_ctx *exec_ctx, void *args, + grpc_error *error) { + struct shutdown_fd_args *shutdown_args = (struct shutdown_fd_args *)args; + gpr_mu_lock(shutdown_args->server_mu); + grpc_fd_shutdown(exec_ctx, shutdown_args->fd, GRPC_ERROR_REF(error)); + gpr_mu_unlock(shutdown_args->server_mu); + gpr_free(shutdown_args); } static void dummy_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { @@ -242,7 +252,10 @@ void grpc_udp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_udp_server *s, if (s->active_ports) { for (sp = s->head; sp; sp = sp->next) { GPR_ASSERT(sp->orphan_cb); - grpc_closure_init(&sp->orphan_fd_closure, shutdown_fd, sp->emfd, + struct shutdown_fd_args *args = gpr_malloc(sizeof(*args)); + args->fd = sp->emfd; + args->server_mu = &s->mu; + grpc_closure_init(&sp->orphan_fd_closure, shutdown_fd, args, grpc_schedule_on_exec_ctx); sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); From ae64b01506b5b5322694c5fc06d09910f4945cbb Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Fri, 21 Apr 2017 16:12:39 -0700 Subject: [PATCH 25/43] updated g meaning for 1.4.x --- BUILD | 2 +- build.yaml | 2 +- doc/g_stands_for.md | 1 + src/core/lib/surface/version.c | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/BUILD b/BUILD index 09b17ad6eb2..5662a9e795b 100644 --- a/BUILD +++ b/BUILD @@ -39,7 +39,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_proto_plugin", "grpc_cc_libraries") # This should be updated along with build.yaml -g_stands_for = "gentle" +g_stands_for = "gregarious" core_version = "3.0.0-dev" diff --git a/build.yaml b/build.yaml index 58a474aabf1..e063f3e3df0 100644 --- a/build.yaml +++ b/build.yaml @@ -13,7 +13,7 @@ settings: '#09': Per-language overrides are possible with (eg) ruby_version tag here '#10': See the expand_version.py for all the quirks here core_version: 4.0.0-dev - g_stands_for: gentle + g_stands_for: gregarious version: 1.4.0-dev filegroups: - name: census diff --git a/doc/g_stands_for.md b/doc/g_stands_for.md index d2fc7a50f95..2078bb37ea1 100644 --- a/doc/g_stands_for.md +++ b/doc/g_stands_for.md @@ -8,3 +8,4 @@ future), and the corresponding version numbers that used them: - 1.1 'g' stands for 'good' - 1.2 'g' stands for 'green' - 1.3 'g' stands for 'gentle' +- 1.4 'g' stands for 'gregarious' diff --git a/src/core/lib/surface/version.c b/src/core/lib/surface/version.c index 3793845559c..cddc595e4c9 100644 --- a/src/core/lib/surface/version.c +++ b/src/core/lib/surface/version.c @@ -38,4 +38,4 @@ const char *grpc_version_string(void) { return "4.0.0-dev"; } -const char *grpc_g_stands_for(void) { return "gentle"; } +const char *grpc_g_stands_for(void) { return "gregarious"; } From ea525ebd3949f89923f30da22471495e9e066326 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 17:50:32 +0000 Subject: [PATCH 26/43] Threaded port_server --- tools/run_tests/python_utils/port_server.py | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index dbd32efc0e8..67ae4715820 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -33,18 +33,20 @@ from __future__ import print_function import argparse -from six.moves import BaseHTTPServer +from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler import hashlib import os import socket import sys import time +from SocketServer import ThreadingMixIn +import threading # increment this number whenever making a change to ensure that # the changes are picked up by running CI servers # note that all changes must be backwards compatible -_MY_VERSION = 9 +_MY_VERSION = 10 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': @@ -111,12 +113,12 @@ def allocate_port(req): keep_running = True -class Handler(BaseHTTPServer.BaseHTTPRequestHandler): +class Handler(BaseHTTPRequestHandler): def setup(self): # If the client is unreachable for 5 seconds, close the connection self.timeout = 5 - BaseHTTPServer.BaseHTTPRequestHandler.setup(self) + BaseHTTPRequestHandler.setup(self) def do_GET(self): global keep_running @@ -158,12 +160,12 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): elif self.path == '/quitquitquit': self.send_response(200) self.end_headers() - keep_running = False + sys.exit(0) +class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): + """Handle requests in a separate thread""" -httpd = BaseHTTPServer.HTTPServer(('', args.port), Handler) -while keep_running: - httpd.handle_request() - sys.stderr.flush() -print('done') +httpd = ThreadedHTTPServer(('', args.port), Handler) +httpd.serve_forever() + From d3ba7cbc8c26659983d9f4a15ad58a17d4a56bb2 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 24 Apr 2017 11:51:07 -0700 Subject: [PATCH 27/43] Don't abort on input --- src/core/lib/channel/connected_channel.c | 4 +++- src/core/lib/security/transport/client_auth_filter.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/lib/channel/connected_channel.c b/src/core/lib/channel/connected_channel.c index 22caf243737..d8985268eba 100644 --- a/src/core/lib/channel/connected_channel.c +++ b/src/core/lib/channel/connected_channel.c @@ -128,7 +128,9 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) { channel_data *cd = (channel_data *)elem->channel_data; - grpc_transport_destroy(exec_ctx, cd->transport); + if (cd->transport) { + grpc_transport_destroy(exec_ctx, cd->transport); + } } static char *con_get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index f526653ffa3..1f0daf73253 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -343,8 +343,16 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, grpc_channel_element_args *args) { grpc_security_connector *sc = grpc_security_connector_find_in_args(args->channel_args); + if (sc == NULL) { + return GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Security connector missing from client auth filter args"); + } grpc_auth_context *auth_context = grpc_find_auth_context_in_args(args->channel_args); + if (auth_context == NULL) { + return GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Auth context missing from client auth filter args"); + } /* grab pointers to our data from the channel element */ channel_data *chand = elem->channel_data; @@ -353,8 +361,6 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, handle the case that there's no 'next' filter to call on the up or down path */ GPR_ASSERT(!args->is_last); - GPR_ASSERT(sc != NULL); - GPR_ASSERT(auth_context != NULL); /* initialize members */ chand->security_connector = From 25149249ec74eade6af512f2573c694c34fab9fd Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 13:42:52 -0700 Subject: [PATCH 28/43] Slow down timers for ubsan builds --- Makefile | 2 +- build.yaml | 2 +- test/core/util/test_config.c | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a650655a7d5..58a36332d51 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ LD_ubsan = clang LDXX_ubsan = clang++ CPPFLAGS_ubsan = -O0 -fsanitize-coverage=edge -fsanitize=undefined -fno-omit-frame-pointer -Wno-unused-command-line-argument -Wvarargs LDFLAGS_ubsan = -fsanitize=undefined,unsigned-integer-overflow -DEFINES_ubsan = NDEBUG +DEFINES_ubsan = NDEBUG GRPC_UBSAN VALID_CONFIG_tsan = 1 REQUIRE_CUSTOM_LIBRARIES_tsan = 1 diff --git a/build.yaml b/build.yaml index 58a474aabf1..5791402f575 100644 --- a/build.yaml +++ b/build.yaml @@ -4464,7 +4464,7 @@ configs: CPPFLAGS: -O0 -fsanitize-coverage=edge -fsanitize=undefined -fno-omit-frame-pointer -Wno-unused-command-line-argument -Wvarargs CXX: clang++ - DEFINES: NDEBUG + DEFINES: NDEBUG GRPC_UBSAN LD: clang LDFLAGS: -fsanitize=undefined,unsigned-integer-overflow LDXX: clang++ diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c index 0180d6f08d4..9a400c54ca2 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -348,6 +348,14 @@ bool BuiltUnderMsan() { #endif } +bool BuiltUnderUbsan() { +#ifdef GRPC_UBSAN + return true; +#else + return false; +#endif +} + int64_t grpc_test_sanitizer_slowdown_factor() { int64_t sanitizer_multiplier = 1; if (BuiltUnderValgrind()) { @@ -358,6 +366,8 @@ int64_t grpc_test_sanitizer_slowdown_factor() { sanitizer_multiplier = 3; } else if (BuiltUnderMsan()) { sanitizer_multiplier = 4; + } else if (BuiltUnderUbsan()) { + sanitizer_multiplier = 5; } return sanitizer_multiplier; } From ec4952426976c60e33fb279aa36a1cd1f89bd938 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 20:55:43 +0000 Subject: [PATCH 29/43] Add a mutex around allocate_port --- tools/run_tests/python_utils/port_server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index 67ae4715820..522cbed9e1c 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -46,7 +46,7 @@ import threading # increment this number whenever making a change to ensure that # the changes are picked up by running CI servers # note that all changes must be backwards compatible -_MY_VERSION = 10 +_MY_VERSION = 11 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': @@ -70,6 +70,7 @@ print('port server running on port %d' % args.port) pool = [] in_use = {} +mu = threading.Lock() def refill_pool(max_timeout, req): @@ -97,16 +98,21 @@ def refill_pool(max_timeout, req): def allocate_port(req): global pool global in_use + global mu + mu.acquire() max_timeout = 600 while not pool: refill_pool(max_timeout, req) if not pool: req.log_message("failed to find ports: retrying soon") + mu.release() time.sleep(1) + mu.acquire() max_timeout /= 2 port = pool[0] pool = pool[1:] in_use[port] = time.time() + mu.release() return port From 7eaca2f7b62d88c1601e59ff4a1dc34706df923c Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 24 Apr 2017 16:34:25 -0700 Subject: [PATCH 30/43] Propagate publish error --- src/core/ext/filters/client_channel/subchannel.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/ext/filters/client_channel/subchannel.c b/src/core/ext/filters/client_channel/subchannel.c index 967e571221c..177a3c2ee7a 100644 --- a/src/core/ext/filters/client_channel/subchannel.c +++ b/src/core/ext/filters/client_channel/subchannel.c @@ -615,7 +615,7 @@ void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, elem->filter->start_transport_op(exec_ctx, elem, op); } -static void publish_transport_locked(grpc_exec_ctx *exec_ctx, +static bool publish_transport_locked(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { grpc_connected_subchannel *con; grpc_channel_stack *stk; @@ -631,15 +631,16 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx, if (!grpc_channel_init_create_stack(exec_ctx, builder, GRPC_CLIENT_SUBCHANNEL)) { grpc_channel_stack_builder_destroy(exec_ctx, builder); - abort(); /* TODO(ctiller): what to do here (previously we just crashed) */ + return false; } grpc_error *error = grpc_channel_stack_builder_finish( exec_ctx, builder, 0, 1, connection_destroy, NULL, (void **)&con); if (error != GRPC_ERROR_NONE) { + grpc_transport_destroy(exec_ctx, c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", grpc_error_string(error)); GRPC_ERROR_UNREF(error); - abort(); /* TODO(ctiller): what to do here? */ + return false; } stk = CHANNEL_STACK_FROM_CONNECTION(con); memset(&c->connecting_result, 0, sizeof(c->connecting_result)); @@ -656,7 +657,7 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx, grpc_channel_stack_destroy(exec_ctx, stk); gpr_free(con); GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - return; + return false; } /* publish */ @@ -678,6 +679,7 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx, /* signal completion */ grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "connected"); + return true; } static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, @@ -688,8 +690,8 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); gpr_mu_lock(&c->mu); c->connecting = false; - if (c->connecting_result.transport != NULL) { - publish_transport_locked(exec_ctx, c); + if (c->connecting_result.transport != NULL && publish_transport_locked(exec_ctx, c)) { + /* do nothing, transport was published */ } else if (c->disconnected) { GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); } else { From 6b42bfde1f710edc5856a3934894aa80d311d0e6 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 24 Apr 2017 16:36:11 -0700 Subject: [PATCH 31/43] Add fuzzer to corpus --- ...erfuzz-testcase-minimized-5175380371570688 | Bin 0 -> 48 bytes tools/run_tests/generated/tests.json | 23 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-minimized-5175380371570688 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-minimized-5175380371570688 b/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-minimized-5175380371570688 new file mode 100644 index 0000000000000000000000000000000000000000..9c7aebc63a291d2d6c3213a1a9fcbf2a56e0033d GIT binary patch literal 48 zcmZQ7PAw`+En;9~OfM=()+ Date: Tue, 25 Apr 2017 08:10:04 -0700 Subject: [PATCH 32/43] clang fmt --- src/core/ext/filters/client_channel/subchannel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/ext/filters/client_channel/subchannel.c b/src/core/ext/filters/client_channel/subchannel.c index 177a3c2ee7a..b2de85c4a12 100644 --- a/src/core/ext/filters/client_channel/subchannel.c +++ b/src/core/ext/filters/client_channel/subchannel.c @@ -690,7 +690,8 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); gpr_mu_lock(&c->mu); c->connecting = false; - if (c->connecting_result.transport != NULL && publish_transport_locked(exec_ctx, c)) { + if (c->connecting_result.transport != NULL && + publish_transport_locked(exec_ctx, c)) { /* do nothing, transport was published */ } else if (c->disconnected) { GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); From b56dae554ca14dfd5a76690462b9efbc38314de0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 08:22:24 -0700 Subject: [PATCH 33/43] Allow a longer fetch time for port server --- test/core/util/port_server_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c index 38054dd1e74..254c3a6b613 100644 --- a/test/core/util/port_server_client.c +++ b/test/core/util/port_server_client.c @@ -103,7 +103,7 @@ void grpc_free_port_using_server(int port) { grpc_resource_quota *resource_quota = grpc_resource_quota_create("port_server_client/free"); grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_timeout_seconds_to_deadline(10), + grpc_timeout_seconds_to_deadline(30), grpc_closure_create(freed_port_from_server, &pr, grpc_schedule_on_exec_ctx), &rsp); @@ -235,7 +235,7 @@ int grpc_pick_port_using_server(void) { grpc_resource_quota_create("port_server_client/pick"); grpc_httpcli_get( &exec_ctx, &context, &pr.pops, resource_quota, &req, - grpc_timeout_seconds_to_deadline(10), + grpc_timeout_seconds_to_deadline(30), grpc_closure_create(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), &pr.response); grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); From c9c6aa7df0442a2861619a6403380350420871c4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 08:27:31 -0700 Subject: [PATCH 34/43] Be resilient against failed runs --- tools/profiling/microbenchmarks/bm_diff.py | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/profiling/microbenchmarks/bm_diff.py b/tools/profiling/microbenchmarks/bm_diff.py index 6ee4cbfc7bb..3c15478774e 100755 --- a/tools/profiling/microbenchmarks/bm_diff.py +++ b/tools/profiling/microbenchmarks/bm_diff.py @@ -204,7 +204,10 @@ def eintr_be_gone(fn): def read_json(filename): - with open(filename) as f: return json.loads(f.read()) + try: + with open(filename) as f: return json.loads(f.read()) + except ValueError, e: + return None def finalize(): @@ -217,16 +220,18 @@ def finalize(): js_old_ctr = read_json('%s.counters.old.%d.json' % (bm, loop)) js_old_opt = read_json('%s.opt.old.%d.json' % (bm, loop)) - for row in bm_json.expand_json(js_new_ctr, js_new_opt): - print row - name = row['cpp_name'] - if name.endswith('_mean') or name.endswith('_stddev'): continue - benchmarks[name].add_sample(row, True) - for row in bm_json.expand_json(js_old_ctr, js_old_opt): - print row - name = row['cpp_name'] - if name.endswith('_mean') or name.endswith('_stddev'): continue - benchmarks[name].add_sample(row, False) + if js_new_ctr: + for row in bm_json.expand_json(js_new_ctr, js_new_opt): + print row + name = row['cpp_name'] + if name.endswith('_mean') or name.endswith('_stddev'): continue + benchmarks[name].add_sample(row, True) + if js_old_ctr: + for row in bm_json.expand_json(js_old_ctr, js_old_opt): + print row + name = row['cpp_name'] + if name.endswith('_mean') or name.endswith('_stddev'): continue + benchmarks[name].add_sample(row, False) really_interesting = set() for name, bm in benchmarks.items(): From 9fd7cf5dc3fca5a07df03b2dda08519a2e6b308a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 08:34:14 -0700 Subject: [PATCH 35/43] Recycle ports --- test/cpp/microbenchmarks/fullstack_fixtures.h | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index f129ede26a6..98aca1c3465 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -113,13 +113,17 @@ class TCP : public FullstackFixture { public: TCP(Service* service, const FixtureConfiguration& fixture_configuration = FixtureConfiguration()) - : FullstackFixture(service, fixture_configuration, MakeAddress()) {} + : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {} + + ~TCP() { grpc_recycle_unused_port(port_); } private: - static grpc::string MakeAddress() { - int port = grpc_pick_unused_port_or_die(); + int port_; + + static grpc::string MakeAddress(int* port) { + *port = grpc_pick_unused_port_or_die(); std::stringstream addr; - addr << "localhost:" << port; + addr << "localhost:" << *port; return addr.str(); } }; @@ -128,14 +132,18 @@ class UDS : public FullstackFixture { public: UDS(Service* service, const FixtureConfiguration& fixture_configuration = FixtureConfiguration()) - : FullstackFixture(service, fixture_configuration, MakeAddress()) {} + : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {} + + ~UDS() { grpc_recycle_unused_port(port_); } private: - static grpc::string MakeAddress() { - int port = grpc_pick_unused_port_or_die(); // just for a unique id - not a - // real port + int port_; + + static grpc::string MakeAddress(int* port) { + *port = grpc_pick_unused_port_or_die(); // just for a unique id - not a + // real port std::stringstream addr; - addr << "unix:/tmp/bm_fullstack." << port; + addr << "unix:/tmp/bm_fullstack." << *port; return addr.str(); } }; From a27edc69c3e9b957a32f8d89f4969abe6cc37580 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 09:20:30 -0700 Subject: [PATCH 36/43] Ensure port server running --- tools/jenkins/run_performance.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/jenkins/run_performance.sh b/tools/jenkins/run_performance.sh index 544e31dcbdb..f530fb46b86 100755 --- a/tools/jenkins/run_performance.sh +++ b/tools/jenkins/run_performance.sh @@ -37,4 +37,5 @@ BENCHMARKS_TO_RUN="bm_fullstack_unary_ping_pong bm_fullstack_streaming_ping_pong # Enter the gRPC repo root cd $(dirname $0)/../.. +tools/run_tests/start_port_server.py tools/profiling/microbenchmarks/bm_diff.py -d origin/$ghprbTargetBranch -b $BENCHMARKS_TO_RUN From 09ebed7bf4c19a8c31195b44c8d911f39779323e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 25 Apr 2017 10:19:10 -0700 Subject: [PATCH 37/43] Ensure port server can shutdown --- tools/run_tests/python_utils/port_server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index 522cbed9e1c..e96ee0b08c1 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -46,7 +46,7 @@ import threading # increment this number whenever making a change to ensure that # the changes are picked up by running CI servers # note that all changes must be backwards compatible -_MY_VERSION = 11 +_MY_VERSION = 14 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': @@ -166,12 +166,11 @@ class Handler(BaseHTTPRequestHandler): elif self.path == '/quitquitquit': self.send_response(200) self.end_headers() - sys.exit(0) + self.server.shutdown() class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread""" -httpd = ThreadedHTTPServer(('', args.port), Handler) -httpd.serve_forever() +ThreadedHTTPServer(('', args.port), Handler).serve_forever() From fcb56a785dfd7b20ec831b6822ffdfcf3d2acd73 Mon Sep 17 00:00:00 2001 From: Zoltan Kuscsik Date: Wed, 19 Apr 2017 15:47:37 +0200 Subject: [PATCH 38/43] core, avl: rename static functions Renamed remove and add static functions to remove_key and add_key --- src/core/lib/support/avl.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/lib/support/avl.c b/src/core/lib/support/avl.c index d8440001536..ffa10c1e4fc 100644 --- a/src/core/lib/support/avl.c +++ b/src/core/lib/support/avl.c @@ -205,8 +205,8 @@ static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key, } } -static gpr_avl_node *add(const gpr_avl_vtable *vtable, gpr_avl_node *node, - void *key, void *value) { +static gpr_avl_node *add_key(const gpr_avl_vtable *vtable, gpr_avl_node *node, + void *key, void *value) { long cmp; if (node == NULL) { return new_node(key, value, NULL, NULL); @@ -217,17 +217,17 @@ static gpr_avl_node *add(const gpr_avl_vtable *vtable, gpr_avl_node *node, } else if (cmp > 0) { return rebalance( vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), - add(vtable, node->left, key, value), ref_node(node->right)); + add_key(vtable, node->left, key, value), ref_node(node->right)); } else { return rebalance(vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), ref_node(node->left), - add(vtable, node->right, key, value)); + add_key(vtable, node->right, key, value)); } } gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value) { gpr_avl_node *old_root = avl.root; - avl.root = add(avl.vtable, avl.root, key, value); + avl.root = add_key(avl.vtable, avl.root, key, value); assert_invariants(avl.root); unref_node(avl.vtable, old_root); return avl; @@ -247,8 +247,8 @@ static gpr_avl_node *in_order_tail(gpr_avl_node *node) { return node; } -static gpr_avl_node *_remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, - void *key) { +static gpr_avl_node *remove_key(const gpr_avl_vtable *vtable, + gpr_avl_node *node, void *key) { long cmp; if (node == NULL) { return NULL; @@ -263,27 +263,27 @@ static gpr_avl_node *_remove(const gpr_avl_vtable *vtable, gpr_avl_node *node, gpr_avl_node *h = in_order_head(node->right); return rebalance(vtable, vtable->copy_key(h->key), vtable->copy_value(h->value), ref_node(node->left), - _remove(vtable, node->right, h->key)); + remove_key(vtable, node->right, h->key)); } else { gpr_avl_node *h = in_order_tail(node->left); return rebalance( vtable, vtable->copy_key(h->key), vtable->copy_value(h->value), - _remove(vtable, node->left, h->key), ref_node(node->right)); + remove_key(vtable, node->left, h->key), ref_node(node->right)); } } else if (cmp > 0) { - return rebalance(vtable, vtable->copy_key(node->key), - vtable->copy_value(node->value), - _remove(vtable, node->left, key), ref_node(node->right)); + return rebalance( + vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), + remove_key(vtable, node->left, key), ref_node(node->right)); } else { return rebalance(vtable, vtable->copy_key(node->key), vtable->copy_value(node->value), ref_node(node->left), - _remove(vtable, node->right, key)); + remove_key(vtable, node->right, key)); } } gpr_avl gpr_avl_remove(gpr_avl avl, void *key) { gpr_avl_node *old_root = avl.root; - avl.root = _remove(avl.vtable, avl.root, key); + avl.root = remove_key(avl.vtable, avl.root, key); assert_invariants(avl.root); unref_node(avl.vtable, old_root); return avl; From 017b452b7b1256cbaa0ef3cb11f363b51ff1e7c5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 22:57:59 -0700 Subject: [PATCH 39/43] Use larger block size in proto write --- include/grpc++/impl/codegen/proto_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc++/impl/codegen/proto_utils.h b/include/grpc++/impl/codegen/proto_utils.h index 6df9de4fd22..8c0c32bfc5d 100644 --- a/include/grpc++/impl/codegen/proto_utils.h +++ b/include/grpc++/impl/codegen/proto_utils.h @@ -52,7 +52,7 @@ namespace internal { class GrpcBufferWriterPeer; -const int kGrpcBufferWriterMaxBufferLength = 8192; +const int kGrpcBufferWriterMaxBufferLength = 1024 * 1024; class GrpcBufferWriter final : public ::grpc::protobuf::io::ZeroCopyOutputStream { From e7c31edb555399b699261cb6e0b9f83fb3d6d9d9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 26 Apr 2017 08:46:44 -0700 Subject: [PATCH 40/43] Print before commenting to ensure theres A copy of the results somewhere --- tools/profiling/microbenchmarks/bm_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/profiling/microbenchmarks/bm_diff.py b/tools/profiling/microbenchmarks/bm_diff.py index 3c15478774e..b2d6f460475 100755 --- a/tools/profiling/microbenchmarks/bm_diff.py +++ b/tools/profiling/microbenchmarks/bm_diff.py @@ -248,8 +248,8 @@ def finalize(): text = 'Performance differences noted:\n' + tabulate.tabulate(rows, headers=headers, floatfmt='+.2f') else: text = 'No significant performance differences' - comment_on_pr.comment_on_pr('```\n%s\n```' % text) print text + comment_on_pr.comment_on_pr('```\n%s\n```' % text) eintr_be_gone(finalize) From ffc23ff17fe1ad33206310b4799aec94cfa9cb5e Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Wed, 26 Apr 2017 19:59:07 +0000 Subject: [PATCH 41/43] Drop Python 2.7-only implication --- src/python/grpcio/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio/README.rst b/src/python/grpcio/README.rst index 3fc318539ea..014a6491dad 100644 --- a/src/python/grpcio/README.rst +++ b/src/python/grpcio/README.rst @@ -6,7 +6,7 @@ Package for gRPC Python. Installation ------------ -gRPC Python is available for Linux, Mac OS X, and Windows running Python 2.7. +gRPC Python is available for Linux, Mac OS X, and Windows. From PyPI ~~~~~~~~~ From b1faf02140890d72c600cebe18cec6329080fbcf Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Wed, 26 Apr 2017 20:07:58 +0000 Subject: [PATCH 42/43] What was once Mac OS X is now called macOS --- src/python/grpcio/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio/README.rst b/src/python/grpcio/README.rst index 014a6491dad..28a27145682 100644 --- a/src/python/grpcio/README.rst +++ b/src/python/grpcio/README.rst @@ -6,7 +6,7 @@ Package for gRPC Python. Installation ------------ -gRPC Python is available for Linux, Mac OS X, and Windows. +gRPC Python is available for Linux, macOS, and Windows. From PyPI ~~~~~~~~~ From 78e0864d3d89bf71d0aa2f817bad4ce7d3fe488e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 08:14:23 -0700 Subject: [PATCH 43/43] Expand allowable resource quota failures: unavailable seems sane --- test/core/end2end/tests/resource_quota_server.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c index 2453ca1b89b..6418f5d01ad 100644 --- a/test/core/end2end/tests/resource_quota_server.c +++ b/test/core/end2end/tests/resource_quota_server.c @@ -169,6 +169,7 @@ void resource_quota_server(grpc_end2end_test_config config) { int cancelled_calls_on_client = 0; int cancelled_calls_on_server = 0; int deadline_exceeded = 0; + int unavailable = 0; grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); @@ -260,6 +261,9 @@ void resource_quota_server(grpc_end2end_test_config config) { case GRPC_STATUS_DEADLINE_EXCEEDED: deadline_exceeded++; break; + case GRPC_STATUS_UNAVAILABLE: + unavailable++; + break; case GRPC_STATUS_OK: break; default: @@ -358,9 +362,9 @@ void resource_quota_server(grpc_end2end_test_config config) { gpr_log(GPR_INFO, "Done. %d total calls: %d cancelled at server, %d cancelled at " - "client, %d timed out.", + "client, %d timed out, %d unavailable.", NUM_CALLS, cancelled_calls_on_server, cancelled_calls_on_client, - deadline_exceeded); + deadline_exceeded, unavailable); grpc_byte_buffer_destroy(request_payload); grpc_slice_unref(request_payload_slice);