From 1eb96dc7fd70d72849b638aafd39de815521b540 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 22 Mar 2017 12:19:03 -0700 Subject: [PATCH 01/48] Fix semantics of LB policy selection. --- doc/service_config.md | 20 ++++++++++++++------ src/core/ext/client_channel/client_channel.c | 18 ++++++++---------- src/core/ext/lb_policy/grpclb/grpclb.c | 8 ++++---- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/doc/service_config.md b/doc/service_config.md index ecc23817d12..c5d4ef42b19 100644 --- a/doc/service_config.md +++ b/doc/service_config.md @@ -13,12 +13,20 @@ The service config is a JSON string of the following form: ``` { // Load balancing policy name. - // Supported values are 'round_robin' and 'grpclb'. - // Optional; if unset, the default behavior is pick the first available - // backend. - // Note that if the resolver returns only balancer addresses and no - // backend addresses, gRPC will always use the 'grpclb' policy, - // regardless of what this field is set to. + // Currently, the only selectable client-side policy provided with gRPC + // is 'round_robin', but third parties may add their own policies. + // This field is optional; if unset, the default behavior is to pick + // the first available backend. + // If the policy name is set via the client API, that value overrides + // the value specified here. + // + // Note that if the resolver returns at least one balancer address (as + // opposed to backend addresses), gRPC will use grpclb (see + // https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), + // regardless of what LB policy is requested either here or via the + // client API. However, if the resolver returns backend addresses as + // well as balancer addresses, the client may fall back to the requested + // policy if it is unable to reach any of the grpclb load balancers. 'loadBalancingPolicy': string, // Per-method configuration. Optional. diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 00c20913b0f..7df211d0000 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -368,27 +368,25 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); lb_policy_name = channel_arg->value.string; } - // Special case: If all of the addresses are balancer addresses, - // assume that we should use the grpclb policy, regardless of what the - // resolver actually specified. + // Special case: If at least one balancer address is present, we use + // the grpclb policy, regardless of what the resolver actually specified. channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); grpc_lb_addresses *addresses = channel_arg->value.pointer.p; - bool found_backend_address = false; + bool found_balancer_address = false; for (size_t i = 0; i < addresses->num_addresses; ++i) { - if (!addresses->addresses[i].is_balancer) { - found_backend_address = true; + if (addresses->addresses[i].is_balancer) { + found_balancer_address = true; break; } } - if (!found_backend_address) { + if (found_balancer_address) { if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { gpr_log(GPR_INFO, - "resolver requested LB policy %s but provided only balancer " - "addresses, no backend addresses -- forcing use of grpclb LB " - "policy", + "resolver requested LB policy %s but provided at least one " + "balancer address -- forcing use of grpclb LB policy", lb_policy_name); } lb_policy_name = "grpclb"; diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index d612591f2eb..e0e5e28eb6f 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -841,10 +841,10 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, /* Count the number of gRPC-LB addresses. There must be at least one. * TODO(roth): For now, we ignore non-balancer addresses, but in the * future, we may change the behavior such that we fall back to using - * the non-balancer addresses if we cannot reach any balancers. At that - * time, this should be changed to allow a list with no balancer addresses, - * since the resolver might fail to return a balancer address even when - * this is the right LB policy to use. */ + * the non-balancer addresses if we cannot reach any balancers. In the + * fallback case, we should use the LB policy indicated by + * GRPC_ARG_LB_POLICY_NAME (although if that specifies grpclb or is + * unset, we should default to pick_first). */ const grpc_arg *arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); From e3ec4b2c287b480d61ddaa2b461cf6d468519313 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 24 Mar 2017 07:33:38 -0700 Subject: [PATCH 02/48] Clarify wording. --- doc/service_config.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/service_config.md b/doc/service_config.md index c5d4ef42b19..8039fcad095 100644 --- a/doc/service_config.md +++ b/doc/service_config.md @@ -24,9 +24,10 @@ The service config is a JSON string of the following form: // opposed to backend addresses), gRPC will use grpclb (see // https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), // regardless of what LB policy is requested either here or via the - // client API. However, if the resolver returns backend addresses as - // well as balancer addresses, the client may fall back to the requested - // policy if it is unable to reach any of the grpclb load balancers. + // client API. However, if the resolver returns at least one backend + // address in addition to the balancer address(es), the client may fall + // back to the requested policy if it is unable to reach any of the + // grpclb load balancers. 'loadBalancingPolicy': string, // Per-method configuration. Optional. From 1383895b7660357298c652e8ccfd45a0190d70e8 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 15:43:07 -0700 Subject: [PATCH 03/48] 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 04/48] 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 2f40ff423ece50964d1041a4ad68939260da9fe6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 16:01:19 -0700 Subject: [PATCH 05/48] Support making hybrid cqs in core --- src/core/lib/surface/completion_queue.c | 167 +++++++++++++++++++++--- src/core/lib/surface/completion_queue.h | 1 - 2 files changed, 149 insertions(+), 19 deletions(-) diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index 35e9f7eb308..e17f094837e 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -60,13 +60,145 @@ typedef struct { void *tag; } plucker; +typedef struct { + size_t (*size)(void); + void (*init)(grpc_pollset *pollset, gpr_mu **mu); + grpc_error *(*kick)(grpc_pollset *pollset, + grpc_pollset_worker *specific_worker); + grpc_error *(*work)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, + grpc_pollset_worker **worker, gpr_timespec now, + gpr_timespec deadline); + void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, + grpc_closure *closure); + void (*destroy)(grpc_pollset *pollset); +} cq_poller_vtable; + +typedef struct non_polling_worker { + gpr_cv cv; + bool kicked; + struct non_polling_worker *next; + struct non_polling_worker *prev; +} non_polling_worker; + +typedef struct { + gpr_mu mu; + non_polling_worker *root; + grpc_closure *shutdown; +} non_polling_poller; + +static size_t non_polling_poller_size(void) { + return sizeof(non_polling_poller); +} + +static void non_polling_poller_init(grpc_pollset *pollset, gpr_mu **mu) { + non_polling_poller *npp = (non_polling_poller *)pollset; + gpr_mu_init(&npp->mu); + *mu = &npp->mu; +} + +static void non_polling_poller_destroy(grpc_pollset *pollset) { + non_polling_poller *npp = (non_polling_poller *)pollset; + gpr_mu_destroy(&npp->mu); +} + +static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, + grpc_pollset *pollset, + grpc_pollset_worker **worker, + gpr_timespec now, + gpr_timespec deadline) { + non_polling_poller *npp = (non_polling_poller *)pollset; + non_polling_worker w; + gpr_cv_init(&w.cv); + *worker = (grpc_pollset_worker *)&w; + if (npp->root == NULL) { + npp->root = w.next = w.prev = &w; + } else { + w.next = npp->root; + w.prev = w.next->prev; + w.next->prev = w.prev->next = &w; + } + w.kicked = false; + while (!npp->shutdown && !w.kicked && !gpr_cv_wait(&w.cv, &npp->mu, deadline)) + ; + if (&w == npp->root) { + npp->root = w.next; + if (&w == npp->root) { + if (npp->shutdown) { + grpc_closure_sched(exec_ctx, npp->shutdown, GRPC_ERROR_NONE); + } + npp->root = NULL; + } + w.next->prev = w.prev; + w.prev->next = w.next; + } + gpr_cv_destroy(&w.cv); + *worker = NULL; + return GRPC_ERROR_NONE; +} + +static grpc_error *non_polling_poller_kick( + grpc_pollset *pollset, grpc_pollset_worker *specific_worker) { + non_polling_poller *p = (non_polling_poller *)pollset; + if (specific_worker == NULL) specific_worker = (grpc_pollset_worker *)p->root; + if (specific_worker != NULL) { + non_polling_worker *w = (non_polling_worker *)specific_worker; + if (!w->kicked) { + w->kicked = true; + gpr_cv_signal(&w->cv); + } + } + return GRPC_ERROR_NONE; +} + +static void non_polling_poller_shutdown(grpc_exec_ctx *exec_ctx, + grpc_pollset *pollset, + grpc_closure *closure) { + non_polling_poller *p = (non_polling_poller *)pollset; + GPR_ASSERT(closure != NULL); + p->shutdown = closure; + if (p->root == NULL) { + grpc_closure_sched(exec_ctx, closure, GRPC_ERROR_NONE); + } else { + non_polling_worker *w = p->root; + do { + gpr_cv_signal(&w->cv); + w = w->next; + } while (w != p->root); + } +} + +static const cq_poller_vtable g_poller_vtable_by_poller_type[] = { + /* GRPC_CQ_DEFAULT_POLLING */ + {.size = grpc_pollset_size, + .init = grpc_pollset_init, + .kick = grpc_pollset_kick, + .work = grpc_pollset_work, + .shutdown = grpc_pollset_shutdown, + .destroy = grpc_pollset_destroy}, + /* GRPC_CQ_NON_LISTENING */ + {.size = grpc_pollset_size, + .init = grpc_pollset_init, + .kick = grpc_pollset_kick, + .work = grpc_pollset_work, + .shutdown = grpc_pollset_shutdown, + .destroy = grpc_pollset_destroy}, + /* GRPC_CQ_NON_POLLING */ + {.size = non_polling_poller_size, + .init = non_polling_poller_init, + .kick = non_polling_poller_kick, + .work = non_polling_poller_work, + .shutdown = non_polling_poller_shutdown, + .destroy = non_polling_poller_destroy}, +}; + /* Completion queue structure */ struct grpc_completion_queue { /** owned by pollset */ gpr_mu *mu; grpc_cq_completion_type completion_type; - grpc_cq_polling_type polling_type; + + const cq_poller_vtable *poller_vtable; /** completed events */ grpc_cq_completion completed_head; @@ -127,15 +259,18 @@ grpc_completion_queue *grpc_completion_queue_create_internal( "polling_type=%d)", 2, (completion_type, polling_type)); - cc = gpr_zalloc(sizeof(grpc_completion_queue) + grpc_pollset_size()); - grpc_pollset_init(POLLSET_FROM_CQ(cc), &cc->mu); + const cq_poller_vtable *poller_vtable = + &g_poller_vtable_by_poller_type[polling_type]; + + cc = gpr_zalloc(sizeof(grpc_completion_queue) + poller_vtable->size()); + poller_vtable->init(POLLSET_FROM_CQ(cc), &cc->mu); #ifndef NDEBUG cc->outstanding_tags = NULL; cc->outstanding_tag_capacity = 0; #endif cc->completion_type = completion_type; - cc->polling_type = polling_type; + cc->poller_vtable = poller_vtable; /* Initial ref is dropped by grpc_completion_queue_shutdown */ gpr_ref_init(&cc->pending_events, 1); @@ -164,10 +299,6 @@ grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cc) { return cc->completion_type; } -grpc_cq_polling_type grpc_get_cq_polling_type(grpc_completion_queue *cc) { - return cc->polling_type; -} - #ifdef GRPC_CQ_REF_COUNT_DEBUG void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason, const char *file, int line) { @@ -195,7 +326,7 @@ void grpc_cq_internal_unref(grpc_completion_queue *cc) { #endif if (gpr_unref(&cc->owning_refs)) { GPR_ASSERT(cc->completed_head.next == (uintptr_t)&cc->completed_head); - grpc_pollset_destroy(POLLSET_FROM_CQ(cc)); + cc->poller_vtable->destroy(POLLSET_FROM_CQ(cc)); #ifndef NDEBUG gpr_free(cc->outstanding_tags); #endif @@ -280,7 +411,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, } } grpc_error *kick_error = - grpc_pollset_kick(POLLSET_FROM_CQ(cc), pluck_worker); + cc->poller_vtable->kick(POLLSET_FROM_CQ(cc), pluck_worker); gpr_mu_unlock(cc->mu); if (kick_error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(kick_error); @@ -295,8 +426,8 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, GPR_ASSERT(!cc->shutdown); GPR_ASSERT(cc->shutdown_called); cc->shutdown = 1; - grpc_pollset_shutdown(exec_ctx, POLLSET_FROM_CQ(cc), - &cc->pollset_shutdown_done); + cc->poller_vtable->shutdown(exec_ctx, POLLSET_FROM_CQ(cc), + &cc->pollset_shutdown_done); gpr_mu_unlock(cc->mu); } @@ -452,8 +583,8 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, gpr_mu_lock(cc->mu); continue; } else { - grpc_error *err = grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), NULL, - now, iteration_deadline); + grpc_error *err = cc->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cc), + NULL, now, iteration_deadline); if (err != GRPC_ERROR_NONE) { gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); @@ -644,8 +775,8 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(cc->mu); } else { - grpc_error *err = grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), - &worker, now, iteration_deadline); + grpc_error *err = cc->poller_vtable->work( + &exec_ctx, POLLSET_FROM_CQ(cc), &worker, now, iteration_deadline); if (err != GRPC_ERROR_NONE) { del_plucker(cc, tag, &worker); gpr_mu_unlock(cc->mu); @@ -689,8 +820,8 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cc) { if (gpr_unref(&cc->pending_events)) { GPR_ASSERT(!cc->shutdown); cc->shutdown = 1; - grpc_pollset_shutdown(&exec_ctx, POLLSET_FROM_CQ(cc), - &cc->pollset_shutdown_done); + cc->poller_vtable->shutdown(&exec_ctx, POLLSET_FROM_CQ(cc), + &cc->pollset_shutdown_done); } gpr_mu_unlock(cc->mu); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 1ff3d64293a..0995a56889b 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -100,7 +100,6 @@ void grpc_cq_mark_server_cq(grpc_completion_queue *cc); int grpc_cq_is_server_cq(grpc_completion_queue *cc); grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cc); -grpc_cq_polling_type grpc_get_cq_polling_type(grpc_completion_queue *cc); grpc_completion_queue *grpc_completion_queue_create_internal( grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type); From 334c4678a326284c17254e91a4498728a9c67f69 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 16:26:07 -0700 Subject: [PATCH 06/48] Start building out C++ interface --- .../grpc++/impl/codegen/completion_queue.h | 12 ++++++--- include/grpc/grpc.h | 26 ------------------- include/grpc/impl/codegen/grpc_types.h | 26 +++++++++++++++++++ src/cpp/server/server_builder.cc | 8 ++++-- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/include/grpc++/impl/codegen/completion_queue.h b/include/grpc++/impl/codegen/completion_queue.h index 61617f2bdc9..906a64693e1 100644 --- a/include/grpc++/impl/codegen/completion_queue.h +++ b/include/grpc++/impl/codegen/completion_queue.h @@ -289,17 +289,21 @@ class CompletionQueue : private GrpcLibraryCodegen { /// by servers. Instantiated by \a ServerBuilder. class ServerCompletionQueue : public CompletionQueue { public: - bool IsFrequentlyPolled() { return is_frequently_polled_; } + bool IsFrequentlyPolled() { return polling_type_ != GRPC_CQ_NON_LISTENING; } private: - bool is_frequently_polled_; + grpc_cq_polling_type polling_type_; friend class ServerBuilder; /// \param is_frequently_polled Informs the GRPC library about whether the /// server completion queue would be actively polled (by calling Next() or /// AsyncNext()). By default all server completion queues are assumed to be /// frequently polled. - ServerCompletionQueue(bool is_frequently_polled = true) - : is_frequently_polled_(is_frequently_polled) {} + ServerCompletionQueue(grpc_cq_polling_type polling_type) + : CompletionQueue(MakeCompletionQueue(polling_type)), + polling_type_(polling_type) {} + + static grpc_completion_queue* MakeCompletionQueue( + grpc_cq_polling_type polling_type); }; } // namespace grpc diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 42cf201da44..f3201edad29 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -102,32 +102,6 @@ typedef enum { GRPC_CQ_PLUCK } grpc_cq_completion_type; -/** Completion queues internally MAY maintain a set of file descriptors in a - structure called 'pollset'. This enum specifies if a completion queue has an - associated pollset and any restrictions on the type of file descriptors that - can be present in the pollset. - - I/O progress can only be made when grpc_completion_queue_next() or - grpc_completion_queue_pluck() are called on the completion queue (unless the - grpc_cq_polling_type is GRPC_CQ_NON_POLLING) and hence it is very important - to actively call these APIs */ -typedef enum { - /** The completion queue will have an associated pollset and there is no - restriction on the type of file descriptors the pollset may contain */ - GRPC_CQ_DEFAULT_POLLING, - - /** Similar to GRPC_CQ_DEFAULT_POLLING except that the completion queues will - not contain any 'listening file descriptors' (i.e file descriptors used to - listen to incoming channels) */ - GRPC_CQ_NON_LISTENING, - - /** The completion queue will not have an associated pollset. Note that - grpc_completion_queue_next() or grpc_completion_queue_pluck() MUST still - be called to pop events from the completion queue; it is not required to - call them actively to make I/O progress */ - GRPC_CQ_NON_POLLING -} grpc_cq_polling_type; - #define GRPC_CQ_CURRENT_VERSION 1 typedef struct grpc_completion_queue_attributes { /* The version number of this structure. More fields might be added to this diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 4383691a837..02732205f5f 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -543,6 +543,32 @@ typedef struct { typedef struct grpc_resource_quota grpc_resource_quota; +/** Completion queues internally MAY maintain a set of file descriptors in a + structure called 'pollset'. This enum specifies if a completion queue has an + associated pollset and any restrictions on the type of file descriptors that + can be present in the pollset. + + I/O progress can only be made when grpc_completion_queue_next() or + grpc_completion_queue_pluck() are called on the completion queue (unless the + grpc_cq_polling_type is GRPC_CQ_NON_POLLING) and hence it is very important + to actively call these APIs */ +typedef enum { + /** The completion queue will have an associated pollset and there is no + restriction on the type of file descriptors the pollset may contain */ + GRPC_CQ_DEFAULT_POLLING, + + /** Similar to GRPC_CQ_DEFAULT_POLLING except that the completion queues will + not contain any 'listening file descriptors' (i.e file descriptors used to + listen to incoming channels) */ + GRPC_CQ_NON_LISTENING, + + /** The completion queue will not have an associated pollset. Note that + grpc_completion_queue_next() or grpc_completion_queue_pluck() MUST still + be called to pop events from the completion queue; it is not required to + call them actively to make I/O progress */ + GRPC_CQ_NON_POLLING +} grpc_cq_polling_type; + #ifdef __cplusplus } #endif diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 4eb4b5a1b21..c6784ea1593 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -83,7 +83,8 @@ ServerBuilder::~ServerBuilder() { std::unique_ptr ServerBuilder::AddCompletionQueue( bool is_frequently_polled) { - ServerCompletionQueue* cq = new ServerCompletionQueue(is_frequently_polled); + ServerCompletionQueue* cq = new ServerCompletionQueue( + is_frequently_polled ? GRPC_CQ_DEFAULT_POLLING : GRPC_CQ_NON_LISTENING); cqs_.push_back(cq); return std::unique_ptr(cq); } @@ -251,9 +252,12 @@ std::unique_ptr ServerBuilder::BuildAndStart() { sync_server_settings_.max_pollers, sync_server_settings_.cq_timeout_msec); + grpc_cq_polling_type polling_type = + cqs_.empty() ? GRPC_CQ_DEFAULT_POLLING : GRPC_CQ_NON_POLLING; + // Create completion queues to listen to incoming rpc requests for (int i = 0; i < sync_server_settings_.num_cqs; i++) { - sync_server_cqs->emplace_back(new ServerCompletionQueue()); + sync_server_cqs->emplace_back(new ServerCompletionQueue(polling_type)); } } From 75bfb9754827ef63ede77e27ad901e3355536419 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 17:55:12 -0700 Subject: [PATCH 07/48] Finish hybrid server stuff, ensure it gets tested --- .../grpc++/impl/codegen/client_unary_call.h | 4 ++- .../grpc++/impl/codegen/completion_queue.h | 32 +++++++++---------- include/grpc++/impl/codegen/core_codegen.h | 9 +++++- .../impl/codegen/core_codegen_interface.h | 6 ++++ include/grpc++/impl/codegen/sync_stream.h | 12 +++++-- include/grpc/grpc.h | 23 ------------- include/grpc/impl/codegen/grpc_types.h | 23 +++++++++++++ src/core/lib/surface/completion_queue.c | 21 +++++++----- src/core/lib/surface/server.c | 7 ++-- src/cpp/common/core_codegen.cc | 12 +++++++ src/cpp/server/server_builder.cc | 26 +++++++++++---- test/cpp/end2end/async_end2end_test.cc | 28 ++++++++++++---- 12 files changed, 134 insertions(+), 69 deletions(-) diff --git a/include/grpc++/impl/codegen/client_unary_call.h b/include/grpc++/impl/codegen/client_unary_call.h index a5a4f3d7398..4bf35ae7785 100644 --- a/include/grpc++/impl/codegen/client_unary_call.h +++ b/include/grpc++/impl/codegen/client_unary_call.h @@ -52,7 +52,9 @@ template Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, const InputMessage& request, OutputMessage* result) { - CompletionQueue cq(true); // Pluckable completion queue + CompletionQueue cq(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, + GRPC_CQ_DEFAULT_POLLING}); // Pluckable completion queue Call call(channel->CreateCall(method, context, &cq)); CallOpSet, diff --git a/include/grpc++/impl/codegen/completion_queue.h b/include/grpc++/impl/codegen/completion_queue.h index 906a64693e1..c8ab726b0f4 100644 --- a/include/grpc++/impl/codegen/completion_queue.h +++ b/include/grpc++/impl/codegen/completion_queue.h @@ -102,7 +102,9 @@ class CompletionQueue : private GrpcLibraryCodegen { public: /// Default constructor. Implicitly creates a \a grpc_completion_queue /// instance. - CompletionQueue() : CompletionQueue(false) {} + CompletionQueue() + : CompletionQueue(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING}) {} /// Wrap \a take, taking ownership of the instance. /// @@ -182,6 +184,16 @@ class CompletionQueue : private GrpcLibraryCodegen { }; void CompleteAvalanching(); + protected: + /// Private constructor of CompletionQueue only visible to friend classes + CompletionQueue(const grpc_completion_queue_attributes& attributes) { + cq_ = g_core_codegen_interface->grpc_completion_queue_create( + g_core_codegen_interface->grpc_completion_queue_factory_lookup( + &attributes), + &attributes, NULL); + InitialAvalanching(); // reserve this for the future shutdown + } + private: // Friend synchronous wrappers so that they can access Pluck(), which is // a semi-private API geared towards the synchronous implementation. @@ -215,18 +227,6 @@ class CompletionQueue : private GrpcLibraryCodegen { const InputMessage& request, OutputMessage* result); - /// Private constructor of CompletionQueue only visible to friend classes - CompletionQueue(bool is_pluck) { - if (is_pluck) { - cq_ = g_core_codegen_interface->grpc_completion_queue_create_for_pluck( - nullptr); - } else { - cq_ = g_core_codegen_interface->grpc_completion_queue_create_for_next( - nullptr); - } - InitialAvalanching(); // reserve this for the future shutdown - } - NextStatus AsyncNextInternal(void** tag, bool* ok, gpr_timespec deadline); /// Wraps \a grpc_completion_queue_pluck. @@ -299,11 +299,9 @@ class ServerCompletionQueue : public CompletionQueue { /// AsyncNext()). By default all server completion queues are assumed to be /// frequently polled. ServerCompletionQueue(grpc_cq_polling_type polling_type) - : CompletionQueue(MakeCompletionQueue(polling_type)), + : CompletionQueue(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_NEXT, polling_type}), polling_type_(polling_type) {} - - static grpc_completion_queue* MakeCompletionQueue( - grpc_cq_polling_type polling_type); }; } // namespace grpc diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index 65151590b25..3cb7da8ef6c 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -44,8 +44,15 @@ namespace grpc { /// Implementation of the core codegen interface. -class CoreCodegen : public CoreCodegenInterface { +class CoreCodegen final : public CoreCodegenInterface { private: + virtual const grpc_completion_queue_factory* + grpc_completion_queue_factory_lookup( + const grpc_completion_queue_attributes* attributes) override; + virtual grpc_completion_queue* grpc_completion_queue_create( + const grpc_completion_queue_factory* factory, + const grpc_completion_queue_attributes* attributes, + void* reserved) override; grpc_completion_queue* grpc_completion_queue_create_for_next( void* reserved) override; grpc_completion_queue* grpc_completion_queue_create_for_pluck( diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h index 529bef687bb..a1a0aaf3cad 100644 --- a/include/grpc++/impl/codegen/core_codegen_interface.h +++ b/include/grpc++/impl/codegen/core_codegen_interface.h @@ -59,6 +59,12 @@ class CoreCodegenInterface { virtual void assert_fail(const char* failed_assertion, const char* file, int line) = 0; + virtual const grpc_completion_queue_factory* + grpc_completion_queue_factory_lookup( + const grpc_completion_queue_attributes* attributes) = 0; + virtual grpc_completion_queue* grpc_completion_queue_create( + const grpc_completion_queue_factory* factory, + const grpc_completion_queue_attributes* attributes, void* reserved) = 0; virtual grpc_completion_queue* grpc_completion_queue_create_for_next( void* reserved) = 0; virtual grpc_completion_queue* grpc_completion_queue_create_for_pluck( diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h index 328d5cb1e83..a010924cefe 100644 --- a/include/grpc++/impl/codegen/sync_stream.h +++ b/include/grpc++/impl/codegen/sync_stream.h @@ -156,7 +156,9 @@ class ClientReader final : public ClientReaderInterface { ClientReader(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, const W& request) : context_(context), - cq_(true), // Pluckable cq + cq_(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, + GRPC_CQ_DEFAULT_POLLING}), // Pluckable cq call_(channel->CreateCall(method, context, &cq_)) { CallOpSet @@ -230,7 +232,9 @@ class ClientWriter : public ClientWriterInterface { ClientWriter(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, R* response) : context_(context), - cq_(true), // Pluckable cq + cq_(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, + GRPC_CQ_DEFAULT_POLLING}), // Pluckable cq call_(channel->CreateCall(method, context, &cq_)) { finish_ops_.RecvMessage(response); finish_ops_.AllowNoMessage(); @@ -330,7 +334,9 @@ class ClientReaderWriter final : public ClientReaderWriterInterface { ClientReaderWriter(ChannelInterface* channel, const RpcMethod& method, ClientContext* context) : context_(context), - cq_(true), // Pluckable cq + cq_(grpc_completion_queue_attributes{ + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, + GRPC_CQ_DEFAULT_POLLING}), // Pluckable cq call_(channel->CreateCall(method, context, &cq_)) { if (!context_->initial_metadata_corked_) { CallOpSet ops; diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index f3201edad29..1a7d0120bfa 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -93,29 +93,6 @@ GRPCAPI const char *grpc_version_string(void); /** Return a string specifying what the 'g' in gRPC stands for */ GRPCAPI const char *grpc_g_stands_for(void); -/** Specifies the type of APIs to use to pop events from the completion queue */ -typedef enum { - /** Events are popped out by calling grpc_completion_queue_next() API ONLY */ - GRPC_CQ_NEXT = 1, - - /** Events are popped out by calling grpc_completion_queue_pluck() API ONLY*/ - GRPC_CQ_PLUCK -} grpc_cq_completion_type; - -#define GRPC_CQ_CURRENT_VERSION 1 -typedef struct grpc_completion_queue_attributes { - /* The version number of this structure. More fields might be added to this - structure in future. */ - int version; /* Set to GRPC_CQ_CURRENT_VERSION */ - - grpc_cq_completion_type cq_completion_type; - - grpc_cq_polling_type cq_polling_type; -} grpc_completion_queue_attributes; - -/** The completion queue factory structure is opaque to the callers of grpc */ -typedef struct grpc_completion_queue_factory grpc_completion_queue_factory; - /** Returns the completion queue factory based on the attributes. MAY return a NULL if no factory can be found */ GRPCAPI const grpc_completion_queue_factory * diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 02732205f5f..a8eda739bf6 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -569,6 +569,29 @@ typedef enum { GRPC_CQ_NON_POLLING } grpc_cq_polling_type; +/** Specifies the type of APIs to use to pop events from the completion queue */ +typedef enum { + /** Events are popped out by calling grpc_completion_queue_next() API ONLY */ + GRPC_CQ_NEXT = 1, + + /** Events are popped out by calling grpc_completion_queue_pluck() API ONLY*/ + GRPC_CQ_PLUCK +} grpc_cq_completion_type; + +#define GRPC_CQ_CURRENT_VERSION 1 +typedef struct grpc_completion_queue_attributes { + /* The version number of this structure. More fields might be added to this + structure in future. */ + int version; /* Set to GRPC_CQ_CURRENT_VERSION */ + + grpc_cq_completion_type cq_completion_type; + + grpc_cq_polling_type cq_polling_type; +} grpc_completion_queue_attributes; + +/** The completion queue factory structure is opaque to the callers of grpc */ +typedef struct grpc_completion_queue_factory grpc_completion_queue_factory; + #ifdef __cplusplus } #endif diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index e17f094837e..ea97a6f374b 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -61,6 +61,7 @@ typedef struct { } plucker; typedef struct { + bool can_get_pollset; size_t (*size)(void); void (*init)(grpc_pollset *pollset, gpr_mu **mu); grpc_error *(*kick)(grpc_pollset *pollset, @@ -107,9 +108,10 @@ static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, gpr_timespec now, gpr_timespec deadline) { non_polling_poller *npp = (non_polling_poller *)pollset; + if (npp->shutdown) return GRPC_ERROR_NONE; non_polling_worker w; gpr_cv_init(&w.cv); - *worker = (grpc_pollset_worker *)&w; + if (worker != NULL) *worker = (grpc_pollset_worker *)&w; if (npp->root == NULL) { npp->root = w.next = w.prev = &w; } else { @@ -128,11 +130,11 @@ static grpc_error *non_polling_poller_work(grpc_exec_ctx *exec_ctx, } npp->root = NULL; } - w.next->prev = w.prev; - w.prev->next = w.next; } + w.next->prev = w.prev; + w.prev->next = w.next; gpr_cv_destroy(&w.cv); - *worker = NULL; + if (worker != NULL) *worker = NULL; return GRPC_ERROR_NONE; } @@ -169,21 +171,24 @@ static void non_polling_poller_shutdown(grpc_exec_ctx *exec_ctx, static const cq_poller_vtable g_poller_vtable_by_poller_type[] = { /* GRPC_CQ_DEFAULT_POLLING */ - {.size = grpc_pollset_size, + {.can_get_pollset = true, + .size = grpc_pollset_size, .init = grpc_pollset_init, .kick = grpc_pollset_kick, .work = grpc_pollset_work, .shutdown = grpc_pollset_shutdown, .destroy = grpc_pollset_destroy}, /* GRPC_CQ_NON_LISTENING */ - {.size = grpc_pollset_size, + {.can_get_pollset = true, + .size = grpc_pollset_size, .init = grpc_pollset_init, .kick = grpc_pollset_kick, .work = grpc_pollset_work, .shutdown = grpc_pollset_shutdown, .destroy = grpc_pollset_destroy}, /* GRPC_CQ_NON_POLLING */ - {.size = non_polling_poller_size, + {.can_get_pollset = false, + .size = non_polling_poller_size, .init = non_polling_poller_init, .kick = non_polling_poller_kick, .work = non_polling_poller_work, @@ -837,7 +842,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue *cc) { } grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) { - return POLLSET_FROM_CQ(cc); + return cc->poller_vtable->can_get_pollset ? POLLSET_FROM_CQ(cc) : NULL; } grpc_completion_queue *grpc_cq_from_pollset(grpc_pollset *ps) { diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 9496f90390d..767c91a5ec5 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -1009,6 +1009,8 @@ void grpc_server_register_completion_queue(grpc_server *server, calls grpc_completion_queue_pluck() on server completion queues */ } + GPR_ASSERT(grpc_cq_pollset(cq)); + register_completion_queue(server, cq, false, reserved); } @@ -1102,8 +1104,9 @@ void grpc_server_start(grpc_server *server) { gpr_malloc(sizeof(*server->requested_calls_per_cq) * server->cq_count); for (i = 0; i < server->cq_count; i++) { if (!grpc_cq_is_non_listening_server_cq(server->cqs[i])) { - server->pollsets[server->pollset_count++] = - grpc_cq_pollset(server->cqs[i]); + grpc_pollset *pollset = grpc_cq_pollset(server->cqs[i]); + GPR_ASSERT(pollset); + server->pollsets[server->pollset_count++] = pollset; } server->request_freelist_per_cq[i] = gpr_stack_lockfree_create((size_t)server->max_requested_calls_per_cq); diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 0dd758ec4e5..8f1de222fb8 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -54,6 +54,18 @@ struct grpc_byte_buffer; namespace grpc { +const grpc_completion_queue_factory* +CoreCodegen::grpc_completion_queue_factory_lookup( + const grpc_completion_queue_attributes* attributes) { + return ::grpc_completion_queue_factory_lookup(attributes); +} + +grpc_completion_queue* CoreCodegen::grpc_completion_queue_create( + const grpc_completion_queue_factory* factory, + const grpc_completion_queue_attributes* attributes, void* reserved) { + return ::grpc_completion_queue_create(factory, attributes, reserved); +} + grpc_completion_queue* CoreCodegen::grpc_completion_queue_create_for_next( void* reserved) { return ::grpc_completion_queue_create_for_next(reserved); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index c6784ea1593..6687fe78b92 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -243,6 +243,16 @@ std::unique_ptr ServerBuilder::BuildAndStart() { sync_server_cqs(std::make_shared< std::vector>>()); + int num_frequently_polled_cqs = 0; + for (auto it = cqs_.begin(); it != cqs_.end(); ++it) { + if ((*it)->IsFrequentlyPolled()) { + num_frequently_polled_cqs++; + } + } + + const bool is_hybrid_server = + has_sync_methods && num_frequently_polled_cqs > 0; + if (has_sync_methods) { // This is a Sync server gpr_log(GPR_INFO, @@ -253,7 +263,7 @@ std::unique_ptr ServerBuilder::BuildAndStart() { sync_server_settings_.cq_timeout_msec); grpc_cq_polling_type polling_type = - cqs_.empty() ? GRPC_CQ_DEFAULT_POLLING : GRPC_CQ_NON_POLLING; + is_hybrid_server ? GRPC_CQ_NON_POLLING : GRPC_CQ_DEFAULT_POLLING; // Create completion queues to listen to incoming rpc requests for (int i = 0; i < sync_server_settings_.num_cqs; i++) { @@ -273,12 +283,15 @@ std::unique_ptr ServerBuilder::BuildAndStart() { // server // 2. cqs_: Completion queues added via AddCompletionQueue() call - // All sync cqs (if any) are frequently polled by ThreadManager - int num_frequently_polled_cqs = sync_server_cqs->size(); - for (auto it = sync_server_cqs->begin(); it != sync_server_cqs->end(); ++it) { - grpc_server_register_completion_queue(server->server_, (*it)->cq(), - nullptr); + if (is_hybrid_server) { + grpc_server_register_non_listening_completion_queue(server->server_, + (*it)->cq(), nullptr); + } else { + grpc_server_register_completion_queue(server->server_, (*it)->cq(), + nullptr); + } + num_frequently_polled_cqs++; } // cqs_ contains the completion queue added by calling the ServerBuilder's @@ -290,7 +303,6 @@ std::unique_ptr ServerBuilder::BuildAndStart() { if ((*it)->IsFrequentlyPolled()) { grpc_server_register_completion_queue(server->server_, (*it)->cq(), nullptr); - num_frequently_polled_cqs++; } else { grpc_server_register_non_listening_completion_queue(server->server_, (*it)->cq(), nullptr); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 0b5215ef8e4..cc3958bf13c 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ #include #include "src/core/lib/iomgr/port.h" +#include "src/proto/grpc/health/v1/health.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -224,13 +226,15 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption { class TestScenario { public: - TestScenario(bool non_block, const grpc::string& creds_type, + TestScenario(bool non_block, const grpc::string& creds_type, bool hcs, const grpc::string& content) : disable_blocking(non_block), + health_check_service(hcs), credentials_type(creds_type), message_content(content) {} void Log() const; bool disable_blocking; + bool health_check_service; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) // manage vector insertion using a copy constructor @@ -243,6 +247,8 @@ static std::ostream& operator<<(std::ostream& out, return out << "TestScenario{disable_blocking=" << (scenario.disable_blocking ? "true" : "false") << ", credentials='" << scenario.credentials_type + << ", health_check_service=" + << (scenario.health_check_service ? "true" : "false") << "', message_size=" << scenario.message_content.size() << "}"; } @@ -252,6 +258,8 @@ void TestScenario::Log() const { gpr_log(GPR_DEBUG, "%s", out.str().c_str()); } +class HealthCheck : public health::v1::Health::Service {}; + class AsyncEnd2endTest : public ::testing::TestWithParam { protected: AsyncEnd2endTest() { GetParam().Log(); } @@ -268,6 +276,9 @@ class AsyncEnd2endTest : public ::testing::TestWithParam { GetParam().credentials_type); builder.AddListeningPort(server_address_.str(), server_creds); builder.RegisterService(&service_); + if (GetParam().health_check_service) { + builder.RegisterService(&health_check_); + } cq_ = builder.AddCompletionQueue(); // TODO(zyc): make a test option to choose wheather sync plugins should be @@ -340,6 +351,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam { std::unique_ptr stub_; std::unique_ptr server_; grpc::testing::EchoTestService::AsyncService service_; + HealthCheck health_check_; std::ostringstream server_address_; int port_; @@ -1754,12 +1766,14 @@ std::vector CreateTestScenarios(bool test_disable_blocking, messages.push_back(big_msg); } - for (auto cred = credentials_types.begin(); cred != credentials_types.end(); - ++cred) { - for (auto msg = messages.begin(); msg != messages.end(); msg++) { - scenarios.emplace_back(false, *cred, *msg); - if (test_disable_blocking) { - scenarios.emplace_back(true, *cred, *msg); + for (auto health_check_service : {false, true}) { + for (auto cred = credentials_types.begin(); cred != credentials_types.end(); + ++cred) { + for (auto msg = messages.begin(); msg != messages.end(); msg++) { + scenarios.emplace_back(false, *cred, health_check_service, *msg); + if (test_disable_blocking) { + scenarios.emplace_back(true, *cred, health_check_service, *msg); + } } } } From 58aa706aaf1c39e092f246202b18e6a2931dc664 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 12 Apr 2017 08:10:58 -0700 Subject: [PATCH 08/48] Fix registration --- src/core/lib/surface/server.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 767c91a5ec5..1680085f67b 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -1009,8 +1009,6 @@ void grpc_server_register_completion_queue(grpc_server *server, calls grpc_completion_queue_pluck() on server completion queues */ } - GPR_ASSERT(grpc_cq_pollset(cq)); - register_completion_queue(server, cq, false, reserved); } @@ -1105,8 +1103,7 @@ void grpc_server_start(grpc_server *server) { for (i = 0; i < server->cq_count; i++) { if (!grpc_cq_is_non_listening_server_cq(server->cqs[i])) { grpc_pollset *pollset = grpc_cq_pollset(server->cqs[i]); - GPR_ASSERT(pollset); - server->pollsets[server->pollset_count++] = pollset; + if (pollset != NULL) server->pollsets[server->pollset_count++] = pollset; } server->request_freelist_per_cq[i] = gpr_stack_lockfree_create((size_t)server->max_requested_calls_per_cq); From 11c5832b3e8be35f16465d8ef38a1d0ba033a822 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 12 Apr 2017 08:21:17 -0700 Subject: [PATCH 09/48] Get rid of second api for marking non-listening cqs --- include/grpc/grpc.h | 9 --------- src/core/lib/surface/completion_queue.c | 12 +++++++++++- src/core/lib/surface/completion_queue.h | 5 ++--- src/core/lib/surface/server.c | 23 +++++------------------ src/cpp/server/server_builder.cc | 18 ++++-------------- 5 files changed, 22 insertions(+), 45 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 1a7d0120bfa..7b37f34acc4 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -376,15 +376,6 @@ GRPCAPI void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved); -/** Register a non-listening completion queue with the server. This API is - similar to grpc_server_register_completion_queue except that the server will - not use this completion_queue to listen to any incoming channels. - - Registering a non-listening completion queue will have negative performance - impact and hence this API is not recommended for production use cases. */ -GRPCAPI void grpc_server_register_non_listening_completion_queue( - grpc_server *server, grpc_completion_queue *q, void *reserved); - /** Add a HTTP2 over plaintext over tcp listener. Returns bound port number on success, 0 on failure. REQUIRES: server not started */ diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index ea97a6f374b..eae3f103b12 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -62,6 +62,7 @@ typedef struct { typedef struct { bool can_get_pollset; + bool can_listen; size_t (*size)(void); void (*init)(grpc_pollset *pollset, gpr_mu **mu); grpc_error *(*kick)(grpc_pollset *pollset, @@ -172,6 +173,7 @@ static void non_polling_poller_shutdown(grpc_exec_ctx *exec_ctx, static const cq_poller_vtable g_poller_vtable_by_poller_type[] = { /* GRPC_CQ_DEFAULT_POLLING */ {.can_get_pollset = true, + .can_listen = true, .size = grpc_pollset_size, .init = grpc_pollset_init, .kick = grpc_pollset_kick, @@ -180,6 +182,7 @@ static const cq_poller_vtable g_poller_vtable_by_poller_type[] = { .destroy = grpc_pollset_destroy}, /* GRPC_CQ_NON_LISTENING */ {.can_get_pollset = true, + .can_listen = false, .size = grpc_pollset_size, .init = grpc_pollset_init, .kick = grpc_pollset_kick, @@ -188,6 +191,7 @@ static const cq_poller_vtable g_poller_vtable_by_poller_type[] = { .destroy = grpc_pollset_destroy}, /* GRPC_CQ_NON_POLLING */ {.can_get_pollset = false, + .can_listen = false, .size = non_polling_poller_size, .init = non_polling_poller_init, .kick = non_polling_poller_kick, @@ -863,4 +867,10 @@ bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc) { void grpc_cq_mark_server_cq(grpc_completion_queue *cc) { cc->is_server_cq = 1; } -int grpc_cq_is_server_cq(grpc_completion_queue *cc) { return cc->is_server_cq; } +bool grpc_cq_is_server_cq(grpc_completion_queue *cc) { + return cc->is_server_cq; +} + +bool grpc_cq_can_listen(grpc_completion_queue *cc) { + return cc->poller_vtable->can_listen; +} diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 0995a56889b..a932087939d 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -94,10 +94,9 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc); grpc_completion_queue *grpc_cq_from_pollset(grpc_pollset *ps); -void grpc_cq_mark_non_listening_server_cq(grpc_completion_queue *cc); -bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc); void grpc_cq_mark_server_cq(grpc_completion_queue *cc); -int grpc_cq_is_server_cq(grpc_completion_queue *cc); +bool grpc_cq_is_server_cq(grpc_completion_queue *cc); +bool grpc_cq_can_listen(grpc_completion_queue *cc); grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cc); diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 1680085f67b..da8b6339b2b 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -974,7 +974,7 @@ const grpc_channel_filter grpc_server_top_filter = { static void register_completion_queue(grpc_server *server, grpc_completion_queue *cq, - bool is_non_listening, void *reserved) { + void *reserved) { size_t i, n; GPR_ASSERT(!reserved); for (i = 0; i < server->cq_count; i++) { @@ -983,10 +983,6 @@ static void register_completion_queue(grpc_server *server, grpc_cq_mark_server_cq(cq); - if (is_non_listening) { - grpc_cq_mark_non_listening_server_cq(cq); - } - GRPC_CQ_INTERNAL_REF(cq, "server"); n = server->cq_count++; server->cqs = gpr_realloc(server->cqs, @@ -1009,16 +1005,7 @@ void grpc_server_register_completion_queue(grpc_server *server, calls grpc_completion_queue_pluck() on server completion queues */ } - register_completion_queue(server, cq, false, reserved); -} - -void grpc_server_register_non_listening_completion_queue( - grpc_server *server, grpc_completion_queue *cq, void *reserved) { - GRPC_API_TRACE( - "grpc_server_register_non_listening_completion_queue(server=%p, cq=%p, " - "reserved=%p)", - 3, (server, cq, reserved)); - register_completion_queue(server, cq, true, reserved); + register_completion_queue(server, cq, reserved); } grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) { @@ -1101,9 +1088,9 @@ void grpc_server_start(grpc_server *server) { server->requested_calls_per_cq = gpr_malloc(sizeof(*server->requested_calls_per_cq) * server->cq_count); for (i = 0; i < server->cq_count; i++) { - if (!grpc_cq_is_non_listening_server_cq(server->cqs[i])) { - grpc_pollset *pollset = grpc_cq_pollset(server->cqs[i]); - if (pollset != NULL) server->pollsets[server->pollset_count++] = pollset; + if (grpc_cq_can_listen(server->cqs[i])) { + server->pollsets[server->pollset_count++] = + grpc_cq_pollset(server->cqs[i]); } server->request_freelist_per_cq[i] = gpr_stack_lockfree_create((size_t)server->max_requested_calls_per_cq); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 6687fe78b92..a92cec643ce 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -284,13 +284,8 @@ std::unique_ptr ServerBuilder::BuildAndStart() { // 2. cqs_: Completion queues added via AddCompletionQueue() call for (auto it = sync_server_cqs->begin(); it != sync_server_cqs->end(); ++it) { - if (is_hybrid_server) { - grpc_server_register_non_listening_completion_queue(server->server_, - (*it)->cq(), nullptr); - } else { - grpc_server_register_completion_queue(server->server_, (*it)->cq(), - nullptr); - } + grpc_server_register_completion_queue(server->server_, (*it)->cq(), + nullptr); num_frequently_polled_cqs++; } @@ -300,13 +295,8 @@ std::unique_ptr ServerBuilder::BuildAndStart() { // listening to incoming channels. Such completion queues must be registered // as non-listening queues for (auto it = cqs_.begin(); it != cqs_.end(); ++it) { - if ((*it)->IsFrequentlyPolled()) { - grpc_server_register_completion_queue(server->server_, (*it)->cq(), - nullptr); - } else { - grpc_server_register_non_listening_completion_queue(server->server_, - (*it)->cq(), nullptr); - } + grpc_server_register_completion_queue(server->server_, (*it)->cq(), + nullptr); } if (num_frequently_polled_cqs == 0) { From b3612d3cd409c421065e9faf53dae507f5fc6d7b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 12 Apr 2017 14:02:13 -0700 Subject: [PATCH 10/48] Remove API --- grpc.def | 1 - include/grpc/grpc.h | 9 --------- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 2 -- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 3 --- 4 files changed, 15 deletions(-) diff --git a/grpc.def b/grpc.def index 1589316a588..da42d736980 100644 --- a/grpc.def +++ b/grpc.def @@ -88,7 +88,6 @@ EXPORTS grpc_server_request_registered_call grpc_server_create grpc_server_register_completion_queue - grpc_server_register_non_listening_completion_queue grpc_server_add_insecure_http2_port grpc_server_start grpc_server_shutdown_and_notify diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index f3201edad29..4da43706655 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -399,15 +399,6 @@ GRPCAPI void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved); -/** Register a non-listening completion queue with the server. This API is - similar to grpc_server_register_completion_queue except that the server will - not use this completion_queue to listen to any incoming channels. - - Registering a non-listening completion queue will have negative performance - impact and hence this API is not recommended for production use cases. */ -GRPCAPI void grpc_server_register_non_listening_completion_queue( - grpc_server *server, grpc_completion_queue *q, void *reserved); - /** Add a HTTP2 over plaintext over tcp listener. Returns bound port number on success, 0 on failure. REQUIRES: server not started */ diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 063f92114c0..fd4fb9ea4d3 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -126,7 +126,6 @@ grpc_server_register_method_type grpc_server_register_method_import; grpc_server_request_registered_call_type grpc_server_request_registered_call_import; grpc_server_create_type grpc_server_create_import; grpc_server_register_completion_queue_type grpc_server_register_completion_queue_import; -grpc_server_register_non_listening_completion_queue_type grpc_server_register_non_listening_completion_queue_import; grpc_server_add_insecure_http2_port_type grpc_server_add_insecure_http2_port_import; grpc_server_start_type grpc_server_start_import; grpc_server_shutdown_and_notify_type grpc_server_shutdown_and_notify_import; @@ -423,7 +422,6 @@ void grpc_rb_load_imports(HMODULE library) { grpc_server_request_registered_call_import = (grpc_server_request_registered_call_type) GetProcAddress(library, "grpc_server_request_registered_call"); grpc_server_create_import = (grpc_server_create_type) GetProcAddress(library, "grpc_server_create"); grpc_server_register_completion_queue_import = (grpc_server_register_completion_queue_type) GetProcAddress(library, "grpc_server_register_completion_queue"); - grpc_server_register_non_listening_completion_queue_import = (grpc_server_register_non_listening_completion_queue_type) GetProcAddress(library, "grpc_server_register_non_listening_completion_queue"); grpc_server_add_insecure_http2_port_import = (grpc_server_add_insecure_http2_port_type) GetProcAddress(library, "grpc_server_add_insecure_http2_port"); grpc_server_start_import = (grpc_server_start_type) GetProcAddress(library, "grpc_server_start"); grpc_server_shutdown_and_notify_import = (grpc_server_shutdown_and_notify_type) GetProcAddress(library, "grpc_server_shutdown_and_notify"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index e036ff7bd63..7289ae3a352 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -329,9 +329,6 @@ extern grpc_server_create_type grpc_server_create_import; typedef void(*grpc_server_register_completion_queue_type)(grpc_server *server, grpc_completion_queue *cq, void *reserved); extern grpc_server_register_completion_queue_type grpc_server_register_completion_queue_import; #define grpc_server_register_completion_queue grpc_server_register_completion_queue_import -typedef void(*grpc_server_register_non_listening_completion_queue_type)(grpc_server *server, grpc_completion_queue *q, void *reserved); -extern grpc_server_register_non_listening_completion_queue_type grpc_server_register_non_listening_completion_queue_import; -#define grpc_server_register_non_listening_completion_queue grpc_server_register_non_listening_completion_queue_import typedef int(*grpc_server_add_insecure_http2_port_type)(grpc_server *server, const char *addr); extern grpc_server_add_insecure_http2_port_type grpc_server_add_insecure_http2_port_import; #define grpc_server_add_insecure_http2_port grpc_server_add_insecure_http2_port_import From cd3ae4f33b6d657b211d3cc186120dd3a297d212 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 12 Apr 2017 14:19:23 -0700 Subject: [PATCH 11/48] Remove API --- src/node/ext/server_generic.cc | 8 +++++--- src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi | 3 --- src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi | 11 +---------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/node/ext/server_generic.cc b/src/node/ext/server_generic.cc index 24573bd52f5..a25b2f1ca74 100644 --- a/src/node/ext/server_generic.cc +++ b/src/node/ext/server_generic.cc @@ -44,9 +44,11 @@ namespace grpc { namespace node { Server::Server(grpc_server *server) : wrapped_server(server) { - shutdown_queue = grpc_completion_queue_create_for_pluck(NULL); - grpc_server_register_non_listening_completion_queue(server, shutdown_queue, - NULL); + grpc_completion_queue_attributes attrs = { + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_NON_LISTENING}; + shutdown_queue = grpc_completion_queue_create( + grpc_completion_queue_factory_lookup(&attrs), &attrs, NULL); + grpc_server_completion_queue(server, shutdown_queue, NULL); } Server::~Server() { diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 0b2bdef48be..74e4bc6a69c 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -356,8 +356,6 @@ cdef extern from "grpc/grpc.h": void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved) nogil - void grpc_server_register_non_listening_completion_queue( - grpc_server *server, grpc_completion_queue *cq, void *reserved) nogil int grpc_server_add_insecure_http2_port( grpc_server *server, const char *addr) nogil void grpc_server_start(grpc_server *server) nogil @@ -502,4 +500,3 @@ cdef extern from "grpc/compression.h": int grpc_compression_options_is_algorithm_enabled( const grpc_compression_options *opts, grpc_compression_algorithm algorithm) nogil - diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index 18db38b6861..97192efda74 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -82,20 +82,11 @@ cdef class Server: self.c_server, queue.c_completion_queue, NULL) self.registered_completion_queues.append(queue) - def register_non_listening_completion_queue( - self, CompletionQueue queue not None): - if self.is_started: - raise ValueError("cannot register completion queues after start") - with nogil: - grpc_server_register_non_listening_completion_queue( - self.c_server, queue.c_completion_queue, NULL) - self.registered_completion_queues.append(queue) - def start(self): if self.is_started: raise ValueError("the server has already started") self.backup_shutdown_queue = CompletionQueue() - self.register_non_listening_completion_queue(self.backup_shutdown_queue) + self.register_completion_queue(self.backup_shutdown_queue) self.is_started = True with nogil: grpc_server_start(self.c_server) From 31d92d42ff8493fc0a9eb419ff662e4e5244096b Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Sat, 8 Apr 2017 15:43:07 -0700 Subject: [PATCH 12/48] 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 13/48] 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 529e4c53854e89f22f66defd766a95ca0a96b0b6 Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Thu, 13 Apr 2017 13:28:16 -0700 Subject: [PATCH 14/48] 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 15/48] 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 16/48] 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 17/48] 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 18/48] 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 19/48] 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 20/48] 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 21/48] 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 22/48] 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 23/48] 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 24/48] 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 25/48] 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 3512ec926b09099b30ea7b496c15dcb559ace7a3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 18 Apr 2017 13:26:32 -0700 Subject: [PATCH 26/48] Fix typo --- src/node/ext/server_generic.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/ext/server_generic.cc b/src/node/ext/server_generic.cc index a25b2f1ca74..088273d527c 100644 --- a/src/node/ext/server_generic.cc +++ b/src/node/ext/server_generic.cc @@ -48,7 +48,7 @@ Server::Server(grpc_server *server) : wrapped_server(server) { GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_NON_LISTENING}; shutdown_queue = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attrs), &attrs, NULL); - grpc_server_completion_queue(server, shutdown_queue, NULL); + grpc_server_register_completion_queue(server, shutdown_queue, NULL); } Server::~Server() { From fb059a2782c33bbbefc65b4c6ee4ef6087cbcf3a Mon Sep 17 00:00:00 2001 From: Mahak Mukhi Date: Tue, 18 Apr 2017 14:40:00 -0700 Subject: [PATCH 27/48] 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 28/48] 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 29/48] 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 30/48] 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 31/48] 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 32/48] 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 0a458b599e723bfcd22cf92755059ac4de0a1489 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 19 Apr 2017 06:35:16 -0700 Subject: [PATCH 33/48] Fix Bazel build --- src/proto/grpc/health/v1/BUILD | 39 ++++++++++++++++++++++++++++++++++ test/cpp/end2end/BUILD | 1 + 2 files changed, 40 insertions(+) create mode 100644 src/proto/grpc/health/v1/BUILD diff --git a/src/proto/grpc/health/v1/BUILD b/src/proto/grpc/health/v1/BUILD new file mode 100644 index 00000000000..dbb91d91392 --- /dev/null +++ b/src/proto/grpc/health/v1/BUILD @@ -0,0 +1,39 @@ +# Copyright 2017, 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. + +licenses(["notice"]) # 3-clause BSD + +package(default_visibility = ["//visibility:public"]) + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library") + +grpc_proto_library( + name = "health_proto", + srcs = ["health.proto"], +) diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 0bf7948fcfe..a74a123aef3 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -156,6 +156,7 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", From ae1e29eed96798cadfed15b2e1e63e92dcf6d36e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 19 Apr 2017 09:07:23 -0700 Subject: [PATCH 34/48] Get dep in the right place --- test/cpp/end2end/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index a74a123aef3..f1212e15c77 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -51,6 +51,7 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", @@ -156,7 +157,6 @@ cc_test( "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", - "//src/proto/grpc/health/v1:health_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", From e6f6a09c171cba7398d04c293763b7593ab853e8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Apr 2017 16:50:00 +0000 Subject: [PATCH 35/48] Eliminate gtest splitting: hopefully allows tuning cpu cost better --- build.yaml | 42 ++-------------- tools/run_tests/generated/tests.json | 74 ++++++++++++++-------------- 2 files changed, 42 insertions(+), 74 deletions(-) diff --git a/build.yaml b/build.yaml index f23de87d11c..8c27c8e3da2 100644 --- a/build.yaml +++ b/build.yaml @@ -3114,7 +3114,7 @@ targets: - linux - posix - name: alarm_cpp_test - gtest: true + cpu_cost: 0.1 build: test language: c++ src: @@ -3127,7 +3127,7 @@ targets: - gpr_test_util - gpr - name: async_end2end_test - gtest: true + cpu_cost: 0.8 build: test language: c++ src: @@ -3140,7 +3140,6 @@ targets: - gpr_test_util - gpr - name: auth_property_iterator_test - gtest: true build: test language: c++ src: @@ -3442,6 +3441,7 @@ targets: - linux - posix - name: bm_pollset + cpu_cost: 0.5 build: test language: c++ src: @@ -3463,7 +3463,6 @@ targets: - linux - posix - name: channel_arguments_test - gtest: true build: test language: c++ src: @@ -3473,7 +3472,6 @@ targets: - grpc - gpr - name: channel_filter_test - gtest: true build: test language: c++ src: @@ -3483,7 +3481,6 @@ targets: - grpc - gpr - name: cli_call_test - gtest: true build: test language: c++ src: @@ -3497,7 +3494,6 @@ targets: - gpr_test_util - gpr - name: client_crash_test - gtest: true cpu_cost: 0.1 build: test language: c++ @@ -3528,7 +3524,6 @@ targets: - gpr_test_util - gpr - name: codegen_test_full - gtest: true build: test language: c++ src: @@ -3545,7 +3540,6 @@ targets: filegroups: - grpc++_codegen_base - name: codegen_test_minimal - gtest: true build: test language: c++ src: @@ -3559,7 +3553,6 @@ targets: - grpc++_codegen_base - grpc++_codegen_base_src - name: credentials_test - gtest: true build: test language: c++ src: @@ -3569,7 +3562,6 @@ targets: - grpc - gpr - name: cxx_byte_buffer_test - gtest: true build: test language: c++ src: @@ -3581,7 +3573,6 @@ targets: - gpr_test_util - gpr - name: cxx_slice_test - gtest: true build: test language: c++ src: @@ -3593,7 +3584,6 @@ targets: - gpr_test_util - gpr - name: cxx_string_ref_test - gtest: true build: test language: c++ src: @@ -3601,7 +3591,6 @@ targets: deps: - grpc++ - name: cxx_time_test - gtest: true build: test language: c++ src: @@ -3613,8 +3602,7 @@ targets: - gpr_test_util - gpr - name: end2end_test - gtest: true - cpu_cost: 0.5 + cpu_cost: 1.0 build: test language: c++ src: @@ -3627,7 +3615,6 @@ targets: - gpr_test_util - gpr - name: error_details_test - gtest: true build: test language: c++ src: @@ -3637,7 +3624,6 @@ targets: - grpc++_error_details - grpc++ - name: filter_end2end_test - gtest: true build: test language: c++ src: @@ -3650,7 +3636,6 @@ targets: - gpr_test_util - gpr - name: generic_end2end_test - gtest: true build: test language: c++ src: @@ -3663,7 +3648,6 @@ targets: - gpr_test_util - gpr - name: golden_file_test - gtest: true build: test language: c++ src: @@ -3757,7 +3741,6 @@ targets: vs_config_type: Application vs_project_guid: '{069E9D05-B78B-4751-9252-D21EBAE7DE8E}' - name: grpc_tool_test - gtest: true build: test language: c++ src: @@ -3777,7 +3760,6 @@ targets: filegroups: - grpc++_codegen_proto - name: grpclb_api_test - gtest: true build: test language: c++ src: @@ -3789,9 +3771,9 @@ targets: - grpc++ - grpc - name: grpclb_test - gtest: false build: test language: c++ + cpu_cost: 0.1 src: - src/proto/grpc/lb/v1/load_balancer.proto - test/cpp/grpclb/grpclb_test.cc @@ -3803,7 +3785,6 @@ targets: - gpr_test_util - gpr - name: health_service_end2end_test - gtest: true build: test language: c++ src: @@ -3932,7 +3913,6 @@ targets: - gpr - grpc++_test_config - name: mock_test - gtest: true build: test language: c++ src: @@ -3953,7 +3933,6 @@ targets: - benchmark defaults: benchmark - name: proto_server_reflection_test - gtest: true build: test language: c++ src: @@ -3968,7 +3947,6 @@ targets: - gpr_test_util - gpr - name: proto_utils_test - gtest: true build: test language: c++ src: @@ -4086,7 +4064,6 @@ targets: - gpr - grpc++_test_config - name: round_robin_end2end_test - gtest: true build: test language: c++ src: @@ -4099,7 +4076,6 @@ targets: - gpr_test_util - gpr - name: secure_auth_context_test - gtest: true build: test language: c++ src: @@ -4129,7 +4105,6 @@ targets: - linux - posix - name: server_builder_plugin_test - gtest: true build: test language: c++ src: @@ -4142,7 +4117,6 @@ targets: - gpr_test_util - gpr - name: server_builder_test - gtest: true build: test language: c++ src: @@ -4157,7 +4131,6 @@ targets: - grpc - gpr - name: server_context_test_spouse_test - gtest: true build: test language: c++ src: @@ -4171,7 +4144,6 @@ targets: uses: - grpc++_test - name: server_crash_test - gtest: true cpu_cost: 0.1 build: test language: c++ @@ -4202,7 +4174,6 @@ targets: - gpr_test_util - gpr - name: shutdown_test - gtest: true build: test language: c++ src: @@ -4226,7 +4197,6 @@ targets: - gpr_test_util - gpr - name: streaming_throughput_test - gtest: true build: test language: c++ src: @@ -4280,7 +4250,6 @@ targets: - gpr - grpc++_test_config - name: thread_stress_test - gtest: true cpu_cost: 100 build: test language: c++ @@ -4294,7 +4263,6 @@ targets: - gpr_test_util - gpr - name: writes_per_rpc_test - gtest: true cpu_cost: 0.5 build: test language: c++ diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 6338ea70127..9b48d85970c 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2591,11 +2591,11 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "alarm_cpp_test", "platforms": [ @@ -2613,11 +2613,11 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.6, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "async_end2end_test", "platforms": [ @@ -2639,7 +2639,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "auth_property_iterator_test", "platforms": [ @@ -2989,7 +2989,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "channel_arguments_test", "platforms": [ @@ -3011,7 +3011,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "channel_filter_test", "platforms": [ @@ -3033,7 +3033,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "cli_call_test", "platforms": [ @@ -3054,7 +3054,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "client_crash_test", "platforms": [ @@ -3075,7 +3075,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "codegen_test_full", "platforms": [ @@ -3097,7 +3097,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "codegen_test_minimal", "platforms": [ @@ -3119,7 +3119,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "credentials_test", "platforms": [ @@ -3141,7 +3141,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "cxx_byte_buffer_test", "platforms": [ @@ -3163,7 +3163,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "cxx_slice_test", "platforms": [ @@ -3185,7 +3185,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "cxx_string_ref_test", "platforms": [ @@ -3207,7 +3207,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "cxx_time_test", "platforms": [ @@ -3229,7 +3229,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "end2end_test", "platforms": [ @@ -3251,7 +3251,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "error_details_test", "platforms": [ @@ -3273,7 +3273,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "filter_end2end_test", "platforms": [ @@ -3295,7 +3295,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "generic_end2end_test", "platforms": [ @@ -3319,7 +3319,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "golden_file_test", "platforms": [ @@ -3341,7 +3341,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "grpc_tool_test", "platforms": [ @@ -3363,7 +3363,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "grpclb_api_test", "platforms": [ @@ -3407,7 +3407,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "health_service_end2end_test", "platforms": [ @@ -3471,7 +3471,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "mock_test", "platforms": [ @@ -3515,7 +3515,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "proto_server_reflection_test", "platforms": [ @@ -3537,7 +3537,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "proto_utils_test", "platforms": [ @@ -3579,7 +3579,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "round_robin_end2end_test", "platforms": [ @@ -3601,7 +3601,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "secure_auth_context_test", "platforms": [ @@ -3643,7 +3643,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "server_builder_plugin_test", "platforms": [ @@ -3665,7 +3665,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "server_builder_test", "platforms": [ @@ -3687,7 +3687,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "server_context_test_spouse_test", "platforms": [ @@ -3708,7 +3708,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "server_crash_test", "platforms": [ @@ -3729,7 +3729,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "shutdown_test", "platforms": [ @@ -3772,7 +3772,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "streaming_throughput_test", "platforms": [ @@ -3815,7 +3815,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "thread_stress_test", "platforms": [ @@ -3836,7 +3836,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": true, + "gtest": false, "language": "c++", "name": "writes_per_rpc_test", "platforms": [ From 41fdf7d6ade3987e44213e591a1c67fee81e12a2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 13 Apr 2017 18:55:46 +0000 Subject: [PATCH 36/48] Better cost estimation --- test/cpp/qps/gen_build_yaml.py | 1 + tools/run_tests/generated/tests.json | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 2f035abeddc..805b0faeece 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -66,6 +66,7 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): + if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) return scenario_json['client_config']['outstanding_rpcs_per_channel'] * scenario_json['client_config']['client_channels'] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 9b48d85970c..a5bc8fa0ea5 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -41374,7 +41374,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41476,7 +41476,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41528,7 +41528,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41953,7 +41953,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42055,7 +42055,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42107,7 +42107,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42580,7 +42580,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42730,7 +42730,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42806,7 +42806,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43435,7 +43435,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 100, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43585,7 +43585,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43661,7 +43661,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": "capacity", + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", From dbc12105a3e9266dde57647ccc6340ea9c50fd2c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Apr 2017 17:08:39 +0000 Subject: [PATCH 37/48] Refine ping-pong cpu requirement estimations; sort tests by cpu cost to get better bin packing --- build.yaml | 6 ++- test/cpp/qps/gen_build_yaml.py | 2 + tools/run_tests/generated/tests.json | 66 ++++++++++++++-------------- tools/run_tests/run_tests.py | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/build.yaml b/build.yaml index 8c27c8e3da2..a2bbcaf41db 100644 --- a/build.yaml +++ b/build.yaml @@ -3638,6 +3638,7 @@ targets: - name: generic_end2end_test build: test language: c++ + cpu_cost: 0.1 src: - test/cpp/end2end/generic_end2end_test.cc deps: @@ -3743,6 +3744,7 @@ targets: - name: grpc_tool_test build: test language: c++ + cpu_cost: 0.2 src: - src/proto/grpc/testing/echo.proto - src/proto/grpc/testing/echo_messages.proto @@ -3771,9 +3773,9 @@ targets: - grpc++ - grpc - name: grpclb_test + cpu_cost: 0.1 build: test language: c++ - cpu_cost: 0.1 src: - src/proto/grpc/lb/v1/load_balancer.proto - test/cpp/grpclb/grpclb_test.cc @@ -4263,7 +4265,7 @@ targets: - gpr_test_util - gpr - name: writes_per_rpc_test - cpu_cost: 0.5 + cpu_cost: 0.8 build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 805b0faeece..2edcb86a684 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -65,6 +65,8 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) + if scenario_json['client_config']['outstanding_rpcs_per_channel'] == 1 and scenario_json['client_config']['client_channels'] == 1: + return 0.4 if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a5bc8fa0ea5..daa9f5b0e66 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2613,7 +2613,7 @@ "posix", "windows" ], - "cpu_cost": 0.6, + "cpu_cost": 0.8, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -2964,7 +2964,7 @@ "mac", "posix" ], - "cpu_cost": 1.0, + "cpu_cost": 0.5, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3225,7 +3225,7 @@ "posix", "windows" ], - "cpu_cost": 0.5, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3381,7 +3381,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3832,7 +3832,7 @@ "mac", "posix" ], - "cpu_cost": 0.5, + "cpu_cost": 0.8, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41274,7 +41274,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41476,7 +41476,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41528,7 +41528,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41553,7 +41553,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41603,7 +41603,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41653,7 +41653,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41753,7 +41753,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41853,7 +41853,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42055,7 +42055,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42107,7 +42107,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42132,7 +42132,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42182,7 +42182,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42232,7 +42232,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42332,7 +42332,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42432,7 +42432,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42730,7 +42730,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42806,7 +42806,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42843,7 +42843,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42917,7 +42917,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42991,7 +42991,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43139,7 +43139,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43287,7 +43287,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43585,7 +43585,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43661,7 +43661,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43698,7 +43698,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43772,7 +43772,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43846,7 +43846,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43994,7 +43994,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": 0.8, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index cfa7071e002..32da7fb02a2 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1466,7 +1466,7 @@ def _build_and_run( # When running on travis, we want out test runs to be as similar as possible # for reproducibility purposes. if args.travis: - massaged_one_run = sorted(one_run, key=lambda x: x.shortname) + massaged_one_run = sorted(one_run, key=lambda x: (x.cpu_cost, x.shortname)) else: # whereas otherwise, we want to shuffle things up to give all tests a # chance to run. From 26f6c1b2390deab5f891003b448793a63bd09130 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 06:40:29 -0700 Subject: [PATCH 38/48] regen projects --- build.yaml | 4 ++-- tools/run_tests/generated/tests.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.yaml b/build.yaml index a8ba1c8e84c..2ffba8cfa9e 100644 --- a/build.yaml +++ b/build.yaml @@ -3643,9 +3643,9 @@ targets: - gpr_test_util - gpr - name: generic_end2end_test + cpu_cost: 0.1 build: test language: c++ - cpu_cost: 0.1 src: - test/cpp/end2end/generic_end2end_test.cc deps: @@ -3749,9 +3749,9 @@ targets: vs_config_type: Application vs_project_guid: '{069E9D05-B78B-4751-9252-D21EBAE7DE8E}' - name: grpc_tool_test + cpu_cost: 0.2 build: test language: c++ - cpu_cost: 0.2 src: - src/proto/grpc/testing/echo.proto - src/proto/grpc/testing/echo_messages.proto diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index ce4684b286d..38bfb2fcdbb 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3291,7 +3291,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3337,7 +3337,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.2, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, From ab424e8702242c36ee1702d87a11520304e4bb80 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 08:05:40 -0700 Subject: [PATCH 39/48] Back out some bad changes --- Makefile | 9 -- build.yaml | 50 +++++++--- tools/run_tests/generated/configs.json | 3 - tools/run_tests/generated/tests.json | 132 ++++++++----------------- tools/run_tests/run_tests.py | 2 +- 5 files changed, 82 insertions(+), 114 deletions(-) diff --git a/Makefile b/Makefile index 36f2f8ee1d0..31953041d19 100644 --- a/Makefile +++ b/Makefile @@ -157,15 +157,6 @@ LDXX_asan-noleaks = clang++ CPPFLAGS_asan-noleaks = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS LDFLAGS_asan-noleaks = -fsanitize=address -VALID_CONFIG_c++-compat = 1 -CC_c++-compat = $(DEFAULT_CC) -CXX_c++-compat = $(DEFAULT_CXX) -LD_c++-compat = $(DEFAULT_CC) -LDXX_c++-compat = $(DEFAULT_CXX) -CFLAGS_c++-compat = -Wc++-compat -CPPFLAGS_c++-compat = -O0 -DEFINES_c++-compat = _DEBUG DEBUG - VALID_CONFIG_ubsan = 1 REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 CC_ubsan = clang diff --git a/build.yaml b/build.yaml index 2ffba8cfa9e..045eb6be3b4 100644 --- a/build.yaml +++ b/build.yaml @@ -3118,7 +3118,7 @@ targets: - linux - posix - name: alarm_cpp_test - cpu_cost: 0.1 + gtest: true build: test language: c++ src: @@ -3131,7 +3131,7 @@ targets: - gpr_test_util - gpr - name: async_end2end_test - cpu_cost: 0.8 + gtest: true build: test language: c++ src: @@ -3144,6 +3144,7 @@ targets: - gpr_test_util - gpr - name: auth_property_iterator_test + gtest: true build: test language: c++ src: @@ -3445,7 +3446,6 @@ targets: - linux - posix - name: bm_pollset - cpu_cost: 0.5 build: test language: c++ src: @@ -3467,6 +3467,7 @@ targets: - linux - posix - name: channel_arguments_test + gtest: true build: test language: c++ src: @@ -3476,6 +3477,7 @@ targets: - grpc - gpr - name: channel_filter_test + gtest: true build: test language: c++ src: @@ -3485,6 +3487,7 @@ targets: - grpc - gpr - name: cli_call_test + gtest: true build: test language: c++ src: @@ -3498,6 +3501,7 @@ targets: - gpr_test_util - gpr - name: client_crash_test + gtest: true cpu_cost: 0.1 build: test language: c++ @@ -3528,6 +3532,7 @@ targets: - gpr_test_util - gpr - name: codegen_test_full + gtest: true build: test language: c++ src: @@ -3544,6 +3549,7 @@ targets: filegroups: - grpc++_codegen_base - name: codegen_test_minimal + gtest: true build: test language: c++ src: @@ -3560,6 +3566,7 @@ targets: - grpc++_codegen_base - grpc++_codegen_base_src - name: credentials_test + gtest: true build: test language: c++ src: @@ -3569,6 +3576,7 @@ targets: - grpc - gpr - name: cxx_byte_buffer_test + gtest: true build: test language: c++ src: @@ -3580,6 +3588,7 @@ targets: - gpr_test_util - gpr - name: cxx_slice_test + gtest: true build: test language: c++ src: @@ -3591,6 +3600,7 @@ targets: - gpr_test_util - gpr - name: cxx_string_ref_test + gtest: true build: test language: c++ src: @@ -3598,6 +3608,7 @@ targets: deps: - grpc++ - name: cxx_time_test + gtest: true build: test language: c++ src: @@ -3609,7 +3620,8 @@ targets: - gpr_test_util - gpr - name: end2end_test - cpu_cost: 1.0 + gtest: true + cpu_cost: 0.5 build: test language: c++ src: @@ -3622,6 +3634,7 @@ targets: - gpr_test_util - gpr - name: error_details_test + gtest: true build: test language: c++ src: @@ -3631,6 +3644,7 @@ targets: - grpc++_error_details - grpc++ - name: filter_end2end_test + gtest: true build: test language: c++ src: @@ -3643,7 +3657,7 @@ targets: - gpr_test_util - gpr - name: generic_end2end_test - cpu_cost: 0.1 + gtest: true build: test language: c++ src: @@ -3656,6 +3670,7 @@ targets: - gpr_test_util - gpr - name: golden_file_test + gtest: true build: test language: c++ src: @@ -3749,7 +3764,7 @@ targets: vs_config_type: Application vs_project_guid: '{069E9D05-B78B-4751-9252-D21EBAE7DE8E}' - name: grpc_tool_test - cpu_cost: 0.2 + gtest: true build: test language: c++ src: @@ -3769,6 +3784,7 @@ targets: filegroups: - grpc++_codegen_proto - name: grpclb_api_test + gtest: true build: test language: c++ src: @@ -3780,7 +3796,7 @@ targets: - grpc++ - grpc - name: grpclb_test - cpu_cost: 0.1 + gtest: false build: test language: c++ src: @@ -3794,6 +3810,7 @@ targets: - gpr_test_util - gpr - name: health_service_end2end_test + gtest: true build: test language: c++ src: @@ -3922,6 +3939,7 @@ targets: - gpr - grpc++_test_config - name: mock_test + gtest: true build: test language: c++ src: @@ -3942,6 +3960,7 @@ targets: - benchmark defaults: benchmark - name: proto_server_reflection_test + gtest: true build: test language: c++ src: @@ -3956,6 +3975,7 @@ targets: - gpr_test_util - gpr - name: proto_utils_test + gtest: true build: test language: c++ src: @@ -4073,6 +4093,7 @@ targets: - gpr - grpc++_test_config - name: round_robin_end2end_test + gtest: true build: test language: c++ src: @@ -4085,6 +4106,7 @@ targets: - gpr_test_util - gpr - name: secure_auth_context_test + gtest: true build: test language: c++ src: @@ -4114,6 +4136,7 @@ targets: - linux - posix - name: server_builder_plugin_test + gtest: true build: test language: c++ src: @@ -4126,6 +4149,7 @@ targets: - gpr_test_util - gpr - name: server_builder_test + gtest: true build: test language: c++ src: @@ -4140,6 +4164,7 @@ targets: - grpc - gpr - name: server_context_test_spouse_test + gtest: true build: test language: c++ src: @@ -4153,6 +4178,7 @@ targets: uses: - grpc++_test - name: server_crash_test + gtest: true cpu_cost: 0.1 build: test language: c++ @@ -4183,6 +4209,7 @@ targets: - gpr_test_util - gpr - name: shutdown_test + gtest: true build: test language: c++ src: @@ -4206,6 +4233,7 @@ targets: - gpr_test_util - gpr - name: streaming_throughput_test + gtest: true build: test language: c++ src: @@ -4259,6 +4287,7 @@ targets: - gpr - grpc++_test_config - name: thread_stress_test + gtest: true cpu_cost: 100 build: test language: c++ @@ -4272,7 +4301,8 @@ targets: - gpr_test_util - gpr - name: writes_per_rpc_test - cpu_cost: 0.8 + gtest: true + cpu_cost: 0.5 build: test language: c++ src: @@ -4354,10 +4384,6 @@ configs: basicprof: CPPFLAGS: -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC DEFINES: NDEBUG - c++-compat: - CFLAGS: -Wc++-compat - CPPFLAGS: -O0 - DEFINES: _DEBUG DEBUG counters: CPPFLAGS: -O2 -DGPR_LOW_LEVEL_COUNTERS DEFINES: NDEBUG diff --git a/tools/run_tests/generated/configs.json b/tools/run_tests/generated/configs.json index abbe76d60c2..93dd6fb3d43 100644 --- a/tools/run_tests/generated/configs.json +++ b/tools/run_tests/generated/configs.json @@ -38,9 +38,6 @@ "ASAN_OPTIONS": "detect_leaks=0:color=always" } }, - { - "config": "c++-compat" - }, { "config": "ubsan", "environ": { diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 27b7c0a8da7..cd7be31edb8 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2591,11 +2591,11 @@ "posix", "windows" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "alarm_cpp_test", "platforms": [ @@ -2613,11 +2613,11 @@ "posix", "windows" ], - "cpu_cost": 0.8, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "async_end2end_test", "platforms": [ @@ -2639,7 +2639,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "auth_property_iterator_test", "platforms": [ @@ -2964,7 +2964,7 @@ "mac", "posix" ], - "cpu_cost": 0.5, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -2989,7 +2989,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "channel_arguments_test", "platforms": [ @@ -3011,7 +3011,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "channel_filter_test", "platforms": [ @@ -3033,7 +3033,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "cli_call_test", "platforms": [ @@ -3054,7 +3054,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "client_crash_test", "platforms": [ @@ -3075,7 +3075,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "codegen_test_full", "platforms": [ @@ -3097,7 +3097,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "codegen_test_minimal", "platforms": [ @@ -3119,7 +3119,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "credentials_test", "platforms": [ @@ -3141,7 +3141,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "cxx_byte_buffer_test", "platforms": [ @@ -3163,7 +3163,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "cxx_slice_test", "platforms": [ @@ -3185,7 +3185,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "cxx_string_ref_test", "platforms": [ @@ -3207,7 +3207,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "cxx_time_test", "platforms": [ @@ -3225,11 +3225,11 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.5, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "end2end_test", "platforms": [ @@ -3251,7 +3251,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "error_details_test", "platforms": [ @@ -3273,7 +3273,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "filter_end2end_test", "platforms": [ @@ -3291,11 +3291,11 @@ "posix", "windows" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "generic_end2end_test", "platforms": [ @@ -3319,7 +3319,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "golden_file_test", "platforms": [ @@ -3337,11 +3337,11 @@ "posix", "windows" ], - "cpu_cost": 0.2, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "grpc_tool_test", "platforms": [ @@ -3363,7 +3363,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "grpclb_api_test", "platforms": [ @@ -3381,7 +3381,7 @@ "posix", "windows" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -3407,7 +3407,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "health_service_end2end_test", "platforms": [ @@ -3471,7 +3471,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "mock_test", "platforms": [ @@ -3515,7 +3515,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "proto_server_reflection_test", "platforms": [ @@ -3537,7 +3537,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "proto_utils_test", "platforms": [ @@ -3579,7 +3579,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "round_robin_end2end_test", "platforms": [ @@ -3601,7 +3601,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "secure_auth_context_test", "platforms": [ @@ -3643,7 +3643,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "server_builder_plugin_test", "platforms": [ @@ -3665,7 +3665,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "server_builder_test", "platforms": [ @@ -3687,7 +3687,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "server_context_test_spouse_test", "platforms": [ @@ -3708,7 +3708,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "server_crash_test", "platforms": [ @@ -3729,7 +3729,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "shutdown_test", "platforms": [ @@ -3772,7 +3772,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "streaming_throughput_test", "platforms": [ @@ -3815,7 +3815,7 @@ "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "thread_stress_test", "platforms": [ @@ -3832,11 +3832,11 @@ "mac", "posix" ], - "cpu_cost": 0.8, + "cpu_cost": 0.5, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, - "gtest": false, + "gtest": true, "language": "c++", "name": "writes_per_rpc_test", "platforms": [ @@ -42392,7 +42392,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42430,7 +42429,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42468,7 +42466,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42506,7 +42503,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42544,7 +42540,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42582,7 +42577,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42620,7 +42614,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42658,7 +42651,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42698,7 +42690,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42736,7 +42727,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42776,7 +42766,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42814,7 +42803,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42852,7 +42840,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42890,7 +42877,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42928,7 +42914,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -42966,7 +42951,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43004,7 +42988,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43042,7 +43025,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43080,7 +43062,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43118,7 +43099,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43156,7 +43136,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43194,7 +43173,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43232,7 +43210,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43270,7 +43247,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43308,7 +43284,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43346,7 +43321,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43384,7 +43358,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43422,7 +43395,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43460,7 +43432,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43498,7 +43469,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43536,7 +43506,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43576,7 +43545,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43614,7 +43582,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43654,7 +43621,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43692,7 +43658,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43730,7 +43695,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43768,7 +43732,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43806,7 +43769,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43844,7 +43806,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43882,7 +43843,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43920,7 +43880,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43958,7 +43917,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -43996,7 +43954,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -44034,7 +43991,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -44072,7 +44028,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", @@ -44110,7 +44065,6 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", - "c++-compat", "counters", "dbg", "gcov", diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index d3e9803a34a..8173cc805c7 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1467,7 +1467,7 @@ def _build_and_run( # When running on travis, we want out test runs to be as similar as possible # for reproducibility purposes. if args.travis: - massaged_one_run = sorted(one_run, key=lambda x: (x.cpu_cost, x.shortname)) + massaged_one_run = sorted(one_run, key=lambda x: x.shortname) else: # whereas otherwise, we want to shuffle things up to give all tests a # chance to run. From 243a12e87a77801ecd21078da52071de9c63d479 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 08:07:14 -0700 Subject: [PATCH 40/48] Reinstate c++-compat --- Makefile | 9 +++++ build.yaml | 4 +++ tools/run_tests/generated/configs.json | 3 ++ tools/run_tests/generated/tests.json | 46 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/Makefile b/Makefile index 31953041d19..36f2f8ee1d0 100644 --- a/Makefile +++ b/Makefile @@ -157,6 +157,15 @@ LDXX_asan-noleaks = clang++ CPPFLAGS_asan-noleaks = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS LDFLAGS_asan-noleaks = -fsanitize=address +VALID_CONFIG_c++-compat = 1 +CC_c++-compat = $(DEFAULT_CC) +CXX_c++-compat = $(DEFAULT_CXX) +LD_c++-compat = $(DEFAULT_CC) +LDXX_c++-compat = $(DEFAULT_CXX) +CFLAGS_c++-compat = -Wc++-compat +CPPFLAGS_c++-compat = -O0 +DEFINES_c++-compat = _DEBUG DEBUG + VALID_CONFIG_ubsan = 1 REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 CC_ubsan = clang diff --git a/build.yaml b/build.yaml index 045eb6be3b4..ed7f4cce649 100644 --- a/build.yaml +++ b/build.yaml @@ -4384,6 +4384,10 @@ configs: basicprof: CPPFLAGS: -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC DEFINES: NDEBUG + c++-compat: + CFLAGS: -Wc++-compat + CPPFLAGS: -O0 + DEFINES: _DEBUG DEBUG counters: CPPFLAGS: -O2 -DGPR_LOW_LEVEL_COUNTERS DEFINES: NDEBUG diff --git a/tools/run_tests/generated/configs.json b/tools/run_tests/generated/configs.json index 93dd6fb3d43..abbe76d60c2 100644 --- a/tools/run_tests/generated/configs.json +++ b/tools/run_tests/generated/configs.json @@ -38,6 +38,9 @@ "ASAN_OPTIONS": "detect_leaks=0:color=always" } }, + { + "config": "c++-compat" + }, { "config": "ubsan", "environ": { diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index cd7be31edb8..53460fb47af 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -42392,6 +42392,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42429,6 +42430,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42466,6 +42468,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42503,6 +42506,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42540,6 +42544,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42577,6 +42582,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42614,6 +42620,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42651,6 +42658,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42690,6 +42698,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42727,6 +42736,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42766,6 +42776,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42803,6 +42814,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42840,6 +42852,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42877,6 +42890,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42914,6 +42928,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42951,6 +42966,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -42988,6 +43004,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43025,6 +43042,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43062,6 +43080,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43099,6 +43118,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43136,6 +43156,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43173,6 +43194,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43210,6 +43232,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43247,6 +43270,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43284,6 +43308,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43321,6 +43346,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43358,6 +43384,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43395,6 +43422,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43432,6 +43460,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43469,6 +43498,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43506,6 +43536,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43545,6 +43576,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43582,6 +43614,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43621,6 +43654,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43658,6 +43692,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43695,6 +43730,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43732,6 +43768,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43769,6 +43806,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43806,6 +43844,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43843,6 +43882,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43880,6 +43920,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43917,6 +43958,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43954,6 +43996,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -43991,6 +44034,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -44028,6 +44072,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", @@ -44065,6 +44110,7 @@ "asan-noleaks", "asan-trace-cmp", "basicprof", + "c++-compat", "counters", "dbg", "gcov", From fefd2f2d8b57386f3bef3128c075c06e605c48c0 Mon Sep 17 00:00:00 2001 From: Dan Zhang Date: Fri, 21 Apr 2017 12:28:48 -0400 Subject: [PATCH 41/48] 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 a8749903dd445e3e01a37a9c111b8887915f6124 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Fri, 21 Apr 2017 16:44:01 +0000 Subject: [PATCH 42/48] Avoid duplication in build rules by expanding the grpc_cc_libraries rule-creation macro --- BUILD | 55 ++++++++++++++----------------------- bazel/grpc_build_system.bzl | 11 +++++--- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/BUILD b/BUILD index 09b17ad6eb2..a919a6328a5 100644 --- a/BUILD +++ b/BUILD @@ -54,33 +54,46 @@ grpc_cc_library( ], ) -grpc_cc_library( - name = "grpc", +grpc_cc_libraries( + name_list = ["grpc", "grpc_unsecure",], srcs = [ "src/core/lib/surface/init.c", - "src/core/plugin_registry/grpc_plugin_registry.c", + ], + additional_src_list = [ + [ + "src/core/plugin_registry/grpc_plugin_registry.c", + ], + [ + "src/core/lib/surface/init_unsecure.c", + "src/core/plugin_registry/grpc_unsecure_plugin_registry.c", + ], ], language = "c", standalone = True, deps = [ "census", "grpc_base", - "grpc_lb_policy_grpclb_secure", "grpc_lb_policy_pick_first", "grpc_lb_policy_round_robin", "grpc_load_reporting", "grpc_max_age_filter", - "grpc_resolver_dns_ares", "grpc_resolver_dns_native", "grpc_resolver_sockaddr", - "grpc_secure", "grpc_transport_chttp2_client_insecure", - "grpc_transport_chttp2_client_secure", "grpc_transport_chttp2_server_insecure", - "grpc_transport_chttp2_server_secure", "grpc_message_size_filter", "grpc_deadline_filter", ], + additional_dep_list = [ + [ + "grpc_secure", + "grpc_resolver_dns_ares", + "grpc_lb_policy_grpclb_secure", + "grpc_transport_chttp2_client_secure", + "grpc_transport_chttp2_server_secure", + ], + [], + ], ) grpc_cc_library( @@ -98,32 +111,6 @@ grpc_cc_library( ], ) -grpc_cc_library( - name = "grpc_unsecure", - srcs = [ - "src/core/lib/surface/init.c", - "src/core/lib/surface/init_unsecure.c", - "src/core/plugin_registry/grpc_unsecure_plugin_registry.c", - ], - language = "c", - standalone = True, - deps = [ - "census", - "grpc_base", - "grpc_lb_policy_grpclb", - "grpc_lb_policy_pick_first", - "grpc_lb_policy_round_robin", - "grpc_load_reporting", - "grpc_max_age_filter", - "grpc_resolver_dns_native", - "grpc_resolver_sockaddr", - "grpc_transport_chttp2_client_insecure", - "grpc_transport_chttp2_server_insecure", - "grpc_message_size_filter", - "grpc_deadline_filter", - ], -) - grpc_cc_library( name = "grpc++", srcs = [ diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 984c06de489..a438186c757 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -49,14 +49,17 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], external_deps ] ) -def grpc_cc_libraries(name_list, additional_dep_list, srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language="C++"): - for i in range(len(name_list)): +def grpc_cc_libraries(name_list, additional_src_list = [], additional_dep_list = [], srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language="C++"): + names = len(name_list) + asl = additional_src_list + [[]]*(names - len(additional_src_list)) + adl = additional_dep_list + [[]]*(names - len(additional_dep_list)) + for i in range(names): grpc_cc_library( name = name_list[i], - srcs = srcs, + srcs = srcs + asl[i], hdrs = hdrs, public_hdrs = public_hdrs, - deps = deps + additional_dep_list[i], + deps = deps + adl[i], external_deps = external_deps, standalone = standalone, language = language From c3fc8342b19e774ef6daf8d4736ca1af61408c75 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Fri, 21 Apr 2017 15:01:18 -0700 Subject: [PATCH 43/48] Demote handshake logging msg to DEBUG --- src/core/ext/transport/chttp2/server/chttp2_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.c b/src/core/ext/transport/chttp2/server/chttp2_server.c index b463506a98f..b9c62c376a1 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.c +++ b/src/core/ext/transport/chttp2/server/chttp2_server.c @@ -80,7 +80,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_lock(&connection_state->server_state->mu); if (error != GRPC_ERROR_NONE || connection_state->server_state->shutdown) { const char *error_str = grpc_error_string(error); - gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str); + gpr_log(GPR_DEBUG, "Handshaking failed: %s", error_str); if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { // We were shut down after handshaking completed successfully, so From 20cb627339c20e86814d64ba4837d7bdd6f35195 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 15:07:13 -0700 Subject: [PATCH 44/48] Fix HTTP proxy tests - heap allocate the pollset shutdown closure (this may be called asynchronously) - ensure a poller remains until all endpoints are closed --- .../end2end/fixtures/http_proxy_fixture.c | 59 +++++++++++++------ test/core/end2end/tests/cancel_after_invoke.c | 9 +-- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index 451ed268d30..02235d96e73 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -59,6 +59,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/port.h" @@ -69,7 +70,7 @@ struct grpc_end2end_http_proxy { grpc_channel_args* channel_args; gpr_mu* mu; grpc_pollset* pollset; - gpr_atm shutdown; + gpr_refcount users; }; // @@ -77,6 +78,8 @@ struct grpc_end2end_http_proxy { // typedef struct proxy_connection { + grpc_end2end_http_proxy* proxy; + grpc_endpoint* client_endpoint; grpc_endpoint* server_endpoint; @@ -103,13 +106,26 @@ typedef struct proxy_connection { grpc_http_request http_request; } proxy_connection; +static void proxy_connection_ref(proxy_connection* conn, const char* reason) { + gpr_log(GPR_DEBUG, "proxy_connection_ref: %p %s %" PRIdPTR " --> %" PRIdPTR, + conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), + gpr_atm_no_barrier_load(&conn->refcount.count) - 1); + gpr_ref(&conn->refcount); +} + // Helper function to destroy the proxy connection. static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, - proxy_connection* conn) { + proxy_connection* conn, const char* reason) { + gpr_log(GPR_DEBUG, "proxy_connection_unref: %p %s %" PRIdPTR " --> %" PRIdPTR, + conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), + gpr_atm_no_barrier_load(&conn->refcount.count) - 1); if (gpr_unref(&conn->refcount)) { + gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, + conn->server_endpoint); grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); - if (conn->server_endpoint != NULL) + if (conn->server_endpoint != NULL) { grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); + } grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, @@ -121,6 +137,7 @@ static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); + gpr_unref(&conn->proxy->users); gpr_free(conn); } } @@ -139,7 +156,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, GRPC_ERROR_REF(error)); } - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "conn_failed"); } // Callback for writing proxy data to the client. @@ -163,7 +180,7 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "write_done"); } } @@ -188,7 +205,7 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "server_write"); } } @@ -214,7 +231,7 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_slice_buffer_move_into(&conn->client_read_buffer, &conn->server_write_buffer); - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "client_read"); grpc_endpoint_write(exec_ctx, conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); @@ -246,7 +263,7 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_slice_buffer_move_into(&conn->server_read_buffer, &conn->client_write_buffer); - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "server_read"); grpc_endpoint_write(exec_ctx, conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); @@ -270,7 +287,9 @@ static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, // Start reading from both client and server. One of the read // requests inherits our ref to conn, but we need to take a new ref // for the other one. - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "client_read"); + proxy_connection_ref(conn, "server_read"); + proxy_connection_unref(exec_ctx, conn, "write_response"); grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, @@ -312,6 +331,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { proxy_connection* conn = arg; + gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, + grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { proxy_connection_failed(exec_ctx, conn, true /* is_client */, "HTTP proxy read request", error); @@ -376,12 +397,15 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, gpr_free(acceptor); grpc_end2end_http_proxy* proxy = arg; // Instantiate proxy_connection. - proxy_connection* conn = gpr_malloc(sizeof(*conn)); - memset(conn, 0, sizeof(*conn)); + proxy_connection* conn = gpr_zalloc(sizeof(*conn)); + gpr_ref(&proxy->users); conn->client_endpoint = endpoint; + conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); + gpr_log(GPR_DEBUG, "on_accept: %p", conn); grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); grpc_closure_init(&conn->on_read_request_done, on_read_request_done, conn, grpc_schedule_on_exec_ctx); grpc_closure_init(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -416,6 +440,7 @@ static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = arg; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; do { + gpr_ref(&proxy->users); const gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); const gpr_timespec deadline = gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN)); @@ -426,7 +451,7 @@ static void thread_main(void* arg) { grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, now, deadline)); gpr_mu_unlock(proxy->mu); grpc_exec_ctx_flush(&exec_ctx); - } while (!gpr_atm_acq_load(&proxy->shutdown)); + } while (!gpr_unref(&proxy->users)); grpc_exec_ctx_finish(&exec_ctx); } @@ -434,6 +459,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_end2end_http_proxy* proxy = gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); + gpr_ref_init(&proxy->users, 1); // Construct proxy address. const int proxy_port = grpc_pick_unused_port_or_die(); gpr_join_host_port(&proxy->proxy_name, "localhost", proxy_port); @@ -474,17 +500,16 @@ static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { - gpr_atm_rel_store(&proxy->shutdown, 1); // Signal proxy thread to shutdown. + gpr_unref(&proxy->users); // Signal proxy thread to shutdown. grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_thd_join(proxy->thd); grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); grpc_tcp_server_unref(&exec_ctx, proxy->server); gpr_free(proxy->proxy_name); grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); - grpc_closure destroyed; - grpc_closure_init(&destroyed, destroy_pollset, proxy->pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, proxy->pollset, &destroyed); + grpc_pollset_shutdown(&exec_ctx, proxy->pollset, + grpc_closure_create(destroy_pollset, proxy->pollset, + grpc_schedule_on_exec_ctx)); gpr_free(proxy); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c index f2aca737ab3..5bc9ed283bb 100644 --- a/test/core/end2end/tests/cancel_after_invoke.c +++ b/test/core/end2end/tests/cancel_after_invoke.c @@ -49,11 +49,12 @@ static void *tag(intptr_t t) { return (void *)t; } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char *test_name, cancellation_mode mode, + size_t test_ops, grpc_channel_args *client_args, grpc_channel_args *server_args) { grpc_end2end_test_fixture f; - gpr_log(GPR_INFO, "Running test: %s/%s/%s", test_name, config.name, - mode.name); + gpr_log(GPR_INFO, "Running test: %s/%s/%s [%" PRIdPTR " ops]", test_name, + config.name, mode.name, test_ops); f = config.create_fixture(client_args, server_args); config.init_server(&f, server_args); config.init_client(&f, client_args); @@ -108,8 +109,8 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_op ops[6]; grpc_op *op; grpc_call *c; - grpc_end2end_test_fixture f = - begin_test(config, "test_cancel_after_invoke", mode, NULL, NULL); + grpc_end2end_test_fixture f = begin_test(config, "test_cancel_after_invoke", + mode, test_ops, NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; From b2b4122c03271a16898c872b13986914ba424116 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 19:05:59 -0700 Subject: [PATCH 45/48] Remove logging --- test/core/end2end/fixtures/http_proxy_fixture.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index 02235d96e73..a9d71b5ba40 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -107,18 +107,12 @@ typedef struct proxy_connection { } proxy_connection; static void proxy_connection_ref(proxy_connection* conn, const char* reason) { - gpr_log(GPR_DEBUG, "proxy_connection_ref: %p %s %" PRIdPTR " --> %" PRIdPTR, - conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), - gpr_atm_no_barrier_load(&conn->refcount.count) - 1); gpr_ref(&conn->refcount); } // Helper function to destroy the proxy connection. static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, proxy_connection* conn, const char* reason) { - gpr_log(GPR_DEBUG, "proxy_connection_unref: %p %s %" PRIdPTR " --> %" PRIdPTR, - conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), - gpr_atm_no_barrier_load(&conn->refcount.count) - 1); if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); From 4a1925444d81ba09878c55d8576cf981d601990c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 19:07:00 -0700 Subject: [PATCH 46/48] Remove more spam --- test/core/end2end/fixtures/http_proxy_fixture.c | 1 - 1 file changed, 1 deletion(-) diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index a9d71b5ba40..f0d09487c62 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -397,7 +397,6 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - gpr_log(GPR_DEBUG, "on_accept: %p", conn); grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); grpc_closure_init(&conn->on_read_request_done, on_read_request_done, conn, From 0d4628479995be4e310f55683f1ebaae2a879e4d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 08:24:21 -0700 Subject: [PATCH 47/48] Rollback some changes --- build.yaml | 2 +- test/cpp/qps/gen_build_yaml.py | 2 - tools/run_tests/generated/tests.json | 58 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/build.yaml b/build.yaml index 58a474aabf1..f2af370522e 100644 --- a/build.yaml +++ b/build.yaml @@ -3806,7 +3806,7 @@ targets: - grpc++ - grpc - name: grpclb_test - gtest: false + cpu_cost: 0.1 build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 2edcb86a684..805b0faeece 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -65,8 +65,6 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) - if scenario_json['client_config']['outstanding_rpcs_per_channel'] == 1 and scenario_json['client_config']['client_channels'] == 1: - return 0.4 if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 203f51b6b89..cb918a0830a 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3403,7 +3403,7 @@ "posix", "windows" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41250,7 +41250,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41452,7 +41452,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41504,7 +41504,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41529,7 +41529,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41579,7 +41579,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41629,7 +41629,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41729,7 +41729,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41829,7 +41829,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42031,7 +42031,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42083,7 +42083,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42108,7 +42108,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42158,7 +42158,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42208,7 +42208,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42308,7 +42308,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42408,7 +42408,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42714,7 +42714,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42792,7 +42792,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42830,7 +42830,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42906,7 +42906,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42982,7 +42982,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43134,7 +43134,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43286,7 +43286,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43592,7 +43592,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43670,7 +43670,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43708,7 +43708,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43784,7 +43784,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43860,7 +43860,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -44012,7 +44012,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 0.8, + "cpu_cost": 2, "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", From c6f6663fb7b8c4b1614b6f881abf966d48cb87c4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 24 Apr 2017 08:29:39 -0700 Subject: [PATCH 48/48] Rollback some changes --- build.yaml | 2 +- test/cpp/qps/gen_build_yaml.py | 1 - tools/run_tests/generated/tests.json | 26 +++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/build.yaml b/build.yaml index f2af370522e..58a474aabf1 100644 --- a/build.yaml +++ b/build.yaml @@ -3806,7 +3806,7 @@ targets: - grpc++ - grpc - name: grpclb_test - cpu_cost: 0.1 + gtest: false build: test language: c++ src: diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 805b0faeece..2f035abeddc 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -66,7 +66,6 @@ def _scenario_json_string(scenario_json, is_tsan): def threads_required(scenario_json, where, is_tsan): scenario_json = mutate_scenario(scenario_json, is_tsan) if scenario_json['%s_config' % where]['%s_type' % where] == 'ASYNC_%s' % where.upper(): - if scenario_json['client_config']['client_channels'] == 1: return 1 return scenario_json['%s_config' % where].get('async_%s_threads' % where, 0) return scenario_json['client_config']['outstanding_rpcs_per_channel'] * scenario_json['client_config']['client_channels'] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index cb918a0830a..120a84e8a4b 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3403,7 +3403,7 @@ "posix", "windows" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [], "flaky": false, @@ -41350,7 +41350,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41452,7 +41452,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41504,7 +41504,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -41929,7 +41929,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42031,7 +42031,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42083,7 +42083,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "tsan", @@ -42560,7 +42560,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42714,7 +42714,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -42792,7 +42792,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43438,7 +43438,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 100, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43592,7 +43592,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks", @@ -43670,7 +43670,7 @@ "ci_platforms": [ "linux" ], - "cpu_cost": 2, + "cpu_cost": "capacity", "defaults": "boringssl", "exclude_configs": [ "asan-noleaks",