diff --git a/BUILD b/BUILD index 9872dc58e5e..4d04c8d518e 100644 --- a/BUILD +++ b/BUILD @@ -897,6 +897,7 @@ grpc_cc_library( name = "grpc++_public_hdrs", hdrs = GRPCXX_PUBLIC_HDRS, external_deps = [ + "absl/log:check", "absl/strings:cord", "absl/synchronization", "protobuf_headers", diff --git a/CMakeLists.txt b/CMakeLists.txt index f15e8576ff4..5c077beadd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ set(gRPC_ABSL_USED_TARGETS absl_bind_front absl_bits absl_charset + absl_check absl_city absl_civil_time absl_cleanup @@ -169,6 +170,8 @@ set(gRPC_ABSL_USED_TARGETS absl_log_entry absl_log_globals absl_log_internal_append_truncated + absl_log_internal_check_impl + absl_log_internal_check_op absl_log_internal_conditions absl_log_internal_config absl_log_internal_fnmatch @@ -4146,6 +4149,7 @@ target_include_directories(grpc++ ) target_link_libraries(grpc++ ${_gRPC_ALLTARGETS_LIBRARIES} + absl::check grpc ${_gRPC_PROTOBUF_LIBRARIES} ) @@ -4887,6 +4891,7 @@ target_include_directories(grpc++_unsecure ) target_link_libraries(grpc++_unsecure ${_gRPC_ALLTARGETS_LIBRARIES} + absl::check grpc_unsecure ${_gRPC_PROTOBUF_LIBRARIES} ) @@ -5815,6 +5820,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) target_link_libraries(fd_conservation_posix_test ${_gRPC_ALLTARGETS_LIBRARIES} + absl::check grpc_test_util ) @@ -6128,6 +6134,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) target_link_libraries(address_sorting_test_unsecure ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc++_unsecure grpc_test_util_unsecure grpc++_test_config @@ -8332,6 +8339,7 @@ target_include_directories(buffer_list_test target_link_libraries(buffer_list_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -12865,6 +12873,7 @@ target_include_directories(endpoint_pair_test target_link_libraries(endpoint_pair_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -13015,6 +13024,7 @@ target_include_directories(error_test target_link_libraries(error_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -15345,7 +15355,6 @@ target_include_directories(grpc_cli target_link_libraries(grpc_cli ${_gRPC_ALLTARGETS_LIBRARIES} - absl::check grpc++ ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} grpc++_test_config @@ -23760,6 +23769,7 @@ target_include_directories(resolve_address_using_ares_resolver_test target_link_libraries(resolve_address_using_ares_resolver_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util grpc++_test_config ) @@ -23866,6 +23876,7 @@ target_include_directories(resolve_address_using_native_resolver_test target_link_libraries(resolve_address_using_native_resolver_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util grpc++_test_config ) @@ -26606,6 +26617,7 @@ target_include_directories(secure_endpoint_test target_link_libraries(secure_endpoint_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -28454,6 +28466,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) target_link_libraries(socket_utils_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -29595,6 +29608,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) target_link_libraries(tcp_posix_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc_test_util ) @@ -30382,6 +30396,7 @@ target_include_directories(test_cpp_client_credentials_test target_link_libraries(test_cpp_client_credentials_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc++ grpc_test_util ) @@ -30541,6 +30556,7 @@ target_include_directories(test_cpp_server_credentials_test target_link_libraries(test_cpp_server_credentials_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc++ grpc_test_util ) @@ -30960,6 +30976,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) target_link_libraries(time_jump_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc++ grpc_test_util ) @@ -31203,6 +31220,7 @@ target_include_directories(timer_test target_link_libraries(timer_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + absl::check grpc++ grpc_test_util ) @@ -36957,7 +36975,7 @@ generate_pkgconfig( "gRPC++" "C++ wrapper for gRPC" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" "libcares openssl re2 zlib" "-lgrpc++" "-laddress_sorting -lupb_textformat_lib -lupb_json_lib -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36968,7 +36986,7 @@ generate_pkgconfig( "gRPC++ unsecure" "C++ wrapper for gRPC without SSL" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" "libcares zlib" "-lgrpc++_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index aaacf89bd7a..e1fa1842c2b 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -3937,6 +3937,7 @@ libs: - src/cpp/util/string_ref.cc - src/cpp/util/time_cc.cc deps: + - absl/log:check - grpc - protobuf baselib: true @@ -4310,6 +4311,7 @@ libs: - src/cpp/util/string_ref.cc - src/cpp/util/time_cc.cc deps: + - absl/log:check - grpc_unsecure - protobuf baselib: true @@ -5140,6 +5142,7 @@ targets: - test/core/util/slice_splitter.cc - test/core/util/tracer_util.cc deps: + - absl/log:check - grpc_test_util platforms: - linux @@ -5310,6 +5313,7 @@ targets: - test/cpp/util/subprocess.cc deps: - gtest + - absl/log:check - grpc++_unsecure - grpc_test_util_unsecure - grpc++_test_config @@ -6274,6 +6278,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util - name: byte_buffer_test gtest: true @@ -8985,6 +8990,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util - name: env_test gtest: true @@ -9042,6 +9048,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util uses_polling: false - name: error_utils_test @@ -10519,7 +10526,6 @@ targets: - test/cpp/util/proto_reflection_descriptor_database.cc - test/cpp/util/service_describer.cc deps: - - absl/log:check - grpc++ - protoc - grpc++_test_config @@ -15310,6 +15316,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util - grpc++_test_config - name: resolve_address_using_native_resolver_posix_test @@ -15379,6 +15386,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util - grpc++_test_config - name: resource_quota_end2end_stress_test @@ -17759,6 +17767,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util - name: security_connector_test gtest: true @@ -18704,6 +18713,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util platforms: - linux @@ -19183,6 +19193,7 @@ targets: - test/core/util/tracer_util.cc deps: - gtest + - absl/log:check - grpc_test_util platforms: - linux @@ -19584,6 +19595,7 @@ targets: - test/cpp/util/tls_test_utils.cc deps: - gtest + - absl/log:check - grpc++ - grpc_test_util - name: test_cpp_end2end_ssl_credentials_test @@ -19651,6 +19663,7 @@ targets: - test/cpp/util/tls_test_utils.cc deps: - gtest + - absl/log:check - grpc++ - grpc_test_util - name: test_cpp_util_slice_test @@ -19782,6 +19795,7 @@ targets: - test/cpp/common/time_jump_test.cc deps: - gtest + - absl/log:check - grpc++ - grpc_test_util platforms: @@ -19914,6 +19928,7 @@ targets: - test/cpp/common/timer_test.cc deps: - gtest + - absl/log:check - grpc++ - grpc_test_util - name: tls_certificate_verifier_test diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index a22f9661f96..0f4908c8e2b 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -242,6 +242,7 @@ Pod::Spec.new do |s| ss.dependency 'abseil/functional/bind_front', abseil_version ss.dependency 'abseil/functional/function_ref', abseil_version ss.dependency 'abseil/hash/hash', abseil_version + ss.dependency 'abseil/log/check', abseil_version ss.dependency 'abseil/log/log', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/meta/type_traits', abseil_version diff --git a/include/grpcpp/client_context.h b/include/grpcpp/client_context.h index 7493f6a8601..2328e3e6fc6 100644 --- a/include/grpcpp/client_context.h +++ b/include/grpcpp/client_context.h @@ -38,6 +38,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -246,7 +248,7 @@ class ClientContext { /// \return A multimap of initial metadata key-value pairs from the server. const std::multimap& GetServerInitialMetadata() const { - GPR_ASSERT(initial_metadata_received_); + CHECK(initial_metadata_received_); return *recv_initial_metadata_.map(); } diff --git a/include/grpcpp/completion_queue.h b/include/grpcpp/completion_queue.h index 23c98e09749..bfd138b5945 100644 --- a/include/grpcpp/completion_queue.h +++ b/include/grpcpp/completion_queue.h @@ -34,6 +34,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -323,7 +325,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; if (tag->FinalizeResult(&ignored, &ok)) { - GPR_ASSERT(ignored == tag); + CHECK(ignored == tag); return ok; } } @@ -344,7 +346,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; // the tag must be swallowed if using TryPluck - GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok)); + CHECK(!tag->FinalizeResult(&ignored, &ok)); } /// Performs a single polling pluck on \a tag. Calls tag->FinalizeResult if @@ -361,7 +363,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary { bool ok = ev.success != 0; void* ignored = tag; - GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok)); + CHECK(!tag->FinalizeResult(&ignored, &ok)); } /// Manage state of avalanching operations : completion queue tags that diff --git a/include/grpcpp/impl/call_op_set.h b/include/grpcpp/impl/call_op_set.h index 48c958a96f6..56ce6289082 100644 --- a/include/grpcpp/impl/call_op_set.h +++ b/include/grpcpp/impl/call_op_set.h @@ -23,6 +23,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -316,7 +318,7 @@ class CallOpSendMessage { return; } if (msg_ != nullptr) { - GPR_ASSERT(serializer_(msg_).ok()); + CHECK(serializer_(msg_).ok()); } serializer_ = nullptr; grpc_op* op = &ops[(*nops)++]; @@ -795,7 +797,7 @@ class CallOpClientRecvStatus { if (recv_status_ == nullptr || hijacked_) return; if (static_cast(status_code_) == StatusCode::OK) { *recv_status_ = Status(); - GPR_DEBUG_ASSERT(debug_error_string_ == nullptr); + DCHECK_EQ(debug_error_string_, nullptr); } else { *recv_status_ = Status(static_cast(status_code_), @@ -974,7 +976,7 @@ class CallOpSet : public CallOpSetInterface, // WritesDone multiple times gpr_log(GPR_ERROR, "API misuse of type %s observed", grpc_call_error_to_string(err)); - GPR_ASSERT(false); + CHECK(false); } } @@ -984,8 +986,8 @@ class CallOpSet : public CallOpSetInterface, done_intercepting_ = true; // The following call_start_batch is internally-generated so no need for an // explanatory log on failure. - GPR_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(), - nullptr) == GRPC_CALL_OK); + CHECK(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(), + nullptr) == GRPC_CALL_OK); } private: diff --git a/include/grpcpp/impl/interceptor_common.h b/include/grpcpp/impl/interceptor_common.h index 81e66df4095..f8b104ba89c 100644 --- a/include/grpcpp/impl/interceptor_common.h +++ b/include/grpcpp/impl/interceptor_common.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -56,16 +58,15 @@ class InterceptorBatchMethodsImpl if (call_->client_rpc_info() != nullptr) { return ProceedClient(); } - GPR_ASSERT(call_->server_rpc_info() != nullptr); + CHECK_NE(call_->server_rpc_info(), nullptr); ProceedServer(); } void Hijack() override { // Only the client can hijack when sending down initial metadata - GPR_ASSERT(!reverse_ && ops_ != nullptr && - call_->client_rpc_info() != nullptr); + CHECK(!reverse_ && ops_ != nullptr && call_->client_rpc_info() != nullptr); // It is illegal to call Hijack twice - GPR_ASSERT(!ran_hijacking_interceptor_); + CHECK(!ran_hijacking_interceptor_); auto* rpc_info = call_->client_rpc_info(); rpc_info->hijacked_ = true; rpc_info->hijacked_interceptor_ = current_interceptor_index_; @@ -80,21 +81,21 @@ class InterceptorBatchMethodsImpl } ByteBuffer* GetSerializedSendMessage() override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); if (*orig_send_message_ != nullptr) { - GPR_ASSERT(serializer_(*orig_send_message_).ok()); + CHECK(serializer_(*orig_send_message_).ok()); *orig_send_message_ = nullptr; } return send_message_; } const void* GetSendMessage() override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); return *orig_send_message_; } void ModifySendMessage(const void* message) override { - GPR_ASSERT(orig_send_message_ != nullptr); + CHECK_NE(orig_send_message_, nullptr); *orig_send_message_ = message; } @@ -129,7 +130,7 @@ class InterceptorBatchMethodsImpl Status* GetRecvStatus() override { return recv_status_; } void FailHijackedSendMessage() override { - GPR_ASSERT(hooks_[static_cast( + CHECK(hooks_[static_cast( experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); *fail_send_message_ = true; } @@ -192,7 +193,7 @@ class InterceptorBatchMethodsImpl } void FailHijackedRecvMessage() override { - GPR_ASSERT(hooks_[static_cast( + CHECK(hooks_[static_cast( experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); *hijacked_recv_message_failed_ = true; } @@ -236,7 +237,7 @@ class InterceptorBatchMethodsImpl // ContinueFinalizeOpsAfterInterception will be called. Note that neither of // them is invoked if there were no interceptors registered. bool RunInterceptors() { - GPR_ASSERT(ops_); + CHECK(ops_); auto* client_rpc_info = call_->client_rpc_info(); if (client_rpc_info != nullptr) { if (client_rpc_info->interceptors_.empty()) { @@ -261,8 +262,8 @@ class InterceptorBatchMethodsImpl // SyncRequest. bool RunInterceptors(std::function f) { // This is used only by the server for initial call request - GPR_ASSERT(reverse_ == true); - GPR_ASSERT(call_->client_rpc_info() == nullptr); + CHECK_EQ(reverse_, true); + CHECK_EQ(call_->client_rpc_info(), nullptr); auto* server_rpc_info = call_->server_rpc_info(); if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) { return true; @@ -356,7 +357,7 @@ class InterceptorBatchMethodsImpl return ops_->ContinueFinalizeResultAfterInterception(); } } - GPR_ASSERT(callback_); + CHECK(callback_); callback_(); } @@ -422,112 +423,98 @@ class CancelInterceptorBatchMethods void Hijack() override { // Only the client can hijack when sending down initial metadata - GPR_ASSERT(false && - "It is illegal to call Hijack on a method which has a " - "Cancel notification"); + CHECK(false) << "It is illegal to call Hijack on a method which has a " + "Cancel notification"; } ByteBuffer* GetSerializedSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetSendMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendMessage on a method which " + "has a Cancel notification"; return nullptr; } bool GetSendMessageStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetSendMessageStatus on a method which " - "has a Cancel notification"); + CHECK(false) + << "It is illegal to call GetSendMessageStatus on a method which " + "has a Cancel notification"; return false; } const void* GetSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetOriginalSendMessage on a method which " - "has a Cancel notification"); + CHECK(false) + << "It is illegal to call GetOriginalSendMessage on a method which " + "has a Cancel notification"; return nullptr; } void ModifySendMessage(const void* /*message*/) override { - GPR_ASSERT(false && - "It is illegal to call ModifySendMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call ModifySendMessage on a method which " + "has a Cancel notification"; } std::multimap* GetSendInitialMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetSendInitialMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendInitialMetadata on a " + "method which has a Cancel notification"; return nullptr; } Status GetSendStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetSendStatus on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendStatus on a method which " + "has a Cancel notification"; return Status(); } void ModifySendStatus(const Status& /*status*/) override { - GPR_ASSERT(false && - "It is illegal to call ModifySendStatus on a method " - "which has a Cancel notification"); + CHECK(false) << "It is illegal to call ModifySendStatus on a method " + "which has a Cancel notification"; } std::multimap* GetSendTrailingMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetSendTrailingMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetSendTrailingMetadata on a " + "method which has a Cancel notification"; return nullptr; } void* GetRecvMessage() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvMessage on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvMessage on a method which " + "has a Cancel notification"; return nullptr; } std::multimap* GetRecvInitialMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvInitialMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvInitialMetadata on a " + "method which has a Cancel notification"; return nullptr; } Status* GetRecvStatus() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvStatus on a method which " - "has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvStatus on a method which " + "has a Cancel notification"; return nullptr; } std::multimap* GetRecvTrailingMetadata() override { - GPR_ASSERT(false && - "It is illegal to call GetRecvTrailingMetadata on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetRecvTrailingMetadata on a " + "method which has a Cancel notification"; return nullptr; } std::unique_ptr GetInterceptedChannel() override { - GPR_ASSERT(false && - "It is illegal to call GetInterceptedChannel on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call GetInterceptedChannel on a " + "method which has a Cancel notification"; return std::unique_ptr(nullptr); } void FailHijackedRecvMessage() override { - GPR_ASSERT(false && - "It is illegal to call FailHijackedRecvMessage on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call FailHijackedRecvMessage on a " + "method which has a Cancel notification"; } void FailHijackedSendMessage() override { - GPR_ASSERT(false && - "It is illegal to call FailHijackedSendMessage on a " - "method which has a Cancel notification"); + CHECK(false) << "It is illegal to call FailHijackedSendMessage on a " + "method which has a Cancel notification"; } }; } // namespace internal diff --git a/include/grpcpp/impl/proto_utils.h b/include/grpcpp/impl/proto_utils.h index c6240ffa84d..0cd4d1bdb4b 100644 --- a/include/grpcpp/impl/proto_utils.h +++ b/include/grpcpp/impl/proto_utils.h @@ -21,6 +21,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -51,8 +53,8 @@ Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb, if (static_cast(byte_size) <= GRPC_SLICE_INLINED_SIZE) { Slice slice(byte_size); // We serialize directly into the allocated slices memory - GPR_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray( - const_cast(slice.begin()))); + CHECK(slice.end() == msg.SerializeWithCachedSizesToArray( + const_cast(slice.begin()))); ByteBuffer tmp(&slice, 1); bb->Swap(&tmp); diff --git a/include/grpcpp/impl/rpc_service_method.h b/include/grpcpp/impl/rpc_service_method.h index 73694263cdd..0ce7d7b96fb 100644 --- a/include/grpcpp/impl/rpc_service_method.h +++ b/include/grpcpp/impl/rpc_service_method.h @@ -25,6 +25,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -75,7 +77,7 @@ class MethodHandler { // retained by the handler. Returns nullptr if deserialization failed. virtual void* Deserialize(grpc_call* /*call*/, grpc_byte_buffer* req, Status* /*status*/, void** /*handler_data*/) { - GPR_ASSERT(req == nullptr); + CHECK_EQ(req, nullptr); return nullptr; } }; diff --git a/include/grpcpp/impl/server_callback_handlers.h b/include/grpcpp/impl/server_callback_handlers.h index b49e17a2c16..f9839973fe9 100644 --- a/include/grpcpp/impl/server_callback_handlers.h +++ b/include/grpcpp/impl/server_callback_handlers.h @@ -18,6 +18,8 @@ #ifndef GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H #define GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H +#include "absl/log/check.h" + #include #include #include @@ -147,7 +149,7 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be marked inline because it // is directly invoking a user-controlled reaction @@ -335,7 +337,7 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -539,7 +541,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -577,7 +579,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { ctx_->sent_initial_metadata_ = true; } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok()); + CHECK(write_ops_.SendMessagePtr(resp, options).ok()); call_.PerformOps(&write_ops_); } @@ -585,7 +587,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler { grpc::Status s) override { // This combines the write into the finish callback // TODO(vjpai): don't assert - GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok()); + CHECK(finish_ops_.SendMessagePtr(resp, options).ok()); Finish(std::move(s)); } @@ -751,7 +753,7 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler { } void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); this->Ref(); // The callback for this function should not be inlined because it invokes // a user-controlled reaction, but any resulting OnDone can be inlined in @@ -789,14 +791,14 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler { ctx_->sent_initial_metadata_ = true; } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok()); + CHECK(write_ops_.SendMessagePtr(resp, options).ok()); call_.PerformOps(&write_ops_); } void WriteAndFinish(const ResponseType* resp, grpc::WriteOptions options, grpc::Status s) override { // TODO(vjpai): don't assert - GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok()); + CHECK(finish_ops_.SendMessagePtr(resp, options).ok()); Finish(std::move(s)); } diff --git a/include/grpcpp/impl/service_type.h b/include/grpcpp/impl/service_type.h index 9699e2328d4..c284026a0f6 100644 --- a/include/grpcpp/impl/service_type.h +++ b/include/grpcpp/impl/service_type.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_IMPL_SERVICE_TYPE_H #define GRPCPP_IMPL_SERVICE_TYPE_H +#include "absl/log/check.h" + #include #include #include @@ -150,9 +152,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'async' because it has already been " - "marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'async' because it has already been " + "marked as 'generic'."; methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); } @@ -160,9 +162,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw' because it has already " - "been marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."; methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); } @@ -170,10 +172,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx]->handler() != nullptr && - "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'raw'."); + CHECK_NE(methods_[idx]->handler(), nullptr) + << "Cannot mark the method as 'generic' because it has already been " + "marked as 'async' or 'raw'."; methods_[idx].reset(); } @@ -181,8 +182,8 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT(methods_[idx] && methods_[idx]->handler() && - "Cannot mark an async or generic method Streamed"); + CHECK(methods_[idx] && methods_[idx]->handler()) + << "Cannot mark an async or generic method Streamed"; methods_[idx]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special @@ -196,10 +197,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'callback' because it has already been " - "marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'callback' because it has already been " + "marked as 'generic'."; methods_[idx]->SetHandler(handler); methods_[idx]->SetServerApiType( internal::RpcServiceMethod::ApiType::CALL_BACK); @@ -209,10 +209,9 @@ class Service { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. size_t idx = static_cast(index); - GPR_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw callback' because it has already " - "been marked as 'generic'."); + CHECK_NE(methods_[idx].get(), nullptr) + << "Cannot mark the method as 'raw callback' because it has already " + "been marked as 'generic'."; methods_[idx]->SetHandler(handler); methods_[idx]->SetServerApiType( internal::RpcServiceMethod::ApiType::RAW_CALL_BACK); diff --git a/include/grpcpp/impl/sync.h b/include/grpcpp/impl/sync.h index 2fadf6fab1c..9288459196a 100644 --- a/include/grpcpp/impl/sync.h +++ b/include/grpcpp/impl/sync.h @@ -27,6 +27,7 @@ #include +#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include @@ -105,7 +106,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock { ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete; void Release() ABSL_UNLOCK_FUNCTION() { - GPR_DEBUG_ASSERT(!released_); + DCHECK(!released_); released_ = true; mu_->Unlock(); } diff --git a/include/grpcpp/server_interface.h b/include/grpcpp/server_interface.h index 5f8f8b54b0f..129562016ac 100644 --- a/include/grpcpp/server_interface.h +++ b/include/grpcpp/server_interface.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SERVER_INTERFACE_H #define GRPCPP_SERVER_INTERFACE_H +#include "absl/log/check.h" + #include #include #include @@ -318,7 +320,7 @@ class ServerInterface : public internal::CallHook { grpc::CompletionQueue* call_cq, grpc::ServerCompletionQueue* notification_cq, void* tag, Message* message) { - GPR_ASSERT(method); + CHECK(method); new PayloadAsyncRequest(method, this, context, stream, call_cq, notification_cq, tag, message); } @@ -329,7 +331,7 @@ class ServerInterface : public internal::CallHook { grpc::CompletionQueue* call_cq, grpc::ServerCompletionQueue* notification_cq, void* tag) { - GPR_ASSERT(method); + CHECK(method); new NoPayloadAsyncRequest(method, this, context, stream, call_cq, notification_cq, tag); } diff --git a/include/grpcpp/support/async_stream.h b/include/grpcpp/support/async_stream.h index 1bf67d301d5..ebc7aebcf51 100644 --- a/include/grpcpp/support/async_stream.h +++ b/include/grpcpp/support/async_stream.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_ASYNC_STREAM_H #define GRPCPP_SUPPORT_ASYNC_STREAM_H +#include "absl/log/check.h" + #include #include #include @@ -200,7 +202,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncReader)); + CHECK_EQ(size, sizeof(ClientAsyncReader)); } // This operator should never be called as the memory should be freed as part @@ -208,10 +210,10 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -225,8 +227,8 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { /// calling code can access the received metadata through the /// \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -234,7 +236,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { } void Read(R* msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -249,7 +251,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata received from the server. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -265,12 +267,12 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface { const W& request, bool start, void* tag) : context_(context), call_(call), started_(start) { // TODO(ctiller): don't assert - GPR_ASSERT(init_ops_.SendMessage(request).ok()); + CHECK(init_ops_.SendMessage(request).ok()); init_ops_.ClientSendClose(); if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -348,7 +350,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncWriter)); + CHECK_EQ(size, sizeof(ClientAsyncWriter)); } // This operator should never be called as the memory should be freed as part @@ -356,10 +358,10 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -372,8 +374,8 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { /// associated with this call is updated, and the calling code can access /// the received metadata through the \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -381,27 +383,27 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { } void Write(const W& msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); write_ops_.ClientSendClose(); } // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } void WritesDone(void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -415,7 +417,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { /// - attempts to fill in the \a response parameter passed to this class's /// constructor with the server's response message. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -435,7 +437,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface { if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -515,7 +517,7 @@ class ClientAsyncReaderWriter final public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncReaderWriter)); + CHECK_EQ(size, sizeof(ClientAsyncReaderWriter)); } // This operator should never be called as the memory should be freed as part @@ -523,10 +525,10 @@ class ClientAsyncReaderWriter final // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall(void* tag) override { - GPR_ASSERT(!started_); + CHECK(!started_); started_ = true; StartCallInternal(tag); } @@ -539,8 +541,8 @@ class ClientAsyncReaderWriter final /// is updated with it, and then the receiving initial metadata can /// be accessed through this \a ClientContext. void ReadInitialMetadata(void* tag) override { - GPR_ASSERT(started_); - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(started_); + CHECK(!context_->initial_metadata_received_); meta_ops_.set_output_tag(tag); meta_ops_.RecvInitialMetadata(context_); @@ -548,7 +550,7 @@ class ClientAsyncReaderWriter final } void Read(R* msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); read_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { read_ops_.RecvInitialMetadata(context_); @@ -558,27 +560,27 @@ class ClientAsyncReaderWriter final } void Write(const W& msg, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); if (options.is_last_message()) { options.set_buffer_hint(); write_ops_.ClientSendClose(); } // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } void WritesDone(void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); write_ops_.set_output_tag(tag); write_ops_.ClientSendClose(); call_.PerformOps(&write_ops_); @@ -589,7 +591,7 @@ class ClientAsyncReaderWriter final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void Finish(grpc::Status* status, void* tag) override { - GPR_ASSERT(started_); + CHECK(started_); finish_ops_.set_output_tag(tag); if (!context_->initial_metadata_received_) { finish_ops_.RecvInitialMetadata(context_); @@ -606,7 +608,7 @@ class ClientAsyncReaderWriter final if (start) { StartCallInternal(tag); } else { - GPR_ASSERT(tag == nullptr); + CHECK(tag == nullptr); } } @@ -706,7 +708,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface { /// - The initial metadata that will be sent to the client from this op will /// be taken from the \a ServerContext associated with the call. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -765,7 +767,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface { /// gRPC doesn't take ownership or a reference to \a status, so it is safe to /// to deallocate once FinishWithError returns. void FinishWithError(const grpc::Status& status, void* tag) override { - GPR_ASSERT(!status.ok()); + CHECK(!status.ok()); finish_ops_.set_output_tag(tag); if (!ctx_->sent_initial_metadata_) { finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -855,7 +857,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -871,7 +873,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } @@ -883,7 +885,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } @@ -902,7 +904,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface { write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); options.set_buffer_hint(); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); call_.PerformOps(&write_ops_); } @@ -1021,7 +1023,7 @@ class ServerAsyncReaderWriter final /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_ops_.set_output_tag(tag); meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -1043,7 +1045,7 @@ class ServerAsyncReaderWriter final write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); // TODO(ctiller): don't assert - GPR_ASSERT(write_ops_.SendMessage(msg).ok()); + CHECK(write_ops_.SendMessage(msg).ok()); call_.PerformOps(&write_ops_); } @@ -1053,7 +1055,7 @@ class ServerAsyncReaderWriter final options.set_buffer_hint(); } EnsureInitialMetadataSent(&write_ops_); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); call_.PerformOps(&write_ops_); } @@ -1073,7 +1075,7 @@ class ServerAsyncReaderWriter final write_ops_.set_output_tag(tag); EnsureInitialMetadataSent(&write_ops_); options.set_buffer_hint(); - GPR_ASSERT(write_ops_.SendMessage(msg, options).ok()); + CHECK(write_ops_.SendMessage(msg, options).ok()); write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); call_.PerformOps(&write_ops_); } diff --git a/include/grpcpp/support/async_unary_call.h b/include/grpcpp/support/async_unary_call.h index a831d73f72f..787d3a56e3d 100644 --- a/include/grpcpp/support/async_unary_call.h +++ b/include/grpcpp/support/async_unary_call.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H #define GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H +#include "absl/log/check.h" + #include #include #include @@ -130,7 +132,7 @@ class ClientAsyncResponseReaderHelper { new (grpc_call_arena_alloc(call, sizeof(SingleBufType))) SingleBufType; *single_buf_ptr = single_buf; // TODO(ctiller): don't assert - GPR_ASSERT(single_buf->SendMessage(request).ok()); + CHECK(single_buf->SendMessage(request).ok()); single_buf->ClientSendClose(); // The purpose of the following functions is to type-erase the actual @@ -220,7 +222,7 @@ class ClientAsyncResponseReader final public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientAsyncResponseReader)); + CHECK_EQ(size, sizeof(ClientAsyncResponseReader)); } // This operator should never be called as the memory should be freed as part @@ -228,10 +230,10 @@ class ClientAsyncResponseReader final // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { - GPR_DEBUG_ASSERT(!started_); + DCHECK(!started_); started_ = true; internal::ClientAsyncResponseReaderHelper::StartCall(context_, single_buf_); } @@ -243,8 +245,8 @@ class ClientAsyncResponseReader final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void ReadInitialMetadata(void* tag) override { - GPR_DEBUG_ASSERT(started_); - GPR_DEBUG_ASSERT(!context_->initial_metadata_received_); + DCHECK(started_); + DCHECK(!context_->initial_metadata_received_); read_initial_metadata_(context_, &call_, single_buf_, tag); initial_metadata_read_ = true; } @@ -255,7 +257,7 @@ class ClientAsyncResponseReader final /// - the \a ClientContext associated with this call is updated with /// possible initial and trailing metadata sent from the server. void Finish(R* msg, grpc::Status* status, void* tag) override { - GPR_DEBUG_ASSERT(started_); + DCHECK(started_); finish_(context_, &call_, initial_metadata_read_, single_buf_, &finish_buf_, static_cast(msg), status, tag); } @@ -304,7 +306,7 @@ class ServerAsyncResponseWriter final /// /// \param[in] tag Tag identifying this request. void SendInitialMetadata(void* tag) override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); meta_buf_.set_output_tag(tag); meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_, @@ -373,7 +375,7 @@ class ServerAsyncResponseWriter final /// deallocate them once the Finish operation is complete (i.e. a result /// arrives in the completion queue). void FinishWithError(const grpc::Status& status, void* tag) { - GPR_ASSERT(!status.ok()); + CHECK(!status.ok()); finish_buf_.set_output_tag(tag); if (!ctx_->sent_initial_metadata_) { finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_, diff --git a/include/grpcpp/support/callback_common.h b/include/grpcpp/support/callback_common.h index 6ae8cfb946a..2868de0bd4d 100644 --- a/include/grpcpp/support/callback_common.h +++ b/include/grpcpp/support/callback_common.h @@ -21,6 +21,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -71,7 +73,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(CallbackWithStatusTag)); + CHECK_EQ(size, sizeof(CallbackWithStatusTag)); } // This operator should never be called as the memory should be freed as part @@ -79,7 +81,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } CallbackWithStatusTag(grpc_call* call, std::function f, CompletionQueueTag* ops) @@ -118,7 +120,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor { // The tag was swallowed return; } - GPR_ASSERT(ignored == ops_); + CHECK(ignored == ops_); // Last use of func_ or status_, so ok to move them out auto func = std::move(func_); @@ -137,7 +139,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(CallbackWithSuccessTag)); + CHECK_EQ(size, sizeof(CallbackWithSuccessTag)); } // This operator should never be called as the memory should be freed as part @@ -145,7 +147,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } CallbackWithSuccessTag() : call_(nullptr) {} @@ -162,7 +164,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { // callbacks. void Set(grpc_call* call, std::function f, CompletionQueueTag* ops, bool can_inline) { - GPR_ASSERT(call_ == nullptr); + CHECK_EQ(call_, nullptr); grpc_call_ref(call); call_ = call; func_ = std::move(f); @@ -208,7 +210,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor { #endif bool do_callback = ops_->FinalizeResult(&ignored, &ok); #ifndef NDEBUG - GPR_DEBUG_ASSERT(ignored == ops); + DCHECK(ignored == ops); #endif if (do_callback) { diff --git a/include/grpcpp/support/client_callback.h b/include/grpcpp/support/client_callback.h index 1c420815de4..49e52bb37aa 100644 --- a/include/grpcpp/support/client_callback.h +++ b/include/grpcpp/support/client_callback.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -70,7 +72,7 @@ class CallbackUnaryCallImpl { const InputMessage* request, OutputMessage* result, std::function on_completion) { grpc::CompletionQueue* cq = channel->CallbackCQ(); - GPR_ASSERT(cq != nullptr); + CHECK_NE(cq, nullptr); grpc::internal::Call call(channel->CreateCall(method, context, cq)); using FullCallOpSet = grpc::internal::CallOpSet< @@ -304,7 +306,7 @@ class ClientBidiReactor : public internal::ClientReactor { /// The argument to AddMultipleHolds must be positive. void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); stream_->AddHold(holds); } void RemoveHold() { stream_->RemoveHold(); } @@ -368,7 +370,7 @@ class ClientReadReactor : public internal::ClientReactor { void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); reader_->AddHold(holds); } void RemoveHold() { reader_->RemoveHold(); } @@ -400,7 +402,7 @@ class ClientWriteReactor : public internal::ClientReactor { void AddHold() { AddMultipleHolds(1); } void AddMultipleHolds(int holds) { - GPR_DEBUG_ASSERT(holds > 0); + DCHECK_GT(holds, 0); writer_->AddHold(holds); } void RemoveHold() { writer_->RemoveHold(); } @@ -461,7 +463,7 @@ class ClientCallbackReaderWriterImpl public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackReaderWriterImpl)); + CHECK_EQ(size, sizeof(ClientCallbackReaderWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -469,7 +471,7 @@ class ClientCallbackReaderWriterImpl // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override { // This call initiates two batches, plus any backlog, each with a callback @@ -527,7 +529,7 @@ class ClientCallbackReaderWriterImpl write_ops_.ClientSendClose(); } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok()); + CHECK(write_ops_.SendMessagePtr(msg, options).ok()); callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed); if (GPR_UNLIKELY(corked_write_needed_)) { write_ops_.SendInitialMetadata(&context_->send_initial_metadata_, @@ -719,7 +721,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackReaderImpl)); + CHECK_EQ(size, sizeof(ClientCallbackReaderImpl)); } // This operator should never be called as the memory should be freed as part @@ -727,7 +729,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { // This call initiates two batches, plus any backlog, each with a callback @@ -804,7 +806,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader { : context_(context), call_(call), reactor_(reactor) { this->BindReactor(reactor); // TODO(vjpai): don't assert - GPR_ASSERT(start_ops_.SendMessagePtr(request).ok()); + CHECK(start_ops_.SendMessagePtr(request).ok()); start_ops_.ClientSendClose(); } @@ -880,7 +882,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackWriterImpl)); + CHECK_EQ(size, sizeof(ClientCallbackWriterImpl)); } // This operator should never be called as the memory should be freed as part @@ -888,7 +890,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override { // This call initiates two batches, plus any backlog, each with a callback @@ -929,7 +931,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter { write_ops_.ClientSendClose(); } // TODO(vjpai): don't assert - GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok()); + CHECK(write_ops_.SendMessagePtr(msg, options).ok()); callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed); if (GPR_UNLIKELY(corked_write_needed_)) { @@ -1110,7 +1112,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { public: // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { - GPR_ASSERT(size == sizeof(ClientCallbackUnaryImpl)); + CHECK_EQ(size, sizeof(ClientCallbackUnaryImpl)); } // This operator should never be called as the memory should be freed as part @@ -1118,7 +1120,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { // delete to the operator new so that some compilers will not complain (see // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this // there are no tests catching the compiler warning. - static void operator delete(void*, void*) { GPR_ASSERT(false); } + static void operator delete(void*, void*) { CHECK(false); } void StartCall() override { // This call initiates two batches, each with a callback @@ -1157,7 +1159,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary { : context_(context), call_(call), reactor_(reactor) { this->BindReactor(reactor); // TODO(vjpai): don't assert - GPR_ASSERT(start_ops_.SendMessagePtr(request).ok()); + CHECK(start_ops_.SendMessagePtr(request).ok()); start_ops_.ClientSendClose(); finish_ops_.RecvMessage(response); finish_ops_.AllowNoMessage(); diff --git a/include/grpcpp/support/client_interceptor.h b/include/grpcpp/support/client_interceptor.h index b2b9dc76917..3bcb2f16256 100644 --- a/include/grpcpp/support/client_interceptor.h +++ b/include/grpcpp/support/client_interceptor.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -139,7 +141,7 @@ class ClientRpcInfo { // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_ASSERT(pos < interceptors_.size()); + CHECK_LT(pos, interceptors_.size()); interceptors_[pos]->Intercept(interceptor_methods); } diff --git a/include/grpcpp/support/method_handler.h b/include/grpcpp/support/method_handler.h index def30a0ad8c..51821c6da38 100644 --- a/include/grpcpp/support/method_handler.h +++ b/include/grpcpp/support/method_handler.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_METHOD_HANDLER_H #define GRPCPP_SUPPORT_METHOD_HANDLER_H +#include "absl/log/check.h" + #include #include #include @@ -57,7 +59,7 @@ template template void UnaryRunHandlerHelper(const MethodHandler::HandlerParameter& param, ResponseType* rsp, grpc::Status& status) { - GPR_ASSERT(!param.server_context->sent_initial_metadata_); + CHECK(!param.server_context->sent_initial_metadata_); grpc::internal::CallOpSet diff --git a/include/grpcpp/support/proto_buffer_reader.h b/include/grpcpp/support/proto_buffer_reader.h index ffec8d76416..f5431d462e4 100644 --- a/include/grpcpp/support/proto_buffer_reader.h +++ b/include/grpcpp/support/proto_buffer_reader.h @@ -21,6 +21,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/cord.h" #include @@ -75,7 +76,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { if (backup_count_ > 0) { *data = GRPC_SLICE_START_PTR(*slice_) + GRPC_SLICE_LENGTH(*slice_) - backup_count_; - GPR_ASSERT(backup_count_ <= INT_MAX); + CHECK_LE(backup_count_, INT_MAX); *size = static_cast(backup_count_); backup_count_ = 0; return true; @@ -86,7 +87,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { } *data = GRPC_SLICE_START_PTR(*slice_); // On win x64, int is only 32bit - GPR_ASSERT(GRPC_SLICE_LENGTH(*slice_) <= INT_MAX); + CHECK_LE(GRPC_SLICE_LENGTH(*slice_), static_cast(INT_MAX)); byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(*slice_)); return true; } @@ -98,7 +99,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { /// bytes that have already been returned by the last call of Next. /// So do the backup and have that ready for a later Next. void BackUp(int count) override { - GPR_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(*slice_))); + CHECK_LE(count, static_cast(GRPC_SLICE_LENGTH(*slice_))); backup_count_ = count; } @@ -174,7 +175,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { return true; } } - GPR_ASSERT(count == 0); + CHECK_EQ(count, 0); return true; } #endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED diff --git a/include/grpcpp/support/proto_buffer_writer.h b/include/grpcpp/support/proto_buffer_writer.h index 83d81060e87..351b2b826d9 100644 --- a/include/grpcpp/support/proto_buffer_writer.h +++ b/include/grpcpp/support/proto_buffer_writer.h @@ -21,6 +21,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/cord.h" #include @@ -64,7 +65,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { total_size_(total_size), byte_count_(0), have_backup_(false) { - GPR_ASSERT(!byte_buffer->Valid()); + CHECK(!byte_buffer->Valid()); /// Create an empty raw byte buffer and look at its underlying slice buffer grpc_byte_buffer* bp = grpc_raw_byte_buffer_create(nullptr, 0); byte_buffer->set_buffer(bp); @@ -81,7 +82,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { /// safe for the caller to write from data[0, size - 1]. bool Next(void** data, int* size) override { // Protobuf should not ask for more memory than total_size_. - GPR_ASSERT(byte_count_ < total_size_); + CHECK_LT(byte_count_, total_size_); // 1. Use the remaining backup slice if we have one // 2. Otherwise allocate a slice, up to the remaining length needed // or our maximum allocation size @@ -106,7 +107,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { } *data = GRPC_SLICE_START_PTR(slice_); // On win x64, int is only 32bit - GPR_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); + CHECK(GRPC_SLICE_LENGTH(slice_) <= static_cast(INT_MAX)); byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(slice_)); // Using grpc_slice_buffer_add could modify slice_ and merge it with the // previous slice. Therefore, use grpc_slice_buffer_add_indexed method to @@ -131,7 +132,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { /// 2. Split it into the needed (if any) and unneeded part /// 3. Add the needed part back to the slice buffer /// 4. Mark that we still have the remaining part (for later use/unref) - GPR_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(slice_))); + CHECK_LE(count, static_cast(GRPC_SLICE_LENGTH(slice_))); grpc_slice_buffer_pop(slice_buffer_); if (static_cast(count) == GRPC_SLICE_LENGTH(slice_)) { backup_slice_ = slice_; diff --git a/include/grpcpp/support/server_interceptor.h b/include/grpcpp/support/server_interceptor.h index ecb4e342598..c30d0aee495 100644 --- a/include/grpcpp/support/server_interceptor.h +++ b/include/grpcpp/support/server_interceptor.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -100,7 +102,7 @@ class ServerRpcInfo { // Runs interceptor at pos \a pos. void RunInterceptor( experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_ASSERT(pos < interceptors_.size()); + CHECK_LT(pos, interceptors_.size()); interceptors_[pos]->Intercept(interceptor_methods); } diff --git a/include/grpcpp/support/sync_stream.h b/include/grpcpp/support/sync_stream.h index ce583f6ed7c..ab6ced7343b 100644 --- a/include/grpcpp/support/sync_stream.h +++ b/include/grpcpp/support/sync_stream.h @@ -19,6 +19,8 @@ #ifndef GRPCPP_SUPPORT_SYNC_STREAM_H #define GRPCPP_SUPPORT_SYNC_STREAM_H +#include "absl/log/check.h" + #include #include #include @@ -184,7 +186,7 @@ class ClientReader final : public ClientReaderInterface { /// the server will be accessible through the \a ClientContext used to /// construct this object. void WaitForInitialMetadata() override { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -230,7 +232,7 @@ class ClientReader final : public ClientReaderInterface { grpc::Status status; ops.ClientRecvStatus(context_, &status); call_.PerformOps(&ops); - GPR_ASSERT(cq_.Pluck(&ops)); + CHECK(cq_.Pluck(&ops)); return status; } @@ -259,7 +261,7 @@ class ClientReader final : public ClientReaderInterface { ops.SendInitialMetadata(&context->send_initial_metadata_, context->initial_metadata_flags()); // TODO(ctiller): don't assert - GPR_ASSERT(ops.SendMessagePtr(&request).ok()); + CHECK(ops.SendMessagePtr(&request).ok()); ops.ClientSendClose(); call_.PerformOps(&ops); cq_.Pluck(&ops); @@ -306,7 +308,7 @@ class ClientWriter : public ClientWriterInterface { /// Once complete, the initial metadata read from the server will be /// accessible through the \a ClientContext used to construct this object. void WaitForInitialMetadata() { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -364,7 +366,7 @@ class ClientWriter : public ClientWriterInterface { } finish_ops_.ClientRecvStatus(context_, &status); call_.PerformOps(&finish_ops_); - GPR_ASSERT(cq_.Pluck(&finish_ops_)); + CHECK(cq_.Pluck(&finish_ops_)); return status; } @@ -455,7 +457,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface { /// Once complete, the initial metadata read from the server will be /// accessible through the \a ClientContext used to construct this object. void WaitForInitialMetadata() override { - GPR_ASSERT(!context_->initial_metadata_received_); + CHECK(!context_->initial_metadata_received_); grpc::internal::CallOpSet ops; ops.RecvInitialMetadata(context_); @@ -536,7 +538,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface { grpc::Status status; ops.ClientRecvStatus(context_, &status); call_.PerformOps(&ops); - GPR_ASSERT(cq_.Pluck(&ops)); + CHECK(cq_.Pluck(&ops)); return status; } @@ -583,7 +585,7 @@ class ServerReader final : public ServerReaderInterface { /// for semantics. Note that initial metadata will be affected by the /// \a ServerContext associated with this call. void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_, @@ -640,7 +642,7 @@ class ServerWriter final : public ServerWriterInterface { /// Note that initial metadata will be affected by the /// \a ServerContext associated with this call. void SendInitialMetadata() override { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_, @@ -713,7 +715,7 @@ class ServerReaderWriterBody final { : call_(call), ctx_(ctx) {} void SendInitialMetadata() { - GPR_ASSERT(!ctx_->sent_initial_metadata_); + CHECK(!ctx_->sent_initial_metadata_); grpc::internal::CallOpSet ops; ops.SendInitialMetadata(&ctx_->initial_metadata_, diff --git a/test/core/iomgr/BUILD b/test/core/iomgr/BUILD index 8fdb9658373..57837c479ea 100644 --- a/test/core/iomgr/BUILD +++ b/test/core/iomgr/BUILD @@ -26,6 +26,7 @@ grpc_cc_library( name = "endpoint_tests", srcs = ["endpoint_tests.cc"], hdrs = ["endpoint_tests.h"], + external_deps = ["absl/log:check"], language = "C++", visibility = [ "//test:__subpackages__", @@ -59,7 +60,10 @@ grpc_cc_test( grpc_cc_test( name = "endpoint_pair_test", srcs = ["endpoint_pair_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:check", + "gtest", + ], language = "C++", tags = [ "endpoint_test", @@ -95,6 +99,7 @@ grpc_cc_test( grpc_cc_test( name = "fd_conservation_posix_test", srcs = ["fd_conservation_posix_test.cc"], + external_deps = ["absl/log:check"], language = "C++", tags = ["no_windows"], deps = [ @@ -180,6 +185,7 @@ grpc_cc_test( name = "resolve_address_using_ares_resolver_test", srcs = ["resolve_address_test.cc"], external_deps = [ + "absl/log:check", "absl/strings", "gtest", ], @@ -198,6 +204,7 @@ grpc_cc_test( name = "resolve_address_using_native_resolver_test", srcs = ["resolve_address_test.cc"], external_deps = [ + "absl/log:check", "absl/strings", "gtest", ], @@ -215,7 +222,10 @@ grpc_cc_test( grpc_cc_test( name = "socket_utils_test", srcs = ["socket_utils_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:check", + "gtest", + ], language = "C++", tags = ["no_windows"], deps = [ @@ -270,7 +280,10 @@ grpc_cc_test( grpc_cc_test( name = "buffer_list_test", srcs = ["buffer_list_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:check", + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/iomgr/buffer_list_test.cc b/test/core/iomgr/buffer_list_test.cc index df46aba58d5..4afd6d591f7 100644 --- a/test/core/iomgr/buffer_list_test.cc +++ b/test/core/iomgr/buffer_list_test.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -37,7 +39,7 @@ extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type); static gpr_timespec g_now; gpr_timespec now_impl(gpr_clock_type clock_type) { - GPR_ASSERT(clock_type != GPR_TIMESPAN); + CHECK(clock_type != GPR_TIMESPAN); gpr_timespec ts = g_now; ts.clock_type = clock_type; return ts; diff --git a/test/core/iomgr/endpoint_pair_test.cc b/test/core/iomgr/endpoint_pair_test.cc index 287b8d3db0b..1e630519856 100644 --- a/test/core/iomgr/endpoint_pair_test.cc +++ b/test/core/iomgr/endpoint_pair_test.cc @@ -22,6 +22,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -58,7 +60,7 @@ grpc_endpoint_pair grpc_iomgr_event_engine_shim_endpoint_pair( std::string target_addr = absl::StrCat( "ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())); auto resolved_addr = URIToResolvedAddress(target_addr); - GPR_ASSERT(resolved_addr.ok()); + CHECK_OK(resolved_addr); std::unique_ptr client_endpoint; std::unique_ptr server_endpoint; grpc_core::Notification client_signal; @@ -80,13 +82,13 @@ grpc_endpoint_pair grpc_iomgr_event_engine_shim_endpoint_pair( std::move(accept_cb), [](absl::Status /*status*/) {}, config, std::make_unique("foo")); - GPR_ASSERT(listener->Bind(*resolved_addr).ok()); - GPR_ASSERT(listener->Start().ok()); + CHECK_OK(listener->Bind(*resolved_addr)); + CHECK_OK(listener->Start()); ee->Connect( [&client_endpoint, &client_signal]( absl::StatusOr> endpoint) { - GPR_ASSERT(endpoint.ok()); + CHECK_OK(endpoint); client_endpoint = std::move(*endpoint); client_signal.Notify(); }, diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc index 1ff46da9765..02cd7b020aa 100644 --- a/test/core/iomgr/endpoint_tests.cc +++ b/test/core/iomgr/endpoint_tests.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -61,7 +63,7 @@ size_t count_slices(grpc_slice* slices, size_t nslices, int* current_data) { for (i = 0; i < nslices; ++i) { buf = GRPC_SLICE_START_PTR(slices[i]); for (j = 0; j < GRPC_SLICE_LENGTH(slices[i]); ++j) { - GPR_ASSERT(buf[j] == *current_data); + CHECK(buf[j] == *current_data); *current_data = (*current_data + 1) % 256; } num_bytes += GRPC_SLICE_LENGTH(slices[i]); @@ -99,7 +101,7 @@ static grpc_slice* allocate_blocks(size_t num_bytes, size_t slice_size, (*current_data)++; } } - GPR_ASSERT(num_bytes_left == 0); + CHECK_EQ(num_bytes_left, 0u); return slices; } @@ -273,9 +275,9 @@ static void read_and_write_test(grpc_endpoint_test_config config, gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { grpc_pollset_worker* worker = nullptr; - GPR_ASSERT(grpc_core::Timestamp::Now() < deadline); - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + CHECK(grpc_core::Timestamp::Now() < deadline); + CHECK(GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(g_pollset, &worker, deadline))); } gpr_mu_unlock(g_mu); grpc_core::ExecCtx::Get()->Flush(); @@ -290,7 +292,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, static void inc_on_failure(void* arg, grpc_error_handle error) { gpr_mu_lock(g_mu); *static_cast(arg) += (!error.ok()); - GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); + CHECK(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); } @@ -302,13 +304,13 @@ static void wait_for_fail_count(int* fail_count, int want_fail_count) { while (grpc_core::Timestamp::Now() < deadline && *fail_count < want_fail_count) { grpc_pollset_worker* worker = nullptr; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline))); + CHECK(GRPC_LOG_IF_ERROR("pollset_work", + grpc_pollset_work(g_pollset, &worker, deadline))); gpr_mu_unlock(g_mu); grpc_core::ExecCtx::Get()->Flush(); gpr_mu_lock(g_mu); } - GPR_ASSERT(*fail_count == want_fail_count); + CHECK(*fail_count == want_fail_count); gpr_mu_unlock(g_mu); } diff --git a/test/core/iomgr/fd_conservation_posix_test.cc b/test/core/iomgr/fd_conservation_posix_test.cc index 2c7d8b7c699..42790583c9f 100644 --- a/test/core/iomgr/fd_conservation_posix_test.cc +++ b/test/core/iomgr/fd_conservation_posix_test.cc @@ -18,6 +18,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -40,7 +42,7 @@ int main(int argc, char** argv) { // verify we can create and destroy many more than this number // of descriptors rlim.rlim_cur = rlim.rlim_max = 1000; - GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); + CHECK_EQ(setrlimit(RLIMIT_NOFILE, &rlim), 0); for (i = 0; i < 10000; i++) { p = grpc_iomgr_create_endpoint_pair("test", nullptr); grpc_endpoint_destroy(p.client); diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index 8e133934ccf..68073e153dd 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -25,6 +25,7 @@ #include #include "absl/functional/bind_front.h" +#include "absl/log/check.h" #include "absl/strings/match.h" #include @@ -546,7 +547,7 @@ int main(int argc, char** argv) { } else if (absl::StrContains(std::string(argv[0]), "using_ares_resolver")) { g_resolver_type = "ares"; } else { - GPR_ASSERT(0); + CHECK(0); } grpc_core::ConfigVars::Overrides overrides; overrides.dns_resolver = g_resolver_type; diff --git a/test/core/iomgr/socket_utils_test.cc b/test/core/iomgr/socket_utils_test.cc index d5b55f1a9fc..4a047dd0ded 100644 --- a/test/core/iomgr/socket_utils_test.cc +++ b/test/core/iomgr/socket_utils_test.cc @@ -28,6 +28,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -198,7 +200,7 @@ TEST(SocketUtilsTest, MainTest) { if (grpc_ipv6_loopback_available()) { sock = socket(AF_INET6, SOCK_STREAM, 0); - GPR_ASSERT(sock > 0); + CHECK_GT(sock, 0); test_set_socket_dscp_ipv6(sock, 8 /*CS1*/); test_set_socket_dscp_ipv6(sock, 16 /*CS2*/); diff --git a/test/core/memory_usage/BUILD b/test/core/memory_usage/BUILD index a0d600a28e0..330d33952b9 100644 --- a/test/core/memory_usage/BUILD +++ b/test/core/memory_usage/BUILD @@ -26,6 +26,7 @@ grpc_cc_library( ], hdrs = ["memstats.h"], external_deps = [ + "absl/log:check", "absl/types:optional", ], tags = [ @@ -44,6 +45,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:check", ], tags = [ "bazel_only", @@ -66,6 +68,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:check", ], tags = [ "bazel_only", @@ -90,6 +93,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:check", "absl/time", ], tags = [ @@ -115,6 +119,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/flags:parse", + "absl/log:check", ], tags = [ "bazel_only", diff --git a/test/core/memory_usage/callback_client.cc b/test/core/memory_usage/callback_client.cc index 723b57f30fe..bd370e8e0f7 100644 --- a/test/core/memory_usage/callback_client.cc +++ b/test/core/memory_usage/callback_client.cc @@ -27,6 +27,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/check.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -124,7 +125,7 @@ std::shared_ptr GetBeforeSnapshot( int main(int argc, char** argv) { absl::ParseCommandLine(argc, argv); char* fake_argv[1]; - GPR_ASSERT(argc >= 1); + CHECK_GE(argc, 1); fake_argv[0] = argv[0]; grpc::testing::TestEnvironment env(&argc, argv); if (absl::GetFlag(FLAGS_target).empty()) { @@ -158,10 +159,10 @@ int main(int argc, char** argv) { // Checking that all channels are still open for (int i = 0; i < size; ++i) { - GPR_ASSERT(!std::exchange(channels_list[i], nullptr) - ->WaitForStateChange(GRPC_CHANNEL_READY, - std::chrono::system_clock::now() + - std::chrono::milliseconds(1))); + CHECK(!std::exchange(channels_list[i], nullptr) + ->WaitForStateChange(GRPC_CHANNEL_READY, + std::chrono::system_clock::now() + + std::chrono::milliseconds(1))); } std::string prefix; diff --git a/test/core/memory_usage/callback_server.cc b/test/core/memory_usage/callback_server.cc index 7737592bb34..ae40b609a1d 100644 --- a/test/core/memory_usage/callback_server.cc +++ b/test/core/memory_usage/callback_server.cc @@ -24,6 +24,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/check.h" #include #include @@ -77,7 +78,7 @@ static void sigint_handler(int /*x*/) { _exit(0); } int main(int argc, char** argv) { absl::ParseCommandLine(argc, argv); char* fake_argv[1]; - GPR_ASSERT(argc >= 1); + CHECK_GE(argc, 1); fake_argv[0] = argv[0]; grpc::testing::TestEnvironment env(&argc, argv); grpc_init(); diff --git a/test/core/memory_usage/client.cc b/test/core/memory_usage/client.cc index 61185fe361e..3f8849d3664 100644 --- a/test/core/memory_usage/client.cc +++ b/test/core/memory_usage/client.cc @@ -27,6 +27,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/check.h" #include "absl/strings/match.h" #include @@ -91,10 +92,10 @@ static void init_ping_pong_request(int call_idx) { grpc_slice_from_static_string("/Reflector/reflectUnary"), &hostname, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, - metadata_ops, - (size_t)(op - metadata_ops), - tag(call_idx), nullptr)); + CHECK(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, + metadata_ops, + (size_t)(op - metadata_ops), + tag(call_idx), nullptr)); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); } @@ -111,10 +112,9 @@ static void finish_ping_pong_request(int call_idx) { op->data.recv_status_on_client.status_details = &calls[call_idx].details; op++; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, - status_ops, - (size_t)(op - status_ops), - tag(call_idx), nullptr)); + CHECK(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, status_ops, + (size_t)(op - status_ops), + tag(call_idx), nullptr)); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv); grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv); @@ -155,17 +155,17 @@ static MemStats send_snapshot_request(int call_idx, grpc_slice call_type) { calls[call_idx].call = grpc_channel_create_call( channel, nullptr, GRPC_PROPAGATE_DEFAULTS, cq, call_type, &hostname, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, - snapshot_ops, - (size_t)(op - snapshot_ops), - (void*)nullptr, nullptr)); + CHECK(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, + snapshot_ops, + (size_t)(op - snapshot_ops), + (void*)nullptr, nullptr)); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); gpr_log(GPR_INFO, "Call %d status %d (%s)", call_idx, calls[call_idx].status, std::string(grpc_core::StringViewFromSlice(calls[call_idx].details)) .c_str()); - GPR_ASSERT(response_payload_recv != nullptr); + CHECK_NE(response_payload_recv, nullptr); grpc_byte_buffer_reader reader; grpc_byte_buffer_reader_init(&reader, response_payload_recv); grpc_slice response = grpc_byte_buffer_reader_readall(&reader); @@ -238,7 +238,7 @@ int main(int argc, char** argv) { grpc_slice slice = grpc_slice_from_copied_string("x"); char* fake_argv[1]; - GPR_ASSERT(argc >= 1); + CHECK_GE(argc, 1); fake_argv[0] = argv[0]; grpc::testing::TestEnvironment env(&argc, argv); diff --git a/test/core/memory_usage/memstats.cc b/test/core/memory_usage/memstats.cc index 5bb34361f93..4a479ca5edd 100644 --- a/test/core/memory_usage/memstats.cc +++ b/test/core/memory_usage/memstats.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include @@ -47,7 +48,7 @@ long GetMemUsage(absl::optional pid) { stat_stream.close(); // pid does not connect to an existing process - GPR_ASSERT(!state.empty()); + CHECK(!state.empty()); // Calculations in case x86-64 is configured to use 2MB pages long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; diff --git a/test/core/memory_usage/server.cc b/test/core/memory_usage/server.cc index a789240f5b3..05fa08a5db7 100644 --- a/test/core/memory_usage/server.cc +++ b/test/core/memory_usage/server.cc @@ -33,6 +33,7 @@ #include "absl/base/attributes.h" #include "absl/flags/flag.h" #include "absl/flags/parse.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include @@ -107,9 +108,8 @@ static void send_initial_metadata_unary(void* tag) { metadata_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA; metadata_ops[0].data.send_initial_metadata.count = 0; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call*)tag).call, - metadata_ops, 1, tag, - nullptr)); + CHECK(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call*)tag).call, + metadata_ops, 1, tag, nullptr)); } static void send_status(void* tag) { @@ -119,9 +119,8 @@ static void send_status(void* tag) { grpc_slice details = grpc_slice_from_static_string(""); status_op.data.send_status_from_server.status_details = &details; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call*)tag).call, - &status_op, 1, tag, - nullptr)); + CHECK(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call*)tag).call, + &status_op, 1, tag, nullptr)); } static void send_snapshot(void* tag, MemStats* snapshot) { @@ -153,9 +152,9 @@ static void send_snapshot(void* tag, MemStats* snapshot) { op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_start_batch((*(fling_call*)tag).call, snapshot_ops, - (size_t)(op - snapshot_ops), tag, nullptr)); + CHECK(GRPC_CALL_OK == + grpc_call_start_batch((*(fling_call*)tag).call, snapshot_ops, + (size_t)(op - snapshot_ops), tag, nullptr)); } // We have some sort of deadlock, so let's not exit gracefully for now. // When that is resolved, please remove the #include above. @@ -179,7 +178,7 @@ int main(int argc, char** argv) { char* fake_argv[1]; - GPR_ASSERT(argc >= 1); + CHECK_GE(argc, 1); fake_argv[0] = argv[0]; grpc::testing::TestEnvironment env(&argc, argv); @@ -226,10 +225,10 @@ int main(int argc, char** argv) { test_server1_cert}; grpc_server_credentials* ssl_creds = grpc_ssl_server_credentials_create( nullptr, &pem_key_cert_pair, 1, 0, nullptr); - GPR_ASSERT(grpc_server_add_http2_port(server, addr.c_str(), ssl_creds)); + CHECK(grpc_server_add_http2_port(server, addr.c_str(), ssl_creds)); grpc_server_credentials_release(ssl_creds); } else { - GPR_ASSERT(grpc_server_add_http2_port( + CHECK(grpc_server_add_http2_port( server, addr.c_str(), grpc_insecure_server_credentials_create())); } @@ -258,10 +257,10 @@ int main(int argc, char** argv) { shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); grpc_server_shutdown_and_notify(server, shutdown_cq, tag(1000)); - GPR_ASSERT(grpc_completion_queue_pluck( - shutdown_cq, tag(1000), - grpc_timeout_seconds_to_deadline(5), nullptr) - .type == GRPC_OP_COMPLETE); + CHECK(grpc_completion_queue_pluck(shutdown_cq, tag(1000), + grpc_timeout_seconds_to_deadline(5), + nullptr) + .type == GRPC_OP_COMPLETE); grpc_completion_queue_destroy(shutdown_cq); grpc_completion_queue_shutdown(cq); shutdown_started = 1; @@ -339,7 +338,7 @@ int main(int argc, char** argv) { } break; case GRPC_QUEUE_SHUTDOWN: - GPR_ASSERT(shutdown_started); + CHECK(shutdown_started); shutdown_finished = 1; break; case GRPC_QUEUE_TIMEOUT: diff --git a/test/cpp/client/BUILD b/test/cpp/client/BUILD index 95fc4aede8e..7fa032a5fa2 100644 --- a/test/cpp/client/BUILD +++ b/test/cpp/client/BUILD @@ -27,6 +27,7 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.pem", ], external_deps = [ + "absl/log:check", "gtest", ], deps = [ diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index e033bc802c8..87e633d854f 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -275,7 +277,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRootsAndDefaultVerifier) { grpc::experimental::TlsChannelCredentialsOptions options; options.set_verify_server_certs(true); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST( @@ -295,21 +297,21 @@ TEST( options.watch_identity_key_cert_pairs(); options.set_identity_cert_name(kIdentityCertName); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithStaticDataCertificateProviderLoadingRootOnly) { auto certificate_provider = std::make_shared(kRootCertContents); - GPR_ASSERT(certificate_provider != nullptr); - GPR_ASSERT(certificate_provider->c_provider() != nullptr); + CHECK_NE(certificate_provider, nullptr); + CHECK_NE(certificate_provider->c_provider(), nullptr); grpc::experimental::TlsChannelCredentialsOptions options; options.set_certificate_provider(certificate_provider); options.watch_root_certs(); options.set_root_cert_name(kRootCertName); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST( @@ -327,7 +329,7 @@ TEST( options.watch_identity_key_cert_pairs(); options.set_identity_cert_name(kIdentityCertName); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST( @@ -342,7 +344,7 @@ TEST( options.watch_identity_key_cert_pairs(); options.set_identity_cert_name(kIdentityCertName); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, @@ -354,7 +356,7 @@ TEST(CredentialsTest, options.watch_root_certs(); options.set_root_cert_name(kRootCertName); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithHostNameVerifier) { @@ -363,7 +365,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithHostNameVerifier) { options.set_verify_server_certs(true); options.set_certificate_verifier(verifier); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithSyncExternalVerifier) { @@ -374,7 +376,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithSyncExternalVerifier) { options.set_certificate_verifier(verifier); options.set_check_call_host(false); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithAsyncExternalVerifier) { @@ -385,7 +387,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithAsyncExternalVerifier) { options.set_certificate_verifier(verifier); options.set_check_call_host(false); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithCrlDirectory) { @@ -399,7 +401,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlDirectory) { options.set_identity_cert_name(kIdentityCertName); options.set_crl_directory(CRL_DIR_PATH); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithCrlProvider) { @@ -408,7 +410,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlProvider) { grpc::experimental::TlsChannelCredentialsOptions options; options.set_crl_provider(*provider); auto channel_credentials = grpc::experimental::TlsCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsChannelCredentialsWithCrlProviderAndDirectory) { @@ -420,7 +422,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlProviderAndDirectory) { auto channel_credentials = grpc::experimental::TlsCredentials(options); // TODO(gtcooke94) - behavior might change to make this return nullptr in the // future - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsCredentialsOptionsCopyConstructor) { @@ -437,8 +439,7 @@ TEST(CredentialsTest, TlsCredentialsOptionsCopyConstructor) { TlsTestCredentialsOptions copied_options = options; // Make sure the copy constructor cloned the internal pointer - GPR_ASSERT(options.internal_cred_opts() != - copied_options.internal_cred_opts()); + CHECK(options.internal_cred_opts() != copied_options.internal_cred_opts()); } TEST(CredentialsTest, TlsCredentialsOptionsDoesNotLeak) { diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index 1039685d5cc..0ac80b42898 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -36,6 +36,7 @@ grpc_cc_test( name = "timer_test", srcs = ["timer_test.cc"], external_deps = [ + "absl/log:check", "gtest", ], flaky = True, @@ -50,6 +51,7 @@ grpc_cc_test( name = "time_jump_test", srcs = ["time_jump_test.cc"], external_deps = [ + "absl/log:check", "gtest", ], tags = [ diff --git a/test/cpp/common/time_jump_test.cc b/test/cpp/common/time_jump_test.cc index 5a58709afd2..9b31abc1a66 100644 --- a/test/cpp/common/time_jump_test.cc +++ b/test/cpp/common/time_jump_test.cc @@ -25,6 +25,7 @@ #include +#include "absl/log/check.h" #include "absl/time/time.h" #include @@ -95,7 +96,7 @@ TEST_P(TimeJumpTest, TimerRunning) { grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(3), GRPC_CLOSURE_CREATE( [](void*, grpc_error_handle error) { - GPR_ASSERT(error == absl::CancelledError()); + CHECK(error == absl::CancelledError()); }, nullptr, grpc_schedule_on_exec_ctx)); gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); @@ -106,7 +107,7 @@ TEST_P(TimeJumpTest, TimerRunning) { // We expect 1 wakeup/sec when there are not timer expiries int64_t wakeups = grpc_timer_manager_get_wakeups_testonly(); gpr_log(GPR_DEBUG, "wakeups: %" PRId64 "", wakeups); - GPR_ASSERT(wakeups <= 3); + CHECK_LE(wakeups, 3); grpc_timer_cancel(&timer); } @@ -127,9 +128,8 @@ TEST_P(TimeJumpTest, TimedWait) { int32_t elapsed_ms = gpr_time_to_millis(gpr_time_sub(after, before)); gpr_log(GPR_DEBUG, "After wait, timedout = %d elapsed_ms = %d", timedout, elapsed_ms); - GPR_ASSERT(1 == timedout); - GPR_ASSERT(1 == - gpr_time_similar(gpr_time_sub(after, before), + CHECK_EQ(timedout, 1); + CHECK(1 == gpr_time_similar(gpr_time_sub(after, before), gpr_time_from_millis(kWaitTimeMs, GPR_TIMESPAN), gpr_time_from_millis(50, GPR_TIMESPAN))); @@ -138,7 +138,7 @@ TEST_P(TimeJumpTest, TimedWait) { // We expect 1 wakeup/sec when there are not timer expiries int64_t wakeups = grpc_timer_manager_get_wakeups_testonly(); gpr_log(GPR_DEBUG, "wakeups: %" PRId64 "", wakeups); - GPR_ASSERT(wakeups <= 3); + CHECK_LE(wakeups, 3); } int main(int argc, char** argv) { diff --git a/test/cpp/common/timer_test.cc b/test/cpp/common/timer_test.cc index 261529df432..63d320b30d3 100644 --- a/test/cpp/common/timer_test.cc +++ b/test/cpp/common/timer_test.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -77,7 +79,7 @@ TEST_F(TimerTest, NoTimers) { // We expect to get 1 wakeup per second. Sometimes we also get a wakeup // during initialization, so in 1.5 seconds we expect to get 1 or 2 wakeups. int64_t wakeups = grpc_timer_manager_get_wakeups_testonly(); - GPR_ASSERT(wakeups == 1 || wakeups == 2); + CHECK(wakeups == 1 || wakeups == 2); } #endif @@ -96,7 +98,7 @@ TEST_F(TimerTest, OneTimerExpires) { }, &timer_fired, grpc_schedule_on_exec_ctx)); gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500)); - GPR_ASSERT(1 == timer_fired); + CHECK_EQ(timer_fired, 1); // We expect to get 1 wakeup/second + 1 wakeup for the expired timer + maybe 1 // wakeup during initialization. i.e. in 1.5 seconds we expect 2 or 3 wakeups. @@ -126,7 +128,7 @@ TEST_F(TimerTest, MultipleTimersExpire) { } gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500)); - GPR_ASSERT(kNumTimers == timer_fired); + CHECK(kNumTimers == timer_fired); // We expect to get 1 wakeup/second + 1 wakeup for per timer fired + maybe 1 // wakeup during initialization. i.e. in 1.5 seconds we expect 11 or 12 @@ -168,7 +170,7 @@ TEST_F(TimerTest, CancelSomeTimers) { } gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500)); - GPR_ASSERT(kNumTimers / 2 == timer_fired); + CHECK(kNumTimers / 2 == timer_fired); // We expect to get 1 wakeup/second + 1 wakeup per timer fired + maybe 1 // wakeup during initialization. i.e. in 1.5 seconds we expect 6 or 7 wakeups. diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index 9999d3957d6..4a850c9fb0c 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -46,7 +46,7 @@ class GrpclbTest : public ::testing::Test { std::string Ip4ToPackedString(const char* ip_str) { struct in_addr ip4; - CHECK(inet_pton(AF_INET, ip_str, &ip4) == 1); + CHECK_EQ(inet_pton(AF_INET, ip_str, &ip4), 1); return std::string(reinterpret_cast(&ip4), sizeof(ip4)); } @@ -60,7 +60,7 @@ std::string PackedStringToIp(const grpc_core::GrpcLbServer& server) { } else { abort(); } - CHECK(inet_ntop(af, (void*)server.ip_addr, ip_str, 46) != nullptr); + CHECK_NE(inet_ntop(af, (void*)server.ip_addr, ip_str, 46), nullptr); return ip_str; } diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 0964b44099c..b09a70d8cf8 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -138,6 +138,7 @@ grpc_cc_library( grpc_cc_binary( name = "interop_client", + external_deps = ["absl/log:check"], language = "C++", deps = [ ":interop_client_main", @@ -280,6 +281,7 @@ grpc_cc_binary( ], external_deps = [ "absl/flags:flag", + "absl/log:check", "otel/exporters/prometheus:prometheus_exporter", "otel/sdk/src/metrics", ], diff --git a/test/cpp/interop/backend_metrics_lb_policy.cc b/test/cpp/interop/backend_metrics_lb_policy.cc index c97267e9716..216c537a9a6 100644 --- a/test/cpp/interop/backend_metrics_lb_policy.cc +++ b/test/cpp/interop/backend_metrics_lb_policy.cc @@ -67,7 +67,7 @@ class BackendMetricsLbPolicy : public LoadBalancingPolicy { : LoadBalancingPolicy(std::move(args), /*initial_refcount=*/2) { load_report_tracker_ = channel_args().GetPointer(kMetricsTrackerArgument); - CHECK(load_report_tracker_ != nullptr); + CHECK_NE(load_report_tracker_, nullptr); Args delegate_args; delegate_args.work_serializer = work_serializer(); delegate_args.args = channel_args(); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index b82424a0faa..1da6d3fef0f 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -1328,7 +1328,7 @@ bool InteropClient::DoRpcSoakTest( int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds, int32_t request_size, int32_t response_size) { gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations); - CHECK(soak_iterations > 0); + CHECK_GT(soak_iterations, 0); PerformSoakTest(server_uri, false /* reset channel per iteration */, soak_iterations, max_failures, max_acceptable_per_iteration_latency_ms, @@ -1345,7 +1345,7 @@ bool InteropClient::DoChannelSoakTest( int32_t request_size, int32_t response_size) { gpr_log(GPR_DEBUG, "Sending %d RPCs, tearing down the channel each time...", soak_iterations); - CHECK(soak_iterations > 0); + CHECK_GT(soak_iterations, 0); PerformSoakTest(server_uri, true /* reset channel per iteration */, soak_iterations, max_failures, max_acceptable_per_iteration_latency_ms, @@ -1358,8 +1358,8 @@ bool InteropClient::DoChannelSoakTest( bool InteropClient::DoLongLivedChannelTest(int32_t soak_iterations, int32_t iteration_interval) { gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations); - CHECK(soak_iterations > 0); - CHECK(iteration_interval > 0); + CHECK_GT(soak_iterations, 0); + CHECK_GT(iteration_interval, 0); SimpleRequest request; SimpleResponse response; int num_failures = 0; diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 54e48c68673..26c51b9869a 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -76,8 +76,8 @@ const char kEchoUserAgentKey[] = "x-grpc-test-echo-useragent"; void MaybeEchoMetadata(ServerContext* context) { const auto& client_metadata = context->client_metadata(); - CHECK(client_metadata.count(kEchoInitialMetadataKey) <= 1); - CHECK(client_metadata.count(kEchoTrailingBinMetadataKey) <= 1); + CHECK_LE(client_metadata.count(kEchoInitialMetadataKey), 1u); + CHECK_LE(client_metadata.count(kEchoTrailingBinMetadataKey), 1u); auto iter = client_metadata.find(kEchoInitialMetadataKey); if (iter != client_metadata.end()) { @@ -420,7 +420,7 @@ void grpc::testing::interop::RunServer( ServerStartedCondition* server_started_condition, std::unique_ptr>> server_options) { - CHECK(port != 0); + CHECK_NE(port, 0); std::ostringstream server_address; server_address << "0.0.0.0:" << port; auto server_metric_recorder = diff --git a/test/cpp/interop/reconnect_interop_server.cc b/test/cpp/interop/reconnect_interop_server.cc index d7057dfedb7..0ab9525e271 100644 --- a/test/cpp/interop/reconnect_interop_server.cc +++ b/test/cpp/interop/reconnect_interop_server.cc @@ -180,8 +180,8 @@ int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); signal(SIGINT, sigint_handler); - CHECK(absl::GetFlag(FLAGS_control_port) != 0); - CHECK(absl::GetFlag(FLAGS_retry_port) != 0); + CHECK_NE(absl::GetFlag(FLAGS_control_port), 0); + CHECK_NE(absl::GetFlag(FLAGS_retry_port), 0); RunServer(); return 0; diff --git a/test/cpp/interop/rpc_behavior_lb_policy.cc b/test/cpp/interop/rpc_behavior_lb_policy.cc index ee0df35fb52..8240000aa63 100644 --- a/test/cpp/interop/rpc_behavior_lb_policy.cc +++ b/test/cpp/interop/rpc_behavior_lb_policy.cc @@ -93,7 +93,7 @@ class RpcBehaviorLbPolicy : public LoadBalancingPolicy { grpc_core::Json::FromArray({grpc_core::Json::FromObject( {{std::string(delegate_->name()), grpc_core::Json::FromObject({})}})})); - CHECK(delegate_config.ok()); + CHECK_OK(delegate_config); args.config = std::move(*delegate_config); return delegate_->UpdateLocked(std::move(args)); } diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index ec49c007642..02879a979d6 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -342,8 +342,8 @@ class XdsUpdateClientConfigureServiceImpl std::vector configs; int request_payload_size = absl::GetFlag(FLAGS_request_payload_size); int response_payload_size = absl::GetFlag(FLAGS_response_payload_size); - CHECK(request_payload_size >= 0); - CHECK(response_payload_size >= 0); + CHECK_GE(request_payload_size, 0); + CHECK_GE(response_payload_size, 0); for (const auto& rpc : request->types()) { RpcConfig config; config.timeout_sec = request->timeout_sec(); @@ -448,7 +448,7 @@ grpc::CsmObservability EnableCsmObservability() { void RunServer(const int port, StatsWatchers* stats_watchers, RpcConfigurationsQueue* rpc_configs_queue) { - CHECK(port != 0); + CHECK_NE(port, 0); std::ostringstream server_address; server_address << "0.0.0.0:" << port; @@ -480,7 +480,7 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) { for (auto& data : rpc_metadata) { std::vector metadata = absl::StrSplit(data, ':', absl::SkipEmpty()); - CHECK(metadata.size() == 3); + CHECK_EQ(metadata.size(), 3u); if (metadata[0] == "EmptyCall") { metadata_map[ClientConfigureRequest::EMPTY_CALL].push_back( {metadata[1], metadata[2]}); @@ -496,8 +496,8 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) { absl::StrSplit(absl::GetFlag(FLAGS_rpc), ',', absl::SkipEmpty()); int request_payload_size = absl::GetFlag(FLAGS_request_payload_size); int response_payload_size = absl::GetFlag(FLAGS_response_payload_size); - CHECK(request_payload_size >= 0); - CHECK(response_payload_size >= 0); + CHECK_GE(request_payload_size, 0); + CHECK_GE(response_payload_size, 0); for (const std::string& rpc_method : rpc_methods) { RpcConfig config; if (rpc_method == "EmptyCall") { diff --git a/test/cpp/naming/BUILD b/test/cpp/naming/BUILD index 258b0cedcec..e7dafa0e4c7 100644 --- a/test/cpp/naming/BUILD +++ b/test/cpp/naming/BUILD @@ -38,7 +38,10 @@ grpc_py_binary( grpc_cc_test( name = "cancel_ares_query_test", srcs = ["cancel_ares_query_test.cc"], - external_deps = ["gtest"], + external_deps = [ + "absl/log:check", + "gtest", + ], tags = ["cancel_ares_query_test"], deps = [ "//:gpr", diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc index 8e0b45872e7..7a5016a972f 100644 --- a/test/cpp/naming/address_sorting_test.cc +++ b/test/cpp/naming/address_sorting_test.cc @@ -24,6 +24,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -74,16 +76,16 @@ grpc_resolved_address TestAddressToGrpcResolvedAddress(TestAddress test_addr) { memset(&in_dest, 0, sizeof(sockaddr_in)); in_dest.sin_port = htons(atoi(port.c_str())); in_dest.sin_family = AF_INET; - GPR_ASSERT(inet_pton(AF_INET, host.c_str(), &in_dest.sin_addr) == 1); + CHECK_EQ(inet_pton(AF_INET, host.c_str(), &in_dest.sin_addr), 1); memcpy(&resolved_addr.addr, &in_dest, sizeof(sockaddr_in)); resolved_addr.len = sizeof(sockaddr_in); } else { - GPR_ASSERT(test_addr.family == AF_INET6); + CHECK(test_addr.family == AF_INET6); sockaddr_in6 in6_dest; memset(&in6_dest, 0, sizeof(sockaddr_in6)); in6_dest.sin6_port = htons(atoi(port.c_str())); in6_dest.sin6_family = AF_INET6; - GPR_ASSERT(inet_pton(AF_INET6, host.c_str(), &in6_dest.sin6_addr) == 1); + CHECK_EQ(inet_pton(AF_INET6, host.c_str(), &in6_dest.sin6_addr), 1); memcpy(&resolved_addr.addr, &in6_dest, sizeof(sockaddr_in6)); resolved_addr.len = sizeof(sockaddr_in6); } diff --git a/test/cpp/naming/cancel_ares_query_test.cc b/test/cpp/naming/cancel_ares_query_test.cc index 9b6cacafd49..472ed54e26e 100644 --- a/test/cpp/naming/cancel_ares_query_test.cc +++ b/test/cpp/naming/cancel_ares_query_test.cc @@ -23,6 +23,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -295,7 +296,7 @@ void TestCancelDuringActiveQuery( grpc_call* call = grpc_channel_create_call( client, nullptr, GRPC_PROPAGATE_DEFAULTS, cq, grpc_slice_from_static_string("/foo"), nullptr, rpc_deadline, nullptr); - GPR_ASSERT(call); + CHECK(call); grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; diff --git a/test/cpp/naming/generate_resolver_component_tests.bzl b/test/cpp/naming/generate_resolver_component_tests.bzl index c93a22619b9..1c9d6a84b76 100755 --- a/test/cpp/naming/generate_resolver_component_tests.bzl +++ b/test/cpp/naming/generate_resolver_component_tests.bzl @@ -32,6 +32,7 @@ def generate_resolver_component_tests(): "address_sorting_test.cc", ], external_deps = [ + "absl/log:check", "gtest", ], deps = [ @@ -53,6 +54,7 @@ def generate_resolver_component_tests(): "resolver_component_test.cc", ], external_deps = [ + "absl/log:check", "gtest", ], deps = [ @@ -75,6 +77,7 @@ def generate_resolver_component_tests(): ], external_deps = [ "absl/flags:flag", + "absl/log:check", "absl/strings", ], deps = [ diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index d7aaef9921f..c5d52612ac4 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -27,6 +27,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -209,7 +210,7 @@ void ArgsInit(ArgsStruct* args) { void DoNothing(void* /*arg*/, grpc_error_handle /*error*/) {} void ArgsFinish(ArgsStruct* args) { - GPR_ASSERT(gpr_event_wait(&args->ev, TestDeadline())); + CHECK(gpr_event_wait(&args->ev, TestDeadline())); grpc_pollset_set_del_pollset(args->pollset_set, args->pollset); grpc_pollset_set_destroy(args->pollset_set); grpc_closure DoNothing_cb; @@ -242,7 +243,7 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) { gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)); gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", args->done, time_left.tv_sec, time_left.tv_nsec); - GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0); + CHECK_GE(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)), 0); grpc_pollset_worker* worker = nullptr; grpc_core::ExecCtx exec_ctx; if (grpc_core::IsEventEngineDnsEnabled()) { @@ -304,7 +305,7 @@ class ResultHandler : public grpc_core::Resolver::ResultHandler { void ReportResult(grpc_core::Resolver::Result result) override { CheckResult(result); grpc_core::MutexLockForGprMu lock(args_->mu); - GPR_ASSERT(!args_->done); + CHECK(!args_->done); args_->done = true; GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args_->pollset, nullptr)); @@ -362,7 +363,7 @@ class CheckingResultHandler : public ResultHandler { "Invalid for setting for --do_ordered_address_comparison. " "Have %s, want True or False", absl::GetFlag(FLAGS_do_ordered_address_comparison).c_str()); - GPR_ASSERT(0); + CHECK(0); } if (!result.service_config.ok()) { CheckServiceConfigResultLocked(nullptr, result.service_config.status(), @@ -405,7 +406,7 @@ void InjectBrokenNameServerList(ares_channel* channel) { memset(dns_server_addrs, 0, sizeof(dns_server_addrs)); std::string unused_host; std::string local_dns_server_port; - GPR_ASSERT(grpc_core::SplitHostPort( + CHECK(grpc_core::SplitHostPort( absl::GetFlag(FLAGS_local_dns_server_address).c_str(), &unused_host, &local_dns_server_port)); gpr_log(GPR_DEBUG, @@ -429,8 +430,7 @@ void InjectBrokenNameServerList(ares_channel* channel) { dns_server_addrs[1].tcp_port = atoi(local_dns_server_port.c_str()); dns_server_addrs[1].udp_port = atoi(local_dns_server_port.c_str()); dns_server_addrs[1].next = nullptr; - GPR_ASSERT(ares_set_servers_ports(*channel, dns_server_addrs) == - ARES_SUCCESS); + CHECK(ares_set_servers_ports(*channel, dns_server_addrs) == ARES_SUCCESS); } void StartResolvingLocked(grpc_core::Resolver* r) { r->StartLocked(); } diff --git a/test/cpp/naming/resolver_component_tests_runner_invoker.cc b/test/cpp/naming/resolver_component_tests_runner_invoker.cc index f5b8c455e9e..4ad878ef181 100644 --- a/test/cpp/naming/resolver_component_tests_runner_invoker.cc +++ b/test/cpp/naming/resolver_component_tests_runner_invoker.cc @@ -27,6 +27,7 @@ #include #include "absl/flags/flag.h" +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -99,12 +100,12 @@ int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::InitTest(&argc, &argv, true); grpc_init(); - GPR_ASSERT(!absl::GetFlag(FLAGS_test_bin_name).empty()); + CHECK(!absl::GetFlag(FLAGS_test_bin_name).empty()); std::string my_bin = argv[0]; int result = 0; if (absl::GetFlag(FLAGS_running_under_bazel)) { - GPR_ASSERT(!absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir) - .empty()); + CHECK(!absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir) + .empty()); // Use bazel's TEST_SRCDIR environment variable to locate the "test data" // binaries. auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); diff --git a/test/cpp/performance/BUILD b/test/cpp/performance/BUILD index 15de8b3d73c..4a9f64c4095 100644 --- a/test/cpp/performance/BUILD +++ b/test/cpp/performance/BUILD @@ -22,6 +22,7 @@ grpc_cc_test( name = "writes_per_rpc_test", srcs = ["writes_per_rpc_test.cc"], external_deps = [ + "absl/log:check", "gtest", ], tags = ["no_windows"], diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 4b38fbbc258..76c93fd9b59 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -79,16 +81,16 @@ class InProcessCHTTP2 { listener_endpoint = std::move(ep); listener_started.Notify(); }, - [](absl::Status status) { GPR_ASSERT(status.ok()); }, config, + [](absl::Status status) { CHECK_OK(status); }, config, std::make_unique("foo")); if (!listener.ok()) { grpc_core::Crash(absl::StrCat("failed to start listener: ", listener.status().ToString())); } auto target_addr = URIToResolvedAddress(addr); - GPR_ASSERT(target_addr.ok()); - GPR_ASSERT((*listener)->Bind(*target_addr).ok()); - GPR_ASSERT((*listener)->Start().ok()); + CHECK_OK(target_addr); + CHECK_OK((*listener)->Bind(*target_addr)); + CHECK_OK((*listener)->Start()); // Creating the client std::unique_ptr client_endpoint; grpc_core::Notification client_connected; @@ -96,7 +98,7 @@ class InProcessCHTTP2 { std::make_unique("client"); std::ignore = fuzzing_engine->Connect( [&](absl::StatusOr> endpoint) { - GPR_ASSERT(endpoint.ok()); + CHECK_OK(endpoint); client_endpoint = std::move(*endpoint); client_connected.Notify(); }, @@ -124,7 +126,7 @@ class InProcessCHTTP2 { for (grpc_pollset* pollset : core_server->pollsets()) { grpc_endpoint_add_to_pollset(iomgr_server_endpoint, pollset); } - GPR_ASSERT(GRPC_LOG_IF_ERROR( + CHECK(GRPC_LOG_IF_ERROR( "SetupTransport", core_server->SetupTransport(transport, nullptr, core_server->channel_args(), nullptr))); @@ -143,7 +145,7 @@ class InProcessCHTTP2 { grpc_core::Transport* transport = grpc_create_chttp2_transport( args, grpc_event_engine_endpoint_create(std::move(client_endpoint)), /*is_client=*/true); - GPR_ASSERT(transport); + CHECK(transport); grpc_channel* channel = grpc_core::ChannelCreate("target", args, GRPC_CLIENT_DIRECT_CHANNEL, transport) @@ -234,20 +236,20 @@ static double UnaryPingPong(ThreadedFuzzingEventEngine* fuzzing_engine, void* t; bool ok; response_reader->Finish(&recv_response, &recv_status, tag(4)); - GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - GPR_ASSERT(ok); - GPR_ASSERT(t == tag(0) || t == tag(1)); + CHECK(fixture->cq()->Next(&t, &ok)); + CHECK(ok); + CHECK(t == tag(0) || t == tag(1)); intptr_t slot = reinterpret_cast(t); ServerEnv* senv = server_env[slot]; senv->response_writer.Finish(send_response, Status::OK, tag(3)); for (int i = (1 << 3) | (1 << 4); i != 0;) { - GPR_ASSERT(fixture->cq()->Next(&t, &ok)); - GPR_ASSERT(ok); + CHECK(fixture->cq()->Next(&t, &ok)); + CHECK(ok); int tagnum = static_cast(reinterpret_cast(t)); - GPR_ASSERT(i & (1 << tagnum)); + CHECK(i & (1 << tagnum)); i -= 1 << tagnum; } - GPR_ASSERT(recv_status.ok()); + CHECK(recv_status.ok()); senv->~ServerEnv(); senv = new (senv) ServerEnv(); diff --git a/test/cpp/qps/parse_json.cc b/test/cpp/qps/parse_json.cc index 69b644f7065..c104550f4a1 100644 --- a/test/cpp/qps/parse_json.cc +++ b/test/cpp/qps/parse_json.cc @@ -57,7 +57,7 @@ std::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg, msg.SerializeToString(&binary); auto status = BinaryToJsonString(type_resolver.get(), type, binary, &json_string); - CHECK(status.ok()); + CHECK_OK(status); return json_string; } diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD index 0927de6c7a0..5bb6532ba93 100644 --- a/test/cpp/server/BUILD +++ b/test/cpp/server/BUILD @@ -72,6 +72,7 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.pem", ], external_deps = [ + "absl/log:check", "gtest", ], deps = [ diff --git a/test/cpp/server/credentials_test.cc b/test/cpp/server/credentials_test.cc index 879c2c101dd..72111a5692b 100644 --- a/test/cpp/server/credentials_test.cc +++ b/test/cpp/server/credentials_test.cc @@ -18,6 +18,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -73,7 +75,7 @@ TEST( options.set_cert_request_type( GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } // ServerCredentials should always have identity credential presented. @@ -95,7 +97,7 @@ TEST(CredentialsTest, options.set_cert_request_type( GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } TEST( @@ -111,7 +113,7 @@ TEST( options.set_cert_request_type( GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } TEST(CredentialsTest, TlsServerCredentialsWithCrlChecking) { @@ -126,7 +128,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlChecking) { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); options.set_crl_directory(CRL_DIR_PATH); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } // ServerCredentials should always have identity credential presented. @@ -142,7 +144,7 @@ TEST( options.set_cert_request_type( GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } TEST(CredentialsTest, TlsServerCredentialsWithSyncExternalVerifier) { @@ -159,7 +161,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithSyncExternalVerifier) { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); options.set_certificate_verifier(verifier); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } TEST(CredentialsTest, TlsServerCredentialsWithAsyncExternalVerifier) { @@ -176,7 +178,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithAsyncExternalVerifier) { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); options.set_certificate_verifier(verifier); auto server_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(server_credentials.get() != nullptr); + CHECK_NE(server_credentials.get(), nullptr); } TEST(CredentialsTest, TlsServerCredentialsWithCrlProvider) { @@ -187,7 +189,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlProvider) { grpc::experimental::TlsServerCredentialsOptions options(certificate_provider); options.set_crl_provider(*provider); auto channel_credentials = grpc::experimental::TlsServerCredentials(options); - GPR_ASSERT(channel_credentials.get() != nullptr); + CHECK_NE(channel_credentials.get(), nullptr); } TEST(CredentialsTest, TlsServerCredentialsWithCrlProviderAndDirectory) { @@ -201,7 +203,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlProviderAndDirectory) { auto server_credentials = grpc::experimental::TlsServerCredentials(options); // TODO(gtcooke94) - behavior might change to make this return nullptr in // the future - GPR_ASSERT(server_credentials != nullptr); + CHECK_NE(server_credentials, nullptr); } TEST(CredentialsTest, TlsCredentialsOptionsDoesNotLeak) { diff --git a/test/cpp/server/load_reporter/BUILD b/test/cpp/server/load_reporter/BUILD index 25c995582bc..475fc9018ea 100644 --- a/test/cpp/server/load_reporter/BUILD +++ b/test/cpp/server/load_reporter/BUILD @@ -34,6 +34,8 @@ grpc_cc_test( name = "lb_load_reporter_test", srcs = ["load_reporter_test.cc"], external_deps = [ + "absl/flags:flag", + "absl/log:check", "gtest", "opencensus-stats-test", ], diff --git a/test/cpp/server/load_reporter/load_reporter_test.cc b/test/cpp/server/load_reporter/load_reporter_test.cc index b88ebb5ef2a..b66b66ddfb9 100644 --- a/test/cpp/server/load_reporter/load_reporter_test.cc +++ b/test/cpp/server/load_reporter/load_reporter_test.cc @@ -24,6 +24,7 @@ #include #include +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "opencensus/stats/testing/test_utils.h" @@ -59,7 +60,7 @@ class MockCensusViewProvider : public CensusViewProvider { const ViewDescriptor& FindViewDescriptor(const std::string& view_name) { auto it = view_descriptor_map().find(view_name); - GPR_ASSERT(it != view_descriptor_map().end()); + CHECK(it != view_descriptor_map().end()); return it->second; } };