[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36438)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK

These changes have been made using string replacement and regex.

Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced.

Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36438

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36438 from tanvi-jagtap:tjagtap_cpp 405efd63c3
PiperOrigin-RevId: 628281347
pull/36481/head
Tanvi Jagtap 10 months ago committed by Copybara-Service
parent 04dc9b1da0
commit 30386413c0
  1. 5
      CMakeLists.txt
  2. 5
      build_autogenerated.yaml
  3. 1
      test/cpp/client/BUILD
  4. 33
      test/cpp/client/credentials_test.cc
  5. 2
      test/cpp/common/BUILD
  6. 12
      test/cpp/common/time_jump_test.cc
  7. 10
      test/cpp/common/timer_test.cc
  8. 4
      test/cpp/grpclb/grpclb_api_test.cc
  9. 2
      test/cpp/interop/BUILD
  10. 2
      test/cpp/interop/backend_metrics_lb_policy.cc
  11. 8
      test/cpp/interop/interop_client.cc
  12. 6
      test/cpp/interop/interop_server.cc
  13. 4
      test/cpp/interop/reconnect_interop_server.cc
  14. 2
      test/cpp/interop/rpc_behavior_lb_policy.cc
  15. 12
      test/cpp/interop/xds_interop_client.cc
  16. 5
      test/cpp/naming/BUILD
  17. 8
      test/cpp/naming/address_sorting_test.cc
  18. 3
      test/cpp/naming/cancel_ares_query_test.cc
  19. 3
      test/cpp/naming/generate_resolver_component_tests.bzl
  20. 14
      test/cpp/naming/resolver_component_test.cc
  21. 7
      test/cpp/naming/resolver_component_tests_runner_invoker.cc
  22. 1
      test/cpp/performance/BUILD
  23. 30
      test/cpp/performance/writes_per_rpc_test.cc
  24. 2
      test/cpp/qps/parse_json.cc
  25. 1
      test/cpp/server/BUILD
  26. 20
      test/cpp/server/credentials_test.cc
  27. 2
      test/cpp/server/load_reporter/BUILD
  28. 3
      test/cpp/server/load_reporter/load_reporter_test.cc

5
CMakeLists.txt generated

@ -6129,6 +6129,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
target_link_libraries(address_sorting_test_unsecure
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc++_unsecure
grpc_test_util_unsecure
grpc++_test_config
@ -30391,6 +30392,7 @@ target_include_directories(test_cpp_client_credentials_test
target_link_libraries(test_cpp_client_credentials_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc++
grpc_test_util
)
@ -30550,6 +30552,7 @@ target_include_directories(test_cpp_server_credentials_test
target_link_libraries(test_cpp_server_credentials_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc++
grpc_test_util
)
@ -30969,6 +30972,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
target_link_libraries(time_jump_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc++
grpc_test_util
)
@ -31212,6 +31216,7 @@ target_include_directories(timer_test
target_link_libraries(timer_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
absl::check
grpc++
grpc_test_util
)

@ -5311,6 +5311,7 @@ targets:
- test/cpp/util/subprocess.cc
deps:
- gtest
- absl/log:check
- grpc++_unsecure
- grpc_test_util_unsecure
- grpc++_test_config
@ -19593,6 +19594,7 @@ targets:
- test/cpp/util/tls_test_utils.cc
deps:
- gtest
- absl/log:check
- grpc++
- grpc_test_util
- name: test_cpp_end2end_ssl_credentials_test
@ -19660,6 +19662,7 @@ targets:
- test/cpp/util/tls_test_utils.cc
deps:
- gtest
- absl/log:check
- grpc++
- grpc_test_util
- name: test_cpp_util_slice_test
@ -19791,6 +19794,7 @@ targets:
- test/cpp/common/time_jump_test.cc
deps:
- gtest
- absl/log:check
- grpc++
- grpc_test_util
platforms:
@ -19923,6 +19927,7 @@ targets:
- test/cpp/common/timer_test.cc
deps:
- gtest
- absl/log:check
- grpc++
- grpc_test_util
- name: tls_certificate_verifier_test

@ -27,6 +27,7 @@ grpc_cc_test(
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [

@ -21,6 +21,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/grpc_crl_provider.h>
#include <grpc/grpc_security.h>
@ -275,7 +277,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRootsAndDefaultVerifier) {
grpc::experimental::TlsChannelCredentialsOptions options;
options.set_verify_server_certs(true);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(
@ -295,21 +297,21 @@ TEST(
options.watch_identity_key_cert_pairs();
options.set_identity_cert_name(kIdentityCertName);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest,
TlsChannelCredentialsWithStaticDataCertificateProviderLoadingRootOnly) {
auto certificate_provider =
std::make_shared<StaticDataCertificateProvider>(kRootCertContents);
GPR_ASSERT(certificate_provider != nullptr);
GPR_ASSERT(certificate_provider->c_provider() != nullptr);
CHECK_NE(certificate_provider, nullptr);
CHECK_NE(certificate_provider->c_provider(), nullptr);
grpc::experimental::TlsChannelCredentialsOptions options;
options.set_certificate_provider(certificate_provider);
options.watch_root_certs();
options.set_root_cert_name(kRootCertName);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(
@ -327,7 +329,7 @@ TEST(
options.watch_identity_key_cert_pairs();
options.set_identity_cert_name(kIdentityCertName);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(
@ -342,7 +344,7 @@ TEST(
options.watch_identity_key_cert_pairs();
options.set_identity_cert_name(kIdentityCertName);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest,
@ -354,7 +356,7 @@ TEST(CredentialsTest,
options.watch_root_certs();
options.set_root_cert_name(kRootCertName);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithHostNameVerifier) {
@ -363,7 +365,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithHostNameVerifier) {
options.set_verify_server_certs(true);
options.set_certificate_verifier(verifier);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithSyncExternalVerifier) {
@ -374,7 +376,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithSyncExternalVerifier) {
options.set_certificate_verifier(verifier);
options.set_check_call_host(false);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithAsyncExternalVerifier) {
@ -385,7 +387,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithAsyncExternalVerifier) {
options.set_certificate_verifier(verifier);
options.set_check_call_host(false);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithCrlDirectory) {
@ -399,7 +401,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlDirectory) {
options.set_identity_cert_name(kIdentityCertName);
options.set_crl_directory(CRL_DIR_PATH);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithCrlProvider) {
@ -408,7 +410,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlProvider) {
grpc::experimental::TlsChannelCredentialsOptions options;
options.set_crl_provider(*provider);
auto channel_credentials = grpc::experimental::TlsCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsChannelCredentialsWithCrlProviderAndDirectory) {
@ -420,7 +422,7 @@ TEST(CredentialsTest, TlsChannelCredentialsWithCrlProviderAndDirectory) {
auto channel_credentials = grpc::experimental::TlsCredentials(options);
// TODO(gtcooke94) - behavior might change to make this return nullptr in the
// future
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsCredentialsOptionsCopyConstructor) {
@ -437,8 +439,7 @@ TEST(CredentialsTest, TlsCredentialsOptionsCopyConstructor) {
TlsTestCredentialsOptions copied_options = options;
// Make sure the copy constructor cloned the internal pointer
GPR_ASSERT(options.internal_cred_opts() !=
copied_options.internal_cred_opts());
CHECK(options.internal_cred_opts() != copied_options.internal_cred_opts());
}
TEST(CredentialsTest, TlsCredentialsOptionsDoesNotLeak) {

@ -36,6 +36,7 @@ grpc_cc_test(
name = "timer_test",
srcs = ["timer_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
flaky = True,
@ -50,6 +51,7 @@ grpc_cc_test(
name = "time_jump_test",
srcs = ["time_jump_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
tags = [

@ -25,6 +25,7 @@
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include "absl/time/time.h"
#include <grpc/grpc.h>
@ -95,7 +96,7 @@ TEST_P(TimeJumpTest, TimerRunning) {
grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(3),
GRPC_CLOSURE_CREATE(
[](void*, grpc_error_handle error) {
GPR_ASSERT(error == absl::CancelledError());
CHECK(error == absl::CancelledError());
},
nullptr, grpc_schedule_on_exec_ctx));
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100));
@ -106,7 +107,7 @@ TEST_P(TimeJumpTest, TimerRunning) {
// We expect 1 wakeup/sec when there are not timer expiries
int64_t wakeups = grpc_timer_manager_get_wakeups_testonly();
gpr_log(GPR_DEBUG, "wakeups: %" PRId64 "", wakeups);
GPR_ASSERT(wakeups <= 3);
CHECK_LE(wakeups, 3);
grpc_timer_cancel(&timer);
}
@ -127,9 +128,8 @@ TEST_P(TimeJumpTest, TimedWait) {
int32_t elapsed_ms = gpr_time_to_millis(gpr_time_sub(after, before));
gpr_log(GPR_DEBUG, "After wait, timedout = %d elapsed_ms = %d", timedout,
elapsed_ms);
GPR_ASSERT(1 == timedout);
GPR_ASSERT(1 ==
gpr_time_similar(gpr_time_sub(after, before),
CHECK_EQ(timedout, 1);
CHECK(1 == gpr_time_similar(gpr_time_sub(after, before),
gpr_time_from_millis(kWaitTimeMs, GPR_TIMESPAN),
gpr_time_from_millis(50, GPR_TIMESPAN)));
@ -138,7 +138,7 @@ TEST_P(TimeJumpTest, TimedWait) {
// We expect 1 wakeup/sec when there are not timer expiries
int64_t wakeups = grpc_timer_manager_get_wakeups_testonly();
gpr_log(GPR_DEBUG, "wakeups: %" PRId64 "", wakeups);
GPR_ASSERT(wakeups <= 3);
CHECK_LE(wakeups, 3);
}
int main(int argc, char** argv) {

@ -20,6 +20,8 @@
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@ -77,7 +79,7 @@ TEST_F(TimerTest, NoTimers) {
// We expect to get 1 wakeup per second. Sometimes we also get a wakeup
// during initialization, so in 1.5 seconds we expect to get 1 or 2 wakeups.
int64_t wakeups = grpc_timer_manager_get_wakeups_testonly();
GPR_ASSERT(wakeups == 1 || wakeups == 2);
CHECK(wakeups == 1 || wakeups == 2);
}
#endif
@ -96,7 +98,7 @@ TEST_F(TimerTest, OneTimerExpires) {
},
&timer_fired, grpc_schedule_on_exec_ctx));
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500));
GPR_ASSERT(1 == timer_fired);
CHECK_EQ(timer_fired, 1);
// We expect to get 1 wakeup/second + 1 wakeup for the expired timer + maybe 1
// wakeup during initialization. i.e. in 1.5 seconds we expect 2 or 3 wakeups.
@ -126,7 +128,7 @@ TEST_F(TimerTest, MultipleTimersExpire) {
}
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500));
GPR_ASSERT(kNumTimers == timer_fired);
CHECK(kNumTimers == timer_fired);
// We expect to get 1 wakeup/second + 1 wakeup for per timer fired + maybe 1
// wakeup during initialization. i.e. in 1.5 seconds we expect 11 or 12
@ -168,7 +170,7 @@ TEST_F(TimerTest, CancelSomeTimers) {
}
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1500));
GPR_ASSERT(kNumTimers / 2 == timer_fired);
CHECK(kNumTimers / 2 == timer_fired);
// We expect to get 1 wakeup/second + 1 wakeup per timer fired + maybe 1
// wakeup during initialization. i.e. in 1.5 seconds we expect 6 or 7 wakeups.

@ -46,7 +46,7 @@ class GrpclbTest : public ::testing::Test {
std::string Ip4ToPackedString(const char* ip_str) {
struct in_addr ip4;
CHECK(inet_pton(AF_INET, ip_str, &ip4) == 1);
CHECK_EQ(inet_pton(AF_INET, ip_str, &ip4), 1);
return std::string(reinterpret_cast<const char*>(&ip4), sizeof(ip4));
}
@ -60,7 +60,7 @@ std::string PackedStringToIp(const grpc_core::GrpcLbServer& server) {
} else {
abort();
}
CHECK(inet_ntop(af, (void*)server.ip_addr, ip_str, 46) != nullptr);
CHECK_NE(inet_ntop(af, (void*)server.ip_addr, ip_str, 46), nullptr);
return ip_str;
}

@ -138,6 +138,7 @@ grpc_cc_library(
grpc_cc_binary(
name = "interop_client",
external_deps = ["absl/log:check"],
language = "C++",
deps = [
":interop_client_main",
@ -280,6 +281,7 @@ grpc_cc_binary(
],
external_deps = [
"absl/flags:flag",
"absl/log:check",
"otel/exporters/prometheus:prometheus_exporter",
"otel/sdk/src/metrics",
],

@ -67,7 +67,7 @@ class BackendMetricsLbPolicy : public LoadBalancingPolicy {
: LoadBalancingPolicy(std::move(args), /*initial_refcount=*/2) {
load_report_tracker_ =
channel_args().GetPointer<LoadReportTracker>(kMetricsTrackerArgument);
CHECK(load_report_tracker_ != nullptr);
CHECK_NE(load_report_tracker_, nullptr);
Args delegate_args;
delegate_args.work_serializer = work_serializer();
delegate_args.args = channel_args();

@ -1328,7 +1328,7 @@ bool InteropClient::DoRpcSoakTest(
int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds,
int32_t request_size, int32_t response_size) {
gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations);
CHECK(soak_iterations > 0);
CHECK_GT(soak_iterations, 0);
PerformSoakTest(server_uri, false /* reset channel per iteration */,
soak_iterations, max_failures,
max_acceptable_per_iteration_latency_ms,
@ -1345,7 +1345,7 @@ bool InteropClient::DoChannelSoakTest(
int32_t request_size, int32_t response_size) {
gpr_log(GPR_DEBUG, "Sending %d RPCs, tearing down the channel each time...",
soak_iterations);
CHECK(soak_iterations > 0);
CHECK_GT(soak_iterations, 0);
PerformSoakTest(server_uri, true /* reset channel per iteration */,
soak_iterations, max_failures,
max_acceptable_per_iteration_latency_ms,
@ -1358,8 +1358,8 @@ bool InteropClient::DoChannelSoakTest(
bool InteropClient::DoLongLivedChannelTest(int32_t soak_iterations,
int32_t iteration_interval) {
gpr_log(GPR_DEBUG, "Sending %d RPCs...", soak_iterations);
CHECK(soak_iterations > 0);
CHECK(iteration_interval > 0);
CHECK_GT(soak_iterations, 0);
CHECK_GT(iteration_interval, 0);
SimpleRequest request;
SimpleResponse response;
int num_failures = 0;

@ -76,8 +76,8 @@ const char kEchoUserAgentKey[] = "x-grpc-test-echo-useragent";
void MaybeEchoMetadata(ServerContext* context) {
const auto& client_metadata = context->client_metadata();
CHECK(client_metadata.count(kEchoInitialMetadataKey) <= 1);
CHECK(client_metadata.count(kEchoTrailingBinMetadataKey) <= 1);
CHECK_LE(client_metadata.count(kEchoInitialMetadataKey), 1u);
CHECK_LE(client_metadata.count(kEchoTrailingBinMetadataKey), 1u);
auto iter = client_metadata.find(kEchoInitialMetadataKey);
if (iter != client_metadata.end()) {
@ -420,7 +420,7 @@ void grpc::testing::interop::RunServer(
ServerStartedCondition* server_started_condition,
std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
server_options) {
CHECK(port != 0);
CHECK_NE(port, 0);
std::ostringstream server_address;
server_address << "0.0.0.0:" << port;
auto server_metric_recorder =

@ -180,8 +180,8 @@ int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true);
signal(SIGINT, sigint_handler);
CHECK(absl::GetFlag(FLAGS_control_port) != 0);
CHECK(absl::GetFlag(FLAGS_retry_port) != 0);
CHECK_NE(absl::GetFlag(FLAGS_control_port), 0);
CHECK_NE(absl::GetFlag(FLAGS_retry_port), 0);
RunServer();
return 0;

@ -93,7 +93,7 @@ class RpcBehaviorLbPolicy : public LoadBalancingPolicy {
grpc_core::Json::FromArray({grpc_core::Json::FromObject(
{{std::string(delegate_->name()),
grpc_core::Json::FromObject({})}})}));
CHECK(delegate_config.ok());
CHECK_OK(delegate_config);
args.config = std::move(*delegate_config);
return delegate_->UpdateLocked(std::move(args));
}

@ -342,8 +342,8 @@ class XdsUpdateClientConfigureServiceImpl
std::vector<RpcConfig> configs;
int request_payload_size = absl::GetFlag(FLAGS_request_payload_size);
int response_payload_size = absl::GetFlag(FLAGS_response_payload_size);
CHECK(request_payload_size >= 0);
CHECK(response_payload_size >= 0);
CHECK_GE(request_payload_size, 0);
CHECK_GE(response_payload_size, 0);
for (const auto& rpc : request->types()) {
RpcConfig config;
config.timeout_sec = request->timeout_sec();
@ -448,7 +448,7 @@ grpc::CsmObservability EnableCsmObservability() {
void RunServer(const int port, StatsWatchers* stats_watchers,
RpcConfigurationsQueue* rpc_configs_queue) {
CHECK(port != 0);
CHECK_NE(port, 0);
std::ostringstream server_address;
server_address << "0.0.0.0:" << port;
@ -480,7 +480,7 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) {
for (auto& data : rpc_metadata) {
std::vector<std::string> metadata =
absl::StrSplit(data, ':', absl::SkipEmpty());
CHECK(metadata.size() == 3);
CHECK_EQ(metadata.size(), 3u);
if (metadata[0] == "EmptyCall") {
metadata_map[ClientConfigureRequest::EMPTY_CALL].push_back(
{metadata[1], metadata[2]});
@ -496,8 +496,8 @@ void BuildRpcConfigsFromFlags(RpcConfigurationsQueue* rpc_configs_queue) {
absl::StrSplit(absl::GetFlag(FLAGS_rpc), ',', absl::SkipEmpty());
int request_payload_size = absl::GetFlag(FLAGS_request_payload_size);
int response_payload_size = absl::GetFlag(FLAGS_response_payload_size);
CHECK(request_payload_size >= 0);
CHECK(response_payload_size >= 0);
CHECK_GE(request_payload_size, 0);
CHECK_GE(response_payload_size, 0);
for (const std::string& rpc_method : rpc_methods) {
RpcConfig config;
if (rpc_method == "EmptyCall") {

@ -38,7 +38,10 @@ grpc_py_binary(
grpc_cc_test(
name = "cancel_ares_query_test",
srcs = ["cancel_ares_query_test.cc"],
external_deps = ["gtest"],
external_deps = [
"absl/log:check",
"gtest",
],
tags = ["cancel_ares_query_test"],
deps = [
"//:gpr",

@ -24,6 +24,8 @@
#include <address_sorting/address_sorting.h>
#include <gmock/gmock.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -74,16 +76,16 @@ grpc_resolved_address TestAddressToGrpcResolvedAddress(TestAddress test_addr) {
memset(&in_dest, 0, sizeof(sockaddr_in));
in_dest.sin_port = htons(atoi(port.c_str()));
in_dest.sin_family = AF_INET;
GPR_ASSERT(inet_pton(AF_INET, host.c_str(), &in_dest.sin_addr) == 1);
CHECK_EQ(inet_pton(AF_INET, host.c_str(), &in_dest.sin_addr), 1);
memcpy(&resolved_addr.addr, &in_dest, sizeof(sockaddr_in));
resolved_addr.len = sizeof(sockaddr_in);
} else {
GPR_ASSERT(test_addr.family == AF_INET6);
CHECK(test_addr.family == AF_INET6);
sockaddr_in6 in6_dest;
memset(&in6_dest, 0, sizeof(sockaddr_in6));
in6_dest.sin6_port = htons(atoi(port.c_str()));
in6_dest.sin6_family = AF_INET6;
GPR_ASSERT(inet_pton(AF_INET6, host.c_str(), &in6_dest.sin6_addr) == 1);
CHECK_EQ(inet_pton(AF_INET6, host.c_str(), &in6_dest.sin6_addr), 1);
memcpy(&resolved_addr.addr, &in6_dest, sizeof(sockaddr_in6));
resolved_addr.len = sizeof(sockaddr_in6);
}

@ -23,6 +23,7 @@
#include <gmock/gmock.h>
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
@ -295,7 +296,7 @@ void TestCancelDuringActiveQuery(
grpc_call* call = grpc_channel_create_call(
client, nullptr, GRPC_PROPAGATE_DEFAULTS, cq,
grpc_slice_from_static_string("/foo"), nullptr, rpc_deadline, nullptr);
GPR_ASSERT(call);
CHECK(call);
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;

@ -32,6 +32,7 @@ def generate_resolver_component_tests():
"address_sorting_test.cc",
],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [
@ -53,6 +54,7 @@ def generate_resolver_component_tests():
"resolver_component_test.cc",
],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [
@ -75,6 +77,7 @@ def generate_resolver_component_tests():
],
external_deps = [
"absl/flags:flag",
"absl/log:check",
"absl/strings",
],
deps = [

@ -27,6 +27,7 @@
#include <gmock/gmock.h>
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
@ -209,7 +210,7 @@ void ArgsInit(ArgsStruct* args) {
void DoNothing(void* /*arg*/, grpc_error_handle /*error*/) {}
void ArgsFinish(ArgsStruct* args) {
GPR_ASSERT(gpr_event_wait(&args->ev, TestDeadline()));
CHECK(gpr_event_wait(&args->ev, TestDeadline()));
grpc_pollset_set_del_pollset(args->pollset_set, args->pollset);
grpc_pollset_set_destroy(args->pollset_set);
grpc_closure DoNothing_cb;
@ -242,7 +243,7 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) {
gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", args->done,
time_left.tv_sec, time_left.tv_nsec);
GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
CHECK_GE(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)), 0);
grpc_pollset_worker* worker = nullptr;
grpc_core::ExecCtx exec_ctx;
if (grpc_core::IsEventEngineDnsEnabled()) {
@ -304,7 +305,7 @@ class ResultHandler : public grpc_core::Resolver::ResultHandler {
void ReportResult(grpc_core::Resolver::Result result) override {
CheckResult(result);
grpc_core::MutexLockForGprMu lock(args_->mu);
GPR_ASSERT(!args_->done);
CHECK(!args_->done);
args_->done = true;
GRPC_LOG_IF_ERROR("pollset_kick",
grpc_pollset_kick(args_->pollset, nullptr));
@ -362,7 +363,7 @@ class CheckingResultHandler : public ResultHandler {
"Invalid for setting for --do_ordered_address_comparison. "
"Have %s, want True or False",
absl::GetFlag(FLAGS_do_ordered_address_comparison).c_str());
GPR_ASSERT(0);
CHECK(0);
}
if (!result.service_config.ok()) {
CheckServiceConfigResultLocked(nullptr, result.service_config.status(),
@ -405,7 +406,7 @@ void InjectBrokenNameServerList(ares_channel* channel) {
memset(dns_server_addrs, 0, sizeof(dns_server_addrs));
std::string unused_host;
std::string local_dns_server_port;
GPR_ASSERT(grpc_core::SplitHostPort(
CHECK(grpc_core::SplitHostPort(
absl::GetFlag(FLAGS_local_dns_server_address).c_str(), &unused_host,
&local_dns_server_port));
gpr_log(GPR_DEBUG,
@ -429,8 +430,7 @@ void InjectBrokenNameServerList(ares_channel* channel) {
dns_server_addrs[1].tcp_port = atoi(local_dns_server_port.c_str());
dns_server_addrs[1].udp_port = atoi(local_dns_server_port.c_str());
dns_server_addrs[1].next = nullptr;
GPR_ASSERT(ares_set_servers_ports(*channel, dns_server_addrs) ==
ARES_SUCCESS);
CHECK(ares_set_servers_ports(*channel, dns_server_addrs) == ARES_SUCCESS);
}
void StartResolvingLocked(grpc_core::Resolver* r) { r->StartLocked(); }

@ -27,6 +27,7 @@
#include <vector>
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include <grpc/grpc.h>
@ -99,12 +100,12 @@ int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc::testing::InitTest(&argc, &argv, true);
grpc_init();
GPR_ASSERT(!absl::GetFlag(FLAGS_test_bin_name).empty());
CHECK(!absl::GetFlag(FLAGS_test_bin_name).empty());
std::string my_bin = argv[0];
int result = 0;
if (absl::GetFlag(FLAGS_running_under_bazel)) {
GPR_ASSERT(!absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir)
.empty());
CHECK(!absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir)
.empty());
// Use bazel's TEST_SRCDIR environment variable to locate the "test data"
// binaries.
auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR");

@ -22,6 +22,7 @@ grpc_cc_test(
name = "writes_per_rpc_test",
srcs = ["writes_per_rpc_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
tags = ["no_windows"],

@ -20,6 +20,8 @@
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpcpp/channel.h>
#include <grpcpp/create_channel.h>
@ -79,16 +81,16 @@ class InProcessCHTTP2 {
listener_endpoint = std::move(ep);
listener_started.Notify();
},
[](absl::Status status) { GPR_ASSERT(status.ok()); }, config,
[](absl::Status status) { CHECK_OK(status); }, config,
std::make_unique<grpc_core::MemoryQuota>("foo"));
if (!listener.ok()) {
grpc_core::Crash(absl::StrCat("failed to start listener: ",
listener.status().ToString()));
}
auto target_addr = URIToResolvedAddress(addr);
GPR_ASSERT(target_addr.ok());
GPR_ASSERT((*listener)->Bind(*target_addr).ok());
GPR_ASSERT((*listener)->Start().ok());
CHECK_OK(target_addr);
CHECK_OK((*listener)->Bind(*target_addr));
CHECK_OK((*listener)->Start());
// Creating the client
std::unique_ptr<EventEngine::Endpoint> client_endpoint;
grpc_core::Notification client_connected;
@ -96,7 +98,7 @@ class InProcessCHTTP2 {
std::make_unique<grpc_core::MemoryQuota>("client");
std::ignore = fuzzing_engine->Connect(
[&](absl::StatusOr<std::unique_ptr<EventEngine::Endpoint>> endpoint) {
GPR_ASSERT(endpoint.ok());
CHECK_OK(endpoint);
client_endpoint = std::move(*endpoint);
client_connected.Notify();
},
@ -124,7 +126,7 @@ class InProcessCHTTP2 {
for (grpc_pollset* pollset : core_server->pollsets()) {
grpc_endpoint_add_to_pollset(iomgr_server_endpoint, pollset);
}
GPR_ASSERT(GRPC_LOG_IF_ERROR(
CHECK(GRPC_LOG_IF_ERROR(
"SetupTransport",
core_server->SetupTransport(transport, nullptr,
core_server->channel_args(), nullptr)));
@ -143,7 +145,7 @@ class InProcessCHTTP2 {
grpc_core::Transport* transport = grpc_create_chttp2_transport(
args, grpc_event_engine_endpoint_create(std::move(client_endpoint)),
/*is_client=*/true);
GPR_ASSERT(transport);
CHECK(transport);
grpc_channel* channel =
grpc_core::ChannelCreate("target", args, GRPC_CLIENT_DIRECT_CHANNEL,
transport)
@ -234,20 +236,20 @@ static double UnaryPingPong(ThreadedFuzzingEventEngine* fuzzing_engine,
void* t;
bool ok;
response_reader->Finish(&recv_response, &recv_status, tag(4));
GPR_ASSERT(fixture->cq()->Next(&t, &ok));
GPR_ASSERT(ok);
GPR_ASSERT(t == tag(0) || t == tag(1));
CHECK(fixture->cq()->Next(&t, &ok));
CHECK(ok);
CHECK(t == tag(0) || t == tag(1));
intptr_t slot = reinterpret_cast<intptr_t>(t);
ServerEnv* senv = server_env[slot];
senv->response_writer.Finish(send_response, Status::OK, tag(3));
for (int i = (1 << 3) | (1 << 4); i != 0;) {
GPR_ASSERT(fixture->cq()->Next(&t, &ok));
GPR_ASSERT(ok);
CHECK(fixture->cq()->Next(&t, &ok));
CHECK(ok);
int tagnum = static_cast<int>(reinterpret_cast<intptr_t>(t));
GPR_ASSERT(i & (1 << tagnum));
CHECK(i & (1 << tagnum));
i -= 1 << tagnum;
}
GPR_ASSERT(recv_status.ok());
CHECK(recv_status.ok());
senv->~ServerEnv();
senv = new (senv) ServerEnv();

@ -57,7 +57,7 @@ std::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg,
msg.SerializeToString(&binary);
auto status =
BinaryToJsonString(type_resolver.get(), type, binary, &json_string);
CHECK(status.ok());
CHECK_OK(status);
return json_string;
}

@ -72,6 +72,7 @@ grpc_cc_test(
"//src/core/tsi/test_creds:server1.pem",
],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [

@ -18,6 +18,8 @@
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/grpc_crl_provider.h>
#include <grpc/grpc_security.h>
@ -73,7 +75,7 @@ TEST(
options.set_cert_request_type(
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
// ServerCredentials should always have identity credential presented.
@ -95,7 +97,7 @@ TEST(CredentialsTest,
options.set_cert_request_type(
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
TEST(
@ -111,7 +113,7 @@ TEST(
options.set_cert_request_type(
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsServerCredentialsWithCrlChecking) {
@ -126,7 +128,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlChecking) {
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
options.set_crl_directory(CRL_DIR_PATH);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
// ServerCredentials should always have identity credential presented.
@ -142,7 +144,7 @@ TEST(
options.set_cert_request_type(
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsServerCredentialsWithSyncExternalVerifier) {
@ -159,7 +161,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithSyncExternalVerifier) {
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
options.set_certificate_verifier(verifier);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsServerCredentialsWithAsyncExternalVerifier) {
@ -176,7 +178,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithAsyncExternalVerifier) {
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
options.set_certificate_verifier(verifier);
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(server_credentials.get() != nullptr);
CHECK_NE(server_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsServerCredentialsWithCrlProvider) {
@ -187,7 +189,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlProvider) {
grpc::experimental::TlsServerCredentialsOptions options(certificate_provider);
options.set_crl_provider(*provider);
auto channel_credentials = grpc::experimental::TlsServerCredentials(options);
GPR_ASSERT(channel_credentials.get() != nullptr);
CHECK_NE(channel_credentials.get(), nullptr);
}
TEST(CredentialsTest, TlsServerCredentialsWithCrlProviderAndDirectory) {
@ -201,7 +203,7 @@ TEST(CredentialsTest, TlsServerCredentialsWithCrlProviderAndDirectory) {
auto server_credentials = grpc::experimental::TlsServerCredentials(options);
// TODO(gtcooke94) - behavior might change to make this return nullptr in
// the future
GPR_ASSERT(server_credentials != nullptr);
CHECK_NE(server_credentials, nullptr);
}
TEST(CredentialsTest, TlsCredentialsOptionsDoesNotLeak) {

@ -34,6 +34,8 @@ grpc_cc_test(
name = "lb_load_reporter_test",
srcs = ["load_reporter_test.cc"],
external_deps = [
"absl/flags:flag",
"absl/log:check",
"gtest",
"opencensus-stats-test",
],

@ -24,6 +24,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "opencensus/stats/testing/test_utils.h"
@ -59,7 +60,7 @@ class MockCensusViewProvider : public CensusViewProvider {
const ViewDescriptor& FindViewDescriptor(const std::string& view_name) {
auto it = view_descriptor_map().find(view_name);
GPR_ASSERT(it != view_descriptor_map().end());
CHECK(it != view_descriptor_map().end());
return it->second;
}
};

Loading…
Cancel
Save