diff --git a/BUILD b/BUILD index 979718b4feb..4d4d2a8b92a 100644 --- a/BUILD +++ b/BUILD @@ -296,7 +296,6 @@ GRPC_PUBLIC_HDRS = [ "include/grpc/grpc_posix.h", "include/grpc/grpc_security.h", "include/grpc/grpc_security_constants.h", - "include/grpc/passive_listener.h", "include/grpc/slice.h", "include/grpc/slice_buffer.h", "include/grpc/status.h", @@ -458,7 +457,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/impl/service_type.h", "include/grpcpp/impl/status.h", "include/grpcpp/impl/sync.h", - "include/grpcpp/passive_listener.h", "include/grpcpp/resource_quota.h", "include/grpcpp/security/audit_logging.h", "include/grpcpp/security/tls_crl_provider.h", @@ -788,7 +786,6 @@ grpc_cc_library( "absl/base:log_severity", "absl/functional:any_invocable", "absl/log", - "absl/log:globals", "absl/memory", "absl/random", "absl/status", @@ -884,7 +881,7 @@ grpc_cc_library( grpc_cc_library( name = "grpc_public_hdrs", - hdrs = GRPC_PUBLIC_HDRS + GRPC_PUBLIC_EVENT_ENGINE_HDRS, + hdrs = GRPC_PUBLIC_HDRS, external_deps = [ "absl/status:statusor", "absl/strings", @@ -1134,6 +1131,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/hash", + "absl/log:check", "absl/memory", "absl/meta:type_traits", "absl/status", @@ -2508,7 +2506,6 @@ grpc_cc_library( "//src/core:grpc_backend_metric_provider", "//src/core:grpc_crl_provider", "//src/core:grpc_service_config", - "//src/core:grpc_transport_chttp2_server", "//src/core:grpc_transport_inproc", "//src/core:json", "//src/core:json_reader", @@ -2567,7 +2564,6 @@ grpc_cc_library( "grpc_security_base", "grpc_service_config_impl", "grpc_trace", - "grpc_transport_chttp2", "grpc_unsecure", "grpcpp_backend_metric_recorder", "grpcpp_call_metric_recorder", @@ -2589,7 +2585,6 @@ grpc_cc_library( "//src/core:grpc_backend_metric_provider", "//src/core:grpc_insecure_credentials", "//src/core:grpc_service_config", - "//src/core:grpc_transport_chttp2_server", "//src/core:grpc_transport_inproc", "//src/core:ref_counted", "//src/core:resource_quota", @@ -3963,6 +3958,9 @@ grpc_cc_library( hdrs = [ "//src/core:tsi/fake_transport_security.h", ], + external_deps = [ + "absl/log:check", + ], language = "c++", visibility = [ "@grpc:public", @@ -4080,6 +4078,7 @@ grpc_cc_library( "//src/core:tsi/alts/handshaker/alts_tsi_utils.h", ], external_deps = [ + "absl/log:check", "absl/strings", "@com_google_protobuf//upb:base", "@com_google_protobuf//upb:mem", @@ -4139,6 +4138,7 @@ grpc_cc_library( "//src/core:tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h", ], external_deps = [ + "absl/log:check", "absl/types:span", "libcrypto", "libssl", @@ -4169,6 +4169,7 @@ grpc_cc_library( "//src/core:tsi/ssl/session_cache/ssl_session_cache.h", ], external_deps = [ + "absl/log:check", "absl/memory", "libssl", ], @@ -4452,6 +4453,7 @@ grpc_cc_library( "//src/core:ext/transport/chttp2/transport/frame.h", ], external_deps = [ + "absl/log:check", "absl/status", "absl/status:statusor", "absl/strings", @@ -4497,6 +4499,7 @@ grpc_cc_library( ], external_deps = [ "absl/functional:function_ref", + "absl/log:check", "absl/status", "absl/strings", ], @@ -4523,6 +4526,7 @@ grpc_cc_library( "//src/core:ext/transport/chttp2/transport/hpack_parse_result.h", ], external_deps = [ + "absl/log:check", "absl/status", "absl/strings", "absl/strings:str_format", @@ -4551,6 +4555,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:check", "absl/random:bit_gen_ref", "absl/status", "absl/strings", @@ -4591,7 +4596,10 @@ grpc_cc_library( hdrs = [ "//src/core:ext/transport/chttp2/transport/hpack_encoder.h", ], - external_deps = ["absl/strings"], + external_deps = [ + "absl/log:check", + "absl/strings", + ], deps = [ "chttp2_bin_encoder", "chttp2_legacy_frame", @@ -4621,6 +4629,9 @@ grpc_cc_library( hdrs = [ "//src/core:ext/transport/chttp2/transport/bin_encoder.h", ], + external_deps = [ + "absl/log:check", + ], deps = [ "gpr", "gpr_platform", @@ -4637,7 +4648,10 @@ grpc_cc_library( hdrs = [ "//src/core:ext/transport/chttp2/transport/varint.h", ], - external_deps = ["absl/base:core_headers"], + external_deps = [ + "absl/base:core_headers", + "absl/log:check", + ], deps = ["gpr"], ) @@ -4696,6 +4710,7 @@ grpc_cc_library( "absl/base:core_headers", "absl/container:flat_hash_map", "absl/hash", + "absl/log:check", "absl/meta:type_traits", "absl/random", "absl/random:bit_gen_ref", diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b717813657..cbe9488506c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1749,7 +1749,6 @@ target_link_libraries(gpr absl::flags_marshalling absl::any_invocable absl::check - absl::log_globals absl::log absl::memory absl::random_random @@ -2747,7 +2746,6 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h - include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -3449,7 +3447,6 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h - include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -4318,7 +4315,6 @@ foreach(_hdr include/grpcpp/impl/service_type.h include/grpcpp/impl/status.h include/grpcpp/impl/sync.h - include/grpcpp/passive_listener.h include/grpcpp/resource_quota.h include/grpcpp/security/audit_logging.h include/grpcpp/security/auth_context.h @@ -5059,7 +5055,6 @@ foreach(_hdr include/grpcpp/impl/service_type.h include/grpcpp/impl/status.h include/grpcpp/impl/sync.h - include/grpcpp/passive_listener.h include/grpcpp/resource_quota.h include/grpcpp/security/audit_logging.h include/grpcpp/security/auth_context.h @@ -5511,7 +5506,6 @@ foreach(_hdr include/grpc/impl/propagation_bits.h include/grpc/impl/slice_type.h include/grpc/load_reporting.h - include/grpc/passive_listener.h include/grpc/slice.h include/grpc/slice_buffer.h include/grpc/status.h @@ -26840,7 +26834,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h - test/core/event_engine/event_engine_test_utils.cc test/core/test_util/cmdline.cc test/core/test_util/fuzzer_util.cc test/core/test_util/grpc_profiler.cc @@ -36929,7 +36922,7 @@ generate_pkgconfig( "gpr" "gRPC platform support library" "${gRPC_CORE_VERSION}" - "absl_any_invocable absl_base absl_check absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_log absl_log_globals absl_log_severity absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time absl_variant" + "absl_any_invocable absl_base absl_check absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_log absl_log_severity absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time absl_variant" "" "-lgpr" "" @@ -36940,7 +36933,7 @@ generate_pkgconfig( "gRPC" "high performance general RPC framework" "${gRPC_CORE_VERSION}" - "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_globals 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" + "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" "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" @@ -36951,7 +36944,7 @@ generate_pkgconfig( "gRPC unsecure" "high performance general RPC framework without SSL" "${gRPC_CORE_VERSION}" - "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_globals 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" + "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" "libcares zlib" "-lgrpc_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36962,7 +36955,7 @@ generate_pkgconfig( "gRPC++" "C++ wrapper for gRPC" "${gRPC_CPP_VERSION}" - "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_globals 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" @@ -36973,7 +36966,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_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_globals 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/Makefile b/Makefile index 6cf36c4aba6..5c3d1bb452e 100644 --- a/Makefile +++ b/Makefile @@ -1776,7 +1776,6 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ - include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ diff --git a/Package.swift b/Package.swift index a4404da9aef..fdad051ca98 100644 --- a/Package.swift +++ b/Package.swift @@ -93,7 +93,6 @@ let package = Package( "include/grpc/impl/propagation_bits.h", "include/grpc/impl/slice_type.h", "include/grpc/load_reporting.h", - "include/grpc/passive_listener.h", "include/grpc/slice.h", "include/grpc/slice_buffer.h", "include/grpc/status.h", diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 73af133207d..41d67c61ef2 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -130,7 +130,6 @@ libs: - absl/flags:marshalling - absl/functional:any_invocable - absl/log:check - - absl/log:globals - absl/log:log - absl/memory:memory - absl/random:random @@ -198,7 +197,6 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -2186,7 +2184,6 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -3794,7 +3791,6 @@ libs: - include/grpcpp/impl/service_type.h - include/grpcpp/impl/status.h - include/grpcpp/impl/sync.h - - include/grpcpp/passive_listener.h - include/grpcpp/resource_quota.h - include/grpcpp/security/audit_logging.h - include/grpcpp/security/auth_context.h @@ -4222,7 +4218,6 @@ libs: - include/grpcpp/impl/service_type.h - include/grpcpp/impl/status.h - include/grpcpp/impl/sync.h - - include/grpcpp/passive_listener.h - include/grpcpp/resource_quota.h - include/grpcpp/security/audit_logging.h - include/grpcpp/security/auth_context.h @@ -4371,7 +4366,6 @@ libs: - include/grpc/impl/propagation_bits.h - include/grpc/impl/slice_type.h - include/grpc/load_reporting.h - - include/grpc/passive_listener.h - include/grpc/slice.h - include/grpc/slice_buffer.h - include/grpc/status.h @@ -17796,7 +17790,6 @@ targets: build: test language: c++ headers: - - test/core/event_engine/event_engine_test_utils.h - test/core/test_util/cmdline.h - test/core/test_util/evaluate_args_test_util.h - test/core/test_util/fuzzer_util.h @@ -17812,7 +17805,6 @@ targets: - src/proto/grpc/testing/echo_messages.proto - src/proto/grpc/testing/simple_messages.proto - src/proto/grpc/testing/xds/v3/orca_load_report.proto - - test/core/event_engine/event_engine_test_utils.cc - test/core/test_util/cmdline.cc - test/core/test_util/fuzzer_util.cc - test/core/test_util/grpc_profiler.cc diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index db422eb9458..acb6ee6f1ed 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -176,7 +176,6 @@ Pod::Spec.new do |s| 'include/grpcpp/impl/service_type.h', 'include/grpcpp/impl/status.h', 'include/grpcpp/impl/sync.h', - 'include/grpcpp/passive_listener.h', 'include/grpcpp/resource_quota.h', 'include/grpcpp/security/audit_logging.h', 'include/grpcpp/security/auth_context.h', @@ -245,7 +244,6 @@ Pod::Spec.new do |s| 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/globals', 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/gRPC-Core.podspec b/gRPC-Core.podspec index c743e7a3b2d..44913a2c38c 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -168,7 +168,6 @@ Pod::Spec.new do |s| 'include/grpc/impl/propagation_bits.h', 'include/grpc/impl/slice_type.h', 'include/grpc/load_reporting.h', - 'include/grpc/passive_listener.h', 'include/grpc/slice.h', 'include/grpc/slice_buffer.h', 'include/grpc/status.h', @@ -217,7 +216,6 @@ Pod::Spec.new do |s| 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/globals', 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/grpc.gemspec b/grpc.gemspec index f59c5e0fec1..4808bada297 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -99,7 +99,6 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/propagation_bits.h ) s.files += %w( include/grpc/impl/slice_type.h ) s.files += %w( include/grpc/load_reporting.h ) - s.files += %w( include/grpc/passive_listener.h ) s.files += %w( include/grpc/slice.h ) s.files += %w( include/grpc/slice_buffer.h ) s.files += %w( include/grpc/status.h ) diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index 30427e21d05..c9219532826 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -38,7 +38,6 @@ header "byte_buffer.h" header "impl/propagation_bits.h" header "impl/slice_type.h" header "load_reporting.h" - header "passive_listener.h" header "slice.h" header "slice_buffer.h" header "status.h" diff --git a/include/grpc/passive_listener.h b/include/grpc/passive_listener.h deleted file mode 100644 index fffc789dba0..00000000000 --- a/include/grpc/passive_listener.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2024 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef GRPC_PASSIVE_LISTENER_H -#define GRPC_PASSIVE_LISTENER_H - -#include - -#include -#include -// #include - -namespace grpc_core { -class Server; - -namespace experimental { -class PassiveListenerImpl; - -/// -- EXPERIMENTAL API -- -/// Interface for used for Server Endpoint injection. -class PassiveListener { - public: - virtual ~PassiveListener() = default; - /// -- EXPERIMENTAL API -- - /// - /// Takes an Endpoint for an established connection, and treats it as if the - /// connection had been accepted by the server. - /// - /// The server must be started before endpoints can be accepted. - virtual absl::Status AcceptConnectedEndpoint( - std::unique_ptr - endpoint) = 0; - - /// -- EXPERIMENTAL API -- - /// - /// Takes a connected file descriptor, and treats it as if the server had - /// accepted the connection itself. - /// - /// Returns a failure status if the server's active EventEngine does not - /// support Endpoint creation from fds. - virtual absl::Status AcceptConnectedFd(int fd) = 0; -}; - -} // namespace experimental -} // namespace grpc_core - -absl::Status grpc_server_add_passive_listener( - grpc_core::Server* server, grpc_server_credentials* credentials, - std::shared_ptr - passive_listener); - -#endif /* GRPC_PASSIVE_LISTENER_H */ diff --git a/include/grpcpp/passive_listener.h b/include/grpcpp/passive_listener.h deleted file mode 100644 index 8def9592b5e..00000000000 --- a/include/grpcpp/passive_listener.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2024 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef GRPCPP_PASSIVE_LISTENER_H -#define GRPCPP_PASSIVE_LISTENER_H - -#include - -namespace grpc { -namespace experimental { - -using grpc_core::experimental::PassiveListener; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_PASSIVE_LISTENER_H diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index e3f5c2bbbfe..fe8c546190d 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -84,7 +84,6 @@ class ServerCredentials : private grpc::internal::GrpcLibrary { // Needed for access to AddPortToServer. friend class Server; // Needed for access to c_creds_. - friend class ServerBuilder; friend std::shared_ptr grpc::XdsServerCredentials( const std::shared_ptr& fallback_credentials); diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index e66ca4301cd..e6266a90d98 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -25,17 +25,13 @@ #include #include -#include -#include #include #include #include #include #include #include -#include #include -#include #include #include #include @@ -295,18 +291,6 @@ class ServerBuilder { void EnableCallMetricRecording( experimental::ServerMetricRecorder* server_metric_recorder = nullptr); - // Creates a passive listener for Server Endpoint injection. - /// - /// \a PasiveListener lets applications provide pre-established connections - /// to gRPC Servers. The server will behave as if it accepted the connection - /// itself on its own listening addresses. - /// - /// This can be called multiple times to create passive listeners with - /// different server credentials. - ServerBuilder& AddPassiveListener( - std::shared_ptr creds, - std::unique_ptr& passive_listener); - private: ServerBuilder* builder_; }; @@ -380,17 +364,6 @@ class ServerBuilder { private: friend class grpc::testing::ServerBuilderPluginTest; - struct UnstartedPassiveListener { - std::weak_ptr - passive_listener; - std::shared_ptr credentials; - UnstartedPassiveListener( - std::weak_ptr listener, - std::shared_ptr creds) - : passive_listener(std::move(listener)), - credentials(std::move(creds)) {} - }; - struct SyncServerSettings { SyncServerSettings() : num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {} @@ -415,7 +388,6 @@ class ServerBuilder { std::vector> options_; std::vector> services_; std::vector ports_; - std::vector unstarted_passive_listeners_; SyncServerSettings sync_server_settings_; diff --git a/package.xml b/package.xml index f9e627ec5a5..a1afab47160 100644 --- a/package.xml +++ b/package.xml @@ -81,7 +81,6 @@ - diff --git a/src/core/BUILD b/src/core/BUILD index eb8a6ea1c7d..b1ae23fa6a6 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -6599,6 +6599,9 @@ grpc_cc_library( hdrs = [ "ext/transport/chttp2/transport/hpack_encoder_table.h", ], + external_deps = [ + "absl/log:check", + ], language = "c++", deps = [ "hpack_constants", @@ -6616,6 +6619,7 @@ grpc_cc_library( ], external_deps = [ "absl/functional:function_ref", + "absl/log:check", "absl/status", "absl/strings", "absl/strings:str_format", @@ -6665,6 +6669,7 @@ grpc_cc_library( "absl/container:flat_hash_map", "absl/functional:any_invocable", "absl/hash", + "absl/log:check", "absl/meta:type_traits", "absl/random:bit_gen_ref", "absl/random:distributions", @@ -6687,6 +6692,9 @@ grpc_cc_library( hdrs = [ "ext/transport/chttp2/transport/write_size_policy.h", ], + external_deps = [ + "absl/log:check", + ], deps = [ "time", "//:gpr", @@ -6725,6 +6733,9 @@ grpc_cc_library( hdrs = [ "ext/transport/chttp2/transport/max_concurrent_streams_policy.h", ], + external_deps = [ + "absl/log:check", + ], deps = [ "//:gpr", "//:gpr_platform", @@ -6782,6 +6793,9 @@ grpc_cc_library( hdrs = [ "ext/transport/chttp2/alpn/alpn.h", ], + external_deps = [ + "absl/log:check", + ], language = "c++", deps = [ "useful", @@ -6799,6 +6813,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:check", "absl/status", "absl/status:statusor", "absl/strings:str_format", @@ -6855,6 +6870,7 @@ grpc_cc_library( ], external_deps = [ "absl/base:core_headers", + "absl/log:check", "absl/status", "absl/status:statusor", "absl/strings", @@ -6869,8 +6885,6 @@ grpc_cc_library( "connection_quota", "error", "error_utils", - "event_engine_extensions", - "event_engine_query_extensions", "grpc_insecure_credentials", "handshaker_registry", "iomgr_fwd", diff --git a/src/core/ext/transport/binder/client/binder_connector.cc b/src/core/ext/transport/binder/client/binder_connector.cc index 0c3db89927c..2dcb0e03746 100644 --- a/src/core/ext/transport/binder/client/binder_connector.cc +++ b/src/core/ext/transport/binder/client/binder_connector.cc @@ -33,6 +33,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/client_channel/connector.h" @@ -60,21 +62,21 @@ class BinderConnector : public grpc_core::SubchannelConnector { size_t id_length = args.address->len - sizeof(un->sun_family); // The c-style string at least will have a null terminator, and the // connection id itself should not be empty - GPR_ASSERT(id_length >= 2); + CHECK_GE(id_length, 2u); // Make sure there is null terminator at the expected location before // reading from it - GPR_ASSERT(un->sun_path[id_length - 1] == '\0'); + CHECK_EQ(un->sun_path[id_length - 1], '\0'); conn_id_ = un->sun_path; } #else - GPR_ASSERT(0); + CHECK(0); #endif gpr_log(GPR_INFO, "BinderConnector %p conn_id_ = %s", this, conn_id_.c_str()); args_ = args; - GPR_ASSERT(notify_ == nullptr); - GPR_ASSERT(notify != nullptr); + CHECK_EQ(notify_, nullptr); + CHECK_NE(notify, nullptr); notify_ = notify; result_ = result; @@ -86,15 +88,15 @@ class BinderConnector : public grpc_core::SubchannelConnector { } void OnConnected(std::unique_ptr endpoint_binder) { - GPR_ASSERT(endpoint_binder != nullptr); + CHECK(endpoint_binder != nullptr); grpc_core::Transport* transport = grpc_create_binder_transport_client( std::move(endpoint_binder), grpc_binder::GetSecurityPolicySetting()->Get(conn_id_)); - GPR_ASSERT(transport != nullptr); + CHECK_NE(transport, nullptr); result_->channel_args = args_.channel_args; result_->transport = transport; - GPR_ASSERT(notify_ != nullptr); + CHECK_NE(notify_, nullptr); // ExecCtx is required here for running grpc_closure because this callback // might be invoked from non-gRPC code if (grpc_core::ExecCtx::Get() == nullptr) { diff --git a/src/core/ext/transport/binder/client/channel_create.cc b/src/core/ext/transport/binder/client/channel_create.cc index 484695537fb..e590b9db51c 100644 --- a/src/core/ext/transport/binder/client/channel_create.cc +++ b/src/core/ext/transport/binder/client/channel_create.cc @@ -34,6 +34,7 @@ #ifdef GPR_SUPPORT_BINDER_TRANSPORT +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/strings/substitute.h" #include "absl/time/clock.h" @@ -102,8 +103,8 @@ std::shared_ptr CreateCustomBinderChannel( const ChannelArguments& args) { grpc_init(); - GPR_ASSERT(jni_env_void != nullptr); - GPR_ASSERT(security_policy != nullptr); + CHECK_NE(jni_env_void, nullptr); + CHECK_NE(security_policy, nullptr); // Generate an unique connection ID that identifies this connection (Useful // for mapping connection between Java and C++ code). @@ -163,7 +164,7 @@ std::shared_ptr CreateBinderChannel( "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } @@ -175,7 +176,7 @@ std::shared_ptr CreateCustomBinderChannel( "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } @@ -186,7 +187,7 @@ std::shared_ptr CreateBinderChannel( "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } @@ -198,7 +199,7 @@ std::shared_ptr CreateCustomBinderChannel( "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } @@ -207,7 +208,7 @@ bool InitializeBinderChannelJavaClass(void* jni_env_void) { "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } @@ -217,7 +218,7 @@ bool InitializeBinderChannelJavaClass( "This APK is compiled with Android API level = %d, which is not " "supported. See port_platform.h for supported versions.", __ANDROID_API__); - GPR_ASSERT(0); + CHECK(0); return {}; } diff --git a/src/core/ext/transport/binder/client/channel_create_impl.cc b/src/core/ext/transport/binder/client/channel_create_impl.cc index 3d80e329c7b..197361104b2 100644 --- a/src/core/ext/transport/binder/client/channel_create_impl.cc +++ b/src/core/ext/transport/binder/client/channel_create_impl.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include "src/core/ext/transport/binder/client/binder_connector.h" #include "src/core/ext/transport/binder/transport/binder_transport.h" #include "src/core/ext/transport/binder/wire_format/binder.h" @@ -50,7 +52,7 @@ grpc_channel* CreateDirectBinderChannelImplForTesting( grpc_core::Transport* transport = grpc_create_binder_transport_client( std::move(endpoint_binder), security_policy); - GPR_ASSERT(transport != nullptr); + CHECK_NE(transport, nullptr); auto channel_args = grpc_core::CoreConfiguration::Get() .channel_args_preconditioning() @@ -60,7 +62,7 @@ grpc_channel* CreateDirectBinderChannelImplForTesting( grpc_core::ChannelCreate("binder_target_placeholder", channel_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); // TODO(mingcl): Handle error properly - GPR_ASSERT(channel.ok()); + CHECK(channel.ok()); grpc_channel_args_destroy(args); return channel->release()->c_ptr(); } diff --git a/src/core/ext/transport/binder/client/connection_id_generator.cc b/src/core/ext/transport/binder/client/connection_id_generator.cc index 8f434338be0..60cba34e31b 100644 --- a/src/core/ext/transport/binder/client/connection_id_generator.cc +++ b/src/core/ext/transport/binder/client/connection_id_generator.cc @@ -18,6 +18,7 @@ #ifndef GRPC_NO_BINDER +#include "absl/log/check.h" #include "absl/strings/str_cat.h" namespace { @@ -55,7 +56,7 @@ std::string ConnectionIdGenerator::Generate(absl::string_view uri) { // Insert a hyphen before serial number ret = absl::StrCat(s, "-", ++count_); } - GPR_ASSERT(ret.length() < kPathLengthLimit); + CHECK_LT(ret.length(), kPathLengthLimit); return ret; } diff --git a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc index 4241ccd77fd..5932ce7a9bf 100644 --- a/src/core/ext/transport/binder/client/endpoint_binder_pool.cc +++ b/src/core/ext/transport/binder/client/endpoint_binder_pool.cc @@ -14,6 +14,8 @@ #include "src/core/ext/transport/binder/client/endpoint_binder_pool.h" +#include "absl/log/check.h" + #include #ifndef GRPC_NO_BINDER @@ -35,12 +37,12 @@ Java_io_grpc_binder_cpp_GrpcBinderConnection_notifyConnected__Ljava_lang_String_ jboolean isCopy; const char* conn_id = jni_env->GetStringUTFChars(conn_id_jstring, &isCopy); gpr_log(GPR_INFO, "%s invoked with conn_id = %s", __func__, conn_id); - GPR_ASSERT(ibinder != nullptr); + CHECK_NE(ibinder, nullptr); grpc_binder::ndk_util::SpAIBinder aibinder = grpc_binder::FromJavaBinder(jni_env, ibinder); gpr_log(GPR_INFO, "%s got aibinder = %p", __func__, aibinder.get()); auto b = std::make_unique(aibinder); - GPR_ASSERT(b != nullptr); + CHECK(b != nullptr); grpc_binder::GetEndpointBinderPool()->AddEndpointBinder(conn_id, std::move(b)); if (isCopy == JNI_TRUE) { @@ -63,7 +65,7 @@ void EndpointBinderPool::GetEndpointBinder( if (binder_map_.count(conn_id)) { b = std::move(binder_map_[conn_id]); binder_map_.erase(conn_id); - GPR_ASSERT(b != nullptr); + CHECK(b != nullptr); } else { if (pending_requests_.count(conn_id) != 0) { gpr_log(GPR_ERROR, @@ -75,14 +77,14 @@ void EndpointBinderPool::GetEndpointBinder( return; } } - GPR_ASSERT(b != nullptr); + CHECK(b != nullptr); cb(std::move(b)); } void EndpointBinderPool::AddEndpointBinder( std::string conn_id, std::unique_ptr b) { gpr_log(GPR_INFO, "EndpointBinder added. conn_id = %s", conn_id.c_str()); - GPR_ASSERT(b != nullptr); + CHECK(b != nullptr); // cb will be set in the following block if there is a pending callback std::function)> cb = nullptr; { diff --git a/src/core/ext/transport/binder/client/jni_utils.cc b/src/core/ext/transport/binder/client/jni_utils.cc index 698fb3242e7..9255b7f1d17 100644 --- a/src/core/ext/transport/binder/client/jni_utils.cc +++ b/src/core/ext/transport/binder/client/jni_utils.cc @@ -14,6 +14,8 @@ #include "src/core/ext/transport/binder/client/jni_utils.h" +#include "absl/log/check.h" + #include #ifndef GRPC_NO_BINDER @@ -41,7 +43,7 @@ jclass FindNativeConnectionHelper( } jclass global_cl = static_cast(env->NewGlobalRef(cl)); env->DeleteLocalRef(cl); - GPR_ASSERT(global_cl != nullptr); + CHECK_NE(global_cl, nullptr); return global_cl; }; static jclass connection_helper_class = do_find(); diff --git a/src/core/ext/transport/binder/client/security_policy_setting.cc b/src/core/ext/transport/binder/client/security_policy_setting.cc index d8739142b4e..318b434e6fa 100644 --- a/src/core/ext/transport/binder/client/security_policy_setting.cc +++ b/src/core/ext/transport/binder/client/security_policy_setting.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/check.h" + #include #ifndef GRPC_NO_BINDER @@ -25,14 +27,14 @@ void SecurityPolicySetting::Set( std::shared_ptr security_policy) { grpc_core::MutexLock l(&m_); - GPR_ASSERT(security_policy_map_.count(std::string(connection_id)) == 0); + CHECK_EQ(security_policy_map_.count(std::string(connection_id)), 0u); security_policy_map_[std::string(connection_id)] = security_policy; } std::shared_ptr SecurityPolicySetting::Get(absl::string_view connection_id) { grpc_core::MutexLock l(&m_); - GPR_ASSERT(security_policy_map_.count(std::string(connection_id)) != 0); + CHECK_NE(security_policy_map_.count(std::string(connection_id)), 0u); return security_policy_map_[std::string(connection_id)]; } diff --git a/src/core/ext/transport/binder/security_policy/binder_security_policy.cc b/src/core/ext/transport/binder/security_policy/binder_security_policy.cc index a97bb6c9459..bd05a038113 100644 --- a/src/core/ext/transport/binder/security_policy/binder_security_policy.cc +++ b/src/core/ext/transport/binder/security_policy/binder_security_policy.cc @@ -23,6 +23,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/ext/transport/binder/client/jni_utils.h" @@ -61,8 +63,8 @@ JNIEnv* GetEnv(JavaVM* vm) { JNIEnv* result = nullptr; jint attach = vm->AttachCurrentThread(&result, nullptr); - GPR_ASSERT(JNI_OK == attach); - GPR_ASSERT(nullptr != result); + CHECK(JNI_OK == attach); + CHECK_NE(result, nullptr); return result; } } // namespace @@ -70,14 +72,14 @@ JNIEnv* GetEnv(JavaVM* vm) { SameSignatureSecurityPolicy::SameSignatureSecurityPolicy(JavaVM* jvm, jobject context) : jvm_(jvm) { - GPR_ASSERT(jvm != nullptr); - GPR_ASSERT(context != nullptr); + CHECK_NE(jvm, nullptr); + CHECK_NE(context, nullptr); JNIEnv* env = GetEnv(jvm_); // Make sure the context is still valid when IsAuthorized() is called context_ = env->NewGlobalRef(context); - GPR_ASSERT(context_ != nullptr); + CHECK_NE(context_, nullptr); } SameSignatureSecurityPolicy::~SameSignatureSecurityPolicy() { diff --git a/src/core/ext/transport/binder/server/binder_server.cc b/src/core/ext/transport/binder/server/binder_server.cc index 617af5da802..faf1641d7d1 100644 --- a/src/core/ext/transport/binder/server/binder_server.cc +++ b/src/core/ext/transport/binder/server/binder_server.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/check.h" #include "absl/memory/memory.h" #include @@ -159,7 +160,7 @@ class BinderServerListener : public Server::ListenerInterface { on_destroy_done_ = on_destroy_done; } - void Orphan() override { Unref(); } + void Orphan() override { delete this; } ~BinderServerListener() override { ExecCtx::Get()->Flush(); @@ -212,7 +213,7 @@ class BinderServerListener : public Server::ListenerInterface { // grpc_create_binder_transport_server(). Transport* server_transport = grpc_create_binder_transport_server( std::move(client_binder), security_policy_); - GPR_ASSERT(server_transport); + CHECK(server_transport); grpc_error_handle error = server_->SetupTransport( server_transport, nullptr, server_->channel_args(), nullptr); return grpc_error_to_absl_status(error); @@ -239,8 +240,9 @@ bool AddBinderPort(const std::string& addr, grpc_server* server, } std::string conn_id = addr.substr(kBinderUriScheme.size()); Server* core_server = Server::FromC(server); - core_server->AddListener(MakeOrphanable( - core_server, conn_id, std::move(factory), security_policy)); + core_server->AddListener( + OrphanablePtr(new BinderServerListener( + core_server, conn_id, std::move(factory), security_policy))); return true; } diff --git a/src/core/ext/transport/binder/server/binder_server_credentials.cc b/src/core/ext/transport/binder/server/binder_server_credentials.cc index 03bbe6229e1..0d8f3dd63af 100644 --- a/src/core/ext/transport/binder/server/binder_server_credentials.cc +++ b/src/core/ext/transport/binder/server/binder_server_credentials.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "absl/log/check.h" + #include #ifndef GRPC_NO_BINDER @@ -59,7 +61,7 @@ class BinderServerCredentialsImpl final : public ServerCredentials { std::shared_ptr BinderServerCredentials( std::shared_ptr security_policy) { - GPR_ASSERT(security_policy != nullptr); + CHECK_NE(security_policy, nullptr); return std::shared_ptr( new BinderServerCredentialsImpl(security_policy)); } diff --git a/src/core/ext/transport/binder/transport/binder_transport.cc b/src/core/ext/transport/binder/transport/binder_transport.cc index 8491277517a..b5e32e913b7 100644 --- a/src/core/ext/transport/binder/transport/binder_transport.cc +++ b/src/core/ext/transport/binder/transport/binder_transport.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -142,7 +143,7 @@ static void cancel_stream_locked(grpc_binder_transport* transport, grpc_error_handle error) { gpr_log(GPR_INFO, "cancel_stream_locked"); if (!stream->is_closed) { - GPR_ASSERT(stream->cancel_self_error.ok()); + CHECK(stream->cancel_self_error.ok()); stream->is_closed = true; stream->cancel_self_error = error; transport->transport_stream_receiver->CancelStream(stream->tx_code); @@ -196,8 +197,8 @@ static void recv_initial_metadata_locked(void* arg, if (!stream->is_closed) { grpc_error_handle error = [&] { - GPR_ASSERT(stream->recv_initial_metadata); - GPR_ASSERT(stream->recv_initial_metadata_ready); + CHECK(stream->recv_initial_metadata); + CHECK(stream->recv_initial_metadata_ready); if (!args->initial_metadata.ok()) { gpr_log(GPR_ERROR, "Failed to parse initial metadata"); return absl_status_to_grpc_error(args->initial_metadata.status()); @@ -233,8 +234,8 @@ static void recv_message_locked(void* arg, grpc_error_handle /*error*/) { if (!stream->is_closed) { grpc_error_handle error = [&] { - GPR_ASSERT(stream->recv_message); - GPR_ASSERT(stream->recv_message_ready); + CHECK(stream->recv_message); + CHECK(stream->recv_message_ready); if (!args->message.ok()) { gpr_log(GPR_ERROR, "Failed to receive message"); if (args->message.status().message() == @@ -277,8 +278,8 @@ static void recv_trailing_metadata_locked(void* arg, if (!stream->is_closed) { grpc_error_handle error = [&] { - GPR_ASSERT(stream->recv_trailing_metadata); - GPR_ASSERT(stream->recv_trailing_metadata_finished); + CHECK(stream->recv_trailing_metadata); + CHECK(stream->recv_trailing_metadata_finished); if (!args->trailing_metadata.ok()) { gpr_log(GPR_ERROR, "Failed to receive trailing metadata"); return absl_status_to_grpc_error(args->trailing_metadata.status()); @@ -339,11 +340,11 @@ class MetadataEncoder { void Encode(grpc_core::HttpPathMetadata, const grpc_core::Slice& value) { // TODO(b/192208403): Figure out if it is correct to simply drop '/' // prefix and treat it as rpc method name - GPR_ASSERT(value[0] == '/'); + CHECK(value[0] == '/'); std::string path = std::string(value.as_string_view().substr(1)); // Only client send method ref. - GPR_ASSERT(is_client_); + CHECK(is_client_); tx_->SetMethodRef(path); } @@ -390,9 +391,9 @@ static void perform_stream_op_locked(void* stream_op, grpc_binder_transport* transport = stream->t; if (op->cancel_stream) { // TODO(waynetu): Is this true? - GPR_ASSERT(!op->send_initial_metadata && !op->send_message && - !op->send_trailing_metadata && !op->recv_initial_metadata && - !op->recv_message && !op->recv_trailing_metadata); + CHECK(!op->send_initial_metadata && !op->send_message && + !op->send_trailing_metadata && !op->recv_initial_metadata && + !op->recv_message && !op->recv_trailing_metadata); gpr_log(GPR_INFO, "cancel_stream is_client = %d", stream->is_client); if (!stream->is_client) { // Send trailing metadata to inform the other end about the cancellation, @@ -741,8 +742,8 @@ grpc_core::Transport* grpc_create_binder_transport_client( security_policy) { gpr_log(GPR_INFO, __func__); - GPR_ASSERT(endpoint_binder != nullptr); - GPR_ASSERT(security_policy != nullptr); + CHECK(endpoint_binder != nullptr); + CHECK_NE(security_policy, nullptr); grpc_binder_transport* t = new grpc_binder_transport( std::move(endpoint_binder), /*is_client=*/true, security_policy); @@ -756,8 +757,8 @@ grpc_core::Transport* grpc_create_binder_transport_server( security_policy) { gpr_log(GPR_INFO, __func__); - GPR_ASSERT(client_binder != nullptr); - GPR_ASSERT(security_policy != nullptr); + CHECK(client_binder != nullptr); + CHECK_NE(security_policy, nullptr); grpc_binder_transport* t = new grpc_binder_transport( std::move(client_binder), /*is_client=*/false, security_policy); diff --git a/src/core/ext/transport/binder/transport/binder_transport.h b/src/core/ext/transport/binder/transport/binder_transport.h index 64f8a28e1f9..d800bcee676 100644 --- a/src/core/ext/transport/binder/transport/binder_transport.h +++ b/src/core/ext/transport/binder/transport/binder_transport.h @@ -22,6 +22,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/check.h" #include #include @@ -74,7 +75,7 @@ struct grpc_binder_transport final : public grpc_core::FilterStackTransport { // TODO(mingcl): Wrap around when all tx codes are used. "If we do detect a // collision however, we will fail the new call with UNAVAILABLE, and shut // down the transport gracefully." - GPR_ASSERT(next_free_tx_code <= LAST_CALL_TRANSACTION); + CHECK(next_free_tx_code <= LAST_CALL_TRANSACTION); return next_free_tx_code++; } diff --git a/src/core/ext/transport/binder/utils/ndk_binder.cc b/src/core/ext/transport/binder/utils/ndk_binder.cc index 39e9e9771e5..1c0ae278ac4 100644 --- a/src/core/ext/transport/binder/utils/ndk_binder.cc +++ b/src/core/ext/transport/binder/utils/ndk_binder.cc @@ -22,6 +22,8 @@ #include +#include "absl/log/check.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -36,7 +38,7 @@ void* GetNdkBinderHandle() { gpr_log( GPR_ERROR, "Cannot open libbinder_ndk.so. Does this device support API level 29?"); - GPR_ASSERT(0); + CHECK(0); } return handle; } @@ -102,7 +104,7 @@ namespace ndk_util { "dlsym failed. Cannot find %s in libbinder_ndk.so. " \ "BinderTransport requires API level >= 33", \ #name); \ - GPR_ASSERT(0); \ + CHECK(0); \ } \ return ptr diff --git a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc index 23c9a4f4734..7005a59aa6e 100644 --- a/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc +++ b/src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -38,7 +40,7 @@ void TransportStreamReceiverImpl::RegisterRecvInitialMetadata( absl::StatusOr initial_metadata{}; { grpc_core::MutexLock l(&m_); - GPR_ASSERT(initial_metadata_cbs_.count(id) == 0); + CHECK_EQ(initial_metadata_cbs_.count(id), 0u); auto iter = pending_initial_metadata_.find(id); if (iter == pending_initial_metadata_.end()) { if (trailing_metadata_recvd_.count(id)) { @@ -66,7 +68,7 @@ void TransportStreamReceiverImpl::RegisterRecvMessage( absl::StatusOr message{}; { grpc_core::MutexLock l(&m_); - GPR_ASSERT(message_cbs_.count(id) == 0); + CHECK_EQ(message_cbs_.count(id), 0u); auto iter = pending_message_.find(id); if (iter == pending_message_.end()) { // If we'd already received trailing-metadata and there's no pending @@ -100,7 +102,7 @@ void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata( std::pair, int> trailing_metadata{}; { grpc_core::MutexLock l(&m_); - GPR_ASSERT(trailing_metadata_cbs_.count(id) == 0); + CHECK_EQ(trailing_metadata_cbs_.count(id), 0u); auto iter = pending_trailing_metadata_.find(id); if (iter == pending_trailing_metadata_.end()) { trailing_metadata_cbs_[id] = std::move(cb); diff --git a/src/core/ext/transport/binder/wire_format/binder_android.cc b/src/core/ext/transport/binder/wire_format/binder_android.cc index 21e32f2da7c..fc816447c59 100644 --- a/src/core/ext/transport/binder/wire_format/binder_android.cc +++ b/src/core/ext/transport/binder/wire_format/binder_android.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" @@ -152,7 +153,7 @@ TransactionReceiverAndroid::TransactionReceiverAndroid( args.wire_reader_ref = wire_reader_ref; args.callback = &transact_cb_; binder_ = ndk_util::AIBinder_new(aibinder_class, &args); - GPR_ASSERT(binder_); + CHECK(binder_); gpr_log(GPR_INFO, "ndk_util::AIBinder_associateClass = %d", static_cast( ndk_util::AIBinder_associateClass(binder_, aibinder_class))); diff --git a/src/core/ext/transport/binder/wire_format/transaction.h b/src/core/ext/transport/binder/wire_format/transaction.h index c4681d19cbc..30f4af67ee1 100644 --- a/src/core/ext/transport/binder/wire_format/transaction.h +++ b/src/core/ext/transport/binder/wire_format/transaction.h @@ -18,6 +18,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/string_view.h" #include @@ -45,33 +46,33 @@ class Transaction { // TODO(mingcl): Consider using string_view void SetPrefix(Metadata prefix_metadata) { prefix_metadata_ = prefix_metadata; - GPR_ASSERT((flags_ & kFlagPrefix) == 0); + CHECK_EQ((flags_ & kFlagPrefix), 0); flags_ |= kFlagPrefix; } void SetMethodRef(std::string method_ref) { - GPR_ASSERT(is_client_); + CHECK(is_client_); method_ref_ = method_ref; } void SetData(std::string message_data) { message_data_ = message_data; - GPR_ASSERT((flags_ & kFlagMessageData) == 0); + CHECK_EQ((flags_ & kFlagMessageData), 0); flags_ |= kFlagMessageData; } void SetSuffix(Metadata suffix_metadata) { - if (is_client_) GPR_ASSERT(suffix_metadata.empty()); + if (is_client_) CHECK(suffix_metadata.empty()); suffix_metadata_ = suffix_metadata; - GPR_ASSERT((flags_ & kFlagSuffix) == 0); + CHECK_EQ((flags_ & kFlagSuffix), 0); flags_ |= kFlagSuffix; } void SetStatusDescription(std::string status_desc) { - GPR_ASSERT(!is_client_); - GPR_ASSERT((flags_ & kFlagStatusDescription) == 0); + CHECK(!is_client_); + CHECK_EQ((flags_ & kFlagStatusDescription), 0); status_desc_ = status_desc; } void SetStatus(int status) { - GPR_ASSERT(!is_client_); - GPR_ASSERT((flags_ >> 16) == 0); - GPR_ASSERT(status < (1 << 16)); + CHECK(!is_client_); + CHECK_EQ((flags_ >> 16), 0); + CHECK(status < (1 << 16)); flags_ |= (status << 16); } diff --git a/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc b/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc index 607127400ae..8595f8bf149 100644 --- a/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc +++ b/src/core/ext/transport/binder/wire_format/wire_reader_impl.cc @@ -25,6 +25,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/check.h" #include "absl/memory/memory.h" #include "absl/status/statusor.h" @@ -305,7 +306,7 @@ absl::Status WireReaderImpl::ProcessStreamingTransaction( absl::Seconds(5))) { return absl::DeadlineExceededError("wire_writer_ is not ready in time!"); } - GPR_ASSERT(wire_writer_); + CHECK(wire_writer_); // wire_writer_ should not be accessed while holding mu_! // Otherwise, it is possible that // 1. wire_writer_::mu_ is acquired before mu_ (NDK call back during @@ -323,7 +324,7 @@ absl::Status WireReaderImpl::ProcessStreamingTransaction( absl::Status WireReaderImpl::ProcessStreamingTransactionImpl( transaction_code_t code, ReadableParcel* parcel, int* cancellation_flags, std::queue>& deferred_func_queue) { - GPR_ASSERT(cancellation_flags); + CHECK(cancellation_flags); num_incoming_bytes_ += parcel->GetDataSize(); gpr_log(GPR_INFO, "Total incoming bytes: %" PRId64, num_incoming_bytes_); @@ -360,8 +361,8 @@ absl::Status WireReaderImpl::ProcessStreamingTransactionImpl( // TODO(waynetu): According to the protocol, "The sequence number will wrap // around to 0 if more than 2^31 messages are sent." For now we'll just // assert that it never reach such circumstances. - GPR_ASSERT(expectation < std::numeric_limits::max() && - "Sequence number too large"); + CHECK(expectation < std::numeric_limits::max()) + << "Sequence number too large"; expectation++; gpr_log(GPR_DEBUG, "sequence number = %d", seq_num); if (flags & kFlagPrefix) { diff --git a/src/core/ext/transport/binder/wire_format/wire_writer.cc b/src/core/ext/transport/binder/wire_format/wire_writer.cc index 1daef583ef5..f81d1d6172f 100644 --- a/src/core/ext/transport/binder/wire_format/wire_writer.cc +++ b/src/core/ext/transport/binder/wire_format/wire_writer.cc @@ -21,6 +21,7 @@ #include #include "absl/cleanup/cleanup.h" +#include "absl/log/check.h" #include "absl/types/variant.h" #include @@ -122,7 +123,7 @@ absl::Status WireWriterImpl::MakeBinderTransaction( gpr_log(GPR_INFO, "Total outgoing bytes: %" PRId64, num_outgoing_bytes_.load()); } - GPR_ASSERT(!is_transacting_); + CHECK(!is_transacting_); is_transacting_ = true; absl::Status result = binder_->Transact(tx_code); is_transacting_ = false; @@ -155,10 +156,10 @@ absl::Status WireWriterImpl::RunStreamTx( bool* is_last_chunk) { Transaction* tx = stream_tx->tx.get(); // Transaction without data flag should go to fast path. - GPR_ASSERT(tx->GetFlags() & kFlagMessageData); + CHECK(tx->GetFlags() & kFlagMessageData); absl::string_view data = tx->GetMessageData(); - GPR_ASSERT(stream_tx->bytes_sent <= static_cast(data.size())); + CHECK(stream_tx->bytes_sent <= static_cast(data.size())); int flags = kFlagMessageData; @@ -206,7 +207,7 @@ absl::Status WireWriterImpl::RunStreamTx( } void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { - GPR_ASSERT(args->writer == this); + CHECK(args->writer == this); if (absl::holds_alternative(args->tx)) { int64_t num_bytes = absl::get(args->tx).num_bytes; @@ -223,7 +224,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { delete args; return; } - GPR_ASSERT(absl::holds_alternative(args->tx)); + CHECK(absl::holds_alternative(args->tx)); RunScheduledTxArgs::StreamTx* stream_tx = &absl::get(args->tx); // Be reservative. Decrease CombinerTxCount after the data size of this @@ -232,7 +233,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { auto decrease_combiner_tx_count = absl::MakeCleanup([this]() { { grpc_core::MutexLock lock(&flow_control_mu_); - GPR_ASSERT(num_non_acked_tx_in_combiner_ > 0); + CHECK_GT(num_non_acked_tx_in_combiner_, 0); num_non_acked_tx_in_combiner_--; } // New transaction might be ready to be scheduled. @@ -271,7 +272,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) { absl::Status WireWriterImpl::RpcCall(std::unique_ptr tx) { // TODO(mingcl): check tx_code <= last call id - GPR_ASSERT(tx->GetTxCode() >= kFirstCallId); + CHECK(tx->GetTxCode() >= kFirstCallId); auto args = new RunScheduledTxArgs(); args->writer = this; args->tx = RunScheduledTxArgs::StreamTx(); diff --git a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc index 7dd94de3090..e00bcc1b379 100644 --- a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc +++ b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.cc @@ -103,8 +103,8 @@ absl::StatusOr ChaoticGoodServerListener::Bind( str.ok() ? str->c_str() : str.status().ToString().c_str()); } EventEngine::Listener::AcceptCallback accept_cb = - [self = RefAsSubclass()]( - std::unique_ptr ep, MemoryAllocator) { + [self = Ref()](std::unique_ptr ep, + MemoryAllocator) { ExecCtx exec_ctx; MutexLock lock(&self->mu_); if (self->shutdown_) return; @@ -149,8 +149,7 @@ absl::Status ChaoticGoodServerListener::StartListening() { ChaoticGoodServerListener::ActiveConnection::ActiveConnection( RefCountedPtr listener, std::unique_ptr endpoint) - : memory_allocator_(listener->memory_allocator_), - listener_(std::move(listener)) { + : memory_allocator_(listener->memory_allocator_), listener_(listener) { handshaking_state_ = MakeRefCounted(Ref()); handshaking_state_->Start(std::move(endpoint)); } diff --git a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h index 0479016c15b..404bbbf946d 100644 --- a/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h +++ b/src/core/ext/transport/chaotic_good/server/chaotic_good_server.h @@ -49,7 +49,9 @@ namespace grpc_core { namespace chaotic_good { -class ChaoticGoodServerListener final : public Server::ListenerInterface { +class ChaoticGoodServerListener final + : public Server::ListenerInterface, + public RefCounted { public: static absl::AnyInvocable DefaultConnectionIDGenerator() { return [bitgen = absl::BitGen()]() mutable { diff --git a/src/core/ext/transport/chttp2/alpn/alpn.cc b/src/core/ext/transport/chttp2/alpn/alpn.cc index 1525e0b26c6..70f576a4448 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.cc +++ b/src/core/ext/transport/chttp2/alpn/alpn.cc @@ -18,6 +18,8 @@ #include "src/core/ext/transport/chttp2/alpn/alpn.h" +#include "absl/log/check.h" + #include #include @@ -42,6 +44,6 @@ size_t grpc_chttp2_num_alpn_versions(void) { } const char* grpc_chttp2_get_alpn_version_index(size_t i) { - GPR_ASSERT(i < GPR_ARRAY_SIZE(supported_versions)); + CHECK_LT(i, GPR_ARRAY_SIZE(supported_versions)); return supported_versions[i]; } diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 95d6ce55d9c..2d64d03e4ff 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -24,6 +24,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" @@ -104,11 +105,11 @@ void Chttp2Connector::Connect(const Args& args, Result* result, grpc_closure* notify) { { MutexLock lock(&mu_); - GPR_ASSERT(notify_ == nullptr); + CHECK_EQ(notify_, nullptr); args_ = args; result_ = result; notify_ = notify; - GPR_ASSERT(endpoint_ == nullptr); + CHECK_EQ(endpoint_, nullptr); event_engine_ = args_.channel_args.GetObject(); } absl::StatusOr address = grpc_sockaddr_to_uri(args.address); @@ -166,7 +167,7 @@ void Chttp2Connector::OnHandshakeDone(void* arg, grpc_error_handle error) { } else if (args->endpoint != nullptr) { self->result_->transport = grpc_create_chttp2_transport(args->args, args->endpoint, true); - GPR_ASSERT(self->result_->transport != nullptr); + CHECK_NE(self->result_->transport, nullptr); self->result_->socket_node = grpc_chttp2_transport_get_socket_node(self->result_->transport); self->result_->channel_args = args->args; @@ -188,7 +189,7 @@ void Chttp2Connector::OnHandshakeDone(void* arg, grpc_error_handle error) { // If the handshaking succeeded but there is no endpoint, then the // handshaker may have handed off the connection to some external // code. Just verify that exit_early flag is set. - GPR_DEBUG_ASSERT(args->exit_early); + DCHECK(args->exit_early); NullThenSchedClosure(DEBUG_LOCATION, &self->notify_, error); } self->handshake_mgr_.reset(); @@ -396,14 +397,14 @@ grpc_channel* grpc_channel_create_from_fd(const char* target, int fd, .SetObject(creds->Ref()); int flags = fcntl(fd, F_GETFL, 0); - GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); + CHECK_EQ(fcntl(fd, F_SETFL, flags | O_NONBLOCK), 0); grpc_endpoint* client = grpc_tcp_create_from_fd( grpc_fd_create(fd, "client", true), grpc_event_engine::experimental::ChannelArgsEndpointConfig(final_args), "fd-client"); grpc_core::Transport* transport = grpc_create_chttp2_transport(final_args, client, true); - GPR_ASSERT(transport); + CHECK(transport); auto channel = grpc_core::ChannelCreate( target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); if (channel.ok()) { @@ -424,7 +425,7 @@ grpc_channel* grpc_channel_create_from_fd(const char* /* target */, int /* fd */, grpc_channel_credentials* /* creds*/, const grpc_channel_args* /* args */) { - GPR_ASSERT(0); + CHECK(0); return nullptr; } diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index df9be768db0..9b7770e4930 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -29,6 +29,7 @@ #include #include "absl/base/thread_annotations.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -41,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -58,8 +58,6 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/event_engine/channel_args_endpoint_config.h" -#include "src/core/lib/event_engine/extensions/supports_fd.h" -#include "src/core/lib/event_engine/query_extensions.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -69,7 +67,6 @@ #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" -#include "src/core/lib/iomgr/event_engine_shims/endpoint.h" #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/iomgr/resolve_address.h" @@ -96,11 +93,9 @@ #endif // GPR_SUPPORT_CHANNELS_FROM_FD namespace grpc_core { +namespace { -using grpc_event_engine::experimental::ChannelArgsEndpointConfig; -using grpc_event_engine::experimental::EventEngine; -using grpc_event_engine::experimental::EventEngineSupportsFdExtension; -using grpc_event_engine::experimental::QueryExtension; +using ::grpc_event_engine::experimental::EventEngine; const char kUnixUriPrefix[] = "unix:"; const char kUnixAbstractUriPrefix[] = "unix-abstract:"; @@ -117,23 +112,14 @@ class Chttp2ServerListener : public Server::ListenerInterface { Server* server, const char* name, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier); - static Chttp2ServerListener* CreateForPassiveListener( - Server* server, const ChannelArgs& args, - std::shared_ptr passive_listener); - // Do not instantiate directly. Use one of the factory methods above. Chttp2ServerListener(Server* server, const ChannelArgs& args, - Chttp2ServerArgsModifier args_modifier, - grpc_server_config_fetcher* config_fetcher, - std::shared_ptr - passive_listener = nullptr); + Chttp2ServerArgsModifier args_modifier); ~Chttp2ServerListener() override; void Start(Server* server, const std::vector* pollsets) override; - void AcceptConnectedEndpoint(std::unique_ptr endpoint); - channelz::ListenSocketNode* channelz_listen_socket_node() const override { return channelz_listen_socket_.get(); } @@ -143,8 +129,6 @@ class Chttp2ServerListener : public Server::ListenerInterface { void Orphan() override; private: - friend class experimental::PassiveListenerImpl; - class ConfigFetcherWatcher : public grpc_server_config_fetcher::WatcherInterface { public: @@ -251,8 +235,34 @@ class Chttp2ServerListener : public Server::ListenerInterface { static void DestroyListener(Server* /*server*/, void* arg, grpc_closure* destroy_done); - Server* const server_ = nullptr; - grpc_tcp_server* tcp_server_ = nullptr; + // The interface required by RefCountedPtr<> has been manually implemented + // here to take a ref on tcp_server_ instead. Note that, the handshaker + // needs tcp_server_ to exist for the lifetime of the handshake since it's + // needed by acceptor. Sharing refs between the listener and tcp_server_ is + // just an optimization to avoid taking additional refs on the listener, + // since TcpServerShutdownComplete already holds a ref to the listener. + void IncrementRefCount() { grpc_tcp_server_ref(tcp_server_); } + void IncrementRefCount(const DebugLocation& /* location */, + const char* /* reason */) { + IncrementRefCount(); + } + + GRPC_MUST_USE_RESULT RefCountedPtr Ref() { + IncrementRefCount(); + return RefCountedPtr(this); + } + GRPC_MUST_USE_RESULT RefCountedPtr Ref( + const DebugLocation& /* location */, const char* /* reason */) { + return Ref(); + } + + void Unref() { grpc_tcp_server_unref(tcp_server_); } + void Unref(const DebugLocation& /* location */, const char* /* reason */) { + Unref(); + } + + Server* const server_; + grpc_tcp_server* tcp_server_; grpc_resolved_address resolved_address_; Chttp2ServerArgsModifier const args_modifier_; ConfigFetcherWatcher* config_fetcher_watcher_ = nullptr; @@ -275,10 +285,6 @@ class Chttp2ServerListener : public Server::ListenerInterface { RefCountedPtr channelz_listen_socket_; MemoryQuotaRefPtr memory_quota_; ConnectionQuotaRefPtr connection_quota_; - grpc_server_config_fetcher* config_fetcher_ = nullptr; - // TODO(yashykt): consider using absl::variant<> to minimize memory usage for - // disjoint cases where different fields are used. - std::shared_ptr passive_listener_; }; // @@ -303,7 +309,7 @@ void Chttp2ServerListener::ConfigFetcherWatcher::UpdateConnectionManager( void set_connections( std::map> connections) { - GPR_ASSERT(connections_.empty()); + CHECK(connections_.empty()); connections_ = std::move(connections); } @@ -329,7 +335,7 @@ void Chttp2ServerListener::ConfigFetcherWatcher::UpdateConnectionManager( StatusToString(error).c_str()); // TODO(yashykt): We wouldn't need to assert here if we bound to the // port earlier during AddPort. - GPR_ASSERT(0); + CHECK(0); } listener_->StartListening(); { @@ -375,17 +381,13 @@ Chttp2ServerListener::ActiveConnection::HandshakingState::HandshakingState( handshake_mgr_(MakeRefCounted()), deadline_(GetConnectionDeadline(args)), interested_parties_(grpc_pollset_set_create()) { - if (accepting_pollset != nullptr) { - grpc_pollset_set_add_pollset(interested_parties_, accepting_pollset_); - } + grpc_pollset_set_add_pollset(interested_parties_, accepting_pollset_); CoreConfiguration::Get().handshaker_registry().AddHandshakers( HANDSHAKER_SERVER, args, interested_parties_, handshake_mgr_.get()); } Chttp2ServerListener::ActiveConnection::HandshakingState::~HandshakingState() { - if (accepting_pollset_ != nullptr) { - grpc_pollset_set_del_pollset(interested_parties_, accepting_pollset_); - } + grpc_pollset_set_del_pollset(interested_parties_, accepting_pollset_); grpc_pollset_set_destroy(interested_parties_); gpr_free(acceptor_); } @@ -707,82 +709,83 @@ void Chttp2ServerListener::ActiveConnection::OnDrainGraceTimeExpiry() { grpc_error_handle Chttp2ServerListener::Create( Server* server, grpc_resolved_address* addr, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier, int* port_num) { - // Create Chttp2ServerListener. - OrphanablePtr listener = - MakeOrphanable(server, args, args_modifier, - server->config_fetcher()); - // The tcp_server will be unreffed when the listener is orphaned, which could - // be at the end of this function if the listener was not added to the - // server's set of listeners. - grpc_error_handle error = grpc_tcp_server_create( - &listener->tcp_server_shutdown_complete_, ChannelArgsEndpointConfig(args), - OnAccept, listener.get(), &listener->tcp_server_); - if (!error.ok()) return error; - if (listener->config_fetcher_ != nullptr) { - listener->resolved_address_ = *addr; - // TODO(yashykt): Consider binding so as to be able to return the port - // number. - } else { - error = grpc_tcp_server_add_port(listener->tcp_server_, addr, port_num); + Chttp2ServerListener* listener = nullptr; + // The bulk of this method is inside of a lambda to make cleanup + // easier without using goto. + grpc_error_handle error = [&]() { + grpc_error_handle error; + // Create Chttp2ServerListener. + listener = new Chttp2ServerListener(server, args, args_modifier); + error = grpc_tcp_server_create( + &listener->tcp_server_shutdown_complete_, + grpc_event_engine::experimental::ChannelArgsEndpointConfig(args), + OnAccept, listener, &listener->tcp_server_); if (!error.ok()) return error; - } - // Create channelz node. - if (args.GetBool(GRPC_ARG_ENABLE_CHANNELZ) - .value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) { - auto string_address = grpc_sockaddr_to_uri(addr); - if (!string_address.ok()) { - return GRPC_ERROR_CREATE(string_address.status().ToString()); + if (server->config_fetcher() != nullptr) { + listener->resolved_address_ = *addr; + // TODO(yashykt): Consider binding so as to be able to return the port + // number. + } else { + error = grpc_tcp_server_add_port(listener->tcp_server_, addr, port_num); + if (!error.ok()) return error; + } + // Create channelz node. + if (args.GetBool(GRPC_ARG_ENABLE_CHANNELZ) + .value_or(GRPC_ENABLE_CHANNELZ_DEFAULT)) { + auto string_address = grpc_sockaddr_to_uri(addr); + if (!string_address.ok()) { + return GRPC_ERROR_CREATE(string_address.status().ToString()); + } + listener->channelz_listen_socket_ = + MakeRefCounted( + *string_address, + absl::StrCat("chttp2 listener ", *string_address)); + } + // Register with the server only upon success + server->AddListener(OrphanablePtr(listener)); + return absl::OkStatus(); + }(); + if (!error.ok()) { + if (listener != nullptr) { + if (listener->tcp_server_ != nullptr) { + // listener is deleted when tcp_server_ is shutdown. + grpc_tcp_server_unref(listener->tcp_server_); + } else { + delete listener; + } } - listener->channelz_listen_socket_ = - MakeRefCounted( - *string_address, absl::StrCat("chttp2 listener ", *string_address)); } - // Register with the server only upon success - server->AddListener(std::move(listener)); - return absl::OkStatus(); + return error; } grpc_error_handle Chttp2ServerListener::CreateWithAcceptor( Server* server, const char* name, const ChannelArgs& args, Chttp2ServerArgsModifier args_modifier) { - auto listener = MakeOrphanable( - server, args, args_modifier, server->config_fetcher()); + Chttp2ServerListener* listener = + new Chttp2ServerListener(server, args, args_modifier); grpc_error_handle error = grpc_tcp_server_create( - &listener->tcp_server_shutdown_complete_, ChannelArgsEndpointConfig(args), - OnAccept, listener.get(), &listener->tcp_server_); - if (!error.ok()) return error; + &listener->tcp_server_shutdown_complete_, + grpc_event_engine::experimental::ChannelArgsEndpointConfig(args), + OnAccept, listener, &listener->tcp_server_); + if (!error.ok()) { + delete listener; + return error; + } // TODO(yangg) channelz TcpServerFdHandler** arg_val = args.GetPointer(name); *arg_val = grpc_tcp_server_create_fd_handler(listener->tcp_server_); - server->AddListener(std::move(listener)); + server->AddListener(OrphanablePtr(listener)); return absl::OkStatus(); } -Chttp2ServerListener* Chttp2ServerListener::CreateForPassiveListener( - Server* server, const ChannelArgs& args, - std::shared_ptr passive_listener) { - // TODO(hork): figure out how to handle channelz in this case - auto listener = MakeOrphanable( - server, args, /*args_modifier=*/ - [](const ChannelArgs& args, grpc_error_handle*) { return args; }, nullptr, - std::move(passive_listener)); - auto listener_ptr = listener.get(); - server->AddListener(std::move(listener)); - return listener_ptr; -} - Chttp2ServerListener::Chttp2ServerListener( Server* server, const ChannelArgs& args, - Chttp2ServerArgsModifier args_modifier, - grpc_server_config_fetcher* config_fetcher, - std::shared_ptr passive_listener) + Chttp2ServerArgsModifier args_modifier) : server_(server), args_modifier_(args_modifier), args_(args), memory_quota_(args.GetObject()->memory_quota()), - connection_quota_(MakeRefCounted()), - config_fetcher_(config_fetcher), - passive_listener_(std::move(passive_listener)) { + connection_quota_(MakeRefCounted()) { auto max_allowed_incoming_connections = args.GetInt(GRPC_ARG_MAX_ALLOWED_INCOMING_CONNECTIONS); if (max_allowed_incoming_connections.has_value()) { @@ -797,9 +800,6 @@ Chttp2ServerListener::~Chttp2ServerListener() { // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. ExecCtx::Get()->Flush(); - if (passive_listener_ != nullptr) { - passive_listener_->ListenerDestroyed(); - } if (on_destroy_done_ != nullptr) { ExecCtx::Run(DEBUG_LOCATION, on_destroy_done_, absl::OkStatus()); ExecCtx::Get()->Flush(); @@ -809,11 +809,10 @@ Chttp2ServerListener::~Chttp2ServerListener() { // Server callback: start listening on our ports void Chttp2ServerListener::Start( Server* /*server*/, const std::vector* /* pollsets */) { - if (config_fetcher_ != nullptr) { - auto watcher = std::make_unique( - RefAsSubclass()); + if (server_->config_fetcher() != nullptr) { + auto watcher = std::make_unique(Ref()); config_fetcher_watcher_ = watcher.get(); - config_fetcher_->StartWatch( + server_->config_fetcher()->StartWatch( grpc_sockaddr_to_string(&resolved_address_, false).value(), std::move(watcher)); } else { @@ -827,9 +826,7 @@ void Chttp2ServerListener::Start( } void Chttp2ServerListener::StartListening() { - if (tcp_server_ != nullptr) { - grpc_tcp_server_start(tcp_server_, &server_->pollsets()); - } + grpc_tcp_server_start(tcp_server_, &server_->pollsets()); } void Chttp2ServerListener::SetOnDestroyDone(grpc_closure* on_destroy_done) { @@ -837,12 +834,6 @@ void Chttp2ServerListener::SetOnDestroyDone(grpc_closure* on_destroy_done) { on_destroy_done_ = on_destroy_done; } -void Chttp2ServerListener::AcceptConnectedEndpoint( - std::unique_ptr endpoint) { - OnAccept(this, grpc_event_engine_endpoint_create(std::move(endpoint)), - /*accepting_pollset=*/nullptr, /*acceptor=*/nullptr); -} - void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { @@ -867,7 +858,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, endpoint_cleanup(error); return; } - if (self->config_fetcher_ != nullptr) { + if (self->server_->config_fetcher() != nullptr) { if (connection_manager == nullptr) { grpc_error_handle error = GRPC_ERROR_CREATE( "No ConnectionManager configured. Closing connection."); @@ -908,7 +899,7 @@ void Chttp2ServerListener::OnAccept(void* arg, grpc_endpoint* tcp, // heap-use-after-free issues where `Ref()` is invoked when the ref of // tcp_server_ has already reached 0. (Ref() implementation of // Chttp2ServerListener is grpc_tcp_server_ref().) - listener_ref = self->RefAsSubclass(); + listener_ref = self->Ref(); self->connections_.emplace(connection.get(), std::move(connection)); } } @@ -923,7 +914,7 @@ void Chttp2ServerListener::TcpServerShutdownComplete( void* arg, grpc_error_handle /*error*/) { Chttp2ServerListener* self = static_cast(arg); self->channelz_listen_socket_.reset(); - self->Unref(); + delete self; } // Server callback: destroy the tcp listener (so we don't generate further @@ -932,8 +923,7 @@ void Chttp2ServerListener::Orphan() { // Cancel the watch before shutting down so as to avoid holding a ref to the // listener in the watcher. if (config_fetcher_watcher_ != nullptr) { - GPR_ASSERT(config_fetcher_ != nullptr); - config_fetcher_->CancelWatch(config_fetcher_watcher_); + server_->config_fetcher()->CancelWatch(config_fetcher_watcher_); } std::map> connections; grpc_tcp_server* tcp_server; @@ -951,14 +941,12 @@ void Chttp2ServerListener::Orphan() { } tcp_server = tcp_server_; } - if (tcp_server != nullptr) { - grpc_tcp_server_shutdown_listeners(tcp_server); - grpc_tcp_server_unref(tcp_server); - } else { - Unref(); - } + grpc_tcp_server_shutdown_listeners(tcp_server); + grpc_tcp_server_unref(tcp_server); } +} // namespace + // // Chttp2ServerAddPort() // @@ -1013,7 +1001,7 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr, if (*port_num == -1) { *port_num = port_temp; } else { - GPR_ASSERT(*port_num == port_temp); + CHECK(*port_num == port_temp); } } } @@ -1059,50 +1047,6 @@ ChannelArgs ModifyArgsForConnection(const ChannelArgs& args, } } // namespace - -namespace experimental { - -absl::Status PassiveListenerImpl::AcceptConnectedEndpoint( - std::unique_ptr endpoint) { - GPR_ASSERT(server_ != nullptr); - RefCountedPtr listener; - { - MutexLock lock(&mu_); - if (listener_ != nullptr) { - listener = - listener_->RefIfNonZero().TakeAsSubclass(); - } - } - if (listener == nullptr) { - return absl::UnavailableError("passive listener already shut down"); - } - ExecCtx exec_ctx; - listener->AcceptConnectedEndpoint(std::move(endpoint)); - return absl::OkStatus(); -} - -absl::Status PassiveListenerImpl::AcceptConnectedFd(int fd) { - GPR_ASSERT(server_ != nullptr); - ExecCtx exec_ctx; - auto& args = server_->channel_args(); - auto* supports_fd = QueryExtension( - /*engine=*/args.GetObjectRef().get()); - if (supports_fd == nullptr) { - return absl::UnimplementedError( - "The server's EventEngine does not support adding endpoints from " - "connected file descriptors."); - } - auto endpoint = - supports_fd->CreateEndpointFromFd(fd, ChannelArgsEndpointConfig(args)); - return AcceptConnectedEndpoint(std::move(endpoint)); -} - -void PassiveListenerImpl::ListenerDestroyed() { - MutexLock lock(&mu_); - listener_ = nullptr; -} - -} // namespace experimental } // namespace grpc_core int grpc_server_add_http2_port(grpc_server* server, const char* addr, @@ -1196,35 +1140,7 @@ void grpc_server_add_channel_from_fd(grpc_server* server, int fd, void grpc_server_add_channel_from_fd(grpc_server* /* server */, int /* fd */, grpc_server_credentials* /* creds */) { - GPR_ASSERT(0); + CHECK(0); } #endif // GPR_SUPPORT_CHANNELS_FROM_FD - -absl::Status grpc_server_add_passive_listener( - grpc_core::Server* server, grpc_server_credentials* credentials, - std::shared_ptr - passive_listener) { - grpc_core::ExecCtx exec_ctx; - GRPC_API_TRACE("grpc_server_add_passive_listener(server=%p, credentials=%p)", - 2, (server, credentials)); - // Create security context. - if (credentials == nullptr) { - return absl::UnavailableError( - "No credentials specified for passive listener"); - } - auto sc = credentials->create_security_connector(grpc_core::ChannelArgs()); - if (sc == nullptr) { - return absl::UnavailableError( - absl::StrCat("Unable to create secure server with credentials of type ", - credentials->type().name())); - } - auto args = server->channel_args() - .SetObject(credentials->Ref()) - .SetObject(std::move(sc)); - passive_listener->listener_ = - grpc_core::Chttp2ServerListener::CreateForPassiveListener( - server, args, passive_listener); - passive_listener->server_ = server->Ref(); - return absl::OkStatus(); -} diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h index 25d38236aed..26c178be917 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.h +++ b/src/core/ext/transport/chttp2/server/chttp2_server.h @@ -21,7 +21,6 @@ #include -#include #include #include "src/core/lib/channel/channel_args.h" @@ -43,38 +42,6 @@ grpc_error_handle Chttp2ServerAddPort( Server* server, const char* addr, const ChannelArgs& args, Chttp2ServerArgsModifier connection_args_modifier, int* port_num); -class Chttp2ServerListener; -namespace experimental { - -// An implementation of the public C++ passive listener interface. -// The server builder holds a weak_ptr to one of these objects, and the -// application owns the instance. -class PassiveListenerImpl final : public PassiveListener { - public: - absl::Status AcceptConnectedEndpoint( - std::unique_ptr - endpoint) override ABSL_LOCKS_EXCLUDED(mu_); - - absl::Status AcceptConnectedFd(GRPC_UNUSED int fd) override - ABSL_LOCKS_EXCLUDED(mu_); - - void ListenerDestroyed() ABSL_LOCKS_EXCLUDED(mu_); - - private: - // note: the grpc_core::Server redundant namespace qualification is - // required for older gcc versions. - friend absl::Status(::grpc_server_add_passive_listener)( - grpc_core::Server* server, grpc_server_credentials* credentials, - std::shared_ptr - passive_listener); - - Mutex mu_; - // Data members will be populated when initialized. - RefCountedPtr server_; - Chttp2ServerListener* listener_; -}; - -} // namespace experimental } // namespace grpc_core #endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_SERVER_CHTTP2_SERVER_H diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 78a55b6cecc..ff23af19c33 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -19,6 +19,7 @@ #include "src/core/ext/transport/chttp2/transport/bin_decoder.h" #include "absl/base/attributes.h" +#include "absl/log/check.h" #include #include @@ -198,8 +199,8 @@ grpc_slice grpc_chttp2_base64_decode(const grpc_slice& input) { grpc_core::CSliceUnref(output); return grpc_empty_slice(); } - GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); - GPR_ASSERT(ctx.input_cur == GRPC_SLICE_END_PTR(input)); + CHECK(ctx.output_cur == GRPC_SLICE_END_PTR(output)); + CHECK(ctx.input_cur == GRPC_SLICE_END_PTR(input)); return output; } @@ -245,7 +246,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(const grpc_slice& input, grpc_core::CSliceUnref(output); return grpc_empty_slice(); } - GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); - GPR_ASSERT(ctx.input_cur <= GRPC_SLICE_END_PTR(input)); + CHECK(ctx.output_cur == GRPC_SLICE_END_PTR(output)); + CHECK(ctx.input_cur <= GRPC_SLICE_END_PTR(input)); return output; } diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index 821006f2ce6..cf024f03d49 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -87,8 +89,8 @@ grpc_slice grpc_chttp2_base64_encode(const grpc_slice& input) { break; } - GPR_ASSERT(out == (char*)GRPC_SLICE_END_PTR(output)); - GPR_ASSERT(in == GRPC_SLICE_END_PTR(input)); + CHECK(out == (char*)GRPC_SLICE_END_PTR(output)); + CHECK(in == GRPC_SLICE_END_PTR(input)); return output; } @@ -131,7 +133,7 @@ grpc_slice grpc_chttp2_huffman_compress(const grpc_slice& input) { static_cast(0xffu >> temp_length)); } - GPR_ASSERT(out == GRPC_SLICE_END_PTR(output)); + CHECK(out == GRPC_SLICE_END_PTR(output)); return output; } @@ -227,9 +229,9 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress( static_cast(0xffu >> out.temp_length)); } - GPR_ASSERT(out.out <= GRPC_SLICE_END_PTR(output)); + CHECK(out.out <= GRPC_SLICE_END_PTR(output)); GRPC_SLICE_SET_LENGTH(output, out.out - start_out); - GPR_ASSERT(in == GRPC_SLICE_END_PTR(input)); + CHECK(in == GRPC_SLICE_END_PTR(input)); return output; } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 1af3a893c6a..9a28649dd52 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -34,6 +34,7 @@ #include "absl/base/attributes.h" #include "absl/container/flat_hash_map.h" #include "absl/hash/hash.h" +#include "absl/log/check.h" #include "absl/meta/type_traits.h" #include "absl/random/random.h" #include "absl/status/status.h" @@ -398,11 +399,11 @@ grpc_chttp2_transport::~grpc_chttp2_transport() { grpc_chttp2_goaway_parser_destroy(&goaway_parser); for (i = 0; i < STREAM_LIST_COUNT; i++) { - GPR_ASSERT(lists[i].head == nullptr); - GPR_ASSERT(lists[i].tail == nullptr); + CHECK_EQ(lists[i].head, nullptr); + CHECK_EQ(lists[i].tail, nullptr); } - GPR_ASSERT(stream_map.empty()); + CHECK(stream_map.empty()); GRPC_COMBINER_UNREF(combiner, "chttp2_transport"); while (write_cb_pool) { @@ -573,7 +574,7 @@ static void read_channel_args(grpc_chttp2_transport* t, static void init_keepalive_pings_if_enabled_locked( grpc_core::RefCountedPtr t, GRPC_UNUSED grpc_error_handle error) { - GPR_DEBUG_ASSERT(error.ok()); + DCHECK(error.ok()); if (t->keepalive_time != grpc_core::Duration::Infinity()) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; t->keepalive_ping_timer_handle = @@ -616,8 +617,8 @@ grpc_chttp2_transport::grpc_chttp2_transport( deframe_state(is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0), is_client(is_client) { cl = new grpc_core::ContextList(); - GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) == - GRPC_CHTTP2_CLIENT_CONNECT_STRLEN); + CHECK(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) == + GRPC_CHTTP2_CLIENT_CONNECT_STRLEN); grpc_slice_buffer_init(&read_buffer); if (is_client) { @@ -706,7 +707,7 @@ static void close_transport_locked(grpc_chttp2_transport* t, grpc_error_add_child(t->close_transport_on_writes_finished, error); return; } - GPR_ASSERT(!error.ok()); + CHECK(!error.ok()); t->closed_with_error = error; connectivity_state_set(t, GRPC_CHANNEL_SHUTDOWN, absl::Status(), "close_transport"); @@ -750,7 +751,7 @@ static void close_transport_locked(grpc_chttp2_transport* t, while (grpc_chttp2_list_pop_writable_stream(t, &s)) { GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:close"); } - GPR_ASSERT(t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE); + CHECK(t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE); grpc_endpoint_shutdown(t->ep, error); } if (t->notify_on_receive_settings != nullptr) { @@ -826,9 +827,9 @@ grpc_chttp2_stream::~grpc_chttp2_stream() { } } - GPR_ASSERT((write_closed && read_closed) || id == 0); + CHECK((write_closed && read_closed) || id == 0); if (id != 0) { - GPR_ASSERT(t->stream_map.count(id) == 0); + CHECK_EQ(t->stream_map.count(id), 0u); } grpc_slice_buffer_destroy(&frame_storage); @@ -841,11 +842,11 @@ grpc_chttp2_stream::~grpc_chttp2_stream() { } } - GPR_ASSERT(send_initial_metadata_finished == nullptr); - GPR_ASSERT(send_trailing_metadata_finished == nullptr); - GPR_ASSERT(recv_initial_metadata_ready == nullptr); - GPR_ASSERT(recv_message_ready == nullptr); - GPR_ASSERT(recv_trailing_metadata_finished == nullptr); + CHECK_EQ(send_initial_metadata_finished, nullptr); + CHECK_EQ(send_trailing_metadata_finished, nullptr); + CHECK_EQ(recv_initial_metadata_ready, nullptr); + CHECK_EQ(recv_message_ready, nullptr); + CHECK_EQ(recv_trailing_metadata_finished, nullptr); grpc_slice_buffer_destroy(&flow_controlled_buffer); grpc_core::ExecCtx::Run(DEBUG_LOCATION, destroy_stream_arg, absl::OkStatus()); } @@ -878,7 +879,7 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, return nullptr; } grpc_chttp2_stream* accepting = nullptr; - GPR_ASSERT(t->accepting_stream == nullptr); + CHECK_EQ(t->accepting_stream, nullptr); t->accepting_stream = &accepting; t->accept_stream_cb(t->accept_stream_cb_user_data, t, reinterpret_cast(id)); @@ -980,7 +981,7 @@ static const char* begin_writing_desc(bool partial) { static void write_action_begin_locked( grpc_core::RefCountedPtr t, grpc_error_handle /*error_ignored*/) { - GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); + CHECK(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); grpc_chttp2_begin_write_result r; if (!t->closed_with_error.ok()) { r.writing = false; @@ -994,7 +995,7 @@ static void write_action_begin_locked( begin_writing_desc(r.partial)); write_action(t.get()); if (t->reading_paused_on_pending_induced_frames) { - GPR_ASSERT(t->num_pending_induced_frames == 0); + CHECK_EQ(t->num_pending_induced_frames, 0u); // We had paused reading, because we had many induced frames (SETTINGS // ACK, PINGS ACK and RST_STREAMS) pending in t->qbuf. Now that we have // been able to flush qbuf, we can resume reading. @@ -1211,7 +1212,7 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) { "HTTP:%s: Transport %p allocating new grpc_chttp2_stream %p to id %d", t->is_client ? "CLI" : "SVR", t, s, t->next_stream_id)); - GPR_ASSERT(s->id == 0); + CHECK_EQ(s->id, 0u); s->id = t->next_stream_id; t->next_stream_id += 2; @@ -1384,7 +1385,7 @@ static void perform_stream_op_locked(void* stream_op, if (t->is_client && t->channelz_socket != nullptr) { t->channelz_socket->RecordStreamStartedFromLocal(); } - GPR_ASSERT(s->send_initial_metadata_finished == nullptr); + CHECK_EQ(s->send_initial_metadata_finished, nullptr); on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; s->send_initial_metadata_finished = add_closure_barrier(on_complete); @@ -1402,7 +1403,7 @@ static void perform_stream_op_locked(void* stream_op, if (!s->write_closed) { if (t->is_client) { if (t->closed_with_error.ok()) { - GPR_ASSERT(s->id == 0); + CHECK_EQ(s->id, 0u); grpc_chttp2_list_add_waiting_for_concurrency(t, s); maybe_start_some_streams(t); } else { @@ -1419,7 +1420,7 @@ static void perform_stream_op_locked(void* stream_op, false); } } else { - GPR_ASSERT(s->id != 0); + CHECK_NE(s->id, 0u); grpc_chttp2_mark_stream_writable(t, s); if (!(op->send_message && (op->payload->send_message.flags & GRPC_WRITE_BUFFER_HINT))) { @@ -1520,7 +1521,7 @@ static void perform_stream_op_locked(void* stream_op, } if (op->send_trailing_metadata) { - GPR_ASSERT(s->send_trailing_metadata_finished == nullptr); + CHECK_EQ(s->send_trailing_metadata_finished, nullptr); on_complete->next_data.scratch |= t->closure_barrier_may_cover_write; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); s->send_trailing_metadata = @@ -1550,7 +1551,7 @@ static void perform_stream_op_locked(void* stream_op, } if (op->recv_initial_metadata) { - GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); + CHECK_EQ(s->recv_initial_metadata_ready, nullptr); s->recv_initial_metadata_ready = op_payload->recv_initial_metadata.recv_initial_metadata_ready; s->recv_initial_metadata = @@ -1564,7 +1565,7 @@ static void perform_stream_op_locked(void* stream_op, } if (op->recv_message) { - GPR_ASSERT(s->recv_message_ready == nullptr); + CHECK_EQ(s->recv_message_ready, nullptr); s->recv_message_ready = op_payload->recv_message.recv_message_ready; s->recv_message = op_payload->recv_message.recv_message; s->recv_message->emplace(); @@ -1575,9 +1576,9 @@ static void perform_stream_op_locked(void* stream_op, } if (op->recv_trailing_metadata) { - GPR_ASSERT(s->collecting_stats == nullptr); + CHECK_EQ(s->collecting_stats, nullptr); s->collecting_stats = op_payload->recv_trailing_metadata.collect_stats; - GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); + CHECK_EQ(s->recv_trailing_metadata_finished, nullptr); s->recv_trailing_metadata_finished = op_payload->recv_trailing_metadata.recv_trailing_metadata_ready; s->recv_trailing_metadata = @@ -1600,14 +1601,14 @@ void grpc_chttp2_transport::PerformStreamOp( if (!is_client) { if (op->send_initial_metadata) { - GPR_ASSERT(!op->payload->send_initial_metadata.send_initial_metadata - ->get(grpc_core::GrpcTimeoutMetadata()) - .has_value()); + CHECK(!op->payload->send_initial_metadata.send_initial_metadata + ->get(grpc_core::GrpcTimeoutMetadata()) + .has_value()); } if (op->send_trailing_metadata) { - GPR_ASSERT(!op->payload->send_trailing_metadata.send_trailing_metadata - ->get(grpc_core::GrpcTimeoutMetadata()) - .has_value()); + CHECK(!op->payload->send_trailing_metadata.send_trailing_metadata + ->get(grpc_core::GrpcTimeoutMetadata()) + .has_value()); } } @@ -1699,8 +1700,8 @@ void grpc_chttp2_retry_initiate_ping( static void retry_initiate_ping_locked( grpc_core::RefCountedPtr t, GRPC_UNUSED grpc_error_handle error) { - GPR_DEBUG_ASSERT(error.ok()); - GPR_ASSERT(t->delayed_ping_timer_handle != TaskHandle::kInvalid); + DCHECK(error.ok()); + CHECK(t->delayed_ping_timer_handle != TaskHandle::kInvalid); t->delayed_ping_timer_handle = TaskHandle::kInvalid; grpc_chttp2_initiate_write(t.get(), GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); @@ -2020,7 +2021,7 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_chttp2_transport* t, } else { if (s->frame_storage.length != 0) { while (true) { - GPR_ASSERT(s->frame_storage.length > 0); + CHECK_GT(s->frame_storage.length, 0u); int64_t min_progress_size; auto r = grpc_deframe_unprocessed_incoming_frames( s, &min_progress_size, &**s->recv_message, s->recv_message_flags); @@ -2106,7 +2107,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, static grpc_chttp2_transport::RemovedStreamHandle remove_stream( grpc_chttp2_transport* t, uint32_t id, grpc_error_handle error) { grpc_chttp2_stream* s = t->stream_map.extract(id).mapped(); - GPR_DEBUG_ASSERT(s); + DCHECK(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; grpc_chttp2_parsing_become_skip_parser(t); @@ -2358,7 +2359,8 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error_get_status(error, s->deadline, &grpc_status, &message, nullptr, nullptr); - GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); + CHECK_GE(grpc_status, 0); + CHECK_LT((int)grpc_status, 100); auto remove_stream_handle = grpc_chttp2_mark_stream_closed(t, s, 1, 1, error); grpc_core::MaybeTarpit( @@ -2399,7 +2401,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = '2'; *p++ = '0'; *p++ = '0'; - GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr)); + CHECK(p == GRPC_SLICE_END_PTR(http_status_hdr)); len += static_cast GRPC_SLICE_LENGTH(http_status_hdr); content_type_hdr = GRPC_SLICE_MALLOC(31); @@ -2435,7 +2437,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 'r'; *p++ = 'p'; *p++ = 'c'; - GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr)); + CHECK(p == GRPC_SLICE_END_PTR(content_type_hdr)); len += static_cast GRPC_SLICE_LENGTH(content_type_hdr); } @@ -2462,11 +2464,11 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = static_cast('0' + (grpc_status / 10)); *p++ = static_cast('0' + (grpc_status % 10)); } - GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); + CHECK(p == GRPC_SLICE_END_PTR(status_hdr)); len += static_cast GRPC_SLICE_LENGTH(status_hdr); size_t msg_len = message.length(); - GPR_ASSERT(msg_len <= UINT32_MAX); + CHECK(msg_len <= UINT32_MAX); grpc_core::VarintWriter<1> msg_len_writer( static_cast(msg_len)); message_pfx = GRPC_SLICE_MALLOC(14 + msg_len_writer.length()); @@ -2487,7 +2489,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 'e'; msg_len_writer.Write(0, p); p += msg_len_writer.length(); - GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); + CHECK(p == GRPC_SLICE_END_PTR(message_pfx)); len += static_cast GRPC_SLICE_LENGTH(message_pfx); len += static_cast(msg_len); @@ -2503,7 +2505,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = static_cast(id >> 16); *p++ = static_cast(id >> 8); *p++ = static_cast(id); - GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); + CHECK(p == GRPC_SLICE_END_PTR(hdr)); grpc_slice_buffer_add(&t->qbuf, hdr); if (!sent_initial_metadata) { @@ -2821,7 +2823,7 @@ static void finish_bdp_ping_locked( t->flow_control.bdp_estimator()->CompletePing(); grpc_chttp2_act_on_flowctl_action(t->flow_control.PeriodicUpdate(), t.get(), nullptr); - GPR_ASSERT(t->next_bdp_ping_timer_handle == TaskHandle::kInvalid); + CHECK(t->next_bdp_ping_timer_handle == TaskHandle::kInvalid); t->next_bdp_ping_timer_handle = t->event_engine->RunAfter(next_ping - grpc_core::Timestamp::Now(), [t] { grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; @@ -2840,7 +2842,7 @@ static void next_bdp_ping_timer_expired(grpc_chttp2_transport* t) { static void next_bdp_ping_timer_expired_locked( grpc_core::RefCountedPtr t, GRPC_UNUSED grpc_error_handle error) { - GPR_DEBUG_ASSERT(error.ok()); + DCHECK(error.ok()); t->next_bdp_ping_timer_handle = TaskHandle::kInvalid; if (t->flow_control.bdp_estimator()->accumulator() == 0) { // Block the bdp ping till we receive more data. @@ -2908,9 +2910,9 @@ static void init_keepalive_ping( static void init_keepalive_ping_locked( grpc_core::RefCountedPtr t, GRPC_UNUSED grpc_error_handle error) { - GPR_DEBUG_ASSERT(error.ok()); - GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); - GPR_ASSERT(t->keepalive_ping_timer_handle != TaskHandle::kInvalid); + DCHECK(error.ok()); + CHECK(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); + CHECK(t->keepalive_ping_timer_handle != TaskHandle::kInvalid); t->keepalive_ping_timer_handle = TaskHandle::kInvalid; if (t->destroying || !t->closed_with_error.ok()) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; @@ -2952,7 +2954,7 @@ static void finish_keepalive_ping_locked( std::string(t->peer_string.as_string_view()).c_str()); } t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; - GPR_ASSERT(t->keepalive_ping_timer_handle == TaskHandle::kInvalid); + CHECK(t->keepalive_ping_timer_handle == TaskHandle::kInvalid); t->keepalive_ping_timer_handle = t->event_engine->RunAfter(t->keepalive_time, [t] { grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 5f8ece36e63..b7dbdb2f0a5 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -27,6 +27,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -336,7 +337,7 @@ void StreamFlowControl::SentUpdate(uint32_t announce) { TransportFlowControl::IncomingUpdateContext tfc_upd(tfc_); pending_size_ = absl::nullopt; tfc_upd.UpdateAnnouncedWindowDelta(&announced_window_delta_, announce); - GPR_ASSERT(DesiredAnnounceSize() == 0); + CHECK_EQ(DesiredAnnounceSize(), 0u); std::ignore = tfc_upd.MakeAction(); } @@ -386,7 +387,7 @@ FlowControlAction StreamFlowControl::UpdateAction(FlowControlAction action) { void StreamFlowControl::IncomingUpdateContext::SetPendingSize( int64_t pending_size) { - GPR_ASSERT(pending_size >= 0); + CHECK_GE(pending_size, 0); sfc_->pending_size_ = pending_size; } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 60ac7686fe3..3891845a4bd 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -27,6 +27,7 @@ #include #include "absl/functional/function_ref.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -132,7 +133,7 @@ class GRPC_MUST_USE_RESULT FlowControlAction { static const char* UrgencyString(Urgency u); std::string DebugString() const; - void AssertEmpty() { GPR_ASSERT(*this == FlowControlAction()); } + void AssertEmpty() { CHECK(*this == FlowControlAction()); } bool operator==(const FlowControlAction& other) const { return send_stream_update_ == other.send_stream_update_ && @@ -195,7 +196,7 @@ class TransportFlowControl final { class IncomingUpdateContext { public: explicit IncomingUpdateContext(TransportFlowControl* tfc) : tfc_(tfc) {} - ~IncomingUpdateContext() { GPR_ASSERT(tfc_ == nullptr); } + ~IncomingUpdateContext() { CHECK_EQ(tfc_, nullptr); } IncomingUpdateContext(const IncomingUpdateContext&) = delete; IncomingUpdateContext& operator=(const IncomingUpdateContext&) = delete; diff --git a/src/core/ext/transport/chttp2/transport/frame.cc b/src/core/ext/transport/chttp2/transport/frame.cc index e416c8d0352..9e05cf6d854 100644 --- a/src/core/ext/transport/chttp2/transport/frame.cc +++ b/src/core/ext/transport/chttp2/transport/frame.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -59,7 +60,7 @@ uint16_t Read2b(const uint8_t* input) { } void Write3b(uint32_t x, uint8_t* output) { - GPR_ASSERT(x < 16777216); + CHECK_LT(x, 16777216u); output[0] = static_cast(x >> 16); output[1] = static_cast(x >> 8); output[2] = static_cast(x); @@ -475,7 +476,7 @@ void Serialize(absl::Span frames, SliceBuffer& out) { absl::StatusOr ParseFramePayload(const Http2FrameHeader& hdr, SliceBuffer payload) { - GPR_ASSERT(payload.Length() == hdr.length); + CHECK(payload.Length() == hdr.length); switch (hdr.type) { case kFrameTypeData: return ParseDataFrame(hdr, payload); diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 551887779f2..3476ab12481 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" @@ -62,7 +63,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, hdr = GRPC_SLICE_MALLOC(header_size); p = GRPC_SLICE_START_PTR(hdr); - GPR_ASSERT(write_bytes < (1 << 24)); + CHECK(write_bytes < (1 << 24)); *p++ = static_cast(write_bytes >> 16); *p++ = static_cast(write_bytes >> 8); *p++ = static_cast(write_bytes); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index 7122d67901d..fadce901392 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -21,6 +21,7 @@ #include #include "absl/base/attributes.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -136,7 +137,7 @@ grpc_error_handle grpc_chttp2_goaway_parser_parse(void* parser, memcpy(p->debug_data + p->debug_pos, cur, static_cast(end - cur)); } - GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); + CHECK((size_t)(end - cur) < UINT32_MAX - p->debug_pos); p->debug_pos += static_cast(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { @@ -157,7 +158,7 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, grpc_slice header = GRPC_SLICE_MALLOC(9 + 4 + 4); uint8_t* p = GRPC_SLICE_START_PTR(header); uint32_t frame_length; - GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); + CHECK(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); frame_length = 4 + 4 + static_cast GRPC_SLICE_LENGTH(debug_data); // frame header: length @@ -183,7 +184,7 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, *p++ = static_cast(error_code >> 16); *p++ = static_cast(error_code >> 8); *p++ = static_cast(error_code); - GPR_ASSERT(p == GRPC_SLICE_END_PTR(header)); + CHECK(p == GRPC_SLICE_END_PTR(header)); grpc_slice_buffer_add(slice_buffer, header); grpc_slice_buffer_add(slice_buffer, debug_data); } diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index e973958a60b..e57f9f02622 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -24,6 +24,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" @@ -93,7 +94,7 @@ grpc_error_handle grpc_chttp2_ping_parser_parse(void* parser, } if (p->byte == 8) { - GPR_ASSERT(is_last); + CHECK(is_last); if (p->is_ack) { if (grpc_ping_trace.enabled()) { gpr_log(GPR_INFO, "%s[%p]: received ping ack %" PRIx64, diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index 635489c953e..22563924a07 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/random/distributions.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -105,7 +106,7 @@ grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void* parser, s->stats.incoming.framing_bytes += static_cast(end - cur); if (p->byte == 4) { - GPR_ASSERT(is_last); + CHECK(is_last); uint32_t reason = ((static_cast(p->reason_bytes[0])) << 24) | ((static_cast(p->reason_bytes[1])) << 16) | ((static_cast(p->reason_bytes[2])) << 8) | diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 5ec5db8d0da..f9824f7e035 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -37,7 +38,7 @@ grpc_slice grpc_chttp2_window_update_create( stats->framing_bytes += frame_size; uint8_t* p = GRPC_SLICE_START_PTR(slice); - GPR_ASSERT(window_delta); + CHECK(window_delta); *p++ = 0; *p++ = 0; @@ -93,7 +94,7 @@ grpc_error_handle grpc_chttp2_window_update_parser_parse( return GRPC_ERROR_CREATE( absl::StrCat("invalid window update bytes: ", p->amount)); } - GPR_ASSERT(is_last); + CHECK(is_last); if (t->incoming_stream_id != 0) { if (s != nullptr) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index c359a4334a7..1d7ece76303 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -61,7 +63,7 @@ static void FillHeader(uint8_t* p, uint8_t type, uint32_t id, size_t len, // max_frame_size is derived from GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE, // which has a max allowable value of 16777215 (see chttp_transport.cc). // Thus, the following assert can be a debug assert. - GPR_DEBUG_ASSERT(len <= 16777216); + DCHECK_LE(len, 16777216u); *p++ = static_cast(len >> 16); *p++ = static_cast(len >> 8); *p++ = static_cast(len); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc index 92ba2f644ba..3492fd5982b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc @@ -16,16 +16,18 @@ #include +#include "absl/log/check.h" + #include #include namespace grpc_core { uint32_t HPackEncoderTable::AllocateIndex(size_t element_size) { - GPR_DEBUG_ASSERT(element_size >= 32); + DCHECK_GE(element_size, 32u); uint32_t new_index = tail_remote_index_ + table_elems_ + 1; - GPR_DEBUG_ASSERT(element_size <= MaxEntrySize()); + DCHECK(element_size <= MaxEntrySize()); if (element_size > max_table_size_) { while (table_size_ > 0) { @@ -40,7 +42,7 @@ uint32_t HPackEncoderTable::AllocateIndex(size_t element_size) { while (table_size_ + element_size > max_table_size_) { EvictOne(); } - GPR_ASSERT(table_elems_ < elem_size_.size()); + CHECK(table_elems_ < elem_size_.size()); elem_size_[new_index % elem_size_.size()] = static_cast(element_size); table_size_ += element_size; @@ -69,17 +71,17 @@ bool HPackEncoderTable::SetMaxSize(uint32_t max_table_size) { void HPackEncoderTable::EvictOne() { tail_remote_index_++; - GPR_ASSERT(tail_remote_index_ > 0); - GPR_ASSERT(table_elems_ > 0); + CHECK_GT(tail_remote_index_, 0u); + CHECK_GT(table_elems_, 0u); auto removing_size = elem_size_[tail_remote_index_ % elem_size_.size()]; - GPR_ASSERT(table_size_ >= removing_size); + CHECK(table_size_ >= removing_size); table_size_ -= removing_size; table_elems_--; } void HPackEncoderTable::Rebuild(uint32_t capacity) { decltype(elem_size_) new_elem_size(capacity); - GPR_ASSERT(table_elems_ <= capacity); + CHECK_LE(table_elems_, capacity); for (uint32_t i = 0; i < table_elems_; i++) { uint32_t ofs = tail_remote_index_ + i + 1; new_elem_size[ofs % capacity] = elem_size_[ofs % elem_size_.size()]; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc b/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc index be7aebf28f5..c8a93a6a0ee 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -53,7 +54,7 @@ class MetadataSizeLimitExceededEncoder { }; absl::Status MakeStreamError(absl::Status error) { - GPR_DEBUG_ASSERT(!error.ok()); + DCHECK(!error.ok()); return grpc_error_set_int(std::move(error), StatusIntProperty::kStreamId, 0); } } // namespace diff --git a/src/core/ext/transport/chttp2/transport/hpack_parse_result.h b/src/core/ext/transport/chttp2/transport/hpack_parse_result.h index f5296f61041..0d3a57ad3df 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parse_result.h @@ -21,6 +21,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -193,7 +194,7 @@ class HpackParseResult { static HpackParseResult InvalidMetadataError(ValidateMetadataResult result, absl::string_view key) { - GPR_DEBUG_ASSERT(result != ValidateMetadataResult::kOk); + DCHECK(result != ValidateMetadataResult::kOk); HpackParseResult p{HpackParseStatus::kInvalidMetadata}; p.state_->key = std::string(key); p.state_->validate_metadata_result = result; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 57a9a1e157a..4c4500dc280 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -27,6 +27,7 @@ #include #include "absl/base/attributes.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -194,7 +195,7 @@ class HPackParser::Input { absl::optional ParseStringPrefix() { auto cur = Next(); if (!cur.has_value()) { - GPR_DEBUG_ASSERT(eof_error()); + DCHECK(eof_error()); return {}; } // Huffman if the top bit is 1 @@ -205,7 +206,7 @@ class HPackParser::Input { // all ones ==> varint string length auto v = ParseVarint(0x7f); if (!v.has_value()) { - GPR_DEBUG_ASSERT(eof_error()); + DCHECK(eof_error()); return {}; } strlen = *v; @@ -228,7 +229,7 @@ class HPackParser::Input { // Intended for errors that are specific to a stream and recoverable. // Callers should ensure that any hpack table updates happen. void SetErrorAndContinueParsing(HpackParseResult error) { - GPR_DEBUG_ASSERT(error.stream_error()); + DCHECK(error.stream_error()); SetError(std::move(error)); } @@ -236,7 +237,7 @@ class HPackParser::Input { // Intended for unrecoverable errors, with the expectation that they will // close the connection on return to chttp2. void SetErrorAndStopParsing(HpackParseResult error) { - GPR_DEBUG_ASSERT(error.connection_error()); + DCHECK(error.connection_error()); SetError(std::move(error)); begin_ = end_; } @@ -245,20 +246,20 @@ class HPackParser::Input { // min_progress_size: how many bytes beyond the current frontier do we need to // read prior to being able to get further in this parse. void UnexpectedEOF(size_t min_progress_size) { - GPR_ASSERT(min_progress_size > 0); + CHECK_GT(min_progress_size, 0u); if (min_progress_size_ != 0 || error_.connection_error()) { - GPR_DEBUG_ASSERT(eof_error()); + DCHECK(eof_error()); return; } // Set min progress size, taking into account bytes parsed already but not // consumed. min_progress_size_ = min_progress_size + (begin_ - frontier_); - GPR_DEBUG_ASSERT(eof_error()); + DCHECK(eof_error()); } // Update the frontier - signifies we've successfully parsed another element void UpdateFrontier() { - GPR_DEBUG_ASSERT(skip_bytes_ == 0); + DCHECK_EQ(skip_bytes_, 0u); frontier_ = begin_; } @@ -375,7 +376,7 @@ HPackParser::String::StringResult HPackParser::String::ParseUncompressed( // Check there's enough bytes if (input->remaining() < length) { input->UnexpectedEOF(/*min_progress_size=*/length); - GPR_DEBUG_ASSERT(input->eof_error()); + DCHECK(input->eof_error()); return StringResult{HpackParseStatus::kEof, wire_size, String{}}; } auto* refcount = input->slice_refcount(); @@ -595,7 +596,7 @@ class HPackParser::Parser { private: bool ParseTop() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kTop); + DCHECK(state_.parse_state == ParseState::kTop); auto cur = *input_->Next(); switch (cur >> 4) { // Literal header not indexed - First byte format: 0000xxxx @@ -765,7 +766,7 @@ class HPackParser::Parser { // Parse an index encoded key and a string encoded value bool StartIdxKey(uint32_t index, bool add_to_table) { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kTop); + DCHECK(state_.parse_state == ParseState::kTop); input_->UpdateFrontier(); const auto* elem = state_.hpack_table.Lookup(index); if (GPR_UNLIKELY(elem == nullptr)) { @@ -781,14 +782,14 @@ class HPackParser::Parser { // Parse a varint index encoded key and a string encoded value bool StartVarIdxKey(uint32_t offset, bool add_to_table) { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kTop); + DCHECK(state_.parse_state == ParseState::kTop); auto index = input_->ParseVarint(offset); if (GPR_UNLIKELY(!index.has_value())) return false; return StartIdxKey(*index, add_to_table); } bool StartParseLiteralKey(bool add_to_table) { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kTop); + DCHECK(state_.parse_state == ParseState::kTop); state_.add_to_table = add_to_table; state_.parse_state = ParseState::kParsingKeyLength; input_->UpdateFrontier(); @@ -823,7 +824,7 @@ class HPackParser::Parser { } bool ParseKeyLength() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kParsingKeyLength); + DCHECK(state_.parse_state == ParseState::kParsingKeyLength); auto pfx = input_->ParseStringPrefix(); if (!pfx.has_value()) return false; state_.is_string_huff_compressed = pfx->huff; @@ -844,14 +845,14 @@ class HPackParser::Parser { } bool ParseKeyBody() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kParsingKeyBody); + DCHECK(state_.parse_state == ParseState::kParsingKeyBody); auto key = String::Parse(input_, state_.is_string_huff_compressed, state_.string_length); switch (key.status) { case HpackParseStatus::kOk: break; case HpackParseStatus::kEof: - GPR_DEBUG_ASSERT(input_->eof_error()); + DCHECK(input_->eof_error()); return false; default: input_->SetErrorAndStopParsing( @@ -891,7 +892,7 @@ class HPackParser::Parser { } bool SkipKeyBody() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kSkippingKeyBody); + DCHECK(state_.parse_state == ParseState::kSkippingKeyBody); if (!SkipStringBody()) return false; input_->UpdateFrontier(); state_.parse_state = ParseState::kSkippingValueLength; @@ -899,7 +900,7 @@ class HPackParser::Parser { } bool SkipValueLength() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kSkippingValueLength); + DCHECK(state_.parse_state == ParseState::kSkippingValueLength); auto pfx = input_->ParseStringPrefix(); if (!pfx.has_value()) return false; state_.string_length = pfx->length; @@ -909,7 +910,7 @@ class HPackParser::Parser { } bool SkipValueBody() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kSkippingValueBody); + DCHECK(state_.parse_state == ParseState::kSkippingValueBody); if (!SkipStringBody()) return false; input_->UpdateFrontier(); state_.parse_state = ParseState::kTop; @@ -920,7 +921,7 @@ class HPackParser::Parser { } bool ParseValueLength() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kParsingValueLength); + DCHECK(state_.parse_state == ParseState::kParsingValueLength); auto pfx = input_->ParseStringPrefix(); if (!pfx.has_value()) return false; state_.is_string_huff_compressed = pfx->huff; @@ -944,7 +945,7 @@ class HPackParser::Parser { } bool ParseValueBody() { - GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kParsingValueBody); + DCHECK(state_.parse_state == ParseState::kParsingValueBody); auto value = state_.is_binary_header ? String::ParseBinary(input_, state_.is_string_huff_compressed, @@ -973,7 +974,7 @@ class HPackParser::Parser { case HpackParseStatus::kOk: break; case HpackParseStatus::kEof: - GPR_DEBUG_ASSERT(input_->eof_error()); + DCHECK(input_->eof_error()); return false; default: { auto result = diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc index 2796f9571e2..d878c3c1b61 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -25,6 +25,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -41,7 +42,7 @@ namespace grpc_core { void HPackTable::MementoRingBuffer::Put(Memento m) { - GPR_ASSERT(num_entries_ < max_entries_); + CHECK_LT(num_entries_, max_entries_); if (entries_.size() < max_entries_) { ++num_entries_; return entries_.push_back(std::move(m)); @@ -52,7 +53,7 @@ void HPackTable::MementoRingBuffer::Put(Memento m) { } auto HPackTable::MementoRingBuffer::PopOne() -> Memento { - GPR_ASSERT(num_entries_ > 0); + CHECK_GT(num_entries_, 0u); size_t index = first_entry_ % max_entries_; ++first_entry_; --num_entries_; @@ -90,7 +91,7 @@ void HPackTable::MementoRingBuffer::ForEach( // Evict one element from the table void HPackTable::EvictOne() { auto first_entry = entries_.PopOne(); - GPR_ASSERT(first_entry.md.transport_size() <= mem_used_); + CHECK(first_entry.md.transport_size() <= mem_used_); mem_used_ -= first_entry.md.transport_size(); } diff --git a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc b/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc index 1479edf450a..355e40898a6 100644 --- a/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc +++ b/src/core/ext/transport/chttp2/transport/max_concurrent_streams_policy.cc @@ -16,6 +16,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -31,7 +33,7 @@ void Chttp2MaxConcurrentStreamsPolicy::FlushedSettings() { } void Chttp2MaxConcurrentStreamsPolicy::AckLastSend() { - GPR_ASSERT(unacked_demerits_ >= sent_demerits_); + CHECK(unacked_demerits_ >= sent_demerits_); unacked_demerits_ -= std::exchange(sent_demerits_, 0); } diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 3a7460392a8..e74596eee01 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -28,6 +28,7 @@ #include "absl/base/attributes.h" #include "absl/container/flat_hash_map.h" +#include "absl/log/check.h" #include "absl/random/bit_gen_ref.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -267,7 +268,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_0: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_frame_size = (static_cast(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_1; @@ -275,7 +276,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_1: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_frame_size |= (static_cast(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_2; @@ -283,7 +284,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_2: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_frame_size |= *cur; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_3; @@ -291,7 +292,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_3: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_frame_type = *cur; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_4; @@ -299,7 +300,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_4: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_frame_flags = *cur; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_5; @@ -307,7 +308,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_5: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_stream_id = ((static_cast(*cur)) & 0x7f) << 24; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_6; @@ -315,7 +316,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_6: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_stream_id |= (static_cast(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_7; @@ -323,7 +324,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_7: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_stream_id |= (static_cast(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_8; @@ -331,7 +332,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FH_8: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); t->incoming_stream_id |= (static_cast(*cur)); if (grpc_http_trace.enabled()) { gpr_log(GPR_INFO, "INCOMING[%p]: %s len:%d id:0x%08x", t, @@ -366,7 +367,7 @@ absl::variant grpc_chttp2_perform_read( } ABSL_FALLTHROUGH_INTENDED; case GRPC_DTS_FRAME: - GPR_DEBUG_ASSERT(cur < end); + DCHECK_LT(cur, end); if (static_cast(end - cur) == t->incoming_frame_size) { err = parse_frame_slice( t, @@ -729,7 +730,7 @@ static grpc_error_handle init_header_frame_parser(grpc_chttp2_transport* t, } else { t->incoming_stream = s; } - GPR_DEBUG_ASSERT(s != nullptr); + DCHECK_NE(s, nullptr); s->stats.incoming.framing_bytes += 9; if (GPR_UNLIKELY(s->read_closed)) { GRPC_CHTTP2_IF_TRACING(gpr_log( diff --git a/src/core/ext/transport/chttp2/transport/ping_callbacks.cc b/src/core/ext/transport/chttp2/transport/ping_callbacks.cc index 4b52aa04bf2..49adbe27fe0 100644 --- a/src/core/ext/transport/chttp2/transport/ping_callbacks.cc +++ b/src/core/ext/transport/chttp2/transport/ping_callbacks.cc @@ -16,6 +16,7 @@ #include +#include "absl/log/check.h" #include "absl/meta/type_traits.h" #include "absl/random/distributions.h" @@ -95,7 +96,7 @@ absl::optional Chttp2PingCallbacks::OnPingTimeout( Duration ping_timeout, grpc_event_engine::experimental::EventEngine* event_engine, Callback callback) { - GPR_ASSERT(started_new_ping_without_setting_timeout_); + CHECK(started_new_ping_without_setting_timeout_); started_new_ping_without_setting_timeout_ = false; auto it = inflight_.find(most_recent_inflight_); if (it == inflight_.end()) return absl::nullopt; diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 7ba1242a7ed..424666044e6 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -16,6 +16,8 @@ // // +#include "absl/log/check.h" + #include #include @@ -57,7 +59,7 @@ static bool stream_list_pop(grpc_chttp2_transport* t, grpc_chttp2_stream* s = t->lists[id].head; if (s) { grpc_chttp2_stream* new_head = s->links[id].next; - GPR_ASSERT(s->included.is_set(id)); + CHECK(s->included.is_set(id)); if (new_head) { t->lists[id].head = new_head; new_head->links[id].prev = nullptr; @@ -77,12 +79,12 @@ static bool stream_list_pop(grpc_chttp2_transport* t, static void stream_list_remove(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { - GPR_ASSERT(s->included.is_set(id)); + CHECK(s->included.is_set(id)); s->included.clear(id); if (s->links[id].prev) { s->links[id].prev->links[id].next = s->links[id].next; } else { - GPR_ASSERT(t->lists[id].head == s); + CHECK(t->lists[id].head == s); t->lists[id].head = s->links[id].next; } if (s->links[id].next) { @@ -111,7 +113,7 @@ static void stream_list_add_tail(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { grpc_chttp2_stream* old_tail; - GPR_ASSERT(!s->included.is_set(id)); + CHECK(!s->included.is_set(id)); old_tail = t->lists[id].tail; s->links[id].next = nullptr; s->links[id].prev = old_tail; @@ -141,7 +143,7 @@ static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s, bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - GPR_ASSERT(s->id != 0); + CHECK_NE(s->id, 0u); return stream_list_add(t, s, GRPC_CHTTP2_LIST_WRITABLE); } diff --git a/src/core/ext/transport/chttp2/transport/varint.h b/src/core/ext/transport/chttp2/transport/varint.h index 3dc97f5240a..c02d5d10313 100644 --- a/src/core/ext/transport/chttp2/transport/varint.h +++ b/src/core/ext/transport/chttp2/transport/varint.h @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -49,7 +51,7 @@ class VarintWriter { explicit VarintWriter(size_t value) : value_(value), length_(value < kMaxInPrefix ? 1 : VarintLength(value - kMaxInPrefix)) { - GPR_ASSERT(value <= UINT32_MAX); + CHECK(value <= UINT32_MAX); } size_t value() const { return value_; } diff --git a/src/core/ext/transport/chttp2/transport/write_size_policy.cc b/src/core/ext/transport/chttp2/transport/write_size_policy.cc index 34ec3e23699..f8ec481d7fe 100644 --- a/src/core/ext/transport/chttp2/transport/write_size_policy.cc +++ b/src/core/ext/transport/chttp2/transport/write_size_policy.cc @@ -16,6 +16,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -24,7 +26,7 @@ namespace grpc_core { size_t Chttp2WriteSizePolicy::WriteTargetSize() { return current_target_; } void Chttp2WriteSizePolicy::BeginWrite(size_t size) { - GPR_ASSERT(experiment_start_time_ == Timestamp::InfFuture()); + CHECK(experiment_start_time_ == Timestamp::InfFuture()); if (size < current_target_ * 7 / 10) { // If we were trending fast but stopped getting enough data to verify, then // reset back to the default state. diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index e3da6d1d65a..e9962375b62 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -26,6 +26,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/types/optional.h" @@ -268,7 +269,7 @@ class WriteContext { grpc_core::Http2Frame frame(std::move(*update)); Serialize(absl::Span(&frame, 1), t_->outbuf); if (t_->keepalive_timeout != grpc_core::Duration::Infinity()) { - GPR_ASSERT( + CHECK( t_->settings_ack_watchdog == grpc_event_engine::experimental::EventEngine::TaskHandle::kInvalid); // We base settings timeout on keepalive timeout, but double it to allow @@ -290,7 +291,7 @@ class WriteContext { // simple writes are queued to qbuf, and flushed here grpc_slice_buffer_move_into(&t_->qbuf, t_->outbuf.c_slice_buffer()); t_->num_pending_induced_frames = 0; - GPR_ASSERT(t_->qbuf.count == 0); + CHECK_EQ(t_->qbuf.count, 0u); } void FlushWindowUpdates() { diff --git a/src/core/lib/event_engine/extensions/supports_fd.h b/src/core/lib/event_engine/extensions/supports_fd.h index 30f0d2ad0e6..66ea1c2b345 100644 --- a/src/core/lib/event_engine/extensions/supports_fd.h +++ b/src/core/lib/event_engine/extensions/supports_fd.h @@ -112,13 +112,6 @@ class EventEngineSupportsFdExtension { int fd, const EndpointConfig& config, MemoryAllocator memory_allocator) = 0; - /// Creates an EventEngine::Endpoint from an fd which is already assumed to be - /// connected to a remote peer. See \a CreatePosixEndpointFromFd for details. - /// This has the same behavior, but the \a memory_allocator is taken from the - /// EndpointConfig's resource quota. - virtual std::unique_ptr CreateEndpointFromFd( - int fd, const EndpointConfig& config) = 0; - /// Called when the posix listener has accepted a new client connection. /// \a listener_fd - The listening socket fd that accepted the new client /// connection. diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.cc b/src/core/lib/event_engine/posix_engine/posix_engine.cc index 0ac3dfcebfe..e96c969617c 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine.cc @@ -25,6 +25,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/functional/any_invocable.h" +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -142,7 +143,7 @@ void AsyncConnect::OnWritable(absl::Status status) absl::StatusOr> ep; mu_.Lock(); - GPR_ASSERT(fd_ != nullptr); + CHECK_NE(fd_, nullptr); fd = std::exchange(fd_, nullptr); bool connect_cancelled = connect_cancelled_; if (fd->IsHandleShutdown() && status.ok()) { @@ -334,7 +335,7 @@ PosixEnginePollerManager::PosixEnginePollerManager( poller_state_(PollerState::kExternal), executor_(nullptr), trigger_shutdown_called_(false) { - GPR_DEBUG_ASSERT(poller_ != nullptr); + DCHECK_NE(poller_, nullptr); } void PosixEnginePollerManager::Run( @@ -351,7 +352,7 @@ void PosixEnginePollerManager::Run(absl::AnyInvocable cb) { } void PosixEnginePollerManager::TriggerShutdown() { - GPR_DEBUG_ASSERT(trigger_shutdown_called_ == false); + DCHECK(trigger_shutdown_called_ == false); trigger_shutdown_called_ = true; // If the poller is external, dont try to shut it down. Otherwise // set poller state to PollerState::kShuttingDown. @@ -467,7 +468,7 @@ PosixEventEngine::~PosixEventEngine() { this, HandleToString(handle).c_str()); } } - GPR_ASSERT(GPR_LIKELY(known_handles_.empty())); + CHECK(GPR_LIKELY(known_handles_.empty())); } timer_manager_->Shutdown(); #if GRPC_PLATFORM_SUPPORTS_POSIX_POLLING @@ -592,7 +593,7 @@ bool PosixEventEngine::CancelConnect(EventEngine::ConnectionHandle handle) { auto it = shard->pending_connections.find(connection_handle); if (it != shard->pending_connections.end()) { ac = it->second; - GPR_ASSERT(ac != nullptr); + CHECK_NE(ac, nullptr); // Trying to acquire ac->mu here would could cause a deadlock because // the OnWritable method tries to acquire the two mutexes used // here in the reverse order. But we dont need to acquire ac->mu before @@ -639,7 +640,7 @@ EventEngine::ConnectionHandle PosixEventEngine::Connect( const EndpointConfig& args, MemoryAllocator memory_allocator, Duration timeout) { #if GRPC_PLATFORM_SUPPORTS_POSIX_POLLING - GPR_ASSERT(poller_manager_ != nullptr); + CHECK_NE(poller_manager_, nullptr); PosixTcpOptions options = TcpOptionsFromEndpointConfig(args); absl::StatusOr socket = PosixSocketWrapper::CreateAndPrepareTcpClientSocket(options, addr); @@ -661,9 +662,9 @@ PosixEventEngine::CreatePosixEndpointFromFd(int fd, const EndpointConfig& config, MemoryAllocator memory_allocator) { #if GRPC_PLATFORM_SUPPORTS_POSIX_POLLING - GPR_ASSERT(fd > 0); + DCHECK_GT(fd, 0); PosixEventPoller* poller = poller_manager_->Poller(); - GPR_DEBUG_ASSERT(poller != nullptr); + DCHECK_NE(poller, nullptr); EventHandle* handle = poller->CreateHandle(fd, "tcp-client", poller->CanTrackErrors()); return CreatePosixEndpoint(handle, nullptr, shared_from_this(), @@ -676,22 +677,6 @@ PosixEventEngine::CreatePosixEndpointFromFd(int fd, #endif // GRPC_PLATFORM_SUPPORTS_POSIX_POLLING } -std::unique_ptr PosixEventEngine::CreateEndpointFromFd( - int fd, const EndpointConfig& config) { - auto options = TcpOptionsFromEndpointConfig(config); - MemoryAllocator allocator; - if (options.memory_allocator_factory != nullptr) { - return CreatePosixEndpointFromFd( - fd, config, - options.memory_allocator_factory->CreateMemoryAllocator( - absl::StrCat("allocator:", fd))); - } - return CreatePosixEndpointFromFd( - fd, config, - options.resource_quota->memory_quota()->CreateMemoryAllocator( - absl::StrCat("allocator:", fd))); -} - absl::StatusOr> PosixEventEngine::CreateListener( Listener::AcceptCallback on_accept, diff --git a/src/core/lib/event_engine/posix_engine/posix_engine.h b/src/core/lib/event_engine/posix_engine/posix_engine.h index ea426c379c9..257cd6b34b5 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine.h +++ b/src/core/lib/event_engine/posix_engine/posix_engine.h @@ -172,8 +172,6 @@ class PosixEventEngine final : public PosixEventEngineWithFdSupport, std::unique_ptr CreatePosixEndpointFromFd( int fd, const EndpointConfig& config, MemoryAllocator memory_allocator) override; - std::unique_ptr CreateEndpointFromFd( - int fd, const EndpointConfig& config) override; absl::StatusOr> CreateListener( Listener::AcceptCallback on_accept, diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 38f1a4615c6..1755d99122d 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -23,7 +23,6 @@ #include #include -#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -39,7 +38,6 @@ #define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR" #endif // !GPR_DEFAULT_LOG_VERBOSITY_STRING -static constexpr int g_absl_vlog_level_for_gpr_verbosity_debug = 2; static constexpr gpr_atm GPR_LOG_SEVERITY_UNSET = GPR_LOG_SEVERITY_ERROR + 10; static constexpr gpr_atm GPR_LOG_SEVERITY_NONE = GPR_LOG_SEVERITY_ERROR + 11; @@ -85,9 +83,8 @@ void gpr_default_log(gpr_log_func_args* args) { } switch (args->severity) { case GPR_LOG_SEVERITY_DEBUG: - VLOG(g_absl_vlog_level_for_gpr_verbosity_debug) - .AtLocation(args->file, args->line) - << args->message; + // Log DEBUG messages as VLOG(2). + VLOG(2).AtLocation(args->file, args->line) << args->message; return; case GPR_LOG_SEVERITY_INFO: LOG(INFO).AtLocation(args->file, args->line) << args->message; @@ -148,12 +145,6 @@ void gpr_log_verbosity_init() { parse_log_severity(verbosity, min_severity_to_print); } gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print); - if (grpc_core::ConfigVars::Get().AbslLogging() && - min_severity_to_print == GPR_LOG_SEVERITY_DEBUG) { - // Matches full file paths that include a `*grpc*` folder, including - // grpcpp. - absl::SetVLogLevel("*grpc*/*", g_absl_vlog_level_for_gpr_verbosity_debug); - } } // init stacktrace_minloglevel when it hasn't been set if ((gpr_atm_no_barrier_load(&g_min_severity_to_print_stacktrace)) == diff --git a/src/core/server/server.h b/src/core/server/server.h index 01b541c233e..9c0f20488f8 100644 --- a/src/core/server/server.h +++ b/src/core/server/server.h @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -76,9 +75,6 @@ "grpc.server.max_pending_requests_hard_limit" namespace grpc_core { -namespace experimental { -class PassiveListenerImpl; -} // namespace experimental extern TraceFlag grpc_server_channel_trace; @@ -117,7 +113,7 @@ class Server : public ServerInterface, /// Interface for listeners. /// Implementations must override the Orphan() method, which should stop /// listening and initiate destruction of the listener. - class ListenerInterface : public InternallyRefCounted { + class ListenerInterface : public Orphanable { public: ~ListenerInterface() override = default; @@ -221,14 +217,6 @@ class Server : public ServerInterface, } private: - // note: the grpc_core::Server redundant namespace qualification is - // required for older gcc versions. - // TODO(yashykt): eliminate this friend statement as part of your upcoming - // server listener refactoring. - friend absl::Status(::grpc_server_add_passive_listener)( - grpc_core::Server* server, grpc_server_credentials* credentials, - std::shared_ptr - passive_listener); struct RequestedCall; class RequestMatcherInterface; diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index 65113b17dcc..88cf0c06223 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/numbers.h" #include "upb/mem/arena.hpp" @@ -117,13 +118,13 @@ typedef struct alts_grpc_handshaker_client { static void handshaker_client_send_buffer_destroy( alts_grpc_handshaker_client* client) { - GPR_ASSERT(client != nullptr); + CHECK_NE(client, nullptr); grpc_byte_buffer_destroy(client->send_buffer); client->send_buffer = nullptr; } static bool is_handshake_finished_properly(grpc_gcp_HandshakerResp* resp) { - GPR_ASSERT(resp != nullptr); + CHECK_NE(resp, nullptr); return grpc_gcp_HandshakerResp_result(resp) != nullptr; } @@ -156,7 +157,7 @@ static void maybe_complete_tsi_next( grpc_core::MutexLock lock(&client->mu); client->receive_status_finished |= receive_status_finished; if (pending_recv_message_result != nullptr) { - GPR_ASSERT(client->pending_recv_message_result == nullptr); + CHECK_EQ(client->pending_recv_message_result, nullptr); client->pending_recv_message_result = pending_recv_message_result; } if (client->pending_recv_message_result == nullptr) { @@ -197,7 +198,7 @@ static void handle_response_done(alts_grpc_handshaker_client* client, void alts_handshaker_client_handle_response(alts_handshaker_client* c, bool is_ok) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); grpc_byte_buffer* recv_buffer = client->recv_buffer; @@ -312,7 +313,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c, static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client, bool is_start) { - GPR_ASSERT(client != nullptr); + CHECK_NE(client, nullptr); grpc_op ops[kHandshakerClientOpNum]; memset(ops, 0, sizeof(ops)); grpc_op* op = ops; @@ -325,34 +326,34 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client, op->flags = 0; op->reserved = nullptr; op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + CHECK(op - ops <= kHandshakerClientOpNum); gpr_ref(&client->refs); grpc_call_error call_error = client->grpc_caller(client->call, ops, static_cast(op - ops), &client->on_status_received); // TODO(apolcyn): return the error here instead, as done for other ops? - GPR_ASSERT(call_error == GRPC_CALL_OK); + CHECK_EQ(call_error, GRPC_CALL_OK); memset(ops, 0, sizeof(ops)); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + CHECK(op - ops <= kHandshakerClientOpNum); op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = &client->recv_initial_metadata; op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + CHECK(op - ops <= kHandshakerClientOpNum); } op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = client->send_buffer; op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + CHECK(op - ops <= kHandshakerClientOpNum); op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &client->recv_buffer; op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); - GPR_ASSERT(client->grpc_caller != nullptr); + CHECK(op - ops <= kHandshakerClientOpNum); + CHECK_NE(client->grpc_caller, nullptr); if (client->grpc_caller(client->call, ops, static_cast(op - ops), &client->on_handshaker_service_resp_recv) != GRPC_CALL_OK) { @@ -450,7 +451,7 @@ void HandshakeDone(bool is_client) { /// make a grpc call. /// static tsi_result make_grpc_call(alts_handshaker_client* c, bool is_start) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); if (is_start) { @@ -500,7 +501,7 @@ static grpc_byte_buffer* get_serialized_handshaker_req( // Create and populate a client_start handshaker request, then serialize it. static grpc_byte_buffer* get_serialized_start_client( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); upb::Arena arena; @@ -565,8 +566,8 @@ static tsi_result handshaker_client_start_client(alts_handshaker_client* c) { // Create and populate a start_server handshaker request, then serialize it. static grpc_byte_buffer* get_serialized_start_server( alts_handshaker_client* c, grpc_slice* bytes_received) { - GPR_ASSERT(c != nullptr); - GPR_ASSERT(bytes_received != nullptr); + CHECK_NE(c, nullptr); + CHECK_NE(bytes_received, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); @@ -623,7 +624,7 @@ static tsi_result handshaker_client_start_server(alts_handshaker_client* c, // Create and populate a next handshaker request, then serialize it. static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) { - GPR_ASSERT(bytes_received != nullptr); + CHECK_NE(bytes_received, nullptr); upb::Arena arena; grpc_gcp_HandshakerReq* req = grpc_gcp_HandshakerReq_new(arena.ptr()); grpc_gcp_NextHandshakeMessageReq* next = @@ -661,7 +662,7 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c, } static void handshaker_client_shutdown(alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); if (client->call != nullptr) { @@ -759,7 +760,8 @@ namespace internal { void alts_handshaker_client_set_grpc_caller_for_testing( alts_handshaker_client* c, alts_grpc_caller caller) { - GPR_ASSERT(c != nullptr && caller != nullptr); + CHECK(c != nullptr); + CHECK_NE(caller, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); client->grpc_caller = caller; @@ -767,7 +769,7 @@ void alts_handshaker_client_set_grpc_caller_for_testing( grpc_byte_buffer* alts_handshaker_client_get_send_buffer_for_testing( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); return client->send_buffer; @@ -775,7 +777,7 @@ grpc_byte_buffer* alts_handshaker_client_get_send_buffer_for_testing( grpc_byte_buffer** alts_handshaker_client_get_recv_buffer_addr_for_testing( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); return &client->recv_buffer; @@ -783,7 +785,7 @@ grpc_byte_buffer** alts_handshaker_client_get_recv_buffer_addr_for_testing( grpc_metadata_array* alts_handshaker_client_get_initial_metadata_for_testing( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); return &client->recv_initial_metadata; @@ -791,7 +793,7 @@ grpc_metadata_array* alts_handshaker_client_get_initial_metadata_for_testing( void alts_handshaker_client_set_recv_bytes_for_testing( alts_handshaker_client* c, grpc_slice* recv_bytes) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); client->recv_bytes = CSliceRef(*recv_bytes); @@ -801,7 +803,7 @@ void alts_handshaker_client_set_fields_for_testing( alts_handshaker_client* c, alts_tsi_handshaker* handshaker, tsi_handshaker_on_next_done_cb cb, void* user_data, grpc_byte_buffer* recv_buffer, bool inject_read_failure) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); client->handshaker = handshaker; @@ -814,22 +816,22 @@ void alts_handshaker_client_set_fields_for_testing( void alts_handshaker_client_check_fields_for_testing( alts_handshaker_client* c, tsi_handshaker_on_next_done_cb cb, void* user_data, bool has_sent_start_message, grpc_slice* recv_bytes) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); - GPR_ASSERT(client->cb == cb); - GPR_ASSERT(client->user_data == user_data); + CHECK(client->cb == cb); + CHECK(client->user_data == user_data); if (recv_bytes != nullptr) { - GPR_ASSERT(grpc_slice_cmp(client->recv_bytes, *recv_bytes) == 0); + CHECK_EQ(grpc_slice_cmp(client->recv_bytes, *recv_bytes), 0); } - GPR_ASSERT(alts_tsi_handshaker_get_has_sent_start_message_for_testing( - client->handshaker) == has_sent_start_message); + CHECK(alts_tsi_handshaker_get_has_sent_start_message_for_testing( + client->handshaker) == has_sent_start_message); } void alts_handshaker_client_set_vtable_for_testing( alts_handshaker_client* c, alts_handshaker_client_vtable* vtable) { - GPR_ASSERT(c != nullptr); - GPR_ASSERT(vtable != nullptr); + CHECK_NE(c, nullptr); + CHECK_NE(vtable, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); client->base.vtable = vtable; @@ -837,7 +839,7 @@ void alts_handshaker_client_set_vtable_for_testing( alts_tsi_handshaker* alts_handshaker_client_get_handshaker_for_testing( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); return client->handshaker; @@ -845,7 +847,7 @@ alts_tsi_handshaker* alts_handshaker_client_get_handshaker_for_testing( void alts_handshaker_client_set_cb_for_testing( alts_handshaker_client* c, tsi_handshaker_on_next_done_cb cb) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); client->cb = cb; @@ -853,7 +855,7 @@ void alts_handshaker_client_set_cb_for_testing( grpc_closure* alts_handshaker_client_get_closure_for_testing( alts_handshaker_client* c) { - GPR_ASSERT(c != nullptr); + CHECK_NE(c, nullptr); alts_grpc_handshaker_client* client = reinterpret_cast(c); return &client->on_handshaker_service_resp_recv; diff --git a/src/core/tsi/alts/handshaker/alts_shared_resource.cc b/src/core/tsi/alts/handshaker/alts_shared_resource.cc index 843335935a5..03e2b4439e1 100644 --- a/src/core/tsi/alts/handshaker/alts_shared_resource.cc +++ b/src/core/tsi/alts/handshaker/alts_shared_resource.cc @@ -18,6 +18,8 @@ #include "src/core/tsi/alts/handshaker/alts_shared_resource.h" +#include "absl/log/check.h" + #include #include @@ -36,11 +38,11 @@ static void thread_worker(void* /*arg*/) { grpc_event event = grpc_completion_queue_next(g_alts_resource_dedicated.cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - GPR_ASSERT(event.type != GRPC_QUEUE_TIMEOUT); + CHECK(event.type != GRPC_QUEUE_TIMEOUT); if (event.type == GRPC_QUEUE_SHUTDOWN) { break; } - GPR_ASSERT(event.type == GRPC_OP_COMPLETE); + CHECK(event.type == GRPC_OP_COMPLETE); alts_handshaker_client* client = static_cast(event.tag); alts_handshaker_client_handle_response(client, event.success); diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc index ac7372cb464..11849b655b8 100644 --- a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +++ b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc @@ -22,6 +22,7 @@ #include #include +#include "absl/log/check.h" #include "upb/mem/arena.hpp" #include @@ -92,14 +93,14 @@ static tsi_result handshaker_result_extract_peer( alts_tsi_handshaker_result* result = reinterpret_cast( const_cast(self)); - GPR_ASSERT(kTsiAltsNumOfPeerProperties == 5); + CHECK_EQ(kTsiAltsNumOfPeerProperties, 5u); tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); int index = 0; if (ok != TSI_OK) { gpr_log(GPR_ERROR, "Failed to construct tsi peer"); return ok; } - GPR_ASSERT(&peer->properties[index] != nullptr); + CHECK_NE(&peer->properties[index], nullptr); ok = tsi_construct_string_peer_property_from_cstring( TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, &peer->properties[index]); @@ -109,7 +110,7 @@ static tsi_result handshaker_result_extract_peer( return ok; } index++; - GPR_ASSERT(&peer->properties[index] != nullptr); + CHECK_NE(&peer->properties[index], nullptr); ok = tsi_construct_string_peer_property_from_cstring( TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, result->peer_identity, &peer->properties[index]); @@ -118,7 +119,7 @@ static tsi_result handshaker_result_extract_peer( gpr_log(GPR_ERROR, "Failed to set tsi peer property"); } index++; - GPR_ASSERT(&peer->properties[index] != nullptr); + CHECK_NE(&peer->properties[index], nullptr); ok = tsi_construct_string_peer_property( TSI_ALTS_RPC_VERSIONS, reinterpret_cast(GRPC_SLICE_START_PTR(result->rpc_versions)), @@ -128,7 +129,7 @@ static tsi_result handshaker_result_extract_peer( gpr_log(GPR_ERROR, "Failed to set tsi peer property"); } index++; - GPR_ASSERT(&peer->properties[index] != nullptr); + CHECK_NE(&peer->properties[index], nullptr); ok = tsi_construct_string_peer_property( TSI_ALTS_CONTEXT, reinterpret_cast(GRPC_SLICE_START_PTR(result->serialized_context)), @@ -138,7 +139,7 @@ static tsi_result handshaker_result_extract_peer( gpr_log(GPR_ERROR, "Failed to set tsi peer property"); } index++; - GPR_ASSERT(&peer->properties[index] != nullptr); + CHECK_NE(&peer->properties[index], nullptr); ok = tsi_construct_string_peer_property_from_cstring( TSI_SECURITY_LEVEL_PEER_PROPERTY, tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY), @@ -147,7 +148,7 @@ static tsi_result handshaker_result_extract_peer( tsi_peer_destruct(peer); gpr_log(GPR_ERROR, "Failed to set tsi peer property"); } - GPR_ASSERT(++index == kTsiAltsNumOfPeerProperties); + CHECK(++index == kTsiAltsNumOfPeerProperties); return ok; } @@ -423,7 +424,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next( handshaker->handshaker_service_url); handshaker->interested_parties = grpc_alts_get_shared_resource_dedicated()->interested_parties; - GPR_ASSERT(handshaker->interested_parties != nullptr); + CHECK_NE(handshaker->interested_parties, nullptr); } grpc_iomgr_cb_func grpc_cb = handshaker->channel == nullptr ? on_handshaker_service_resp_recv_dedicated @@ -445,7 +446,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next( } { grpc_core::MutexLock lock(&handshaker->mu); - GPR_ASSERT(handshaker->client == nullptr); + CHECK_EQ(handshaker->client, nullptr); handshaker->client = client; if (handshaker->shutdown) { gpr_log(GPR_INFO, "TSI handshake shutdown"); @@ -457,8 +458,8 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next( } if (handshaker->channel == nullptr && handshaker->client_vtable_for_testing == nullptr) { - GPR_ASSERT(grpc_cq_begin_op(grpc_alts_get_shared_resource_dedicated()->cq, - handshaker->client)); + CHECK(grpc_cq_begin_op(grpc_alts_get_shared_resource_dedicated()->cq, + handshaker->client)); } grpc_slice slice = (received_bytes == nullptr || received_bytes_size == 0) ? grpc_empty_slice() @@ -500,7 +501,7 @@ static void alts_tsi_handshaker_create_channel( alts_tsi_handshaker_continue_handshaker_next_args* next_args = static_cast(arg); alts_tsi_handshaker* handshaker = next_args->handshaker; - GPR_ASSERT(handshaker->channel == nullptr); + CHECK_EQ(handshaker->channel, nullptr); grpc_channel_credentials* creds = grpc_insecure_credentials_create(); // Disable retries so that we quickly get a signal when the // handshake server is not reachable. @@ -592,7 +593,7 @@ static tsi_result handshaker_next_dedicated( } static void handshaker_shutdown(tsi_handshaker* self) { - GPR_ASSERT(self != nullptr); + CHECK_NE(self, nullptr); alts_tsi_handshaker* handshaker = reinterpret_cast(self); grpc_core::MutexLock lock(&handshaker->mu); @@ -638,7 +639,7 @@ static const tsi_handshaker_vtable handshaker_vtable_dedicated = { handshaker_shutdown}; bool alts_tsi_handshaker_has_shutdown(alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); + CHECK_NE(handshaker, nullptr); grpc_core::MutexLock lock(&handshaker->mu); return handshaker->shutdown; } @@ -676,7 +677,8 @@ tsi_result alts_tsi_handshaker_create( void alts_tsi_handshaker_result_set_unused_bytes(tsi_handshaker_result* result, grpc_slice* recv_bytes, size_t bytes_consumed) { - GPR_ASSERT(recv_bytes != nullptr && result != nullptr); + CHECK(recv_bytes != nullptr); + CHECK_NE(result, nullptr); if (GRPC_SLICE_LENGTH(*recv_bytes) == bytes_consumed) { return; } @@ -695,19 +697,19 @@ namespace internal { bool alts_tsi_handshaker_get_has_sent_start_message_for_testing( alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); + CHECK_NE(handshaker, nullptr); return handshaker->has_sent_start_message; } void alts_tsi_handshaker_set_client_vtable_for_testing( alts_tsi_handshaker* handshaker, alts_handshaker_client_vtable* vtable) { - GPR_ASSERT(handshaker != nullptr); + CHECK_NE(handshaker, nullptr); handshaker->client_vtable_for_testing = vtable; } bool alts_tsi_handshaker_get_is_client_for_testing( alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); + CHECK_NE(handshaker, nullptr); return handshaker->is_client; } diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc index 762af6d2679..05e5400a7d8 100644 --- a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +++ b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc @@ -18,6 +18,8 @@ #include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" +#include "absl/log/check.h" + #include #include @@ -43,8 +45,8 @@ tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code) { grpc_gcp_HandshakerResp* alts_tsi_utils_deserialize_response( grpc_byte_buffer* resp_buffer, upb_Arena* arena) { - GPR_ASSERT(resp_buffer != nullptr); - GPR_ASSERT(arena != nullptr); + CHECK_NE(resp_buffer, nullptr); + CHECK_NE(arena, nullptr); grpc_byte_buffer_reader bbr; grpc_byte_buffer_reader_init(&bbr, resp_buffer); grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc index 01cf48f635a..81df2cbb131 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -142,14 +144,14 @@ static tsi_result alts_grpc_integrity_only_unprotect( grpc_slice_buffer_reset_and_unref(&rp->header_sb); grpc_slice_buffer_move_first(protected_slices, rp->header_length, &rp->header_sb); - GPR_ASSERT(rp->header_sb.length == rp->header_length); + CHECK(rp->header_sb.length == rp->header_length); iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp); // Moves protected slices data to data_sb and leaves the remaining tag. grpc_slice_buffer_reset_and_unref(&integrity_only_record_protocol->data_sb); grpc_slice_buffer_move_first(protected_slices, protected_slices->length - rp->tag_length, &integrity_only_record_protocol->data_sb); - GPR_ASSERT(protected_slices->length == rp->tag_length); + CHECK(protected_slices->length == rp->tag_length); iovec_t tag_iovec = {nullptr, rp->tag_length}; if (protected_slices->count == 1) { tag_iovec.iov_base = GRPC_SLICE_START_PTR(protected_slices->slices[0]); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc index c03dde032d0..bd1f1fc7fcd 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc @@ -20,6 +20,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -34,7 +36,8 @@ const size_t kInitialIovecBufferSize = 8; // Makes sure iovec_buf in alts_grpc_record_protocol is large enough. static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb) { - GPR_ASSERT(rp != nullptr && sb != nullptr); + CHECK(rp != nullptr); + CHECK_NE(sb, nullptr); if (sb->count <= rp->iovec_buf_length) { return; } @@ -49,7 +52,8 @@ static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp, void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb) { - GPR_ASSERT(rp != nullptr && sb != nullptr); + CHECK(rp != nullptr); + CHECK_NE(sb, nullptr); ensure_iovec_buf_size(rp, sb); for (size_t i = 0; i < sb->count; i++) { rp->iovec_buf[i].iov_base = GRPC_SLICE_START_PTR(sb->slices[i]); @@ -59,7 +63,8 @@ void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src, unsigned char* dst) { - GPR_ASSERT(src != nullptr && dst != nullptr); + CHECK(src != nullptr); + CHECK_NE(dst, nullptr); for (size_t i = 0; i < src->count; i++) { size_t slice_length = GRPC_SLICE_LENGTH(src->slices[i]); memcpy(dst, GRPC_SLICE_START_PTR(src->slices[i]), slice_length); diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index 617a19b7f3d..6847dfdaa96 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -23,6 +23,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -84,7 +86,7 @@ static bool read_frame_size(const grpc_slice_buffer* sb, remaining -= slice_length; } } - GPR_ASSERT(remaining == 0); + CHECK_EQ(remaining, 0u); // Gets little-endian frame size. uint32_t frame_size = (static_cast(frame_size_buffer[3]) << 24) | (static_cast(frame_size_buffer[2]) << 16) | @@ -294,7 +296,7 @@ tsi_result alts_zero_copy_grpc_protector_create( impl->max_unprotected_data_size = alts_grpc_record_protocol_max_unprotected_data_size( impl->record_protocol, max_protected_frame_size_to_set); - GPR_ASSERT(impl->max_unprotected_data_size > 0); + CHECK_GT(impl->max_unprotected_data_size, 0u); // Allocates internal slice buffers. grpc_slice_buffer_init(&impl->unprotected_staging_sb); grpc_slice_buffer_init(&impl->protected_sb); diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index e612af27d3c..a2aca84009b 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -124,7 +126,8 @@ static void store32_little_endian(uint32_t value, unsigned char* buf) { } static uint32_t read_frame_size(const grpc_slice_buffer* sb) { - GPR_ASSERT(sb != nullptr && sb->length >= TSI_FAKE_FRAME_HEADER_SIZE); + CHECK(sb != nullptr); + CHECK(sb->length >= TSI_FAKE_FRAME_HEADER_SIZE); uint8_t frame_size_buffer[TSI_FAKE_FRAME_HEADER_SIZE]; uint8_t* buf = frame_size_buffer; // Copies the first 4 bytes to a temporary buffer. @@ -141,7 +144,7 @@ static uint32_t read_frame_size(const grpc_slice_buffer* sb) { remaining -= slice_length; } } - GPR_ASSERT(remaining == 0); + CHECK_EQ(remaining, 0u); return load32_little_endian(frame_size_buffer); } diff --git a/src/core/tsi/ssl/key_logging/ssl_key_logging.cc b/src/core/tsi/ssl/key_logging/ssl_key_logging.cc index d290ed30feb..e1a496cc519 100644 --- a/src/core/tsi/ssl/key_logging/ssl_key_logging.cc +++ b/src/core/tsi/ssl/key_logging/ssl_key_logging.cc @@ -16,6 +16,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -47,8 +49,8 @@ TlsSessionKeyLoggerCache::TlsSessionKeyLogger::TlsSessionKeyLogger( grpc_core::RefCountedPtr cache) : tls_session_key_log_file_path_(std::move(tls_session_key_log_file_path)), cache_(std::move(cache)) { - GPR_ASSERT(!tls_session_key_log_file_path_.empty()); - GPR_ASSERT(cache_ != nullptr); + CHECK(!tls_session_key_log_file_path_.empty()); + CHECK(cache_ != nullptr); fd_ = fopen(tls_session_key_log_file_path_.c_str(), "a"); if (fd_ == nullptr) { grpc_error_handle error = GRPC_OS_ERROR(errno, "fopen"); @@ -109,7 +111,7 @@ TlsSessionKeyLoggerCache::~TlsSessionKeyLoggerCache() { grpc_core::RefCountedPtr TlsSessionKeyLoggerCache::Get( std::string tls_session_key_log_file_path) { gpr_once_init(&g_cache_mutex_init, do_cache_mutex_init); - GPR_DEBUG_ASSERT(g_tls_session_key_log_cache_mu != nullptr); + DCHECK_NE(g_tls_session_key_log_cache_mu, nullptr); if (tls_session_key_log_file_path.empty()) { return nullptr; } diff --git a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc index 26f751fd600..4f33c4722ac 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_cache.cc @@ -18,6 +18,8 @@ #include "src/core/tsi/ssl/session_cache/ssl_session_cache.h" +#include "absl/log/check.h" + #include #include #include @@ -112,7 +114,7 @@ void SslSessionLRUCache::Put(const char* key, SslSessionPtr session) { entry_by_key_.emplace(key, node); AssertInvariants(); if (use_order_list_size_ > capacity_) { - GPR_ASSERT(use_order_list_tail_); + CHECK(use_order_list_tail_); node = use_order_list_tail_; Remove(node); // Order matters, key is destroyed after deleting node. @@ -143,7 +145,7 @@ void SslSessionLRUCache::Remove(SslSessionLRUCache::Node* node) { } else { node->next_->prev_ = node->prev_; } - GPR_ASSERT(use_order_list_size_ >= 1); + CHECK_GE(use_order_list_size_, 1u); use_order_list_size_--; } @@ -169,16 +171,16 @@ void SslSessionLRUCache::AssertInvariants() { Node* current = use_order_list_head_; while (current != nullptr) { size++; - GPR_ASSERT(current->prev_ == prev); + CHECK(current->prev_ == prev); auto it = entry_by_key_.find(current->key()); - GPR_ASSERT(it != entry_by_key_.end()); - GPR_ASSERT(it->second == current); + CHECK(it != entry_by_key_.end()); + CHECK(it->second == current); prev = current; current = current->next_; } - GPR_ASSERT(prev == use_order_list_tail_); - GPR_ASSERT(size == use_order_list_size_); - GPR_ASSERT(entry_by_key_.size() == use_order_list_size_); + CHECK(prev == use_order_list_tail_); + CHECK(size == use_order_list_size_); + CHECK(entry_by_key_.size() == use_order_list_size_); } #else void SslSessionLRUCache::AssertInvariants() {} diff --git a/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc b/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc index ba797476e24..ad427950e1d 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc @@ -15,8 +15,8 @@ // limitations under the License. // // +#include "absl/log/check.h" -#include #include #include "src/core/lib/gprpp/crash.h" @@ -43,11 +43,11 @@ class OpenSslCachedSession : public SslCachedSession { public: OpenSslCachedSession(SslSessionPtr session) { int size = i2d_SSL_SESSION(session.get(), nullptr); - GPR_ASSERT(size > 0); + CHECK_GT(size, 0); grpc_slice slice = grpc_slice_malloc(size_t(size)); unsigned char* start = GRPC_SLICE_START_PTR(slice); int second_size = i2d_SSL_SESSION(session.get(), &start); - GPR_ASSERT(size == second_size); + CHECK(size == second_size); serialized_session_ = slice; } diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 9235782bb29..eb092155ae2 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -45,6 +45,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -194,7 +195,7 @@ static void init_openssl(void) { #if OPENSSL_VERSION_NUMBER < 0x10100000 if (!CRYPTO_get_locking_callback()) { int num_locks = CRYPTO_num_locks(); - GPR_ASSERT(num_locks > 0); + CHECK_GT(num_locks, 0); g_openssl_mutexes = static_cast( gpr_malloc(static_cast(num_locks) * sizeof(gpr_mu))); for (int i = 0; i < num_locks; i++) { @@ -208,15 +209,15 @@ static void init_openssl(void) { #endif g_ssl_ctx_ex_factory_index = SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr); - GPR_ASSERT(g_ssl_ctx_ex_factory_index != -1); + CHECK_NE(g_ssl_ctx_ex_factory_index, -1); g_ssl_ctx_ex_crl_provider_index = SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr); - GPR_ASSERT(g_ssl_ctx_ex_crl_provider_index != -1); + CHECK_NE(g_ssl_ctx_ex_crl_provider_index, -1); g_ssl_ex_verified_root_cert_index = SSL_get_ex_new_index( 0, nullptr, nullptr, nullptr, verified_root_cert_free); - GPR_ASSERT(g_ssl_ex_verified_root_cert_index != -1); + CHECK_NE(g_ssl_ex_verified_root_cert_index, -1); } // --- Ssl utils. --- @@ -475,7 +476,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, : 0; size_t property_count; tsi_result result; - GPR_ASSERT(subject_alt_name_count >= 0); + CHECK_GE(subject_alt_name_count, 0); property_count = (include_certificate_type ? size_t{1} : 0) + 3 /* subject, common name, certificate */ + static_cast(subject_alt_name_count); @@ -530,7 +531,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, } if (result != TSI_OK) tsi_peer_destruct(peer); - GPR_ASSERT((int)peer->property_count == current_insert_index); + CHECK((int)peer->property_count == current_insert_index); return result; } @@ -541,7 +542,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, tsi_result result = TSI_OK; X509* certificate = nullptr; BIO* pem; - GPR_ASSERT(pem_cert_chain_size <= INT_MAX); + CHECK_LE(pem_cert_chain_size, static_cast(INT_MAX)); pem = BIO_new_mem_buf(pem_cert_chain, static_cast(pem_cert_chain_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; @@ -661,7 +662,7 @@ static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context, tsi_result result = TSI_OK; EVP_PKEY* private_key = nullptr; BIO* pem; - GPR_ASSERT(pem_key_size <= INT_MAX); + CHECK_LE(pem_key_size, static_cast(INT_MAX)); pem = BIO_new_mem_buf(pem_key, static_cast(pem_key_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { @@ -706,7 +707,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store, X509* root = nullptr; X509_NAME* root_name = nullptr; BIO* pem; - GPR_ASSERT(pem_roots_size <= INT_MAX); + CHECK_LE(pem_roots_size, static_cast(INT_MAX)); pem = BIO_new_mem_buf(pem_roots, static_cast(pem_roots_size)); if (cert_store == nullptr) return TSI_INVALID_ARGUMENT; if (pem == nullptr) return TSI_OUT_OF_RESOURCES; @@ -1372,7 +1373,7 @@ static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable = {nullptr}; // allocating memory for the factory. static void tsi_ssl_handshaker_factory_init( tsi_ssl_handshaker_factory* factory) { - GPR_ASSERT(factory != nullptr); + CHECK_NE(factory, nullptr); factory->vtable = &handshaker_factory_vtable; gpr_ref_init(&factory->refcount, 1); @@ -1600,7 +1601,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer( if (error != nullptr) *error = "invalid argument"; return TSI_INVALID_ARGUMENT; } - GPR_ASSERT(*bytes_size <= INT_MAX); + CHECK_LE(*bytes_size, static_cast(INT_MAX)); bytes_read_from_ssl = BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_read_from_ssl < 0) { @@ -1671,7 +1672,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( if (error != nullptr) *error = "invalid argument"; return TSI_INVALID_ARGUMENT; } - GPR_ASSERT(*bytes_size <= INT_MAX); + CHECK_LE(*bytes_size, static_cast(INT_MAX)); bytes_written_into_ssl_size = BIO_write(impl->network_io, bytes, static_cast(*bytes_size)); if (bytes_written_into_ssl_size < 0) { @@ -2135,7 +2136,7 @@ static int server_handshaker_factory_npn_advertised_callback( tsi_ssl_server_handshaker_factory* factory = static_cast(arg); *out = factory->alpn_protocol_list; - GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); + CHECK(factory->alpn_protocol_list_length <= UINT_MAX); *outlen = static_cast(factory->alpn_protocol_list_length); return SSL_TLSEXT_ERR_OK; } @@ -2169,7 +2170,7 @@ static int server_handshaker_factory_new_session_callback( template static void ssl_keylogging_callback(const SSL* ssl, const char* info) { SSL_CTX* ssl_context = SSL_get_SSL_CTX(ssl); - GPR_ASSERT(ssl_context != nullptr); + CHECK_NE(ssl_context, nullptr); void* arg = SSL_CTX_get_ex_data(ssl_context, g_ssl_ctx_ex_factory_index); T* factory = static_cast(arg); factory->key_logger->LogSessionKeys(ssl_context, info); @@ -2303,7 +2304,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( break; } #if TSI_OPENSSL_ALPN_SUPPORT - GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX); + CHECK(impl->alpn_protocol_list_length < UINT_MAX); if (SSL_CTX_set_alpn_protos( ssl_context, impl->alpn_protocol_list, static_cast(impl->alpn_protocol_list_length))) { @@ -2631,8 +2632,8 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, absl::string_view name) { const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable( tsi_ssl_handshaker_factory* factory, tsi_ssl_handshaker_factory_vtable* new_vtable) { - GPR_ASSERT(factory != nullptr); - GPR_ASSERT(factory->vtable != nullptr); + CHECK_NE(factory, nullptr); + CHECK_NE(factory->vtable, nullptr); const tsi_ssl_handshaker_factory_vtable* orig_vtable = factory->vtable; factory->vtable = new_vtable; diff --git a/src/core/tsi/ssl_transport_security_utils.cc b/src/core/tsi/ssl_transport_security_utils.cc index 6ba2ee7a23e..2660e51e0de 100644 --- a/src/core/tsi/ssl_transport_security_utils.cc +++ b/src/core/tsi/ssl_transport_security_utils.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/check.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -68,7 +69,7 @@ void LogSslErrorStack(void) { tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes, size_t unprotected_bytes_size) { - GPR_ASSERT(unprotected_bytes_size <= INT_MAX); + CHECK_LE(unprotected_bytes_size, static_cast(INT_MAX)); ERR_clear_error(); int ssl_write_result = SSL_write(ssl, unprotected_bytes, static_cast(unprotected_bytes_size)); @@ -89,7 +90,7 @@ tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes, tsi_result DoSslRead(SSL* ssl, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { - GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); + CHECK_LE(*unprotected_bytes_size, static_cast(INT_MAX)); ERR_clear_error(); int read_from_ssl = SSL_read(ssl, unprotected_bytes, static_cast(*unprotected_bytes_size)); @@ -134,7 +135,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, int pending_in_ssl = static_cast(BIO_pending(network_io)); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; - GPR_ASSERT(*protected_output_frames_size <= INT_MAX); + CHECK_LE(*protected_output_frames_size, static_cast(INT_MAX)); read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { @@ -161,7 +162,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes, result = DoSslWrite(ssl, buffer, buffer_size); if (result != TSI_OK) return result; - GPR_ASSERT(*protected_output_frames_size <= INT_MAX); + CHECK_LE(*protected_output_frames_size, static_cast(INT_MAX)); read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl < 0) { @@ -191,11 +192,11 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset, } pending = static_cast(BIO_pending(network_io)); - GPR_ASSERT(pending >= 0); + CHECK_GE(pending, 0); *still_pending_size = static_cast(pending); if (*still_pending_size == 0) return TSI_OK; - GPR_ASSERT(*protected_output_frames_size <= INT_MAX); + CHECK_LE(*protected_output_frames_size, static_cast(INT_MAX)); read_from_ssl = BIO_read(network_io, protected_output_frames, static_cast(*protected_output_frames_size)); if (read_from_ssl <= 0) { @@ -204,7 +205,7 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset, } *protected_output_frames_size = static_cast(read_from_ssl); pending = static_cast(BIO_pending(network_io)); - GPR_ASSERT(pending >= 0); + CHECK_GE(pending, 0); *still_pending_size = static_cast(pending); return TSI_OK; } @@ -232,7 +233,7 @@ tsi_result SslProtectorUnprotect(const unsigned char* protected_frames_bytes, *unprotected_bytes_size = output_bytes_size - output_bytes_offset; // Then, try to write some data to ssl. - GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); + CHECK_LE(*protected_frames_bytes_size, static_cast(INT_MAX)); written_into_ssl = BIO_write(network_io, protected_frames_bytes, static_cast(*protected_frames_bytes_size)); if (written_into_ssl < 0) { diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index b9f71915981..f989703fe1a 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -48,38 +47,11 @@ #include #include -#include "src/core/ext/transport/chttp2/server/chttp2_server.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" -#include "src/core/server/server.h" #include "src/cpp/server/external_connection_acceptor_impl.h" namespace grpc { -namespace { - -// A PIMPL wrapper class that owns the only ref to the passive listener -// implementation. This is returned to the application. -class PassiveListenerOwner final - : public grpc_core::experimental::PassiveListener { - public: - explicit PassiveListenerOwner(std::shared_ptr listener) - : listener_(std::move(listener)) {} - - absl::Status AcceptConnectedEndpoint( - std::unique_ptr - endpoint) override { - return listener_->AcceptConnectedEndpoint(std::move(endpoint)); - } - - absl::Status AcceptConnectedFd(int fd) override { - return listener_->AcceptConnectedFd(fd); - } - - private: - std::shared_ptr listener_; -}; - -} // namespace static std::vector (*)()>* g_plugin_factory_list; @@ -253,18 +225,6 @@ ServerBuilder& ServerBuilder::SetResourceQuota( return *this; } -ServerBuilder& ServerBuilder::experimental_type::AddPassiveListener( - std::shared_ptr creds, - std::unique_ptr& passive_listener) { - auto core_passive_listener = - std::make_shared(); - builder_->unstarted_passive_listeners_.emplace_back(core_passive_listener, - std::move(creds)); - passive_listener = - std::make_unique(std::move(core_passive_listener)); - return *builder_; -} - ServerBuilder& ServerBuilder::AddListeningPort( const std::string& addr_uri, std::shared_ptr creds, int* selected_port) { @@ -438,26 +398,6 @@ std::unique_ptr ServerBuilder::BuildAndStart() { cq->RegisterServer(server.get()); } - for (auto& unstarted_listener : unstarted_passive_listeners_) { - has_frequently_polled_cqs = true; - auto passive_listener = unstarted_listener.passive_listener.lock(); - auto* core_server = grpc_core::Server::FromC(server->c_server()); - if (passive_listener != nullptr) { - auto* creds = unstarted_listener.credentials->c_creds(); - if (creds == nullptr) { - gpr_log(GPR_ERROR, "Credentials missing for PassiveListener"); - return nullptr; - } - auto success = grpc_server_add_passive_listener( - core_server, creds, std::move(passive_listener)); - if (!success.ok()) { - gpr_log(GPR_ERROR, "Failed to create a passive listener: %s", - success.ToString().c_str()); - return nullptr; - } - } - } - if (!has_frequently_polled_cqs) { gpr_log(GPR_ERROR, "At least one of the completion queues must be frequently polled"); diff --git a/test/core/event_engine/event_engine_test_utils.h b/test/core/event_engine/event_engine_test_utils.h index debef7a0449..67bbe42d35d 100644 --- a/test/core/event_engine/event_engine_test_utils.h +++ b/test/core/event_engine/event_engine_test_utils.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -160,70 +159,6 @@ class NotifyOnDelete { grpc_core::Notification* signal_; }; -// An endpoint implementation that supports Read and Write via std::threads. -// Passing a grpc_core::Notification will allow owners to know when all -// in-flight callbacks have been run, and all endpoint state has been destroyed. -class ThreadedNoopEndpoint : public EventEngine::Endpoint { - public: - explicit ThreadedNoopEndpoint(grpc_core::Notification* destroyed) - : state_(std::make_shared(destroyed)) {} - ~ThreadedNoopEndpoint() override { - std::thread deleter([state = state_]() { - CleanupThread(state->read); - CleanupThread(state->write); - }); - deleter.detach(); - } - - bool Read(absl::AnyInvocable on_read, SliceBuffer* buffer, - const ReadArgs* /* args */) override { - buffer->Clear(); - CleanupThread(state_->read); - state_->read = new std::thread([cb = std::move(on_read)]() mutable { - cb(absl::UnknownError("test")); - }); - return false; - } - - bool Write(absl::AnyInvocable on_writable, - SliceBuffer* data, const WriteArgs* /* args */) override { - data->Clear(); - CleanupThread(state_->write); - state_->write = new std::thread([cb = std::move(on_writable)]() mutable { - cb(absl::UnknownError("test")); - }); - return false; - } - - const EventEngine::ResolvedAddress& GetPeerAddress() const override { - return peer_; - } - - const EventEngine::ResolvedAddress& GetLocalAddress() const override { - return local_; - } - - private: - struct EndpointState { - explicit EndpointState(grpc_core::Notification* deleter) - : delete_notifier_(deleter) {} - std::thread* read = nullptr; - std::thread* write = nullptr; - NotifyOnDelete delete_notifier_; - }; - - static void CleanupThread(std::thread* thd) { - if (thd != nullptr) { - thd->join(); - delete thd; - } - } - - std::shared_ptr state_; - EventEngine::ResolvedAddress peer_; - EventEngine::ResolvedAddress local_; -}; - } // namespace experimental } // namespace grpc_event_engine diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD index b65ec5c9e86..ba2f115ee7a 100644 --- a/test/cpp/server/BUILD +++ b/test/cpp/server/BUILD @@ -28,7 +28,6 @@ grpc_cc_test( deps = [ "//:grpc++_unsecure", "//src/proto/grpc/testing:echo_proto", - "//test/core/event_engine:event_engine_test_utils", "//test/core/test_util:grpc_test_util_base", "//test/core/test_util:grpc_test_util_unsecure", ], diff --git a/test/cpp/server/server_builder_test.cc b/test/cpp/server/server_builder_test.cc index 089f7c38ecf..1765a1d59bf 100644 --- a/test/cpp/server/server_builder_test.cc +++ b/test/cpp/server/server_builder_test.cc @@ -16,19 +16,14 @@ // // -#include - #include -#include #include #include #include #include -#include "src/core/lib/gprpp/notification.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" -#include "test/core/event_engine/event_engine_test_utils.h" #include "test/core/test_util/port.h" #include "test/core/test_util/test_config.h" @@ -88,56 +83,6 @@ TEST_F(ServerBuilderTest, CreateServerRepeatedPortWithDisallowedReusePort) { nullptr); } -TEST_F(ServerBuilderTest, AddPassiveListener) { - std::unique_ptr passive_listener; - auto server = - ServerBuilder() - .experimental() - .AddPassiveListener(InsecureServerCredentials(), passive_listener) - .BuildAndStart(); - server->Shutdown(); -} - -TEST_F(ServerBuilderTest, PassiveListenerAcceptConnectedFd) { - std::unique_ptr passive_listener; - ServerBuilder builder; - auto cq = builder.AddCompletionQueue(); - // TODO(hork): why is the service necessary? Queue isn't drained otherwise. - auto server = - builder.RegisterService(&g_service) - .experimental() - .AddPassiveListener(InsecureServerCredentials(), passive_listener) - .BuildAndStart(); - ASSERT_NE(server.get(), nullptr); -#ifdef GPR_SUPPORT_CHANNELS_FROM_FD - int fd = socket(AF_INET, SOCK_STREAM, 0); - auto accept_status = passive_listener->AcceptConnectedFd(fd); - ASSERT_TRUE(accept_status.ok()) << accept_status; -#else - int fd = -1; - auto accept_status = passive_listener->AcceptConnectedFd(fd); - ASSERT_FALSE(accept_status.ok()) << accept_status; -#endif - server->Shutdown(); -} - -TEST_F(ServerBuilderTest, PassiveListenerAcceptConnectedEndpoint) { - std::unique_ptr passive_listener; - auto server = - ServerBuilder() - .experimental() - .AddPassiveListener(InsecureServerCredentials(), passive_listener) - .BuildAndStart(); - grpc_core::Notification endpoint_destroyed; - auto success = passive_listener->AcceptConnectedEndpoint( - std::make_unique( - &endpoint_destroyed)); - ASSERT_TRUE(success.ok()) - << "AcceptConnectedEndpoint failure: " << success.ToString(); - endpoint_destroyed.WaitForNotification(); - server->Shutdown(); -} - } // namespace } // namespace grpc diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index c9df11d7982..95b28274cc0 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -45,6 +45,7 @@ grpc_cc_library( hdrs = [ "proto_reflection_descriptor_database.h", ], + external_deps = ["absl/log:log"], deps = [ "//:grpc++", "//:grpc++_config_proto", @@ -78,6 +79,7 @@ grpc_cc_library( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "protobuf", ], deps = [ @@ -141,6 +143,7 @@ grpc_cc_library( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "protobuf", "protobuf_clib", ], @@ -175,6 +178,7 @@ grpc_cc_library( hdrs = [ "metrics_server.h", ], + external_deps = ["absl/log:log"], deps = [ "//:grpc++", "//src/proto/grpc/testing:metrics_proto", @@ -338,6 +342,7 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", "absl/strings", ], language = "c++", @@ -364,6 +369,7 @@ grpc_cc_test( ], external_deps = [ "absl/log:check", + "absl/log:log", "gtest", ], flaky = True, diff --git a/test/cpp/util/channelz_sampler.cc b/test/cpp/util/channelz_sampler.cc index f4aee2244f7..2619a5481d1 100644 --- a/test/cpp/util/channelz_sampler.cc +++ b/test/cpp/util/channelz_sampler.cc @@ -28,6 +28,7 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "google/protobuf/text_format.h" @@ -133,8 +134,8 @@ class ChannelzSampler final { Status status = channelz_stub_->GetChannel( &get_channel_context, get_channel_request, &get_channel_response); if (!status.ok()) { - gpr_log(GPR_ERROR, "GetChannelRPC failed: %s", - get_channel_context.debug_error_string().c_str()); + LOG(ERROR) << "GetChannelRPC failed: " + << get_channel_context.debug_error_string(); CHECK(0); } return get_channel_response.channel(); @@ -152,8 +153,8 @@ class ChannelzSampler final { get_subchannel_request, &get_subchannel_response); if (!status.ok()) { - gpr_log(GPR_ERROR, "GetSubchannelRPC failed: %s", - get_subchannel_context.debug_error_string().c_str()); + LOG(ERROR) << "GetSubchannelRPC failed: " + << get_subchannel_context.debug_error_string(); CHECK(0); } return get_subchannel_response.subchannel(); @@ -170,8 +171,8 @@ class ChannelzSampler final { Status status = channelz_stub_->GetSocket( &get_socket_context, get_socket_request, &get_socket_response); if (!status.ok()) { - gpr_log(GPR_ERROR, "GetSocketRPC failed: %s", - get_socket_context.debug_error_string().c_str()); + LOG(ERROR) << "GetSocketRPC failed: " + << get_socket_context.debug_error_string(); CHECK(0); } return get_socket_response.socket(); @@ -297,10 +298,9 @@ class ChannelzSampler final { grpc::testing::GetCredentialsProvider()->GetChannelCredentials( custom_credentials_type, &channel_args); if (!channel_creds) { - gpr_log(GPR_ERROR, - "Wrong user credential type: %s. Allowed credential types: " - "INSECURE_CREDENTIALS, ssl, alts, google_default_credentials.", - custom_credentials_type.c_str()); + LOG(ERROR) << "Wrong user credential type: " << custom_credentials_type + << ". Allowed credential types: INSECURE_CREDENTIALS, ssl, " + "alts, google_default_credentials."; CHECK(0); } std::shared_ptr channel = @@ -324,15 +324,14 @@ class ChannelzSampler final { &get_servers_context, get_servers_request, &get_servers_response); if (!status.ok()) { if (status.error_code() == StatusCode::UNIMPLEMENTED) { - gpr_log(GPR_ERROR, - "Error status UNIMPLEMENTED. Please check and make sure " - "channelz has been registered on the server being queried."); + LOG(ERROR) << "Error status UNIMPLEMENTED. Please check and make " + "sure channelz has been registered on the server being " + "queried."; } else { - gpr_log(GPR_ERROR, - "GetServers RPC with GetServersRequest.server_start_id=%d, " - "failed: %s", - static_cast(server_start_id), - get_servers_context.debug_error_string().c_str()); + LOG(ERROR) << "GetServers RPC with " + "GetServersRequest.server_start_id=" + << server_start_id << ", failed: " + << get_servers_context.debug_error_string(); } CHECK(0); } @@ -384,11 +383,10 @@ class ChannelzSampler final { &get_top_channels_context, get_top_channels_request, &get_top_channels_response); if (!status.ok()) { - gpr_log(GPR_ERROR, - "GetTopChannels RPC with " - "GetTopChannelsRequest.channel_start_id=%d failed: %s", - static_cast(channel_start_id), - get_top_channels_context.debug_error_string().c_str()); + LOG(ERROR) << "GetTopChannels RPC with " + "GetTopChannelsRequest.channel_start_id=" + << channel_start_id << " failed: " + << get_top_channels_context.debug_error_string(); CHECK(0); } for (const auto& _topchannel : get_top_channels_response.channel()) { diff --git a/test/cpp/util/channelz_sampler_test.cc b/test/cpp/util/channelz_sampler_test.cc index 76db3a1efab..fde2a019f97 100644 --- a/test/cpp/util/channelz_sampler_test.cc +++ b/test/cpp/util/channelz_sampler_test.cc @@ -25,6 +25,7 @@ #include #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "gtest/gtest.h" @@ -85,7 +86,7 @@ void RunClient(const std::string& client_id, gpr_event* done_ev) { std::unique_ptr stub = grpc::testing::TestService::NewStub( grpc::CreateChannel(server_address, channel_creds)); - gpr_log(GPR_INFO, "Client %s is echoing!", client_id.c_str()); + LOG(INFO) << "Client " << client_id << " is echoing!"; while (true) { if (gpr_event_wait(done_ev, grpc_timeout_seconds_to_deadline(1)) != nullptr) { @@ -96,7 +97,7 @@ void RunClient(const std::string& client_id, gpr_event* done_ev) { ClientContext context; Status status = stub->EmptyCall(&context, request, &response); if (!status.ok()) { - gpr_log(GPR_ERROR, "Client echo failed."); + LOG(ERROR) << "Client echo failed."; CHECK(0); } } @@ -125,7 +126,7 @@ TEST(ChannelzSamplerTest, SimpleTest) { builder.AddListeningPort(server_address, server_creds); builder.RegisterService(&service); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Server listening on %s", server_address.c_str()); + LOG(INFO) << "Server listening on " << server_address; const int kWaitForServerSeconds = 10; ASSERT_TRUE(WaitForConnection(kWaitForServerSeconds)); // client threads @@ -144,19 +145,17 @@ TEST(ChannelzSamplerTest, SimpleTest) { int status = test_driver->Join(); if (WIFEXITED(status)) { if (WEXITSTATUS(status)) { - gpr_log(GPR_ERROR, - "Channelz sampler test test-runner exited with code %d", - WEXITSTATUS(status)); + LOG(ERROR) << "Channelz sampler test test-runner exited with code " + << WEXITSTATUS(status); CHECK(0); // log the line number of the assertion failure } } else if (WIFSIGNALED(status)) { - gpr_log(GPR_ERROR, "Channelz sampler test test-runner ended from signal %d", - WTERMSIG(status)); + LOG(ERROR) << "Channelz sampler test test-runner ended from signal " + << WTERMSIG(status); CHECK(0); } else { - gpr_log(GPR_ERROR, - "Channelz sampler test test-runner ended with unknown status %d", - status); + LOG(ERROR) << "Channelz sampler test test-runner ended with unknown status " + << status; CHECK(0); } delete test_driver; diff --git a/test/cpp/util/cli_credentials.cc b/test/cpp/util/cli_credentials.cc index bf9e974a196..8b178524df8 100644 --- a/test/cpp/util/cli_credentials.cc +++ b/test/cpp/util/cli_credentials.cc @@ -19,6 +19,7 @@ #include "test/cpp/util/cli_credentials.h" #include "absl/flags/flag.h" +#include "absl/log/log.h" #include #include @@ -97,9 +98,9 @@ CliCredentials::GetChannelCredentials() const { auto cert = grpc_core::LoadFile(absl::GetFlag(FLAGS_ssl_client_cert), /*add_null_terminator=*/false); if (!cert.ok()) { - gpr_log(GPR_ERROR, "error loading file %s: %s", - absl::GetFlag(FLAGS_ssl_client_cert).c_str(), - cert.status().ToString().c_str()); + LOG(ERROR) << "error loading file " + << absl::GetFlag(FLAGS_ssl_client_cert) << ": " + << cert.status(); } else { ssl_creds_options.pem_cert_chain = std::string(cert->as_string_view()); } @@ -108,9 +109,9 @@ CliCredentials::GetChannelCredentials() const { auto key = grpc_core::LoadFile(absl::GetFlag(FLAGS_ssl_client_key), /*add_null_terminator=*/false); if (!key.ok()) { - gpr_log(GPR_ERROR, "error loading file %s: %s", - absl::GetFlag(FLAGS_ssl_client_key).c_str(), - key.status().ToString().c_str()); + LOG(ERROR) << "error loading file " + << absl::GetFlag(FLAGS_ssl_client_key) << ": " + << key.status(); } else { ssl_creds_options.pem_private_key = std::string(key->as_string_view()); } diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc index f816659f3ed..59d3dcead15 100644 --- a/test/cpp/util/metrics_server.cc +++ b/test/cpp/util/metrics_server.cc @@ -18,6 +18,8 @@ #include "test/cpp/util/metrics_server.h" +#include "absl/log/log.h" + #include #include #include @@ -54,7 +56,7 @@ long QpsGauge::Get() { grpc::Status MetricsServiceImpl::GetAllGauges( ServerContext* /*context*/, const EmptyMessage* /*request*/, ServerWriter* writer) { - gpr_log(GPR_DEBUG, "GetAllGauges called"); + VLOG(2) << "GetAllGauges called"; std::lock_guard lock(mu_); for (auto it = qps_gauges_.begin(); it != qps_gauges_.end(); it++) { @@ -99,7 +101,7 @@ std::shared_ptr MetricsServiceImpl::CreateQpsGauge( // Starts the metrics server and returns the grpc::Server instance. Call Wait() // on the returned server instance. std::unique_ptr MetricsServiceImpl::StartServer(int port) { - gpr_log(GPR_INFO, "Building metrics server.."); + LOG(INFO) << "Building metrics server.."; const std::string address = "0.0.0.0:" + std::to_string(port); @@ -108,8 +110,8 @@ std::unique_ptr MetricsServiceImpl::StartServer(int port) { builder.RegisterService(this); std::unique_ptr server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Metrics server %s started. Ready to receive requests..", - address.c_str()); + LOG(INFO) << "Metrics server " << address + << " started. Ready to receive requests.."; return server; } diff --git a/test/cpp/util/proto_reflection_descriptor_database.cc b/test/cpp/util/proto_reflection_descriptor_database.cc index 80b095c6d4b..b5441f87596 100644 --- a/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/test/cpp/util/proto_reflection_descriptor_database.cc @@ -20,7 +20,7 @@ #include -#include +#include "absl/log/log.h" #include "src/core/lib/gprpp/crash.h" @@ -86,23 +86,19 @@ bool ProtoReflectionDescriptorDatabase::FindFileByName( ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { - gpr_log(GPR_INFO, "NOT_FOUND from server for FindFileByName(%s)", - filename.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindFileByName(" << filename + << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileByName(%s)\n\tError code: %d\n" - "\tError Message: %s", - filename.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileByName(" << filename + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileByName(%s) response type\n" - "\tExpecting: %d\n\tReceived: %d", - filename.c_str(), - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileByName(" << filename + << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileByName(filename, output); @@ -134,24 +130,19 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingSymbol( const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { missing_symbols_.insert(symbol_name); - gpr_log(GPR_INFO, - "NOT_FOUND from server for FindFileContainingSymbol(%s)", - symbol_name.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindFileContainingSymbol(" + << symbol_name << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileContainingSymbol(%s)\n" - "\tError code: %d\n\tError Message: %s", - symbol_name.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileContainingSymbol(" << symbol_name + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileContainingSymbol(%s) response type\n" - "\tExpecting: %d\n\tReceived: %d", - symbol_name.c_str(), - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileContainingSymbol(" << symbol_name + << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileContainingSymbol(symbol_name, output); } @@ -167,7 +158,7 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingExtension( if (missing_extensions_.find(containing_type) != missing_extensions_.end() && missing_extensions_[containing_type].find(field_number) != missing_extensions_[containing_type].end()) { - gpr_log(GPR_INFO, "nested map."); + LOG(INFO) << "nested map."; return false; } @@ -194,24 +185,20 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingExtension( missing_extensions_[containing_type] = {}; } missing_extensions_[containing_type].insert(field_number); - gpr_log(GPR_INFO, - "NOT_FOUND from server for FindFileContainingExtension(%s, %d)", - containing_type.c_str(), field_number); + LOG(INFO) << "NOT_FOUND from server for FindFileContainingExtension(" + << containing_type << ", " << field_number << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileContainingExtension(%s, %d)\n" - "\tError code: %d\n\tError Message: %s", - containing_type.c_str(), field_number, error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileContainingExtension(" << containing_type + << ", " << field_number + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileContainingExtension(%s, %d) response type\n" - "\tExpecting: %d\n\tReceived: %d", - containing_type.c_str(), field_number, - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileContainingExtension(" << containing_type + << ", " << field_number << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileContainingExtension(containing_type, field_number, @@ -245,14 +232,12 @@ bool ProtoReflectionDescriptorDatabase::FindAllExtensionNumbers( ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { - gpr_log(GPR_INFO, "NOT_FOUND from server for FindAllExtensionNumbers(%s)", - extendee_type.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindAllExtensionNumbers(" + << extendee_type << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindAllExtensionNumbersExtension(%s)\n" - "\tError code: %d\n\tError Message: %s", - extendee_type.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindAllExtensionNumbersExtension(" << extendee_type + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } return false; @@ -278,16 +263,13 @@ bool ProtoReflectionDescriptorDatabase::GetServices( } else if (response.message_response_case() == ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); - gpr_log(GPR_INFO, - "Error on GetServices()\n\tError code: %d\n" - "\tError Message: %s", - error.error_code(), error.error_message().c_str()); + LOG(INFO) << "Error on GetServices()\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } else { - gpr_log( - GPR_INFO, - "Error on GetServices() response type\n\tExpecting: %d\n\tReceived: %d", - ServerReflectionResponse::MessageResponseCase::kListServicesResponse, - response.message_response_case()); + LOG(INFO) + << "Error on GetServices() response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase::kListServicesResponse + << "\n\tReceived: " << response.message_response_case(); } return false; } diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index c85de0a8b25..c94f0a054bd 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -27,6 +27,7 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include #include @@ -104,7 +105,7 @@ class DefaultCredentialsProvider : public CredentialsProvider { auto it(std::find(added_secure_type_names_.begin(), added_secure_type_names_.end(), type)); if (it == added_secure_type_names_.end()) { - gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); + LOG(ERROR) << "Unsupported credentials type " << type; return nullptr; } return added_secure_type_providers_[it - added_secure_type_names_.begin()] @@ -137,7 +138,7 @@ class DefaultCredentialsProvider : public CredentialsProvider { auto it(std::find(added_secure_type_names_.begin(), added_secure_type_names_.end(), type)); if (it == added_secure_type_names_.end()) { - gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); + LOG(ERROR) << "Unsupported credentials type " << type; return nullptr; } return added_secure_type_providers_[it - added_secure_type_names_.begin()] diff --git a/tools/distrib/check_namespace_qualification.py b/tools/distrib/check_namespace_qualification.py index 51ccb71aeb8..6634d8b8830 100755 --- a/tools/distrib/check_namespace_qualification.py +++ b/tools/distrib/check_namespace_qualification.py @@ -77,10 +77,6 @@ IGNORED_FILES = [ "src/core/lib/gprpp/global_config_env.h", "src/core/lib/profiling/timers.h", "src/core/lib/gprpp/crash.h", - # The grpc_core::Server redundant namespace qualification is required for - # older gcc versions. - "src/core/ext/transport/chttp2/server/chttp2_server.h", - "src/core/server/server.h", ] # find our home diff --git a/tools/distrib/check_redundant_namespace_qualifiers.py b/tools/distrib/check_redundant_namespace_qualifiers.py index 72a5d8b7a3c..0322332209b 100755 --- a/tools/distrib/check_redundant_namespace_qualifiers.py +++ b/tools/distrib/check_redundant_namespace_qualifiers.py @@ -21,13 +21,6 @@ import os import re import sys -IGNORED_FILES = [ - # note: the grpc_core::Server redundant namespace qualification is required - # for older gcc versions. - "src/core/ext/transport/chttp2/server/chttp2_server.h", - "src/core/server/server.h", -] - def find_closing_mustache(contents, initial_depth): """Find the closing mustache for a given number of open mustaches.""" @@ -173,8 +166,6 @@ for config in _CONFIGURATION: for file in files: if file.endswith(".cc") or file.endswith(".h"): path = os.path.join(root, file) - if path in IGNORED_FILES: - continue try: with open(path) as f: contents = f.read() diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index c630913e944..6e0f4316174 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -928,7 +928,6 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ -include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ @@ -1041,7 +1040,6 @@ include/grpcpp/impl/server_initializer.h \ include/grpcpp/impl/service_type.h \ include/grpcpp/impl/status.h \ include/grpcpp/impl/sync.h \ -include/grpcpp/passive_listener.h \ include/grpcpp/resource_quota.h \ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 487cb445903..2d91f97c04f 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -928,7 +928,6 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ -include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ @@ -1041,7 +1040,6 @@ include/grpcpp/impl/server_initializer.h \ include/grpcpp/impl/service_type.h \ include/grpcpp/impl/status.h \ include/grpcpp/impl/sync.h \ -include/grpcpp/passive_listener.h \ include/grpcpp/resource_quota.h \ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 20b553dadfe..592e357f54f 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -861,7 +861,6 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ -include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 7a0b84e75a1..30818623b3d 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -861,7 +861,6 @@ include/grpc/impl/grpc_types.h \ include/grpc/impl/propagation_bits.h \ include/grpc/impl/slice_type.h \ include/grpc/load_reporting.h \ -include/grpc/passive_listener.h \ include/grpc/slice.h \ include/grpc/slice_buffer.h \ include/grpc/status.h \ diff --git a/tools/internal_ci/linux/grpc_xds_k8s_lb.cfg b/tools/internal_ci/linux/grpc_xds_k8s_lb.cfg index 3ba9db6be9e..67f0c0dc523 100644 --- a/tools/internal_ci/linux/grpc_xds_k8s_lb.cfg +++ b/tools/internal_ci/linux/grpc_xds_k8s_lb.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/grpc_xds_k8s_lb.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-cpp.sh" timeout_mins: 240 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "lb" +} diff --git a/tools/internal_ci/linux/grpc_xds_k8s_lb.sh b/tools/internal_ci/linux/grpc_xds_k8s_lb.sh deleted file mode 100755 index 63579d7e752..00000000000 --- a/tools/internal_ci/linux/grpc_xds_k8s_lb.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building C++ xDS interop test app Docker images" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_client" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_server" -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping C++ test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# SECONDARY_KUBE_CONTEXT: The name of kubectl context with secondary GKE cluster access, if any -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --kube_context="${KUBE_CONTEXT}" \ - --secondary_kube_context="${SECONDARY_KUBE_CONTEXT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - ${@:2} \ - |& tee "${out_dir}/sponge_log.log" -} - -run_alpha_test() { - local test_name=$1 - run_test ${test_name} \ - --compute_api_version="v1alpha" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster access, if any -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test captured from the master branch. - echo "Sourcing test driver install captured from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_LB - activate_secondary_gke_cluster GKE_CLUSTER_PSM_LB - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - run_alpha_test subsetting_test || (( ++failed_tests )) - test_suites=( - "app_net_test" - "affinity_test" - "api_listener_test" - "change_backend_service_test" - "custom_lb_test" - "failover_test" - "outlier_detection_test" - "remove_neg_test" - "round_robin_test" - ) - if [[ "${TESTING_VERSION}" =~ "master" ]]; then - test_suites+=('bootstrap_generator_test') - fi - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - -main "$@" diff --git a/tools/internal_ci/linux/grpc_xds_k8s_lb_python.cfg b/tools/internal_ci/linux/grpc_xds_k8s_lb_python.cfg index 7de169c802b..12d92f51b82 100644 --- a/tools/internal_ci/linux/grpc_xds_k8s_lb_python.cfg +++ b/tools/internal_ci/linux/grpc_xds_k8s_lb_python.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/grpc_xds_k8s_lb_python.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-python.sh" timeout_mins: 180 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "lb" +} diff --git a/tools/internal_ci/linux/grpc_xds_k8s_lb_python.sh b/tools/internal_ci/linux/grpc_xds_k8s_lb_python.sh deleted file mode 100755 index 31444e7225b..00000000000 --- a/tools/internal_ci/linux/grpc_xds_k8s_lb_python.sh +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" -readonly LANGUAGE_NAME="Python" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building ${LANGUAGE_NAME} xDS interop test app Docker images" - - pushd "${SRC_DIR}" - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.client \ - -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.server \ - -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - popd - - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping ${LANGUAGE_NAME} test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# SECONDARY_KUBE_CONTEXT: The name of kubectl context with secondary GKE cluster access, if any -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --kube_context="${KUBE_CONTEXT}" \ - --secondary_kube_context="${SECONDARY_KUBE_CONTEXT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster access, if any -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_LB - activate_secondary_gke_cluster GKE_CLUSTER_PSM_LB - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - test_suites=( - "app_net_test" - "api_listener_test" - "change_backend_service_test" - "failover_test" - "outlier_detection_test" - "remove_neg_test" - "round_robin_test" - ) - if [[ "${TESTING_VERSION}" =~ "master" ]]; then - test_suites+=('bootstrap_generator_test') - fi - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - -main "$@" diff --git a/tools/internal_ci/linux/grpc_xds_url_map.cfg b/tools/internal_ci/linux/grpc_xds_url_map.cfg index 9ac47292452..51612499205 100644 --- a/tools/internal_ci/linux/grpc_xds_url_map.cfg +++ b/tools/internal_ci/linux/grpc_xds_url_map.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/grpc_xds_url_map.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-cpp.sh" timeout_mins: 90 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "url_map" +} diff --git a/tools/internal_ci/linux/grpc_xds_url_map.sh b/tools/internal_ci/linux/grpc_xds_url_map.sh deleted file mode 100755 index bc90935573f..00000000000 --- a/tools/internal_ci/linux/grpc_xds_url_map.sh +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building C++ xDS interop test app Docker images" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_client" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping C++ test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --flagfile="config/url-map.cfg" \ - --kube_context="${KUBE_CONTEXT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_BASIC - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - run_test url_map || echo "Failed url_map test" -} - -main "$@" diff --git a/tools/internal_ci/linux/grpc_xds_url_map_python.cfg b/tools/internal_ci/linux/grpc_xds_url_map_python.cfg index 4e91dc5b8f3..efc17f5e3e3 100644 --- a/tools/internal_ci/linux/grpc_xds_url_map_python.cfg +++ b/tools/internal_ci/linux/grpc_xds_url_map_python.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/grpc_xds_url_map_python.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-python.sh" timeout_mins: 90 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "url_map" +} diff --git a/tools/internal_ci/linux/grpc_xds_url_map_python.sh b/tools/internal_ci/linux/grpc_xds_url_map_python.sh deleted file mode 100755 index e12cda8afe7..00000000000 --- a/tools/internal_ci/linux/grpc_xds_url_map_python.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" -readonly LANGUAGE_NAME="Python" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building ${LANGUAGE_NAME} xDS interop test app Docker images" - - pushd "${SRC_DIR}" - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.client \ - -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - popd - - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping ${LANGUAGE_NAME} test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --flagfile="config/url-map.cfg" \ - --kube_context="${KUBE_CONTEXT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_BASIC - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - run_test url_map || echo "Failed url_map test" -} - -main "$@" diff --git a/tools/internal_ci/linux/psm-csm-python.cfg b/tools/internal_ci/linux/psm-csm-python.cfg index 5ae3f83063d..857f1fb2936 100644 --- a/tools/internal_ci/linux/psm-csm-python.cfg +++ b/tools/internal_ci/linux/psm-csm-python.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/psm-csm-python.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-python.sh" timeout_mins: 240 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "csm" +} diff --git a/tools/internal_ci/linux/psm-csm-python.sh b/tools/internal_ci/linux/psm-csm-python.sh deleted file mode 100755 index 4b6ee20ce3d..00000000000 --- a/tools/internal_ci/linux/psm-csm-python.sh +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2024 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test server/client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test, f.e. v1.42.x, master -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building Python xDS interop test app Docker images" - - pushd "${SRC_DIR}" - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.client \ - -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.server \ - -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - popd - - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping Python test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --flagfile="config/common-csm.cfg" \ - --kube_context="${KUBE_CONTEXT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --nocheck_local_certs \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" - set +x -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_CSM - - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - test_suites=( - "gamma.gamma_baseline_test" - "gamma.affinity_session_drain_test" - "gamma.affinity_test" - "app_net_ssa_test" - ) - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - - -main "$@" diff --git a/tools/internal_ci/linux/psm-csm.cfg b/tools/internal_ci/linux/psm-csm.cfg index 0545b9298d8..bc44a745869 100644 --- a/tools/internal_ci/linux/psm-csm.cfg +++ b/tools/internal_ci/linux/psm-csm.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/psm-csm.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-cpp.sh" timeout_mins: 120 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "csm" +} diff --git a/tools/internal_ci/linux/psm-csm.sh b/tools/internal_ci/linux/psm-csm.sh deleted file mode 100755 index 7b0c596e431..00000000000 --- a/tools/internal_ci/linux/psm-csm.sh +++ /dev/null @@ -1,175 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test server/client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test, f.e. v1.42.x, master -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building C++ xDS interop test app Docker images" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_client" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_server" -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping C++ test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --flagfile="config/common-csm.cfg" \ - --kube_context="${KUBE_CONTEXT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_CSM - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - test_suites=( - "gamma.gamma_baseline_test" - "gamma.affinity_test" - "gamma.affinity_session_drain_test" - "gamma.csm_observability_test" - "app_net_ssa_test" - ) - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - -main "$@" diff --git a/tools/internal_ci/linux/psm-interop-build-cpp.sh b/tools/internal_ci/linux/psm-interop-build-cpp.sh new file mode 100755 index 00000000000..672cb4f156c --- /dev/null +++ b/tools/internal_ci/linux/psm-interop-build-cpp.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +####################################### +# Builds test app Docker images and pushes them to GCR. +# Called from psm_interop_kokoro_lib.sh. +# +# Globals: +# SRC_DIR: Absolute path to the source repo on Kokoro VM +# SERVER_IMAGE_NAME: Test server Docker image name +# CLIENT_IMAGE_NAME: Test client Docker image name +# GIT_COMMIT: SHA-1 of git commit being built +# DOCKER_REGISTRY: Docker registry to push to +# Outputs: +# Writes the output of docker image build stdout, stderr +####################################### +psm::lang::build_docker_images() { + local client_dockerfile="tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_client" + local server_dockerfile="tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_server" + psm::build::docker_images_generic "${client_dockerfile}" "${server_dockerfile}" +} diff --git a/tools/internal_ci/linux/psm-interop-build-python.sh b/tools/internal_ci/linux/psm-interop-build-python.sh new file mode 100755 index 00000000000..5a2ab9e8c01 --- /dev/null +++ b/tools/internal_ci/linux/psm-interop-build-python.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +####################################### +# Builds test app Docker images and pushes them to GCR. +# Called from psm_interop_kokoro_lib.sh. +# +# Globals: +# SRC_DIR: Absolute path to the source repo on Kokoro VM +# SERVER_IMAGE_NAME: Test server Docker image name +# CLIENT_IMAGE_NAME: Test client Docker image name +# GIT_COMMIT: SHA-1 of git commit being built +# DOCKER_REGISTRY: Docker registry to push to +# Outputs: +# Writes the output of docker image build stdout, stderr +####################################### +psm::lang::build_docker_images() { + local client_dockerfile="src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.client" + local server_dockerfile="src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.server" + psm::build::docker_images_generic "${client_dockerfile}" "${server_dockerfile}" +} diff --git a/tools/internal_ci/linux/psm-interop-install-lib.sh b/tools/internal_ci/linux/psm-interop-install-lib.sh new file mode 100755 index 00000000000..8b92344e392 --- /dev/null +++ b/tools/internal_ci/linux/psm-interop-install-lib.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +# Used locally. +readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" + +psm::lang::source_install_lib() { + echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" + local install_lib + # Download to a tmp file. + install_lib="$(mktemp -d)/psm_interop_kokoro_lib.sh" + curl -s --retry-connrefused --retry 5 -o "${install_lib}" "${TEST_DRIVER_INSTALL_SCRIPT_URL}" + # Checksum. + if command -v sha256sum &> /dev/null; then + echo "Install script checksum:" + sha256sum "${install_lib}" + fi + source "${install_lib}" +} diff --git a/tools/internal_ci/linux/psm-interop-test-cpp.sh b/tools/internal_ci/linux/psm-interop-test-cpp.sh new file mode 100755 index 00000000000..8774b81b245 --- /dev/null +++ b/tools/internal_ci/linux/psm-interop-test-cpp.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +# Input parameters to psm:: methods of the install script. +readonly GRPC_LANGUAGE="cpp" +readonly BUILD_SCRIPT_DIR="$(dirname "$0")" + +source "${BUILD_SCRIPT_DIR}/psm-interop-install-lib.sh" +psm::lang::source_install_lib +source "${BUILD_SCRIPT_DIR}/psm-interop-build-${GRPC_LANGUAGE}.sh" +psm::run "${PSM_TEST_SUITE}" diff --git a/tools/internal_ci/linux/psm-interop-test-python.sh b/tools/internal_ci/linux/psm-interop-test-python.sh new file mode 100755 index 00000000000..3b804946389 --- /dev/null +++ b/tools/internal_ci/linux/psm-interop-test-python.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -eo pipefail + +# Input parameters to psm:: methods of the install script. +readonly GRPC_LANGUAGE="python" +readonly BUILD_SCRIPT_DIR="$(dirname "$0")" + +source "${BUILD_SCRIPT_DIR}/psm-interop-install-lib.sh" +psm::lang::source_install_lib +source "${BUILD_SCRIPT_DIR}/psm-interop-build-${GRPC_LANGUAGE}.sh" +psm::run "${PSM_TEST_SUITE}" diff --git a/tools/internal_ci/linux/psm-security-python.cfg b/tools/internal_ci/linux/psm-security-python.cfg index 02fe4044929..54660a18512 100644 --- a/tools/internal_ci/linux/psm-security-python.cfg +++ b/tools/internal_ci/linux/psm-security-python.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/psm-security-python.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-python.sh" timeout_mins: 240 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "security" +} diff --git a/tools/internal_ci/linux/psm-security-python.sh b/tools/internal_ci/linux/psm-security-python.sh deleted file mode 100755 index ee1aa70e7c0..00000000000 --- a/tools/internal_ci/linux/psm-security-python.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test server/client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/python-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" -readonly LANGUAGE_NAME="Python" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test, f.e. v1.42.x, master -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building ${LANGUAGE_NAME} xDS interop test app Docker images" - - pushd "${SRC_DIR}" - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.client \ - -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - docker build \ - -f src/python/grpcio_tests/tests_py3_only/interop/Dockerfile.server \ - -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - . - - popd - - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping ${LANGUAGE_NAME} test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --kube_context="${KUBE_CONTEXT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --nocheck_local_certs \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" - set +x -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_SECURITY - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - test_suites=("baseline_test" "security_test" "authz_test") - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - -main "$@" diff --git a/tools/internal_ci/linux/psm-security.cfg b/tools/internal_ci/linux/psm-security.cfg index 9b00aaf40d4..098a0d60e72 100644 --- a/tools/internal_ci/linux/psm-security.cfg +++ b/tools/internal_ci/linux/psm-security.cfg @@ -15,7 +15,7 @@ # Config file for the internal CI (in protobuf text format) # Location of the continuous shell script in repository. -build_file: "grpc/tools/internal_ci/linux/psm-security.sh" +build_file: "grpc/tools/internal_ci/linux/psm-interop-test-cpp.sh" timeout_mins: 240 action { define_artifacts { @@ -24,3 +24,7 @@ action { strip_prefix: "artifacts" } } +env_vars { + key: "PSM_TEST_SUITE" + value: "security" +} diff --git a/tools/internal_ci/linux/psm-security.sh b/tools/internal_ci/linux/psm-security.sh deleted file mode 100755 index 9a55367e097..00000000000 --- a/tools/internal_ci/linux/psm-security.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eo pipefail - -# Constants -readonly GITHUB_REPOSITORY_NAME="grpc" -readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh" -## xDS test server/client Docker images -readonly DOCKER_REGISTRY="us-docker.pkg.dev" -readonly SERVER_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-server" -readonly CLIENT_IMAGE_NAME="us-docker.pkg.dev/grpc-testing/psm-interop/cpp-client" -readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" -readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing" - -####################################### -# Builds test app Docker images and pushes them to GCR -# Globals: -# BUILD_APP_PATH -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test, f.e. v1.42.x, master -# Arguments: -# None -# Outputs: -# Writes the output of `gcloud builds submit` to stdout, stderr -####################################### -build_test_app_docker_images() { - echo "Building C++ xDS interop test app Docker images" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_client" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - docker build -f "${SRC_DIR}/tools/dockerfile/interoptest/grpc_interop_cxx_xds/Dockerfile.xds_server" -t "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" - gcloud -q auth configure-docker "${DOCKER_REGISTRY}" - docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" - docker push "${SERVER_IMAGE_NAME}:${GIT_COMMIT}" - if is_version_branch "${TESTING_VERSION}"; then - tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - tag_and_push_docker_image "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" - fi -} - -####################################### -# Builds test app and its docker images unless they already exist -# Globals: -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# FORCE_IMAGE_BUILD -# Arguments: -# None -# Outputs: -# Writes the output to stdout, stderr -####################################### -build_docker_images_if_needed() { - # Check if images already exist - server_tags="$(gcloud_gcr_list_image_tags "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Server image: %s:%s\n" "${SERVER_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${server_tags:-Server image not found}" - - client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" - printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" - echo "${client_tags:-Client image not found}" - - # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 - if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${server_tags}" || -z "${client_tags}" ]]; then - build_test_app_docker_images - else - echo "Skipping C++ test app build" - fi -} - -####################################### -# Executes the test case -# Globals: -# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile -# KUBE_CONTEXT: The name of kubectl context with GKE cluster access -# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report -# SERVER_IMAGE_NAME: Test server Docker image name -# CLIENT_IMAGE_NAME: Test client Docker image name -# GIT_COMMIT: SHA-1 of git commit being built -# TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM -# features. -# Arguments: -# Test case name -# Outputs: -# Writes the output of test execution to stdout, stderr -# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml -####################################### -run_test() { - # Test driver usage: - # https://github.com/grpc/psm-interop#basic-usage - local test_name="${1:?Usage: run_test test_name}" - local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" - mkdir -pv "${out_dir}" - set -x - python3 -m "tests.${test_name}" \ - --flagfile="${TEST_DRIVER_FLAGFILE}" \ - --kube_context="${KUBE_CONTEXT}" \ - --server_image="${SERVER_IMAGE_NAME}:${GIT_COMMIT}" \ - --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ - --testing_version="${TESTING_VERSION}" \ - --nocheck_local_certs \ - --force_cleanup \ - --collect_app_logs \ - --log_dir="${out_dir}" \ - --xml_output_file="${out_dir}/sponge_log.xml" \ - |& tee "${out_dir}/sponge_log.log" -} - -####################################### -# Main function: provision software necessary to execute tests, and run them -# Globals: -# KOKORO_ARTIFACTS_DIR -# GITHUB_REPOSITORY_NAME -# SRC_DIR: Populated with absolute path to the source repo -# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing -# the test driver -# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code -# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile -# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report -# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build -# GIT_COMMIT: Populated with the SHA-1 of git commit being built -# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built -# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access -# Arguments: -# None -# Outputs: -# Writes the output of test execution to stdout, stderr -####################################### -main() { - local script_dir - script_dir="$(dirname "$0")" - - # Source the test driver from the master branch. - echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" - source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" - - activate_gke_cluster GKE_CLUSTER_PSM_SECURITY - - set -x - if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then - kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" - else - local_setup_test_driver "${script_dir}" - fi - build_docker_images_if_needed - # Run tests - cd "${TEST_DRIVER_FULL_DIR}" - local failed_tests=0 - test_suites=("baseline_test" "security_test" "authz_test") - for test in "${test_suites[@]}"; do - run_test $test || (( ++failed_tests )) - done - echo "Failed test suites: ${failed_tests}" -} - -main "$@" diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index bcb9bcf8769..ccaf83cc1e6 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -132,6 +132,7 @@ LANG_RELEASE_MATRIX = { ("v1.60.0", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), + ("v1.63.0", ReleaseInfo()), ] ), "go": OrderedDict( @@ -781,6 +782,12 @@ LANG_RELEASE_MATRIX = { runtimes=["python"], testcases_file="python__master" ), ), + ( + "v1.63.0", + ReleaseInfo( + runtimes=["python"], testcases_file="python__master" + ), + ), ] ), "node": OrderedDict( @@ -877,6 +884,7 @@ LANG_RELEASE_MATRIX = { ("v1.60.0", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), + ("v1.63.0", ReleaseInfo()), ] ), "php": OrderedDict( @@ -937,6 +945,7 @@ LANG_RELEASE_MATRIX = { ("v1.60.0", ReleaseInfo()), ("v1.61.0", ReleaseInfo()), ("v1.62.0", ReleaseInfo()), + ("v1.63.0", ReleaseInfo()), ] ), "csharp": OrderedDict(