diff --git a/BUILD b/BUILD index 1678426118f..e26d4e2ba02 100644 --- a/BUILD +++ b/BUILD @@ -786,6 +786,8 @@ grpc_cc_library( "absl/base:log_severity", "absl/functional:any_invocable", "absl/log", + "absl/log:check", + "absl/log:globals", "absl/memory", "absl/random", "absl/status", @@ -2962,6 +2964,7 @@ grpc_cc_library( external_deps = [ "absl/base:core_headers", "absl/container:inlined_vector", + "absl/log:check", ], language = "c++", visibility = ["@grpc:client_channel"], @@ -4836,6 +4839,7 @@ grpc_cc_library( "//src/core:lib/gpr/subprocess.h", ], external_deps = [ + "absl/log:check", "absl/strings", "absl/types:span", ], diff --git a/CMakeLists.txt b/CMakeLists.txt index bc07d003268..f24293cc3be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1749,6 +1749,7 @@ target_link_libraries(gpr absl::flags_marshalling absl::any_invocable absl::check + absl::log_globals absl::log absl::memory absl::random_random @@ -36919,7 +36920,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_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_globals absl_log_severity absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time absl_variant" "" "-lgpr" "" @@ -36930,7 +36931,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_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_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" "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" @@ -36941,7 +36942,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_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_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" "libcares zlib" "-lgrpc_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36952,7 +36953,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_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_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" "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" @@ -36963,7 +36964,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_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_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" "libcares zlib" "-lgrpc++_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 23c54fb841f..64ff8ce6d14 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -130,6 +130,7 @@ libs: - absl/flags:marshalling - absl/functional:any_invocable - absl/log:check + - absl/log:globals - absl/log:log - absl/memory:memory - absl/random:random diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 9fd6d1f6d06..d075e053e37 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -244,6 +244,7 @@ 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 f15894c41d5..173742c4f21 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -216,6 +216,7 @@ 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/src/core/BUILD b/src/core/BUILD index 2476fab4002..fb16f2b8eea 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -329,6 +329,9 @@ grpc_cc_library( grpc_cc_library( name = "chunked_vector", hdrs = ["lib/gprpp/chunked_vector.h"], + external_deps = [ + "absl/log:check", + ], deps = [ "arena", "gpr_manual_constructor", @@ -352,6 +355,7 @@ grpc_cc_library( "lib/gprpp/status_helper.h", ], external_deps = [ + "absl/log:check", "absl/status", "absl/strings", "absl/strings:cord", @@ -1648,6 +1652,7 @@ grpc_cc_library( "lib/gprpp/time.h", ], external_deps = [ + "absl/log:check", "absl/strings:str_format", "absl/types:optional", ], @@ -3085,6 +3090,9 @@ grpc_cc_library( hdrs = [ "lib/gprpp/single_set_ptr.h", ], + external_deps = [ + "absl/log:check", + ], language = "c++", deps = ["//:gpr"], ) diff --git a/src/core/lib/gpr/alloc.cc b/src/core/lib/gpr/alloc.cc index 67e07f81f09..a8b92260a92 100644 --- a/src/core/lib/gpr/alloc.cc +++ b/src/core/lib/gpr/alloc.cc @@ -21,6 +21,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -59,7 +61,7 @@ void* gpr_realloc(void* p, size_t size) { } void* gpr_malloc_aligned(size_t size, size_t alignment) { - GPR_ASSERT(((alignment - 1) & alignment) == 0); // Must be power of 2. + CHECK_EQ(((alignment - 1) & alignment), 0u); // Must be power of 2. size_t extra = alignment - 1 + sizeof(void*); void* p = gpr_malloc(size + extra); void** ret = reinterpret_cast( diff --git a/src/core/lib/gpr/posix/sync.cc b/src/core/lib/gpr/posix/sync.cc index 4e57b2c6181..912a1a6b48e 100644 --- a/src/core/lib/gpr/posix/sync.cc +++ b/src/core/lib/gpr/posix/sync.cc @@ -24,6 +24,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -33,36 +35,36 @@ void gpr_mu_init(gpr_mu* mu) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_mutex_init(&mu->mutex, nullptr) == 0); + CHECK_EQ(pthread_mutex_init(&mu->mutex, nullptr), 0); mu->leak_checker = static_cast(malloc(sizeof(*mu->leak_checker))); - GPR_ASSERT(mu->leak_checker != nullptr); + CHECK_NE(mu->leak_checker, nullptr); #else - GPR_ASSERT(pthread_mutex_init(mu, nullptr) == 0); + CHECK_EQ(pthread_mutex_init(mu, nullptr), 0); #endif } void gpr_mu_destroy(gpr_mu* mu) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_mutex_destroy(&mu->mutex) == 0); + CHECK_EQ(pthread_mutex_destroy(&mu->mutex), 0); free(mu->leak_checker); #else - GPR_ASSERT(pthread_mutex_destroy(mu) == 0); + CHECK_EQ(pthread_mutex_destroy(mu), 0); #endif } void gpr_mu_lock(gpr_mu* mu) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_mutex_lock(&mu->mutex) == 0); + CHECK_EQ(pthread_mutex_lock(&mu->mutex), 0); #else - GPR_ASSERT(pthread_mutex_lock(mu) == 0); + CHECK_EQ(pthread_mutex_lock(mu), 0); #endif } void gpr_mu_unlock(gpr_mu* mu) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_mutex_unlock(&mu->mutex) == 0); + CHECK_EQ(pthread_mutex_unlock(&mu->mutex), 0); #else - GPR_ASSERT(pthread_mutex_unlock(mu) == 0); + CHECK_EQ(pthread_mutex_unlock(mu), 0); #endif } @@ -73,7 +75,7 @@ int gpr_mu_trylock(gpr_mu* mu) { #else err = pthread_mutex_trylock(mu); #endif - GPR_ASSERT(err == 0 || err == EBUSY); + CHECK(err == 0 || err == EBUSY); return err == 0; } @@ -81,26 +83,26 @@ int gpr_mu_trylock(gpr_mu* mu) { void gpr_cv_init(gpr_cv* cv) { pthread_condattr_t attr; - GPR_ASSERT(pthread_condattr_init(&attr) == 0); + CHECK_EQ(pthread_condattr_init(&attr), 0); #if GPR_LINUX - GPR_ASSERT(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0); + CHECK_EQ(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC), 0); #endif // GPR_LINUX #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_cond_init(&cv->cond_var, &attr) == 0); + CHECK_EQ(pthread_cond_init(&cv->cond_var, &attr), 0); cv->leak_checker = static_cast(malloc(sizeof(*cv->leak_checker))); - GPR_ASSERT(cv->leak_checker != nullptr); + CHECK_NE(cv->leak_checker, nullptr); #else - GPR_ASSERT(pthread_cond_init(cv, &attr) == 0); + CHECK_EQ(pthread_cond_init(cv, &attr), 0); #endif } void gpr_cv_destroy(gpr_cv* cv) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_cond_destroy(&cv->cond_var) == 0); + CHECK_EQ(pthread_cond_destroy(&cv->cond_var), 0); free(cv->leak_checker); #else - GPR_ASSERT(pthread_cond_destroy(cv) == 0); + CHECK_EQ(pthread_cond_destroy(cv), 0); #endif } @@ -129,30 +131,30 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) { err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); #endif } - GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN); + CHECK(err == 0 || err == ETIMEDOUT || err == EAGAIN); return err == ETIMEDOUT; } void gpr_cv_signal(gpr_cv* cv) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_cond_signal(&cv->cond_var) == 0); + CHECK_EQ(pthread_cond_signal(&cv->cond_var), 0); #else - GPR_ASSERT(pthread_cond_signal(cv) == 0); + CHECK_EQ(pthread_cond_signal(cv), 0); #endif } void gpr_cv_broadcast(gpr_cv* cv) { #ifdef GRPC_ASAN_ENABLED - GPR_ASSERT(pthread_cond_broadcast(&cv->cond_var) == 0); + CHECK_EQ(pthread_cond_broadcast(&cv->cond_var), 0); #else - GPR_ASSERT(pthread_cond_broadcast(cv) == 0); + CHECK_EQ(pthread_cond_broadcast(cv), 0); #endif } //---------------------------------------- void gpr_once_init(gpr_once* once, void (*init_function)(void)) { - GPR_ASSERT(pthread_once(once, init_function) == 0); + CHECK_EQ(pthread_once(once, init_function), 0); } #endif // defined(GPR_POSIX_SYNC) && !defined(GPR_ABSEIL_SYNC) && diff --git a/src/core/lib/gpr/posix/time.cc b/src/core/lib/gpr/posix/time.cc index 050cbf87dbc..f292198fede 100644 --- a/src/core/lib/gpr/posix/time.cc +++ b/src/core/lib/gpr/posix/time.cc @@ -28,6 +28,8 @@ #ifdef __linux__ #include #endif +#include "absl/log/check.h" + #include #include #include @@ -38,7 +40,8 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) { struct timespec rv; if (sizeof(time_t) < sizeof(int64_t)) { // fine to assert, as this is only used in gpr_sleep_until - GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN); + CHECK(gts.tv_sec <= INT32_MAX); + CHECK(gts.tv_sec >= INT32_MIN); } rv.tv_sec = static_cast(gts.tv_sec); rv.tv_nsec = gts.tv_nsec; @@ -67,7 +70,7 @@ void gpr_time_init(void) { gpr_precise_clock_init(); } static gpr_timespec now_impl(gpr_clock_type clock_type) { struct timespec now; - GPR_ASSERT(clock_type != GPR_TIMESPAN); + CHECK(clock_type != GPR_TIMESPAN); if (clock_type == GPR_CLOCK_PRECISE) { gpr_timespec ret; gpr_precise_clock_now(&ret); @@ -87,12 +90,12 @@ gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl; gpr_timespec gpr_now(gpr_clock_type clock_type) { // validate clock type - GPR_ASSERT(clock_type == GPR_CLOCK_MONOTONIC || - clock_type == GPR_CLOCK_REALTIME || - clock_type == GPR_CLOCK_PRECISE); + CHECK(clock_type == GPR_CLOCK_MONOTONIC || clock_type == GPR_CLOCK_REALTIME || + clock_type == GPR_CLOCK_PRECISE); gpr_timespec ts = gpr_now_impl(clock_type); // tv_nsecs must be in the range [0, 1e9). - GPR_ASSERT(ts.tv_nsec >= 0 && ts.tv_nsec < 1e9); + CHECK(ts.tv_nsec >= 0); + CHECK(ts.tv_nsec < 1e9); return ts; } diff --git a/src/core/lib/gpr/posix/tmpfile.cc b/src/core/lib/gpr/posix/tmpfile.cc index 4d838af72bc..cbc2b4cf3d8 100644 --- a/src/core/lib/gpr/posix/tmpfile.cc +++ b/src/core/lib/gpr/posix/tmpfile.cc @@ -25,6 +25,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -42,7 +44,7 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { if (tmp_filename != nullptr) *tmp_filename = nullptr; gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix); - GPR_ASSERT(filename_template != nullptr); + CHECK_NE(filename_template, nullptr); fd = mkstemp(filename_template); if (fd == -1) { diff --git a/src/core/lib/gpr/subprocess_posix.cc b/src/core/lib/gpr/subprocess_posix.cc index 5444bd82201..5dc73a3fac5 100644 --- a/src/core/lib/gpr/subprocess_posix.cc +++ b/src/core/lib/gpr/subprocess_posix.cc @@ -28,6 +28,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/substitute.h" #include @@ -81,8 +82,8 @@ gpr_subprocess* gpr_subprocess_create_with_envp(int argc, const char** argv, int stdout_pipe[2]; int p0 = pipe(stdin_pipe); int p1 = pipe(stdout_pipe); - GPR_ASSERT(p0 != -1); - GPR_ASSERT(p1 != -1); + CHECK_NE(p0, -1); + CHECK_NE(p1, -1); pid = fork(); if (pid == -1) { return nullptr; @@ -145,7 +146,7 @@ bool gpr_subprocess_communicate(gpr_subprocess* p, std::string& input_data, continue; } else { std::cerr << "select: " << strerror(errno) << std::endl; - GPR_ASSERT(0); + CHECK(0); } } @@ -192,7 +193,7 @@ bool gpr_subprocess_communicate(gpr_subprocess* p, std::string& input_data, while (waitpid(p->pid, &status, 0) == -1) { if (errno != EINTR) { std::cerr << "waitpid: " << strerror(errno) << std::endl; - GPR_ASSERT(0); + CHECK(0); } } diff --git a/src/core/lib/gpr/sync.cc b/src/core/lib/gpr/sync.cc index 446fe523751..b70435a992b 100644 --- a/src/core/lib/gpr/sync.cc +++ b/src/core/lib/gpr/sync.cc @@ -22,6 +22,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -59,11 +61,11 @@ void gpr_event_init(gpr_event* ev) { void gpr_event_set(gpr_event* ev, void* value) { struct sync_array_s* s = hash(ev); gpr_mu_lock(&s->mu); - GPR_ASSERT(gpr_atm_acq_load(&ev->state) == 0); + CHECK_EQ(gpr_atm_acq_load(&ev->state), 0); gpr_atm_rel_store(&ev->state, (gpr_atm)value); gpr_cv_broadcast(&s->cv); gpr_mu_unlock(&s->mu); - GPR_ASSERT(value != nullptr); + CHECK_NE(value, nullptr); } void* gpr_event_get(gpr_event* ev) { @@ -102,7 +104,7 @@ void gpr_refn(gpr_refcount* r, int n) { int gpr_unref(gpr_refcount* r) { gpr_atm prior = gpr_atm_full_fetch_add(&r->count, -1); - GPR_ASSERT(prior > 0); + CHECK_GT(prior, 0); return prior == 1; } diff --git a/src/core/lib/gpr/time.cc b/src/core/lib/gpr/time.cc index 472cd204e11..a46e95ef352 100644 --- a/src/core/lib/gpr/time.cc +++ b/src/core/lib/gpr/time.cc @@ -24,6 +24,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -31,7 +33,7 @@ int gpr_time_cmp(gpr_timespec a, gpr_timespec b) { int cmp = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec); - GPR_ASSERT(a.clock_type == b.clock_type); + CHECK(a.clock_type == b.clock_type); if (cmp == 0 && a.tv_sec != INT64_MAX && a.tv_sec != INT64_MIN) { cmp = (a.tv_nsec > b.tv_nsec) - (a.tv_nsec < b.tv_nsec); } @@ -79,7 +81,7 @@ static gpr_timespec to_seconds_from_sub_second_time(int64_t time_in_units, } else if (time_in_units == INT64_MIN) { out = gpr_inf_past(type); } else { - GPR_DEBUG_ASSERT(GPR_NS_PER_SEC % units_per_sec == 0); + DCHECK_EQ(GPR_NS_PER_SEC % units_per_sec, 0); out.tv_sec = time_in_units / units_per_sec; out.tv_nsec = @@ -139,11 +141,11 @@ gpr_timespec gpr_time_from_hours(int64_t h, gpr_clock_type clock_type) { gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) { gpr_timespec sum; int64_t inc = 0; - GPR_ASSERT(b.clock_type == GPR_TIMESPAN); + CHECK(b.clock_type == GPR_TIMESPAN); // tv_nsec in a timespan is always +ve. -ve timespan is represented as (-ve // tv_sec, +ve tv_nsec). For example, timespan = -2.5 seconds is represented // as {-3, 5e8, GPR_TIMESPAN} - GPR_ASSERT(b.tv_nsec >= 0); + CHECK_GE(b.tv_nsec, 0); sum.clock_type = a.clock_type; sum.tv_nsec = a.tv_nsec + b.tv_nsec; if (sum.tv_nsec >= GPR_NS_PER_SEC) { @@ -177,9 +179,9 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) { // tv_nsec in a timespan is always +ve. -ve timespan is represented as (-ve // tv_sec, +ve tv_nsec). For example, timespan = -2.5 seconds is represented // as {-3, 5e8, GPR_TIMESPAN} - GPR_ASSERT(b.tv_nsec >= 0); + CHECK_GE(b.tv_nsec, 0); } else { - GPR_ASSERT(a.clock_type == b.clock_type); + CHECK(a.clock_type == b.clock_type); diff.clock_type = GPR_TIMESPAN; } diff.tv_nsec = a.tv_nsec - b.tv_nsec; @@ -210,8 +212,8 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) { int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { int cmp_ab; - GPR_ASSERT(a.clock_type == b.clock_type); - GPR_ASSERT(threshold.clock_type == GPR_TIMESPAN); + CHECK(a.clock_type == b.clock_type); + CHECK(threshold.clock_type == GPR_TIMESPAN); cmp_ab = gpr_time_cmp(a, b); if (cmp_ab == 0) return 1; diff --git a/src/core/lib/gpr/windows/sync.cc b/src/core/lib/gpr/windows/sync.cc index 2fb6748f89b..800188bf29d 100644 --- a/src/core/lib/gpr/windows/sync.cc +++ b/src/core/lib/gpr/windows/sync.cc @@ -23,6 +23,8 @@ #if defined(GPR_WINDOWS) && !defined(GPR_ABSEIL_SYNC) && \ !defined(GPR_CUSTOM_SYNC) +#include "absl/log/check.h" + #include #include #include @@ -38,7 +40,7 @@ void gpr_mu_destroy(gpr_mu* mu) { DeleteCriticalSection(&mu->cs); } void gpr_mu_lock(gpr_mu* mu) { EnterCriticalSection(&mu->cs); - GPR_ASSERT(!mu->locked); + CHECK(!mu->locked); mu->locked = 1; } diff --git a/src/core/lib/gpr/windows/time.cc b/src/core/lib/gpr/windows/time.cc index 52b23c421d8..0aafa4a5959 100644 --- a/src/core/lib/gpr/windows/time.cc +++ b/src/core/lib/gpr/windows/time.cc @@ -26,6 +26,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -97,7 +99,8 @@ void gpr_sleep_until(gpr_timespec until) { delta = gpr_time_sub(until, now); sleep_millis = delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; - GPR_ASSERT((sleep_millis >= 0) && (sleep_millis <= INT_MAX)); + CHECK_GE(sleep_millis, 0); + CHECK_LE(sleep_millis, INT_MAX); Sleep((DWORD)sleep_millis); } } diff --git a/src/core/lib/gprpp/chunked_vector.h b/src/core/lib/gprpp/chunked_vector.h index 9eecf13fd29..b60bdac65ad 100644 --- a/src/core/lib/gprpp/chunked_vector.h +++ b/src/core/lib/gprpp/chunked_vector.h @@ -19,6 +19,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -86,9 +88,9 @@ class ChunkedVector { // Remove the last element and return it. T PopBack() { - GPR_ASSERT(append_ != nullptr); + CHECK_NE(append_, nullptr); if (append_->count == 0) { - GPR_ASSERT(first_ != append_); + CHECK(first_ != append_); Chunk* chunk = first_; while (chunk->next != append_) { chunk = chunk->next; @@ -234,7 +236,7 @@ class ChunkedVector { private: ManualConstructor* AppendSlot() { if (append_ == nullptr) { - GPR_ASSERT(first_ == nullptr); + CHECK_EQ(first_, nullptr); first_ = arena_->New(); append_ = first_; } else if (append_->count == kChunkSize) { diff --git a/src/core/lib/gprpp/down_cast.h b/src/core/lib/gprpp/down_cast.h index 56e31f387b7..ca1b2d78029 100644 --- a/src/core/lib/gprpp/down_cast.h +++ b/src/core/lib/gprpp/down_cast.h @@ -18,6 +18,7 @@ #include #include "absl/base/config.h" +#include "absl/log/check.h" #include #include @@ -32,7 +33,7 @@ inline To DownCast(From* f) { // If we have RTTI & we're in debug, assert that the cast is legal. #if ABSL_INTERNAL_HAS_RTTI #ifndef NDEBUG - if (f != nullptr) GPR_ASSERT(dynamic_cast(f) != nullptr); + if (f != nullptr) CHECK_NE(dynamic_cast(f), nullptr); #endif #endif return static_cast(f); diff --git a/src/core/lib/gprpp/dual_ref_counted.h b/src/core/lib/gprpp/dual_ref_counted.h index f9016269e2a..5641b0970d4 100644 --- a/src/core/lib/gprpp/dual_ref_counted.h +++ b/src/core/lib/gprpp/dual_ref_counted.h @@ -20,6 +20,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -92,7 +94,7 @@ class DualRefCounted { gpr_log(GPR_INFO, "%s:%p unref %d -> %d, weak_ref %d -> %d", trace_, this, strong_refs, strong_refs - 1, weak_refs, weak_refs + 1); } - GPR_ASSERT(strong_refs > 0); + CHECK_GT(strong_refs, 0u); #endif if (GPR_UNLIKELY(strong_refs == 1)) { Orphaned(); @@ -111,7 +113,7 @@ class DualRefCounted { trace_, this, location.file(), location.line(), strong_refs, strong_refs - 1, weak_refs, weak_refs + 1, reason); } - GPR_ASSERT(strong_refs > 0); + CHECK_GT(strong_refs, 0u); #else // Avoid unused-parameter warnings for debug-only parameters (void)location; @@ -210,7 +212,7 @@ class DualRefCounted { gpr_log(GPR_INFO, "%s:%p weak_unref %d -> %d (refs=%d)", trace, this, weak_refs, weak_refs - 1, strong_refs); } - GPR_ASSERT(weak_refs > 0); + CHECK_GT(weak_refs, 0u); #endif if (GPR_UNLIKELY(prev_ref_pair == MakeRefPair(0, 1))) { delete static_cast(this); @@ -233,7 +235,7 @@ class DualRefCounted { this, location.file(), location.line(), weak_refs, weak_refs - 1, strong_refs, reason); } - GPR_ASSERT(weak_refs > 0); + CHECK_GT(weak_refs, 0u); #else // Avoid unused-parameter warnings for debug-only parameters (void)location; @@ -289,7 +291,7 @@ class DualRefCounted { refs_.fetch_add(MakeRefPair(1, 0), std::memory_order_relaxed); const uint32_t strong_refs = GetStrongRefs(prev_ref_pair); const uint32_t weak_refs = GetWeakRefs(prev_ref_pair); - GPR_ASSERT(strong_refs != 0); + CHECK_NE(strong_refs, 0u); if (trace_ != nullptr) { gpr_log(GPR_INFO, "%s:%p ref %d -> %d; (weak_refs=%d)", trace_, this, strong_refs, strong_refs + 1, weak_refs); @@ -304,7 +306,7 @@ class DualRefCounted { refs_.fetch_add(MakeRefPair(1, 0), std::memory_order_relaxed); const uint32_t strong_refs = GetStrongRefs(prev_ref_pair); const uint32_t weak_refs = GetWeakRefs(prev_ref_pair); - GPR_ASSERT(strong_refs != 0); + CHECK_NE(strong_refs, 0u); if (trace_ != nullptr) { gpr_log(GPR_INFO, "%s:%p %s:%d ref %d -> %d (weak_refs=%d) %s", trace_, this, location.file(), location.line(), strong_refs, diff --git a/src/core/lib/gprpp/host_port.cc b/src/core/lib/gprpp/host_port.cc index 0805a25aeb5..7e5ae646ca7 100644 --- a/src/core/lib/gprpp/host_port.cc +++ b/src/core/lib/gprpp/host_port.cc @@ -20,6 +20,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" @@ -92,8 +93,10 @@ bool SplitHostPort(absl::string_view name, absl::string_view* host, bool SplitHostPort(absl::string_view name, std::string* host, std::string* port) { - GPR_DEBUG_ASSERT(host != nullptr && host->empty()); - GPR_DEBUG_ASSERT(port != nullptr && port->empty()); + DCHECK(host != nullptr); + DCHECK(host->empty()); + DCHECK(port != nullptr); + DCHECK(port->empty()); absl::string_view host_view; absl::string_view port_view; bool has_port; diff --git a/src/core/lib/gprpp/mpscq.h b/src/core/lib/gprpp/mpscq.h index bb19073c98f..c33d34ffa13 100644 --- a/src/core/lib/gprpp/mpscq.h +++ b/src/core/lib/gprpp/mpscq.h @@ -21,6 +21,8 @@ #include +#include "absl/log/check.h" + #include #include @@ -40,8 +42,8 @@ class MultiProducerSingleConsumerQueue { MultiProducerSingleConsumerQueue() : head_{&stub_}, tail_(&stub_) {} ~MultiProducerSingleConsumerQueue() { - GPR_ASSERT(head_.load(std::memory_order_relaxed) == &stub_); - GPR_ASSERT(tail_ == &stub_); + CHECK(head_.load(std::memory_order_relaxed) == &stub_); + CHECK(tail_ == &stub_); } // Push a node diff --git a/src/core/lib/gprpp/posix/stat.cc b/src/core/lib/gprpp/posix/stat.cc index 58f9f2e8ad4..f46741af5c9 100644 --- a/src/core/lib/gprpp/posix/stat.cc +++ b/src/core/lib/gprpp/posix/stat.cc @@ -27,6 +27,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/lib/gprpp/stat.h" @@ -35,8 +37,8 @@ namespace grpc_core { absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) { - GPR_ASSERT(filename != nullptr); - GPR_ASSERT(timestamp != nullptr); + CHECK_NE(filename, nullptr); + CHECK_NE(timestamp, nullptr); struct stat buf; if (stat(filename, &buf) != 0) { std::string error_msg = StrError(errno); diff --git a/src/core/lib/gprpp/posix/thd.cc b/src/core/lib/gprpp/posix/thd.cc index b599ca20f7f..be3f8224ea0 100644 --- a/src/core/lib/gprpp/posix/thd.cc +++ b/src/core/lib/gprpp/posix/thd.cc @@ -32,6 +32,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -88,7 +90,7 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { // don't use gpr_malloc as we may cause an infinite recursion with // the profiling code thd_arg* info = static_cast(malloc(sizeof(*info))); - GPR_ASSERT(info != nullptr); + CHECK_NE(info, nullptr); info->thread = this; info->body = thd_body; info->arg = arg; @@ -99,18 +101,16 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { Fork::IncThreadCount(); } - GPR_ASSERT(pthread_attr_init(&attr) == 0); + CHECK_EQ(pthread_attr_init(&attr), 0); if (options.joinable()) { - GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == - 0); + CHECK(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == 0); } else { - GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == - 0); + CHECK(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); } if (options.stack_size() != 0) { size_t stack_size = MinValidStackSize(options.stack_size()); - GPR_ASSERT(pthread_attr_setstacksize(&attr, stack_size) == 0); + CHECK_EQ(pthread_attr_setstacksize(&attr, stack_size), 0); } int pthread_create_err = pthread_create( @@ -154,7 +154,7 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface { info); *success = (pthread_create_err == 0); - GPR_ASSERT(pthread_attr_destroy(&attr) == 0); + CHECK_EQ(pthread_attr_destroy(&attr), 0); if (!(*success)) { gpr_log(GPR_ERROR, "pthread_create failed: %s", diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index 8076690dcec..7d9f8c4d11d 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -23,6 +23,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -164,7 +166,7 @@ class RefCount { gpr_log(GPR_INFO, "%s:%p unref %" PRIdPTR " -> %" PRIdPTR, trace, this, prior, prior - 1); } - GPR_DEBUG_ASSERT(prior > 0); + DCHECK_GT(prior, 0); #endif return prior == 1; } @@ -182,7 +184,7 @@ class RefCount { trace, this, location.file(), location.line(), prior, prior - 1, reason); } - GPR_DEBUG_ASSERT(prior > 0); + DCHECK_GT(prior, 0); #else // Avoid unused-parameter warnings for debug-only parameters (void)location; diff --git a/src/core/lib/gprpp/single_set_ptr.h b/src/core/lib/gprpp/single_set_ptr.h index b4839df8096..369e777bd23 100644 --- a/src/core/lib/gprpp/single_set_ptr.h +++ b/src/core/lib/gprpp/single_set_ptr.h @@ -18,6 +18,8 @@ #include #include +#include "absl/log/check.h" + #include #include @@ -67,7 +69,7 @@ class SingleSetPtr { T* operator->() const { T* p = p_.load(std::memory_order_acquire); - GPR_DEBUG_ASSERT(p != nullptr); + DCHECK_NE(p, nullptr); return p; } diff --git a/src/core/lib/gprpp/status_helper.cc b/src/core/lib/gprpp/status_helper.cc index 44f373dbf26..fe76efb87a3 100644 --- a/src/core/lib/gprpp/status_helper.cc +++ b/src/core/lib/gprpp/status_helper.cc @@ -22,6 +22,7 @@ #include +#include "absl/log/check.h" #include "absl/strings/cord.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" @@ -153,7 +154,7 @@ std::vector ParseChildren(absl::Cord children) { while (buf.size() - cur >= sizeof(uint32_t)) { size_t msg_size = DecodeUInt32FromBytes(buf.data() + cur); cur += sizeof(uint32_t); - GPR_ASSERT(buf.size() - cur >= msg_size); + CHECK(buf.size() - cur >= msg_size); google_rpc_Status* msg = google_rpc_Status_parse(buf.data() + cur, msg_size, arena.ptr()); cur += msg_size; diff --git a/src/core/lib/gprpp/sync.h b/src/core/lib/gprpp/sync.h index 76198091731..16efe619cd5 100644 --- a/src/core/lib/gprpp/sync.h +++ b/src/core/lib/gprpp/sync.h @@ -20,6 +20,7 @@ #define GRPC_SRC_CORE_LIB_GPRPP_SYNC_H #include "absl/base/thread_annotations.h" +#include "absl/log/check.h" #include "absl/synchronization/mutex.h" #include @@ -112,7 +113,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock { ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete; void Release() ABSL_UNLOCK_FUNCTION() { - GPR_DEBUG_ASSERT(!released_); + DCHECK(!released_); released_ = true; mu_->Unlock(); } @@ -178,13 +179,13 @@ class ABSL_SCOPED_LOCKABLE LockableAndReleasableMutexLock { const LockableAndReleasableMutexLock&) = delete; void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION() { - GPR_DEBUG_ASSERT(released_); + DCHECK(released_); mu_->Lock(); released_ = false; } void Release() ABSL_UNLOCK_FUNCTION() { - GPR_DEBUG_ASSERT(!released_); + DCHECK(!released_); released_ = true; mu_->Unlock(); } diff --git a/src/core/lib/gprpp/thd.h b/src/core/lib/gprpp/thd.h index 827db3891b9..44ff3b22e3c 100644 --- a/src/core/lib/gprpp/thd.h +++ b/src/core/lib/gprpp/thd.h @@ -27,6 +27,7 @@ #include #include "absl/functional/any_invocable.h" +#include "absl/log/check.h" #include #include @@ -124,7 +125,7 @@ class Thread { Thread& operator=(Thread&& other) noexcept { if (this != &other) { // TODO(vjpai): if we can be sure that all Thread's are actually - // constructed, then we should assert GPR_ASSERT(impl_ == nullptr) here. + // constructed, then we should assert CHECK(impl_ == nullptr) here. // However, as long as threads come in structures that are // allocated via gpr_malloc, this will not be the case, so we cannot // assert it for the time being. @@ -143,11 +144,11 @@ class Thread { /// the Join function kills it, or it was detached (non-joinable) and it has /// run to completion and is now killing itself. The destructor shouldn't have /// to do anything. - ~Thread() { GPR_ASSERT(!options_.joinable() || impl_ == nullptr); } + ~Thread() { CHECK(!options_.joinable() || impl_ == nullptr); } void Start() { if (impl_ != nullptr) { - GPR_ASSERT(state_ == ALIVE); + CHECK(state_ == ALIVE); state_ = STARTED; impl_->Start(); // If the Thread is not joinable, then the impl_ will cause the deletion @@ -156,7 +157,7 @@ class Thread { // no need to change the value of the impl_ or state_ . The next operation // on this object will be the deletion, which will trigger the destructor. } else { - GPR_ASSERT(state_ == FAILED); + CHECK(state_ == FAILED); } } @@ -168,7 +169,7 @@ class Thread { state_ = DONE; impl_ = nullptr; } else { - GPR_ASSERT(state_ == FAILED); + CHECK(state_ == FAILED); } } diff --git a/src/core/lib/gprpp/time.cc b/src/core/lib/gprpp/time.cc index 58e0a56d1e3..02240710a54 100644 --- a/src/core/lib/gprpp/time.cc +++ b/src/core/lib/gprpp/time.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/log/check.h" #include "absl/strings/str_format.h" #include @@ -66,13 +67,13 @@ GPR_ATTRIBUTE_NOINLINE std::pair InitTime() { } // Check time has increased past 1 second. - GPR_ASSERT(process_epoch_seconds > 1); + CHECK_GT(process_epoch_seconds, 1); // Fake the epoch to always return >=1 second from our monotonic clock (to // avoid bugs elsewhere) process_epoch_seconds -= 1; int64_t expected = 0; gpr_cycle_counter process_epoch_cycles = (cycles_start + cycles_end) / 2; - GPR_ASSERT(process_epoch_cycles != 0); + CHECK_NE(process_epoch_cycles, 0); if (!g_process_epoch_seconds.compare_exchange_strong( expected, process_epoch_seconds, std::memory_order_relaxed, std::memory_order_relaxed)) { @@ -119,7 +120,7 @@ gpr_timespec MillisecondsAsTimespec(int64_t millis, gpr_clock_type clock_type) { } int64_t TimespanToMillisRoundUp(gpr_timespec ts) { - GPR_ASSERT(ts.clock_type == GPR_TIMESPAN); + CHECK(ts.clock_type == GPR_TIMESPAN); double x = GPR_MS_PER_SEC * static_cast(ts.tv_sec) + static_cast(ts.tv_nsec) / GPR_NS_PER_MS + static_cast(GPR_NS_PER_SEC - 1) / @@ -134,7 +135,7 @@ int64_t TimespanToMillisRoundUp(gpr_timespec ts) { } int64_t TimespanToMillisRoundDown(gpr_timespec ts) { - GPR_ASSERT(ts.clock_type == GPR_TIMESPAN); + CHECK(ts.clock_type == GPR_TIMESPAN); double x = GPR_MS_PER_SEC * static_cast(ts.tv_sec) + static_cast(ts.tv_nsec) / GPR_NS_PER_MS; if (x <= static_cast(std::numeric_limits::min())) { diff --git a/src/core/lib/gprpp/time_util.cc b/src/core/lib/gprpp/time_util.cc index 6c44608945c..3a1cd376370 100644 --- a/src/core/lib/gprpp/time_util.cc +++ b/src/core/lib/gprpp/time_util.cc @@ -19,6 +19,8 @@ #include #include +#include "absl/log/check.h" + #include #include #include @@ -54,7 +56,7 @@ gpr_timespec ToGprTimeSpec(absl::Time time) { } absl::Duration ToAbslDuration(gpr_timespec ts) { - GPR_ASSERT(ts.clock_type == GPR_TIMESPAN); + CHECK(ts.clock_type == GPR_TIMESPAN); if (gpr_time_cmp(ts, gpr_inf_future(GPR_TIMESPAN)) == 0) { return absl::InfiniteDuration(); } else if (gpr_time_cmp(ts, gpr_inf_past(GPR_TIMESPAN)) == 0) { @@ -65,7 +67,7 @@ absl::Duration ToAbslDuration(gpr_timespec ts) { } absl::Time ToAbslTime(gpr_timespec ts) { - GPR_ASSERT(ts.clock_type != GPR_TIMESPAN); + CHECK(ts.clock_type != GPR_TIMESPAN); gpr_timespec rts = gpr_convert_clock_type(ts, GPR_CLOCK_REALTIME); if (gpr_time_cmp(rts, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { return absl::InfiniteFuture(); diff --git a/src/core/lib/gprpp/windows/stat.cc b/src/core/lib/gprpp/windows/stat.cc index 20fc4335566..3d2d42f814b 100644 --- a/src/core/lib/gprpp/windows/stat.cc +++ b/src/core/lib/gprpp/windows/stat.cc @@ -22,6 +22,8 @@ #include #include +#include "absl/log/check.h" + #include #include "src/core/lib/gprpp/crash.h" @@ -31,8 +33,8 @@ namespace grpc_core { absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) { - GPR_ASSERT(filename != nullptr); - GPR_ASSERT(timestamp != nullptr); + CHECK_NE(filename, nullptr); + CHECK_NE(timestamp, nullptr); struct _stat buf; if (_stat(filename, &buf) != 0) { std::string error_msg = StrError(errno); diff --git a/src/core/lib/gprpp/windows/thd.cc b/src/core/lib/gprpp/windows/thd.cc index ffabe3545fe..20a060f2b33 100644 --- a/src/core/lib/gprpp/windows/thd.cc +++ b/src/core/lib/gprpp/windows/thd.cc @@ -23,6 +23,8 @@ #include +#include "absl/log/check.h" + #include #include #include @@ -101,7 +103,7 @@ class ThreadInternalsWindows void Join() override { DWORD ret = WaitForSingleObject(info_->join_event, INFINITE); - GPR_ASSERT(ret == WAIT_OBJECT_0); + CHECK(ret == WAIT_OBJECT_0); destroy_thread(); } @@ -121,7 +123,7 @@ class ThreadInternalsWindows g_thd_info->body(g_thd_info->arg); if (g_thd_info->joinable) { BOOL ret = SetEvent(g_thd_info->join_event); - GPR_ASSERT(ret); + CHECK(ret); } else { gpr_free(g_thd_info); } diff --git a/src/core/lib/gprpp/work_serializer.cc b/src/core/lib/gprpp/work_serializer.cc index 27a2f84f13f..605877fddcd 100644 --- a/src/core/lib/gprpp/work_serializer.cc +++ b/src/core/lib/gprpp/work_serializer.cc @@ -27,6 +27,7 @@ #include #include "absl/container/inlined_vector.h" +#include "absl/log/check.h" #include #include @@ -107,7 +108,7 @@ class WorkSerializer::LegacyWorkSerializer final : public WorkSerializerImpl { // First 16 bits indicate ownership of the WorkSerializer, next 48 bits are // queue size (i.e., refs). static uint64_t MakeRefPair(uint16_t owners, uint64_t size) { - GPR_ASSERT(size >> 48 == 0); + CHECK_EQ(size >> 48, 0u); return (static_cast(owners) << 48) + static_cast(size); } static uint32_t GetOwners(uint64_t ref_pair) { @@ -145,7 +146,7 @@ void WorkSerializer::LegacyWorkSerializer::Run(std::function callback, const uint64_t prev_ref_pair = refs_.fetch_add(MakeRefPair(1, 1), std::memory_order_acq_rel); // The work serializer should not have been orphaned. - GPR_DEBUG_ASSERT(GetSize(prev_ref_pair) > 0); + DCHECK_GT(GetSize(prev_ref_pair), 0u); if (GetOwners(prev_ref_pair) == 0) { // We took ownership of the WorkSerializer. Invoke callback and drain queue. SetCurrentThread(); @@ -424,7 +425,7 @@ void WorkSerializer::DispatchingWorkSerializer::Run( running_start_time_ = std::chrono::steady_clock::now(); items_processed_during_run_ = 0; time_running_items_ = std::chrono::steady_clock::duration(); - GPR_ASSERT(processing_.empty()); + CHECK(processing_.empty()); processing_.emplace_back(std::move(callback), location); event_engine_->Run(this); } else { diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 2f0dce7ad62..9fb12f279e4 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -24,6 +24,7 @@ #include "absl/functional/any_invocable.h" #include "absl/functional/function_ref.h" +#include "absl/log/check.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -162,8 +163,8 @@ class Call : public CppImplOf, arena_(arena), send_deadline_(send_deadline), is_client_(is_client) { - GPR_DEBUG_ASSERT(arena_ != nullptr); - GPR_DEBUG_ASSERT(channel_ != nullptr); + DCHECK_NE(arena_, nullptr); + DCHECK(channel_ != nullptr); } ~Call() override = default; @@ -172,7 +173,7 @@ class Call : public CppImplOf, ParentCall* GetOrCreateParentCall(); ParentCall* parent_call(); Channel* channel() const { - GPR_DEBUG_ASSERT(channel_ != nullptr); + DCHECK(channel_ != nullptr); return channel_.get(); } diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 1915c957ad6..76b49f88be9 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -109,6 +109,7 @@ grpc_cc_library( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:log", ], language = "C++", deps = [ diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 6db13b25363..d6b2118fe25 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -27,6 +27,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/log/check.h" +#include "absl/log/log.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -205,11 +206,10 @@ bool InteropClient::AssertStatusCode(const Status& s, StatusCode expected_code, return true; } - gpr_log(GPR_ERROR, - "Error status code: %d (expected: %d), message: %s," - " debug string: %s", - s.error_code(), expected_code, s.error_message().c_str(), - optional_debug_string.c_str()); + LOG(ERROR) << "Error status code: " << s.error_code() + << " (expected: " << expected_code + << "), message: " << s.error_message() + << ", debug string: " << optional_debug_string; // In case of transient transient/retryable failures (like a broken // connection) we may or may not abort (see TransientFailureOrAbort()) @@ -221,7 +221,7 @@ bool InteropClient::AssertStatusCode(const Status& s, StatusCode expected_code, } bool InteropClient::DoEmpty() { - gpr_log(GPR_DEBUG, "Sending an empty rpc..."); + VLOG(2) << "Sending an empty rpc..."; Empty request; Empty response; @@ -233,7 +233,7 @@ bool InteropClient::DoEmpty() { return false; } - gpr_log(GPR_DEBUG, "Empty rpc done."); + VLOG(2) << "Empty rpc done."; return true; } @@ -273,8 +273,7 @@ bool InteropClient::PerformLargeUnary(SimpleRequest* request, bool InteropClient::DoComputeEngineCreds( const std::string& default_service_account, const std::string& oauth_scope) { - gpr_log(GPR_DEBUG, - "Sending a large unary rpc with compute engine credentials ..."); + VLOG(2) << "Sending a large unary rpc with compute engine credentials ..."; SimpleRequest request; SimpleResponse response; request.set_fill_username(true); @@ -284,21 +283,20 @@ bool InteropClient::DoComputeEngineCreds( return false; } - gpr_log(GPR_DEBUG, "Got username %s", response.username().c_str()); - gpr_log(GPR_DEBUG, "Got oauth_scope %s", response.oauth_scope().c_str()); + VLOG(2) << "Got username " << response.username(); + VLOG(2) << "Got oauth_scope " << response.oauth_scope(); CHECK(!response.username().empty()); CHECK(response.username() == default_service_account); CHECK(!response.oauth_scope().empty()); const char* oauth_scope_str = response.oauth_scope().c_str(); CHECK(absl::StrContains(oauth_scope, oauth_scope_str)); - gpr_log(GPR_DEBUG, "Large unary with compute engine creds done."); + VLOG(2) << "Large unary with compute engine creds done."; return true; } bool InteropClient::DoOauth2AuthToken(const std::string& username, const std::string& oauth_scope) { - gpr_log(GPR_DEBUG, - "Sending a unary rpc with raw oauth2 access token credentials ..."); + VLOG(2) << "Sending a unary rpc with raw oauth2 access token credentials ..."; SimpleRequest request; SimpleResponse response; request.set_fill_username(true); @@ -317,12 +315,12 @@ bool InteropClient::DoOauth2AuthToken(const std::string& username, CHECK(username == response.username()); const char* oauth_scope_str = response.oauth_scope().c_str(); CHECK(absl::StrContains(oauth_scope, oauth_scope_str)); - gpr_log(GPR_DEBUG, "Unary with oauth2 access token credentials done."); + VLOG(2) << "Unary with oauth2 access token credentials done."; return true; } bool InteropClient::DoPerRpcCreds(const std::string& json_key) { - gpr_log(GPR_DEBUG, "Sending a unary rpc with per-rpc JWT access token ..."); + VLOG(2) << "Sending a unary rpc with per-rpc JWT access token ..."; SimpleRequest request; SimpleResponse response; request.set_fill_username(true); @@ -342,13 +340,12 @@ bool InteropClient::DoPerRpcCreds(const std::string& json_key) { CHECK(!response.username().empty()); CHECK(json_key.find(response.username()) != std::string::npos); - gpr_log(GPR_DEBUG, "Unary with per-rpc JWT access token done."); + VLOG(2) << "Unary with per-rpc JWT access token done."; return true; } bool InteropClient::DoJwtTokenCreds(const std::string& username) { - gpr_log(GPR_DEBUG, - "Sending a large unary rpc with JWT token credentials ..."); + VLOG(2) << "Sending a large unary rpc with JWT token credentials ..."; SimpleRequest request; SimpleResponse response; request.set_fill_username(true); @@ -359,14 +356,13 @@ bool InteropClient::DoJwtTokenCreds(const std::string& username) { CHECK(!response.username().empty()); CHECK(username.find(response.username()) != std::string::npos); - gpr_log(GPR_DEBUG, "Large unary with JWT token creds done."); + VLOG(2) << "Large unary with JWT token creds done."; return true; } bool InteropClient::DoGoogleDefaultCredentials( const std::string& default_service_account) { - gpr_log(GPR_DEBUG, - "Sending a large unary rpc with GoogleDefaultCredentials..."); + VLOG(2) << "Sending a large unary rpc with GoogleDefaultCredentials..."; SimpleRequest request; SimpleResponse response; request.set_fill_username(true); @@ -375,21 +371,21 @@ bool InteropClient::DoGoogleDefaultCredentials( return false; } - gpr_log(GPR_DEBUG, "Got username %s", response.username().c_str()); + VLOG(2) << "Got username " << response.username(); CHECK(!response.username().empty()); CHECK(response.username() == default_service_account); - gpr_log(GPR_DEBUG, "Large unary rpc with GoogleDefaultCredentials done."); + VLOG(2) << "Large unary rpc with GoogleDefaultCredentials done."; return true; } bool InteropClient::DoLargeUnary() { - gpr_log(GPR_DEBUG, "Sending a large unary rpc..."); + VLOG(2) << "Sending a large unary rpc..."; SimpleRequest request; SimpleResponse response; if (!PerformLargeUnary(&request, &response)) { return false; } - gpr_log(GPR_DEBUG, "Large unary done."); + VLOG(2) << "Large unary done."; return true; } @@ -405,35 +401,32 @@ bool InteropClient::DoClientCompressedUnary() { probe_req.set_response_size(kLargeResponseSize); probe_req.mutable_payload()->set_body(std::string(kLargeRequestSize, '\0')); - gpr_log(GPR_DEBUG, "Sending probe for compressed unary request."); + VLOG(2) << "Sending probe for compressed unary request."; const Status s = serviceStub_.Get()->UnaryCall(&probe_context, probe_req, &probe_res); if (s.error_code() != grpc::StatusCode::INVALID_ARGUMENT) { // The server isn't able to evaluate incoming compression, making the rest // of this test moot. - gpr_log(GPR_DEBUG, "Compressed unary request probe failed"); + VLOG(2) << "Compressed unary request probe failed"; return false; } - gpr_log(GPR_DEBUG, "Compressed unary request probe succeeded. Proceeding."); + VLOG(2) << "Compressed unary request probe succeeded. Proceeding."; const std::vector compressions = {true, false}; for (size_t i = 0; i < compressions.size(); i++) { std::string log_suffix = absl::StrFormat("(compression=%s)", compressions[i] ? "true" : "false"); - gpr_log(GPR_DEBUG, "Sending compressed unary request %s.", - log_suffix.c_str()); + VLOG(2) << "Sending compressed unary request " << log_suffix; SimpleRequest request; SimpleResponse response; request.mutable_expect_compressed()->set_value(compressions[i]); if (!PerformLargeUnary(&request, &response, UnaryCompressionChecks)) { - gpr_log(GPR_ERROR, "Compressed unary request failed %s", - log_suffix.c_str()); + LOG(ERROR) << "Compressed unary request failed " << log_suffix; return false; } - gpr_log(GPR_DEBUG, "Compressed unary request failed %s", - log_suffix.c_str()); + VLOG(2) << "Compressed unary request failed " << log_suffix; } return true; @@ -445,20 +438,17 @@ bool InteropClient::DoServerCompressedUnary() { std::string log_suffix = absl::StrFormat("(compression=%s)", compressions[i] ? "true" : "false"); - gpr_log(GPR_DEBUG, "Sending unary request for compressed response %s.", - log_suffix.c_str()); + VLOG(2) << "Sending unary request for compressed response " << log_suffix; SimpleRequest request; SimpleResponse response; request.mutable_response_compressed()->set_value(compressions[i]); if (!PerformLargeUnary(&request, &response, UnaryCompressionChecks)) { - gpr_log(GPR_ERROR, "Request for compressed unary failed %s", - log_suffix.c_str()); + LOG(ERROR) << "Request for compressed unary failed " << log_suffix; return false; } - gpr_log(GPR_DEBUG, "Request for compressed unary failed %s", - log_suffix.c_str()); + VLOG(2) << "Request for compressed unary failed " << log_suffix; } return true; @@ -475,7 +465,7 @@ bool InteropClient::TransientFailureOrAbort() { } bool InteropClient::DoRequestStreaming() { - gpr_log(GPR_DEBUG, "Sending request steaming rpc ..."); + VLOG(2) << "Sending request steaming rpc ..."; ClientContext context; StreamingInputCallRequest request; @@ -489,7 +479,7 @@ bool InteropClient::DoRequestStreaming() { Payload* payload = request.mutable_payload(); payload->set_body(std::string(request_stream_sizes[i], '\0')); if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoRequestStreaming(): stream->Write() failed"); + LOG(ERROR) << "DoRequestStreaming(): stream->Write() failed."; return TransientFailureOrAbort(); } aggregated_payload_size += request_stream_sizes[i]; @@ -506,7 +496,7 @@ bool InteropClient::DoRequestStreaming() { } bool InteropClient::DoResponseStreaming() { - gpr_log(GPR_DEBUG, "Receiving response streaming rpc ..."); + VLOG(2) << "Receiving response streaming rpc ..."; ClientContext context; StreamingOutputCallRequest request; @@ -528,10 +518,9 @@ bool InteropClient::DoResponseStreaming() { if (i < response_stream_sizes.size()) { // stream->Read() failed before reading all the expected messages. This is // most likely due to connection failure. - gpr_log(GPR_ERROR, - "DoResponseStreaming(): Read fewer streams (%d) than " - "response_stream_sizes.size() (%" PRIuPTR ")", - i, response_stream_sizes.size()); + LOG(ERROR) << "DoResponseStreaming(): Read fewer streams (" << i + << ") than response_stream_sizes.size() (" + << response_stream_sizes.size() << ")"; return TransientFailureOrAbort(); } @@ -540,7 +529,7 @@ bool InteropClient::DoResponseStreaming() { return false; } - gpr_log(GPR_DEBUG, "Response streaming done."); + VLOG(2) << "Response streaming done."; return true; } @@ -554,24 +543,23 @@ bool InteropClient::DoClientCompressedStreaming() { probe_req.mutable_expect_compressed()->set_value(true); // lies! probe_req.mutable_payload()->set_body(std::string(27182, '\0')); - gpr_log(GPR_DEBUG, "Sending probe for compressed streaming request."); + VLOG(2) << "Sending probe for compressed streaming request."; std::unique_ptr> probe_stream( serviceStub_.Get()->StreamingInputCall(&probe_context, &probe_res)); if (!probe_stream->Write(probe_req)) { - gpr_log(GPR_ERROR, "%s(): stream->Write() failed", __func__); + LOG(ERROR) << __func__ << "(): stream->Write() failed"; return TransientFailureOrAbort(); } Status s = probe_stream->Finish(); if (s.error_code() != grpc::StatusCode::INVALID_ARGUMENT) { // The server isn't able to evaluate incoming compression, making the rest // of this test moot. - gpr_log(GPR_DEBUG, "Compressed streaming request probe failed"); + VLOG(2) << "Compressed streaming request probe failed"; return false; } - gpr_log(GPR_DEBUG, - "Compressed streaming request probe succeeded. Proceeding."); + VLOG(2) << "Compressed streaming request probe succeeded. Proceeding."; ClientContext context; StreamingInputCallRequest request; @@ -583,9 +571,9 @@ bool InteropClient::DoClientCompressedStreaming() { request.mutable_payload()->set_body(std::string(27182, '\0')); request.mutable_expect_compressed()->set_value(true); - gpr_log(GPR_DEBUG, "Sending streaming request with compression enabled"); + VLOG(2) << "Sending streaming request with compression enabled"; if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "%s(): stream->Write() failed", __func__); + LOG(ERROR) << __func__ << "(): stream->Write() failed."; return TransientFailureOrAbort(); } @@ -593,9 +581,9 @@ bool InteropClient::DoClientCompressedStreaming() { wopts.set_no_compression(); request.mutable_payload()->set_body(std::string(45904, '\0')); request.mutable_expect_compressed()->set_value(false); - gpr_log(GPR_DEBUG, "Sending streaming request with compression disabled"); + VLOG(2) << "Sending streaming request with compression disabled"; if (!stream->Write(request, wopts)) { - gpr_log(GPR_ERROR, "%s(): stream->Write() failed", __func__); + LOG(ERROR) << __func__ << "(): stream->Write() failed"; return TransientFailureOrAbort(); } CHECK(stream->WritesDone()); @@ -618,7 +606,7 @@ bool InteropClient::DoServerCompressedStreaming() { absl::StrFormat("(compression=%s; size=%d)", compressions[i] ? "true" : "false", sizes[i]); - gpr_log(GPR_DEBUG, "Sending request streaming rpc %s.", log_suffix.c_str()); + VLOG(2) << "Sending request streaming rpc " << log_suffix.c_str(); ResponseParameters* const response_parameter = request.add_response_parameters(); @@ -650,10 +638,9 @@ bool InteropClient::DoServerCompressedStreaming() { if (k < sizes.size()) { // stream->Read() failed before reading all the expected messages. This // is most likely due to a connection failure. - gpr_log(GPR_ERROR, - "%s(): Responses read (k=%" PRIuPTR - ") is less than the expected number of messages (%" PRIuPTR ").", - __func__, k, sizes.size()); + LOG(ERROR) << __func__ << "(): Responses read (k=" << k + << ") is less than the expected number of messages (" + << sizes.size() << ")."; return TransientFailureOrAbort(); } @@ -662,7 +649,7 @@ bool InteropClient::DoServerCompressedStreaming() { } bool InteropClient::DoResponseStreamingWithSlowConsumer() { - gpr_log(GPR_DEBUG, "Receiving response streaming rpc with slow consumer ..."); + VLOG(2) << "Receiving response streaming rpc with slow consumer ..."; ClientContext context; StreamingOutputCallRequest request; @@ -678,7 +665,7 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() { int i = 0; while (stream->Read(&response)) { CHECK(response.payload().body() == std::string(kResponseMessageSize, '\0')); - gpr_log(GPR_DEBUG, "received message %d", i); + VLOG(2) << "received message " << i; gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(kReceiveDelayMilliSeconds, GPR_TIMESPAN))); @@ -686,10 +673,11 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() { } if (i < kNumResponseMessages) { - gpr_log(GPR_ERROR, - "DoResponseStreamingWithSlowConsumer(): Responses read (i=%d) is " - "less than the expected messages (i.e kNumResponseMessages = %d)", - i, kNumResponseMessages); + LOG(ERROR) << "DoResponseStreamingWithSlowConsumer(): Responses read (i=" + << i + << ") is less than the expected messages (i.e " + "kNumResponseMessages = " + << kNumResponseMessages << ")."; return TransientFailureOrAbort(); } @@ -699,12 +687,12 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() { return false; } - gpr_log(GPR_DEBUG, "Response streaming done."); + VLOG(2) << "Response streaming done."; return true; } bool InteropClient::DoHalfDuplex() { - gpr_log(GPR_DEBUG, "Sending half-duplex streaming rpc ..."); + VLOG(2) << "Sending half-duplex streaming rpc ..."; ClientContext context; std::unique_ptrset_size(response_stream_sizes[i]); if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoHalfDuplex(): stream->Write() failed. i=%d", i); + LOG(ERROR) << "DoHalfDuplex(): stream->Write() failed. i=" << i; return TransientFailureOrAbort(); } } @@ -734,10 +722,10 @@ bool InteropClient::DoHalfDuplex() { if (i < response_stream_sizes.size()) { // stream->Read() failed before reading all the expected messages. This is // most likely due to a connection failure - gpr_log(GPR_ERROR, - "DoHalfDuplex(): Responses read (i=%d) are less than the expected " - "number of messages response_stream_sizes.size() (%" PRIuPTR ")", - i, response_stream_sizes.size()); + LOG(ERROR) << "DoHalfDuplex(): Responses read (i=" << i + << ") are less than the expected number of messages " + "response_stream_sizes.size() (" + << response_stream_sizes.size() << ")."; return TransientFailureOrAbort(); } @@ -746,12 +734,12 @@ bool InteropClient::DoHalfDuplex() { return false; } - gpr_log(GPR_DEBUG, "Half-duplex streaming rpc done."); + VLOG(2) << "Half-duplex streaming rpc done."; return true; } bool InteropClient::DoPingPong() { - gpr_log(GPR_DEBUG, "Sending Ping Pong streaming rpc ..."); + VLOG(2) << "Sending Ping Pong streaming rpc ..."; ClientContext context; std::unique_ptrset_body(std::string(request_stream_sizes[i], '\0')); if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoPingPong(): stream->Write() failed. i: %d", i); + LOG(ERROR) << "DoPingPong(): stream->Write() failed. i: " << i; return TransientFailureOrAbort(); } if (!stream->Read(&response)) { - gpr_log(GPR_ERROR, "DoPingPong(): stream->Read() failed. i:%d", i); + LOG(ERROR) << "DoPingPong(): stream->Read() failed. i:" << i; return TransientFailureOrAbort(); } @@ -790,12 +778,12 @@ bool InteropClient::DoPingPong() { return false; } - gpr_log(GPR_DEBUG, "Ping pong streaming done."); + VLOG(2) << "Ping pong streaming done."; return true; } bool InteropClient::DoCancelAfterBegin() { - gpr_log(GPR_DEBUG, "Sending request streaming rpc ..."); + VLOG(2) << "Sending request streaming rpc ..."; ClientContext context; StreamingInputCallRequest request; @@ -804,7 +792,7 @@ bool InteropClient::DoCancelAfterBegin() { std::unique_ptr> stream( serviceStub_.Get()->StreamingInputCall(&context, &response)); - gpr_log(GPR_DEBUG, "Trying to cancel..."); + VLOG(2) << "Trying to cancel..."; context.TryCancel(); Status s = stream->Finish(); @@ -813,12 +801,12 @@ bool InteropClient::DoCancelAfterBegin() { return false; } - gpr_log(GPR_DEBUG, "Canceling streaming done."); + VLOG(2) << "Canceling streaming done."; return true; } bool InteropClient::DoCancelAfterFirstResponse() { - gpr_log(GPR_DEBUG, "Sending Ping Pong streaming rpc ..."); + VLOG(2) << "Sending Ping Pong streaming rpc ..."; ClientContext context; std::unique_ptrWrite(request)) { - gpr_log(GPR_ERROR, "DoCancelAfterFirstResponse(): stream->Write() failed"); + LOG(ERROR) << "DoCancelAfterFirstResponse(): stream->Write() failed"; return TransientFailureOrAbort(); } if (!stream->Read(&response)) { - gpr_log(GPR_ERROR, "DoCancelAfterFirstResponse(): stream->Read failed"); + LOG(ERROR) << "DoCancelAfterFirstResponse(): stream->Read failed"; return TransientFailureOrAbort(); } CHECK(response.payload().body() == std::string(31415, '\0')); - gpr_log(GPR_DEBUG, "Trying to cancel..."); + VLOG(2) << "Trying to cancel..."; context.TryCancel(); Status s = stream->Finish(); - gpr_log(GPR_DEBUG, "Canceling pingpong streaming done."); + VLOG(2) << "Canceling pingpong streaming done."; return true; } bool InteropClient::DoTimeoutOnSleepingServer() { - gpr_log(GPR_DEBUG, - "Sending Ping Pong streaming rpc with a short deadline..."); + VLOG(2) << "Sending Ping Pong streaming rpc with a short deadline..."; ClientContext context; std::chrono::system_clock::time_point deadline = @@ -872,12 +859,12 @@ bool InteropClient::DoTimeoutOnSleepingServer() { return false; } - gpr_log(GPR_DEBUG, "Pingpong streaming timeout done."); + VLOG(2) << "Pingpong streaming timeout done."; return true; } bool InteropClient::DoEmptyStream() { - gpr_log(GPR_DEBUG, "Starting empty_stream."); + VLOG(2) << "Starting empty_stream."; ClientContext context; std::unique_ptrc_str()); } CHECK(!load_report_tracker_.GetNextLoadReport().has_value()); - gpr_log(GPR_DEBUG, "orca per rpc successfully finished"); + VLOG(2) << "orca per rpc successfully finished"; return true; } bool InteropClient::DoOrcaOob() { static constexpr auto kTimeout = absl::Seconds(10); - gpr_log(GPR_INFO, "testing orca oob"); + LOG(INFO) << "testing orca oob"; load_report_tracker_.ResetCollectedLoadReports(); // Make the backup poller poll very frequently in order to pick up // updates from all the subchannels's FDs. @@ -1047,11 +1032,11 @@ bool InteropClient::DoOrcaOob() { orca_report->mutable_utilization()->emplace("util", 0.30499); StreamingOutputCallResponse response; if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoOrcaOob(): stream->Write() failed"); + LOG(ERROR) << "DoOrcaOob(): stream->Write() failed"; return TransientFailureOrAbort(); } if (!stream->Read(&response)) { - gpr_log(GPR_ERROR, "DoOrcaOob(): stream->Read failed"); + LOG(ERROR) << "DoOrcaOob(): stream->Read failed"; return TransientFailureOrAbort(); } CHECK(load_report_tracker_ @@ -1059,8 +1044,7 @@ bool InteropClient::DoOrcaOob() { [orca_report](const auto& actual) { auto value = OrcaLoadReportsDiff(*orca_report, actual); if (value.has_value()) { - gpr_log(GPR_DEBUG, "Reports mismatch: %s", - value->c_str()); + VLOG(2) << "Reports mismatch: " << value->c_str(); return false; } return true; @@ -1077,11 +1061,11 @@ bool InteropClient::DoOrcaOob() { orca_report->mutable_utilization()->emplace("util", 0.2039); StreamingOutputCallResponse response; if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoOrcaOob(): stream->Write() failed"); + LOG(ERROR) << "DoOrcaOob(): stream->Write() failed"; return TransientFailureOrAbort(); } if (!stream->Read(&response)) { - gpr_log(GPR_ERROR, "DoOrcaOob(): stream->Read failed"); + LOG(ERROR) << "DoOrcaOob(): stream->Read failed"; return TransientFailureOrAbort(); } CHECK( @@ -1093,7 +1077,7 @@ bool InteropClient::DoOrcaOob() { kTimeout, 10) .has_value()); } - gpr_log(GPR_INFO, "orca oob successfully finished"); + LOG(INFO) << "orca oob successfully finished"; return true; } @@ -1105,7 +1089,7 @@ bool InteropClient::DoCustomMetadata() { const std::string kTrailingBinValue("\x0a\x0b\x0a\x0b\x0a\x0b"); { - gpr_log(GPR_DEBUG, "Sending RPC with custom metadata"); + VLOG(2) << "Sending RPC with custom metadata"; ClientContext context; context.AddMetadata(kEchoInitialMetadataKey, kInitialMetadataValue); context.AddMetadata(kEchoTrailingBinMetadataKey, kTrailingBinValue); @@ -1130,11 +1114,11 @@ bool InteropClient::DoCustomMetadata() { CHECK(std::string(iter->second.begin(), iter->second.end()) == kTrailingBinValue); - gpr_log(GPR_DEBUG, "Done testing RPC with custom metadata"); + VLOG(2) << "Done testing RPC with custom metadata"; } { - gpr_log(GPR_DEBUG, "Sending stream with custom metadata"); + VLOG(2) << "Sending stream with custom metadata"; ClientContext context; context.AddMetadata(kEchoInitialMetadataKey, kInitialMetadataValue); context.AddMetadata(kEchoTrailingBinMetadataKey, kTrailingBinValue); @@ -1150,14 +1134,14 @@ bool InteropClient::DoCustomMetadata() { StreamingOutputCallResponse response; if (!stream->Write(request)) { - gpr_log(GPR_ERROR, "DoCustomMetadata(): stream->Write() failed"); + LOG(ERROR) << "DoCustomMetadata(): stream->Write() failed"; return TransientFailureOrAbort(); } stream->WritesDone(); if (!stream->Read(&response)) { - gpr_log(GPR_ERROR, "DoCustomMetadata(): stream->Read() failed"); + LOG(ERROR) << "DoCustomMetadata(): stream->Read() failed"; return TransientFailureOrAbort(); } @@ -1180,7 +1164,7 @@ bool InteropClient::DoCustomMetadata() { CHECK(std::string(iter->second.begin(), iter->second.end()) == kTrailingBinValue); - gpr_log(GPR_DEBUG, "Done testing stream with custom metadata"); + VLOG(2) << "Done testing stream with custom metadata"; } return true; @@ -1254,17 +1238,14 @@ void InteropClient::PerformSoakTest( std::string peer = std::get<3>(result); results.push_back(result); if (!success) { - gpr_log(GPR_INFO, - "soak iteration: %d elapsed_ms: %d peer: %s server_uri: %s " - "failed: %s", - i, elapsed_ms, peer.c_str(), server_uri.c_str(), - debug_string.c_str()); + LOG(INFO) << "soak iteration: " << i << " elapsed_ms: " << elapsed_ms + << " peer: " << peer << " server_uri: " << server_uri + << " failed: " << debug_string; total_failures++; } else { - gpr_log( - GPR_INFO, - "soak iteration: %d elapsed_ms: %d peer: %s server_uri: %s succeeded", - i, elapsed_ms, peer.c_str(), server_uri.c_str()); + LOG(INFO) << "soak iteration: " << i << " elapsed_ms: " << elapsed_ms + << " peer: " << peer << " server_uri: " << server_uri + << " succeeded"; } grpc_histogram_add(latencies_ms_histogram, std::get<1>(result)); iterations_ran++; @@ -1277,48 +1258,40 @@ void InteropClient::PerformSoakTest( double latency_ms_worst = grpc_histogram_maximum(latencies_ms_histogram); grpc_histogram_destroy(latencies_ms_histogram); if (iterations_ran < soak_iterations) { - gpr_log( - GPR_ERROR, - "(server_uri: %s) soak test consumed all %d seconds of time and quit " - "early, only " - "having ran %d out of desired %d iterations. " - "total_failures: %d. " - "max_failures_threshold: %d. " - "median_soak_iteration_latency: %lf ms. " - "90th_soak_iteration_latency: %lf ms. " - "worst_soak_iteration_latency: %lf ms. " - "Some or all of the iterations that did run were unexpectedly slow. " - "See breakdown above for which iterations succeeded, failed, and " - "why for more info.", - server_uri.c_str(), overall_timeout_seconds, iterations_ran, - soak_iterations, total_failures, max_failures, latency_ms_median, - latency_ms_90th, latency_ms_worst); + LOG(ERROR) << "(server_uri: " << server_uri << ") soak test consumed all " + << overall_timeout_seconds + << " seconds of time and quit early, only having ran " + << iterations_ran << " out of desired " << soak_iterations + << " iterations. total_failures: " << total_failures + << ". max_failures_threshold: " << max_failures + << ". median_soak_iteration_latency: " << latency_ms_median + << " ms. 90th_soak_iteration_latency: " << latency_ms_90th + << " ms. worst_soak_iteration_latency: " << latency_ms_worst + << " ms. Some or all of the iterations that did run were " + "unexpectedly slow. See breakdown above for which iterations " + "succeeded, failed, and why for more info."; CHECK(0); } else if (total_failures > max_failures) { - gpr_log(GPR_ERROR, - "(server_uri: %s) soak test ran: %d iterations. total_failures: %d " - "exceeds " - "max_failures_threshold: %d. " - "median_soak_iteration_latency: %lf ms. " - "90th_soak_iteration_latency: %lf ms. " - "worst_soak_iteration_latency: %lf ms. " - "See breakdown above for which iterations succeeded, failed, and " - "why for more info.", - server_uri.c_str(), soak_iterations, total_failures, max_failures, - latency_ms_median, latency_ms_90th, latency_ms_worst); + LOG(ERROR) << "(server_uri: " << server_uri + << ") soak test ran: " << soak_iterations + << " iterations. total_failures: " << total_failures + << " exceeds max_failures_threshold: " << max_failures + << ". median_soak_iteration_latency: " << latency_ms_median + << " ms. 90th_soak_iteration_latency: " << latency_ms_90th + << " ms. worst_soak_iteration_latency: " << latency_ms_worst + << " ms. See breakdown above for which iterations succeeded, " + "failed, and why for more info."; CHECK(0); } else { - gpr_log(GPR_INFO, - "(server_uri: %s) soak test ran: %d iterations. total_failures: %d " - "is within " - "max_failures_threshold: %d. " - "median_soak_iteration_latency: %lf ms. " - "90th_soak_iteration_latency: %lf ms. " - "worst_soak_iteration_latency: %lf ms. " - "See breakdown above for which iterations succeeded, failed, and " - "why for more info.", - server_uri.c_str(), soak_iterations, total_failures, max_failures, - latency_ms_median, latency_ms_90th, latency_ms_worst); + LOG(INFO) << "(server_uri: " << server_uri + << ") soak test ran: " << soak_iterations + << " iterations. total_failures: " << total_failures + << " is within max_failures_threshold: " << max_failures + << ". median_soak_iteration_latency: " << latency_ms_median + << " ms. 90th_soak_iteration_latency: " << latency_ms_90th + << " ms. worst_soak_iteration_latency: " << latency_ms_worst + << " ms. See breakdown above for which iterations succeeded, " + "failed, and why for more info."; } } @@ -1327,14 +1300,14 @@ bool InteropClient::DoRpcSoakTest( int32_t max_failures, int64_t max_acceptable_per_iteration_latency_ms, int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds, int32_t request_size, int32_t response_size) { - gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations); + VLOG(2) << "Sending " << soak_iterations << " RPCs..."; CHECK_GT(soak_iterations, 0); PerformSoakTest(server_uri, false /* reset channel per iteration */, soak_iterations, max_failures, max_acceptable_per_iteration_latency_ms, soak_min_time_ms_between_rpcs, overall_timeout_seconds, request_size, response_size); - gpr_log(GPR_DEBUG, "rpc_soak test done."); + VLOG(2) << "rpc_soak test done."; return true; } @@ -1343,30 +1316,30 @@ bool InteropClient::DoChannelSoakTest( int32_t max_failures, int64_t max_acceptable_per_iteration_latency_ms, int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds, int32_t request_size, int32_t response_size) { - gpr_log(GPR_DEBUG, "Sending %d RPCs, tearing down the channel each time...", - soak_iterations); + VLOG(2) << "Sending " << soak_iterations + << " RPCs, tearing down the channel each time..."; CHECK_GT(soak_iterations, 0); PerformSoakTest(server_uri, true /* reset channel per iteration */, soak_iterations, max_failures, max_acceptable_per_iteration_latency_ms, soak_min_time_ms_between_rpcs, overall_timeout_seconds, request_size, response_size); - gpr_log(GPR_DEBUG, "channel_soak test done."); + VLOG(2) << "channel_soak test done."; return true; } bool InteropClient::DoLongLivedChannelTest(int32_t soak_iterations, int32_t iteration_interval) { - gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations); + VLOG(2) << "Sending " << soak_iterations << " RPCs..."; CHECK_GT(soak_iterations, 0); CHECK_GT(iteration_interval, 0); SimpleRequest request; SimpleResponse response; int num_failures = 0; for (int i = 0; i < soak_iterations; ++i) { - gpr_log(GPR_DEBUG, "Sending RPC number %d...", i); + VLOG(2) << "Sending RPC number " << i << "..."; if (!PerformLargeUnary(&request, &response)) { - gpr_log(GPR_ERROR, "Iteration %d failed.", i); + LOG(ERROR) << "Iteration " << i << " failed."; num_failures++; } gpr_sleep_until( @@ -1374,17 +1347,17 @@ bool InteropClient::DoLongLivedChannelTest(int32_t soak_iterations, gpr_time_from_seconds(iteration_interval, GPR_TIMESPAN))); } if (num_failures == 0) { - gpr_log(GPR_DEBUG, "long_lived_channel test done."); + VLOG(2) << "long_lived_channel test done."; return true; } else { - gpr_log(GPR_DEBUG, "long_lived_channel test failed with %d rpc failures.", - num_failures); + VLOG(2) << "long_lived_channel test failed with " << num_failures + << " rpc failures."; return false; } } bool InteropClient::DoUnimplementedService() { - gpr_log(GPR_DEBUG, "Sending a request for an unimplemented service..."); + VLOG(2) << "Sending a request for an unimplemented service..."; Empty request; Empty response; @@ -1399,12 +1372,12 @@ bool InteropClient::DoUnimplementedService() { return false; } - gpr_log(GPR_DEBUG, "unimplemented service done."); + VLOG(2) << "unimplemented service done."; return true; } bool InteropClient::DoUnimplementedMethod() { - gpr_log(GPR_DEBUG, "Sending a request for an unimplemented rpc..."); + VLOG(2) << "Sending a request for an unimplemented rpc..."; Empty request; Empty response; @@ -1418,7 +1391,7 @@ bool InteropClient::DoUnimplementedMethod() { return false; } - gpr_log(GPR_DEBUG, "unimplemented rpc done."); + VLOG(2) << "unimplemented rpc done."; return true; }