diff --git a/Makefile b/Makefile index 6eccd06952c..52a4cb4ebed 100644 --- a/Makefile +++ b/Makefile @@ -1211,7 +1211,12 @@ pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc +ifeq ($(EMBED_OPENSSL),true) privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl_aes_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_asn1_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_base64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bio_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bn_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bytestring_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_aead_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cipher_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ed25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_dh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_digest_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ec_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_err_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_extra_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pbkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs12_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs8_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_poly1305_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_rsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x509_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ssl_test_lib.a +else +privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a +endif + ifeq ($(HAS_ZOOKEEPER),true) privatelibs_zookeeper: @@ -1377,6 +1382,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/uri_fuzzer_test_one_entry \ +ifeq ($(EMBED_OPENSSL),true) buildtests_cxx: buildtests_zookeeper privatelibs_cxx \ $(BINDIR)/$(CONFIG)/alarm_cpp_test \ $(BINDIR)/$(CONFIG)/async_end2end_test \ @@ -1460,6 +1466,54 @@ buildtests_cxx: buildtests_zookeeper privatelibs_cxx \ $(BINDIR)/$(CONFIG)/boringssl_pqueue_test \ $(BINDIR)/$(CONFIG)/boringssl_ssl_test \ +else +buildtests_cxx: buildtests_zookeeper privatelibs_cxx \ + $(BINDIR)/$(CONFIG)/alarm_cpp_test \ + $(BINDIR)/$(CONFIG)/async_end2end_test \ + $(BINDIR)/$(CONFIG)/auth_property_iterator_test \ + $(BINDIR)/$(CONFIG)/channel_arguments_test \ + $(BINDIR)/$(CONFIG)/cli_call_test \ + $(BINDIR)/$(CONFIG)/client_crash_test \ + $(BINDIR)/$(CONFIG)/client_crash_test_server \ + $(BINDIR)/$(CONFIG)/codegen_test_full \ + $(BINDIR)/$(CONFIG)/codegen_test_minimal \ + $(BINDIR)/$(CONFIG)/credentials_test \ + $(BINDIR)/$(CONFIG)/cxx_byte_buffer_test \ + $(BINDIR)/$(CONFIG)/cxx_slice_test \ + $(BINDIR)/$(CONFIG)/cxx_string_ref_test \ + $(BINDIR)/$(CONFIG)/cxx_time_test \ + $(BINDIR)/$(CONFIG)/end2end_test \ + $(BINDIR)/$(CONFIG)/generic_end2end_test \ + $(BINDIR)/$(CONFIG)/golden_file_test \ + $(BINDIR)/$(CONFIG)/grpc_cli \ + $(BINDIR)/$(CONFIG)/grpclb_api_test \ + $(BINDIR)/$(CONFIG)/hybrid_end2end_test \ + $(BINDIR)/$(CONFIG)/interop_client \ + $(BINDIR)/$(CONFIG)/interop_server \ + $(BINDIR)/$(CONFIG)/interop_test \ + $(BINDIR)/$(CONFIG)/json_run_localhost \ + $(BINDIR)/$(CONFIG)/metrics_client \ + $(BINDIR)/$(CONFIG)/mock_test \ + $(BINDIR)/$(CONFIG)/proto_server_reflection_test \ + $(BINDIR)/$(CONFIG)/qps_interarrival_test \ + $(BINDIR)/$(CONFIG)/qps_json_driver \ + $(BINDIR)/$(CONFIG)/qps_openloop_test \ + $(BINDIR)/$(CONFIG)/qps_worker \ + $(BINDIR)/$(CONFIG)/reconnect_interop_client \ + $(BINDIR)/$(CONFIG)/reconnect_interop_server \ + $(BINDIR)/$(CONFIG)/secure_auth_context_test \ + $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test \ + $(BINDIR)/$(CONFIG)/server_builder_plugin_test \ + $(BINDIR)/$(CONFIG)/server_crash_test \ + $(BINDIR)/$(CONFIG)/server_crash_test_client \ + $(BINDIR)/$(CONFIG)/shutdown_test \ + $(BINDIR)/$(CONFIG)/status_test \ + $(BINDIR)/$(CONFIG)/streaming_throughput_test \ + $(BINDIR)/$(CONFIG)/stress_test \ + $(BINDIR)/$(CONFIG)/thread_stress_test \ + +endif + ifeq ($(HAS_ZOOKEEPER),true) buildtests_zookeeper: privatelibs_zookeeper \ diff --git a/doc/cpp-style-guide.md b/doc/cpp-style-guide.md index 9408c4abd68..0138ceb7371 100644 --- a/doc/cpp-style-guide.md +++ b/doc/cpp-style-guide.md @@ -53,6 +53,12 @@ default capture). Other C++ functional features such as (../include/grpc++/impl/codegen/config.h). Instead, pointers should be checked for validity using their implicit conversion to `bool`. In other words, use `if (p)` rather than `if (p != nullptr)` +- Do not initialize global/static pointer variables to `nullptr`. Just let + the compiler implicitly initialize them to `nullptr` (which it will + definitely do). The reason is that `nullptr` is an actual object in + our implementation rather than just a constant pointer value, so + static/global constructors will be called in a potentially + undesirable sequence. - Do not use `final` or `override` as these are not supported by some compilers. Instead use `GRPC_FINAL` and `GRPC_OVERRIDE` . These compile down to the traditional C++ forms for compilers that support diff --git a/include/grpc++/ext/proto_server_reflection_plugin.h b/include/grpc++/ext/proto_server_reflection_plugin.h index 517c4737f59..3e54882d41f 100644 --- a/include/grpc++/ext/proto_server_reflection_plugin.h +++ b/include/grpc++/ext/proto_server_reflection_plugin.h @@ -56,7 +56,7 @@ class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin { bool has_sync_methods() const GRPC_OVERRIDE; private: - std::shared_ptr<::grpc::ProtoServerReflection> reflection_service_; + std::shared_ptr reflection_service_; }; // Add proto reflection plugin to ServerBuilder. This function should be called diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index d720f27a8fa..fab85d15176 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -337,7 +337,7 @@ class DeserializeFuncType GRPC_FINAL : public DeserializeFunc { return SerializationTraits::Deserialize(buf, message_, max_message_size); } - ~DeserializeFuncType() override {} + ~DeserializeFuncType() GRPC_OVERRIDE {} private: R* message_; // Not a managed pointer because management is external to this diff --git a/include/grpc++/impl/codegen/config.h b/include/grpc++/impl/codegen/config.h index d782d5f5713..0c754388681 100644 --- a/include/grpc++/impl/codegen/config.h +++ b/include/grpc++/impl/codegen/config.h @@ -54,6 +54,7 @@ // nullptr was added in gcc 4.6 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 406) #define GRPC_CXX0X_NO_NULLPTR 1 +#define GRPC_CXX0X_LIMITED_TOSTRING 1 #endif // final and override were added in gcc 4.7 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 407) @@ -78,6 +79,7 @@ #endif #ifdef GRPC_CXX0X_NO_NULLPTR +#include #include namespace grpc { const class { @@ -95,6 +97,10 @@ const class { return std::shared_ptr(static_cast(0)); } operator bool() const { return false; } + template + operator std::function() const { + return std::function(); + } private: void operator&() const = delete; @@ -111,6 +117,17 @@ namespace grpc { typedef GRPC_CUSTOM_STRING string; +#ifdef GRPC_CXX0X_LIMITED_TOSTRING +inline grpc::string to_string(const int x) { + return std::to_string(static_cast(x)); +} +inline grpc::string to_string(const unsigned int x) { + return std::to_string(static_cast(x)); +} +#else +using std::to_string; +#endif + } // namespace grpc #endif // GRPCXX_IMPL_CODEGEN_CONFIG_H diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index 656b11e7e72..b0c4c57e66a 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -42,42 +42,44 @@ namespace grpc { /// Implementation of the core codegen interface. class CoreCodegen : public CoreCodegenInterface { private: - grpc_completion_queue* grpc_completion_queue_create(void* reserved) override; - void grpc_completion_queue_destroy(grpc_completion_queue* cq) override; + grpc_completion_queue* grpc_completion_queue_create(void* reserved) + GRPC_OVERRIDE; + void grpc_completion_queue_destroy(grpc_completion_queue* cq) GRPC_OVERRIDE; grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, - void* reserved) override; + void* reserved) GRPC_OVERRIDE; - void* gpr_malloc(size_t size) override; - void gpr_free(void* p) override; + void* gpr_malloc(size_t size) GRPC_OVERRIDE; + void gpr_free(void* p) GRPC_OVERRIDE; - void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override; + void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) GRPC_OVERRIDE; void grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, - grpc_byte_buffer* buffer) override; - void grpc_byte_buffer_reader_destroy( - grpc_byte_buffer_reader* reader) override; + grpc_byte_buffer* buffer) GRPC_OVERRIDE; + void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader* reader) + GRPC_OVERRIDE; int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader, - gpr_slice* slice) override; + gpr_slice* slice) GRPC_OVERRIDE; grpc_byte_buffer* grpc_raw_byte_buffer_create(gpr_slice* slice, - size_t nslices) override; + size_t nslices) GRPC_OVERRIDE; - gpr_slice gpr_slice_malloc(size_t length) override; - void gpr_slice_unref(gpr_slice slice) override; - gpr_slice gpr_slice_split_tail(gpr_slice* s, size_t split) override; - void gpr_slice_buffer_add(gpr_slice_buffer* sb, gpr_slice slice) override; - void gpr_slice_buffer_pop(gpr_slice_buffer* sb) override; + gpr_slice gpr_slice_malloc(size_t length) GRPC_OVERRIDE; + void gpr_slice_unref(gpr_slice slice) GRPC_OVERRIDE; + gpr_slice gpr_slice_split_tail(gpr_slice* s, size_t split) GRPC_OVERRIDE; + void gpr_slice_buffer_add(gpr_slice_buffer* sb, + gpr_slice slice) GRPC_OVERRIDE; + void gpr_slice_buffer_pop(gpr_slice_buffer* sb) GRPC_OVERRIDE; - void grpc_metadata_array_init(grpc_metadata_array* array) override; - void grpc_metadata_array_destroy(grpc_metadata_array* array) override; + void grpc_metadata_array_init(grpc_metadata_array* array) GRPC_OVERRIDE; + void grpc_metadata_array_destroy(grpc_metadata_array* array) GRPC_OVERRIDE; - gpr_timespec gpr_inf_future(gpr_clock_type type) override; + gpr_timespec gpr_inf_future(gpr_clock_type type) GRPC_OVERRIDE; - virtual const Status& ok() override; - virtual const Status& cancelled() override; + virtual const Status& ok() GRPC_OVERRIDE; + virtual const Status& cancelled() GRPC_OVERRIDE; - void assert_fail(const char* failed_assertion) override; + void assert_fail(const char* failed_assertion) GRPC_OVERRIDE; }; } // namespace grpc diff --git a/include/grpc++/impl/server_builder_option.h b/include/grpc++/impl/server_builder_option.h index 2b7e89f5e5d..bd2018fa6b2 100644 --- a/include/grpc++/impl/server_builder_option.h +++ b/include/grpc++/impl/server_builder_option.h @@ -50,8 +50,7 @@ class ServerBuilderOption { virtual void UpdateArguments(ChannelArguments* args) = 0; /// Alter the ServerBuilderPlugin map that will be added into ServerBuilder. virtual void UpdatePlugins( - std::map >* - plugins) = 0; + std::vector>* plugins) = 0; }; } // namespace grpc diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index aa7588d34d3..b9c49f0b192 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -174,7 +174,7 @@ class ServerBuilder { std::vector ports_; std::vector cqs_; std::shared_ptr creds_; - std::map> plugins_; + std::vector> plugins_; AsyncGenericService* generic_service_; struct { bool is_set; diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index e2f127094ad..2288ba41636 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -73,9 +73,10 @@ void PrintIncludes(Printer *printer, const std::vector& headers, c vars["l"] = params.use_system_headers ? '<' : '"'; vars["r"] = params.use_system_headers ? '>' : '"'; - if (!params.grpc_search_path.empty()) { - vars["l"] += params.grpc_search_path; - if (params.grpc_search_path.back() != '/') { + auto& s = params.grpc_search_path; + if (!s.empty()) { + vars["l"] += s; + if (s[s.size()-1] != '/') { vars["l"] += '/'; } } diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h index 53391bc41ab..9a88c2bfccd 100644 --- a/src/compiler/generator_helpers.h +++ b/src/compiler/generator_helpers.h @@ -253,7 +253,8 @@ inline void GetComment(const grpc::protobuf::FileDescriptor *desc, inline grpc::string GenerateCommentsWithPrefix( const std::vector &in, const grpc::string &prefix) { std::ostringstream oss; - for (const grpc::string &elem : in) { + for (auto it = in.begin(); it != in.end(); it++) { + const grpc::string& elem = *it; if (elem.empty()) { oss << prefix << "\n"; } else if (elem[0] == ' ') { diff --git a/src/core/lib/support/log.c b/src/core/lib/support/log.c index 882abf673c1..bae0957df72 100644 --- a/src/core/lib/support/log.c +++ b/src/core/lib/support/log.c @@ -96,4 +96,6 @@ void gpr_log_verbosity_init() { } } -void gpr_set_log_function(gpr_log_func f) { g_log_func = f; } +void gpr_set_log_function(gpr_log_func f) { + g_log_func = f ? f : gpr_default_log; +} diff --git a/src/cpp/codegen/codegen_init.cc b/src/cpp/codegen/codegen_init.cc index c5d22124b71..103a7c12589 100644 --- a/src/cpp/codegen/codegen_init.cc +++ b/src/cpp/codegen/codegen_init.cc @@ -34,12 +34,12 @@ #include #include -/// Initializes the global gRPC variables for the codegen library. These will +/// Null-initializes the global gRPC variables for the codegen library. These /// stay null in the absence of of grpc++ library. In this case, no gRPC /// features such as the ability to perform calls will be available. Trying to /// perform them would result in a segmentation fault when trying to deference /// the following nulled globals. These should be associated with actual /// as part of the instantiation of a \a grpc::GrpcLibraryInitializer variable. -grpc::CoreCodegenInterface* grpc::g_core_codegen_interface = nullptr; -grpc::GrpcLibraryInterface* grpc::g_glip = nullptr; +grpc::CoreCodegenInterface* grpc::g_core_codegen_interface; +grpc::GrpcLibraryInterface* grpc::g_glip; diff --git a/src/cpp/ext/proto_server_reflection.cc b/src/cpp/ext/proto_server_reflection.cc index 348a035f0f3..3973bfb58ea 100644 --- a/src/cpp/ext/proto_server_reflection.cc +++ b/src/cpp/ext/proto_server_reflection.cc @@ -197,8 +197,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers( std::vector extensions; descriptor_pool_->FindAllExtensions(desc, &extensions); - for (auto extension : extensions) { - response->add_extension_number(extension->number()); + for (auto it = extensions.begin(); it != extensions.end(); it++) { + response->add_extension_number((*it)->number()); } response->set_base_type_name(type); return Status::OK; diff --git a/src/cpp/ext/proto_server_reflection_plugin.cc b/src/cpp/ext/proto_server_reflection_plugin.cc index f31d102a9e6..5b806ce1ae1 100644 --- a/src/cpp/ext/proto_server_reflection_plugin.cc +++ b/src/cpp/ext/proto_server_reflection_plugin.cc @@ -60,21 +60,21 @@ void ProtoServerReflectionPlugin::ChangeArguments(const grpc::string& name, void* value) {} bool ProtoServerReflectionPlugin::has_sync_methods() const { - if (reflection_service_ != nullptr) { + if (reflection_service_) { return reflection_service_->has_synchronous_methods(); } return false; } bool ProtoServerReflectionPlugin::has_async_methods() const { - if (reflection_service_ != nullptr) { + if (reflection_service_) { return reflection_service_->has_async_methods(); } return false; } -static std::unique_ptr<::grpc::ServerBuilderPlugin> CreateProtoReflection() { - return std::unique_ptr<::grpc::ServerBuilderPlugin>( +static std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateProtoReflection() { + return std::unique_ptr< ::grpc::ServerBuilderPlugin>( new ProtoServerReflectionPlugin()); } diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 50fc4733a16..fb4c68ebe49 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -67,7 +67,7 @@ static std::shared_ptr g_callbacks = nullptr; static gpr_once g_once_init_callbacks = GPR_ONCE_INIT; static void InitGlobalCallbacks() { - if (g_callbacks == nullptr) { + if (!g_callbacks) { g_callbacks.reset(new DefaultGlobalCallbacks()); } } @@ -324,8 +324,8 @@ Server::~Server() { } void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) { - GPR_ASSERT(g_callbacks == nullptr); - GPR_ASSERT(callbacks != nullptr); + GPR_ASSERT(!g_callbacks); + GPR_ASSERT(callbacks); g_callbacks.reset(callbacks); } diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 279981744ad..45bb858e2ed 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -55,9 +55,10 @@ static void do_plugin_list_init(void) { ServerBuilder::ServerBuilder() : max_message_size_(-1), generic_service_(nullptr) { gpr_once_init(&once_init_plugin_list, do_plugin_list_init); - for (auto factory : (*g_plugin_factory_list)) { - std::unique_ptr plugin = factory(); - plugins_[plugin->name()] = std::move(plugin); + for (auto it = g_plugin_factory_list->begin(); + it != g_plugin_factory_list->end(); it++) { + auto& factory = *it; + plugins_.emplace_back(factory()); } // all compression algorithms enabled by default. enabled_compression_algorithms_bitset_ = @@ -141,7 +142,7 @@ std::unique_ptr ServerBuilder::BuildAndStart() { bool has_sync_methods = false; for (auto it = services_.begin(); it != services_.end(); ++it) { if ((*it)->service->has_synchronous_methods()) { - if (thread_pool == nullptr) { + if (!thread_pool) { thread_pool.reset(CreateDefaultThreadPool()); has_sync_methods = true; break; @@ -153,9 +154,9 @@ std::unique_ptr ServerBuilder::BuildAndStart() { (*option)->UpdateArguments(&args); (*option)->UpdatePlugins(&plugins_); } - if (thread_pool == nullptr) { + if (!thread_pool) { for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) { - if ((*plugin).second->has_sync_methods()) { + if ((*plugin)->has_sync_methods()) { thread_pool.reset(CreateDefaultThreadPool()); has_sync_methods = true; break; @@ -212,7 +213,7 @@ std::unique_ptr ServerBuilder::BuildAndStart() { } } for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) { - (*plugin).second->InitServer(initializer); + (*plugin)->InitServer(initializer); } if (generic_service_) { server->RegisterAsyncGenericService(generic_service_); @@ -238,7 +239,7 @@ std::unique_ptr ServerBuilder::BuildAndStart() { return nullptr; } for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) { - (*plugin).second->Finish(initializer); + (*plugin)->Finish(initializer); } return server; } diff --git a/templates/Makefile.template b/templates/Makefile.template index 079fef65ae8..02039541e65 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -923,6 +923,7 @@ pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc + ifeq ($(EMBED_OPENSSL),true) privatelibs_cxx: \ % for lib in libs: % if 'Makefile' in lib.get('build_system', ['Makefile']): @@ -931,6 +932,18 @@ % endif % endif % endfor + + else + privatelibs_cxx: \ + % for lib in libs: + % if 'Makefile' in lib.get('build_system', ['Makefile']): + % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl: + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endif + % endfor + + endif ifeq ($(HAS_ZOOKEEPER),true) @@ -958,12 +971,23 @@ % endfor + ifeq ($(EMBED_OPENSSL),true) buildtests_cxx: buildtests_zookeeper privatelibs_cxx <%text>\ % for tgt in targets: % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None): $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\ % endif % endfor + + else + buildtests_cxx: buildtests_zookeeper privatelibs_cxx <%text>\ + % for tgt in targets: + % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: + $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\ + % endif + % endfor + + endif ifeq ($(HAS_ZOOKEEPER),true) diff --git a/templates/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile.template b/templates/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile.template index 79567987817..e77b3d9e414 100644 --- a/templates/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile.template @@ -36,7 +36,9 @@ RUN apt-get update && apt-get install -y ${'\\'} gcc-4.4 ${'\\'} - gcc-4.4-multilib + gcc-4.4-multilib ${'\\'} + g++-4.4 ${'\\'} + g++-4.4-multilib RUN wget ${openssl_fallback.base_uri + openssl_fallback.tarball} diff --git a/test/core/support/log_test.c b/test/core/support/log_test.c index 0ae298aa4c0..807a8175d79 100644 --- a/test/core/support/log_test.c +++ b/test/core/support/log_test.c @@ -78,11 +78,13 @@ int main(int argc, char **argv) { gpr_set_log_function(test_callback); gpr_log_message(GPR_INFO, "hello 1 2 3"); gpr_log(GPR_INFO, "hello %d %d %d", 1, 2, 3); + gpr_set_log_function(NULL); /* gpr_log_verbosity_init() will be effective only once, and only before * gpr_set_log_verbosity() is called */ gpr_setenv("GRPC_VERBOSITY", "ERROR"); gpr_log_verbosity_init(); + test_log_function_reached(GPR_ERROR); test_log_function_unreached(GPR_INFO); test_log_function_unreached(GPR_DEBUG); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 8229bda6bf2..6c7eae53a40 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -31,6 +31,7 @@ * */ +#include #include #include @@ -207,12 +208,11 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption { public: void UpdateArguments(ChannelArguments* arg) GRPC_OVERRIDE {} - void UpdatePlugins( - std::map>* plugins) + void UpdatePlugins(std::vector>* plugins) GRPC_OVERRIDE { auto plugin = plugins->begin(); while (plugin != plugins->end()) { - if ((*plugin).second->has_sync_methods()) { + if ((*plugin)->has_sync_methods()) { plugins->erase(plugin++); } else { plugin++; @@ -235,8 +235,11 @@ class TestScenario { disable_blocking, credentials_type.c_str(), message_content.size()); } bool disable_blocking; - const grpc::string credentials_type; - const grpc::string message_content; + // 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 + grpc::string credentials_type; + grpc::string message_content; }; class AsyncEnd2endTest : public ::testing::TestWithParam { @@ -940,7 +943,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { // Client sends 3 messages (tags 3, 4 and 5) for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { - send_request.set_message("Ping " + std::to_string(tag_idx)); + send_request.set_message("Ping " + grpc::to_string(tag_idx)); cli_stream->Write(send_request, tag(tag_idx)); Verifier(GetParam().disable_blocking) .Expect(tag_idx, true) @@ -1106,7 +1109,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { // Server sends three messages (tags 3, 4 and 5) // But if want_done tag is true, we might also see tag 11 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { - send_response.set_message("Pong " + std::to_string(tag_idx)); + send_response.set_message("Pong " + grpc::to_string(tag_idx)); srv_stream.Write(send_response, tag(tag_idx)); // Note that we'll add something to the verifier and verify that // something was seen, but it might be tag 11 and not what we @@ -1397,9 +1400,9 @@ std::vector CreateTestScenarios(bool test_disable_blocking, for (auto cred = credentials_types.begin(); cred != credentials_types.end(); ++cred) { for (auto msg = messages.begin(); msg != messages.end(); msg++) { - scenarios.push_back(TestScenario(false, *cred, *msg)); + scenarios.emplace_back(false, *cred, *msg); if (test_disable_blocking) { - scenarios.push_back(TestScenario(true, *cred, *msg)); + scenarios.emplace_back(true, *cred, *msg); } } } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index e3667cf26bd..8de9d339f63 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -199,7 +199,10 @@ class TestScenario { credentials_type.c_str()); } bool use_proxy; - const grpc::string credentials_type; + // Although the below grpc::string is 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 + grpc::string credentials_type; }; class End2endTest : public ::testing::TestWithParam { @@ -329,7 +332,7 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel value in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); auto stream = stub_->RequestStream(&context, &response); @@ -402,7 +405,7 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); request.set_message("hello"); auto stream = stub_->ResponseStream(&context, request); @@ -413,7 +416,7 @@ class End2endServerTryCancelTest : public End2endTest { break; } EXPECT_EQ(response.message(), - request.message() + std::to_string(num_msgs_read)); + request.message() + grpc::to_string(num_msgs_read)); num_msgs_read++; } gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); @@ -479,14 +482,14 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); auto stream = stub_->BidiStream(&context); int num_msgs_read = 0; int num_msgs_sent = 0; while (num_msgs_sent < num_messages) { - request.set_message("hello " + std::to_string(num_msgs_sent)); + request.set_message("hello " + grpc::to_string(num_msgs_sent)); if (!stream->Write(request)) { break; } @@ -548,7 +551,7 @@ TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) { ClientContext context; context.AddMetadata(kServerTryCancelRequest, - std::to_string(CANCEL_BEFORE_PROCESSING)); + grpc::to_string(CANCEL_BEFORE_PROCESSING)); Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); @@ -1431,9 +1434,9 @@ std::vector CreateTestScenarios(bool use_proxy, } for (auto it = credentials_types.begin(); it != credentials_types.end(); ++it) { - scenarios.push_back(TestScenario(false, *it)); + scenarios.emplace_back(false, *it); if (use_proxy) { - scenarios.push_back(TestScenario(true, *it)); + scenarios.emplace_back(true, *it); } } return scenarios; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 2c05db345b4..7e0c0e8a7ca 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -347,47 +347,50 @@ class HybridEnd2endTest : public ::testing::Test { } grpc::testing::UnimplementedService::Service unimplemented_service_; - std::vector > cqs_; + std::vector> cqs_; std::unique_ptr stub_; std::unique_ptr server_; std::ostringstream server_address_; }; TEST_F(HybridEnd2endTest, AsyncEcho) { - EchoTestService::WithAsyncMethod_Echo service; + typedef EchoTestService::WithAsyncMethod_Echo SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread echo_handler_thread( - [this, &service] { HandleEcho(&service, cqs_[0].get(), false); }); + std::thread echo_handler_thread(HandleEcho, &service, cqs_[0].get(), + false); TestAllMethods(); echo_handler_thread.join(); } TEST_F(HybridEnd2endTest, AsyncEchoRequestStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_Echo > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_Echo> + SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread echo_handler_thread( - [this, &service] { HandleEcho(&service, cqs_[0].get(), false); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread echo_handler_thread(HandleEcho, &service, cqs_[0].get(), + false); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); echo_handler_thread.join(); request_stream_handler_thread.join(); } TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream> + SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); response_stream_handler_thread.join(); request_stream_handler_thread.join(); @@ -395,16 +398,17 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream) { // Add a second service with one sync method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream> + SType; + SType service; TestServiceImplDupPkg dup_service; SetUpServer(&service, &dup_service, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); SendEchoToDupService(); response_stream_handler_thread.join(); @@ -413,18 +417,20 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { // Add a second service with one async method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream> + SType; + SType service; duplicate::EchoTestService::AsyncService dup_service; SetUpServer(&service, &dup_service, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); std::thread echo_handler_thread( - [this, &dup_service] { HandleEcho(&dup_service, cqs_[2].get(), true); }); + HandleEcho, &dup_service, + cqs_[2].get(), true); TestAllMethods(); SendEchoToDupService(); response_stream_handler_thread.join(); @@ -437,25 +443,24 @@ TEST_F(HybridEnd2endTest, GenericEcho) { AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); TestAllMethods(); generic_handler_thread.join(); } TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); generic_handler_thread.join(); request_stream_handler_thread.join(); @@ -463,18 +468,18 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { // Add a second service with one sync method. TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_SyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo> + SType; + SType service; AsyncGenericService generic_service; TestServiceImplDupPkg dup_service; SetUpServer(&service, &dup_service, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); SendEchoToDupService(); generic_handler_thread.join(); @@ -483,20 +488,21 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_SyncDupService) { // Add a second service with one async method. TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_AsyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo> + SType; + SType service; AsyncGenericService generic_service; duplicate::EchoTestService::AsyncService dup_service; SetUpServer(&service, &dup_service, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); std::thread echo_handler_thread( - [this, &dup_service] { HandleEcho(&dup_service, cqs_[2].get(), true); }); + HandleEcho, &dup_service, + cqs_[2].get(), true); TestAllMethods(); SendEchoToDupService(); generic_handler_thread.join(); @@ -505,20 +511,20 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_AsyncDupService) { } TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { - EchoTestService::WithAsyncMethod_RequestStream< + typedef EchoTestService::WithAsyncMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream > > - service; + EchoTestService::WithAsyncMethod_ResponseStream>> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[2].get()); TestAllMethods(); generic_handler_thread.join(); request_stream_handler_thread.join(); @@ -526,21 +532,20 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { } TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { - EchoTestService::WithGenericMethod_RequestStream< + typedef EchoTestService::WithGenericMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream > > - service; + EchoTestService::WithAsyncMethod_ResponseStream>> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread generic_handler_thread2([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[1].get()); - }); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread generic_handler_thread2(HandleGenericCall, &generic_service, + cqs_[1].get()); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[2].get()); TestAllMethods(); generic_handler_thread.join(); generic_handler_thread2.join(); @@ -552,7 +557,7 @@ TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { TEST_F(HybridEnd2endTest, GenericMethodWithoutGenericService) { EchoTestService::WithGenericMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream > > + EchoTestService::WithAsyncMethod_ResponseStream>> service; SetUpServer(&service, nullptr, nullptr); EXPECT_EQ(nullptr, server_.get()); diff --git a/test/cpp/end2end/server_builder_plugin_test.cc b/test/cpp/end2end/server_builder_plugin_test.cc index 1c1095087a3..75f23b64a73 100644 --- a/test/cpp/end2end/server_builder_plugin_test.cc +++ b/test/cpp/end2end/server_builder_plugin_test.cc @@ -113,15 +113,14 @@ class InsertPluginServerBuilderOption : public ServerBuilderOption { void UpdateArguments(ChannelArguments* arg) GRPC_OVERRIDE {} - void UpdatePlugins( - std::map>* plugins) + void UpdatePlugins(std::vector>* plugins) GRPC_OVERRIDE { plugins->clear(); std::unique_ptr plugin( new TestServerBuilderPlugin()); if (register_service_) plugin->SetRegisterService(); - (*plugins)[plugin->name()] = std::move(plugin); + plugins->emplace_back(std::move(plugin)); } void SetRegisterService() { register_service_ = true; } @@ -162,7 +161,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { void InsertPlugin() { if (GetParam()) { // Add ServerBuilder plugin in static initialization - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); + CheckPresent(); } else { // Add ServerBuilder plugin using ServerBuilder::SetOption() builder_->SetOption(std::unique_ptr( @@ -173,10 +172,8 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { void InsertPluginWithTestService() { if (GetParam()) { // Add ServerBuilder plugin in static initialization - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); - auto plugin = static_cast( - builder_->plugins_[PLUGIN_NAME].get()); - EXPECT_TRUE(plugin != nullptr); + auto plugin = CheckPresent(); + EXPECT_TRUE(plugin); plugin->SetRegisterService(); } else { // Add ServerBuilder plugin using ServerBuilder::SetOption() @@ -192,7 +189,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { builder_->AddListeningPort(server_address, InsecureServerCredentials()); cq_ = builder_->AddCompletionQueue(); server_ = builder_->BuildAndStart(); - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); + EXPECT_TRUE(CheckPresent()); } void ResetStub() { @@ -202,10 +199,8 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { } void TearDown() GRPC_OVERRIDE { - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); - auto plugin = static_cast( - builder_->plugins_[PLUGIN_NAME].get()); - EXPECT_TRUE(plugin != nullptr); + auto plugin = CheckPresent(); + EXPECT_TRUE(plugin); EXPECT_TRUE(plugin->init_server_is_called()); EXPECT_TRUE(plugin->finish_is_called()); server_->Shutdown(); @@ -230,6 +225,19 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam { std::unique_ptr server_; TestServiceImpl service_; int port_; + + private: + TestServerBuilderPlugin* CheckPresent() { + auto it = builder_->plugins_.begin(); + for (; it != builder_->plugins_.end(); it++) { + if ((*it)->name() == PLUGIN_NAME) break; + } + if (it != builder_->plugins_.end()) { + return static_cast(it->get()); + } else { + return nullptr; + } + } }; TEST_P(ServerBuilderPluginTest, PluginWithoutServiceTest) { diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index cbaee922289..52abd80d690 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -33,6 +33,7 @@ #include "test/cpp/end2end/test_service_impl.h" +#include #include #include @@ -253,7 +254,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context, } for (int i = 0; i < kNumResponseStreamsMsgs; i++) { - response.set_message(request->message() + std::to_string(i)); + response.set_message(request->message() + grpc::to_string(i)); writer->Write(response); } diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 94541f9a453..b021b345236 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -230,7 +230,7 @@ class CommonStressTestSyncServer : public CommonStressTest { }; class CommonStressTestAsyncServer - : public CommonStressTest<::grpc::testing::EchoTestService::AsyncService> { + : public CommonStressTest { public: void SetUp() GRPC_OVERRIDE { shutting_down_ = false; @@ -394,7 +394,7 @@ class AsyncClientEnd2endTest : public ::testing::Test { for (int i = 0; i < num_rpcs; ++i) { AsyncClientCall* call = new AsyncClientCall; EchoRequest request; - request.set_message("Hello: " + std::to_string(i)); + request.set_message("Hello: " + grpc::to_string(i)); call->response_reader = common_.GetStub()->AsyncEcho(&call->context, request, &cq_); call->response_reader->Finish(&call->response, &call->status, diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 0bf1fd6f737..608f902d6fe 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -31,10 +31,8 @@ * */ -#include "test/cpp/interop/interop_client.h" - #include - +#include #include #include @@ -51,6 +49,7 @@ #include "src/proto/grpc/testing/messages.grpc.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" #include "test/cpp/interop/client_helper.h" +#include "test/cpp/interop/interop_client.h" namespace grpc { namespace testing { diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index ae75762bb8f..c8d6810c12e 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -45,9 +45,9 @@ namespace grpc { namespace testing { // Function pointer for custom checks. -using CheckerFn = - std::function; +typedef std::function + CheckerFn; class InteropClient { public: diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 6ad4c320b55..3d98ab09390 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -249,7 +249,8 @@ class AsyncUnaryClient GRPC_FINAL : public AsyncClient { public: explicit AsyncUnaryClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, BenchmarkStubCreator) { + : AsyncClient( + config, SetupCtx, BenchmarkStubCreator) { StartThreads(num_async_threads_); } ~AsyncUnaryClient() GRPC_OVERRIDE { EndThreads(); } @@ -376,7 +377,8 @@ class AsyncStreamingClient GRPC_FINAL : public AsyncClient { public: explicit AsyncStreamingClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, BenchmarkStubCreator) { + : AsyncClient( + config, SetupCtx, BenchmarkStubCreator) { StartThreads(num_async_threads_); } @@ -511,7 +513,8 @@ class GenericAsyncStreamingClient GRPC_FINAL : public AsyncClient { public: explicit GenericAsyncStreamingClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, GenericStubCreator) { + : AsyncClient(config, SetupCtx, + GenericStubCreator) { StartThreads(num_async_threads_); } diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 83dbdc3e59e..08bf0458832 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -31,6 +31,7 @@ * */ +#include #include #include #include diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc index cc6b39b7532..1c7cd6382a8 100644 --- a/test/cpp/util/metrics_server.cc +++ b/test/cpp/util/metrics_server.cc @@ -99,7 +99,7 @@ std::shared_ptr MetricsServiceImpl::CreateQpsGauge( std::lock_guard lock(mu_); std::shared_ptr qps_gauge(new QpsGauge()); - const auto p = qps_gauges_.emplace(name, qps_gauge); + const auto p = qps_gauges_.insert(std::make_pair(name, qps_gauge)); // p.first is an iterator pointing to > pair. // p.second is a boolean which is set to 'true' if the QpsGauge is @@ -114,7 +114,7 @@ std::shared_ptr MetricsServiceImpl::CreateQpsGauge( std::unique_ptr MetricsServiceImpl::StartServer(int port) { gpr_log(GPR_INFO, "Building metrics server.."); - const grpc::string address = "0.0.0.0:" + std::to_string(port); + const grpc::string address = "0.0.0.0:" + grpc::to_string(port); ServerBuilder builder; builder.AddListeningPort(address, grpc::InsecureServerCredentials()); diff --git a/test/cpp/util/proto_reflection_descriptor_database.cc b/test/cpp/util/proto_reflection_descriptor_database.cc index 6907d97bd5e..25b720aee0a 100644 --- a/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/test/cpp/util/proto_reflection_descriptor_database.cc @@ -298,7 +298,7 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse( const std::shared_ptr ProtoReflectionDescriptorDatabase::GetStream() { - if (stream_ == nullptr) { + if (!stream_) { stream_ = stub_->ServerReflectionInfo(&ctx_); } return stream_; diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 9c09a73115b..6e68f59e6ac 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -41,15 +41,9 @@ #include "test/core/end2end/data/ssl_test_data.h" +namespace grpc { namespace { -using grpc::ChannelArguments; -using grpc::ChannelCredentials; -using grpc::InsecureChannelCredentials; -using grpc::InsecureServerCredentials; -using grpc::ServerCredentials; -using grpc::SslCredentialsOptions; -using grpc::SslServerCredentialsOptions; using grpc::testing::CredentialTypeProvider; // Provide test credentials. Thread-safe. @@ -69,19 +63,27 @@ class CredentialsProvider { class DefaultCredentialsProvider : public CredentialsProvider { public: - ~DefaultCredentialsProvider() override {} + ~DefaultCredentialsProvider() GRPC_OVERRIDE {} - void AddSecureType( - const grpc::string& type, - std::unique_ptr type_provider) override { + void AddSecureType(const grpc::string& type, + std::unique_ptr type_provider) + GRPC_OVERRIDE { // This clobbers any existing entry for type, except the defaults, which // can't be clobbered. grpc::unique_lock lock(mu_); - added_secure_types_[type] = std::move(type_provider); + auto it = std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type); + if (it == added_secure_type_names_.end()) { + added_secure_type_names_.push_back(type); + added_secure_type_providers_.push_back(std::move(type_provider)); + } else { + added_secure_type_providers_[it - added_secure_type_names_.begin()] = + std::move(type_provider); + } } std::shared_ptr GetChannelCredentials( - const grpc::string& type, ChannelArguments* args) override { + const grpc::string& type, ChannelArguments* args) GRPC_OVERRIDE { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureChannelCredentials(); } else if (type == grpc::testing::kTlsCredentialsType) { @@ -90,17 +92,19 @@ class DefaultCredentialsProvider : public CredentialsProvider { return SslCredentials(ssl_opts); } else { grpc::unique_lock lock(mu_); - auto it(added_secure_types_.find(type)); - if (it == added_secure_types_.end()) { + auto it(std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type)); + if (it == added_secure_type_names_.end()) { gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); return nullptr; } - return it->second->GetChannelCredentials(args); + return added_secure_type_providers_[it - added_secure_type_names_.begin()] + ->GetChannelCredentials(args); } } std::shared_ptr GetServerCredentials( - const grpc::string& type) override { + const grpc::string& type) GRPC_OVERRIDE { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureServerCredentials(); } else if (type == grpc::testing::kTlsCredentialsType) { @@ -112,28 +116,32 @@ class DefaultCredentialsProvider : public CredentialsProvider { return SslServerCredentials(ssl_opts); } else { grpc::unique_lock lock(mu_); - auto it(added_secure_types_.find(type)); - if (it == added_secure_types_.end()) { + auto it(std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type)); + if (it == added_secure_type_names_.end()) { gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); return nullptr; } - return it->second->GetServerCredentials(); + return added_secure_type_providers_[it - added_secure_type_names_.begin()] + ->GetServerCredentials(); } } - std::vector GetSecureCredentialsTypeList() override { + std::vector GetSecureCredentialsTypeList() GRPC_OVERRIDE { std::vector types; types.push_back(grpc::testing::kTlsCredentialsType); grpc::unique_lock lock(mu_); - for (const auto& type_pair : added_secure_types_) { - types.push_back(type_pair.first); + for (auto it = added_secure_type_names_.begin(); + it != added_secure_type_names_.end(); it++) { + types.push_back(*it); } return types; } private: grpc::mutex mu_; - std::unordered_map > - added_secure_types_; + std::vector added_secure_type_names_; + std::vector> + added_secure_type_providers_; }; gpr_once g_once_init_provider = GPR_ONCE_INIT; @@ -148,7 +156,6 @@ CredentialsProvider* GetProvider() { } // namespace -namespace grpc { namespace testing { void AddSecureType(const grpc::string& type, diff --git a/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile b/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile index 6f330f9166c..dd9a79b1ed5 100644 --- a/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile +++ b/tools/dockerfile/test/cxx_wheezy_x64/Dockerfile @@ -70,7 +70,9 @@ RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev c RUN apt-get update && apt-get install -y \ gcc-4.4 \ - gcc-4.4-multilib + gcc-4.4-multilib \ + g++-4.4 \ + g++-4.4-multilib RUN wget https://openssl.org/source/old/1.0.2/openssl-1.0.2f.tar.gz diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 882b3494b29..ab42c49292c 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -793,6 +793,7 @@ argp.add_argument('-n', '--runs_per_test', default=1, type=runs_per_test_type, help='A positive integer or "inf". If "inf", all tests will run in an ' 'infinite loop. Especially useful in combination with "-f"') argp.add_argument('-r', '--regex', default='.*', type=str) +argp.add_argument('--regex_exclude', default='', type=str) argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int) argp.add_argument('-s', '--slowdown', default=1.0, type=float) argp.add_argument('-f', '--forever', @@ -1209,7 +1210,9 @@ def _build_and_run( spec for language in languages for spec in language.test_specs() - if re.search(args.regex, spec.shortname)) + if (re.search(args.regex, spec.shortname) and + (args.regex_exclude == '' or + not re.search(args.regex_exclude, spec.shortname)))) # When running on travis, we want out test runs to be as similar as possible # for reproducibility purposes. if args.travis: