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

[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 #36437

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36437 from tanvi-jagtap:tjagtap_core_util_01 719e3e20e1
PiperOrigin-RevId: 628043154
pull/36442/head
Tanvi Jagtap 9 months ago committed by Copybara-Service
parent b0de95507c
commit e61fa603cc
  1. 171
      CMakeLists.txt
  2. 171
      build_autogenerated.yaml
  3. 7
      test/core/util/BUILD
  4. 11
      test/core/util/cmdline.cc
  5. 6
      test/core/util/fake_stats_plugin.cc
  6. 40
      test/core/util/fake_udp_and_tcp_server.cc
  7. 3
      test/core/util/fuzzer_corpus_test.cc
  8. 16
      test/core/util/histogram.cc
  9. 3
      test/core/util/mock_endpoint.cc
  10. 4
      test/core/util/one_corpus_entry_fuzzer.cc
  11. 4
      test/core/util/parse_hexstring.cc
  12. 10
      test/core/util/port.cc
  13. 4
      test/core/util/port_isolated_runtime_environment.cc
  14. 18
      test/core/util/port_server_client.cc
  15. 3
      test/core/util/resolve_localhost_ip46.cc
  16. 5
      test/core/util/test_lb_policies.cc
  17. 8
      test/core/util/test_tcp_server.cc
  18. 20
      test/core/util/tls_utils.cc

171
CMakeLists.txt generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -81,6 +81,7 @@ grpc_cc_library(
"tracer_util.h",
],
external_deps = [
"absl/log:check",
"absl/status:statusor",
"absl/strings",
"absl/strings:str_format",
@ -118,6 +119,7 @@ grpc_cc_library(
external_deps = [
"absl/base:core_headers",
"absl/debugging:failure_signal_handler",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/strings",
@ -163,6 +165,7 @@ grpc_cc_library(
hdrs = TEST_UTILS_THAT_USE_GRPC_H_HEADERS,
external_deps = [
"absl/debugging:failure_signal_handler",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/strings",
@ -218,6 +221,7 @@ grpc_cc_library(
srcs = ["fuzzer_corpus_test.cc"],
external_deps = [
"absl/flags:flag",
"absl/log:check",
"gtest",
],
linkstatic = True,
@ -298,6 +302,7 @@ grpc_cc_library(
srcs = ["test_lb_policies.cc"],
hdrs = ["test_lb_policies.h"],
external_deps = [
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/strings",
@ -336,6 +341,7 @@ grpc_cc_library(
srcs = ["fake_udp_and_tcp_server.cc"],
hdrs = ["fake_udp_and_tcp_server.h"],
external_deps = [
"absl/log:check",
"absl/status:statusor",
"absl/strings",
],
@ -500,6 +506,7 @@ grpc_cc_library(
external_deps = [
"absl/container:flat_hash_map",
"absl/functional:any_invocable",
"absl/log:check",
"absl/status",
"absl/strings",
"absl/types:optional",

@ -26,6 +26,7 @@
#include <algorithm>
#include <vector>
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
@ -90,7 +91,7 @@ static void add_arg(gpr_cmdline* cl, const char* name, const char* help,
arg* a;
for (a = cl->args; a; a = a->next) {
GPR_ASSERT(0 != strcmp(a->name, name));
CHECK_NE(strcmp(a->name, name), 0);
}
a = static_cast<arg*>(gpr_zalloc(sizeof(arg)));
@ -120,8 +121,8 @@ void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, const char* help,
void gpr_cmdline_on_extra_arg(
gpr_cmdline* cl, const char* name, const char* help,
void (*on_extra_arg)(void* user_data, const char* arg), void* user_data) {
GPR_ASSERT(!cl->extra_arg);
GPR_ASSERT(on_extra_arg);
CHECK(!cl->extra_arg);
CHECK(on_extra_arg);
cl->extra_arg = on_extra_arg;
cl->extra_arg_user_data = user_data;
@ -203,7 +204,7 @@ static int value_state(gpr_cmdline* cl, char* str) {
long intval;
char* end;
GPR_ASSERT(cl->cur_arg);
CHECK(cl->cur_arg);
switch (cl->cur_arg->type) {
case ARGTYPE_INT:
@ -309,7 +310,7 @@ static int normal_state(gpr_cmdline* cl, char* str) {
int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv) {
int i;
GPR_ASSERT(argc >= 1);
CHECK_GE(argc, 1);
cl->argv0 = argv[0];
for (i = 1; i < argc; i++) {

@ -14,6 +14,8 @@
#include "test/core/util/fake_stats_plugin.h"
#include "absl/log/check.h"
#include "src/core/lib/config/core_configuration.h"
namespace grpc_core {
@ -45,7 +47,7 @@ FakeStatsClientFilter::Create(const ChannelArgs& args,
auto* fake_client_call_tracer_factory =
args.GetPointer<FakeClientCallTracerFactory>(
GRPC_ARG_INJECT_FAKE_CLIENT_CALL_TRACER_FACTORY);
GPR_ASSERT(fake_client_call_tracer_factory != nullptr);
CHECK_NE(fake_client_call_tracer_factory, nullptr);
return std::make_unique<FakeStatsClientFilter>(
fake_client_call_tracer_factory);
}
@ -87,7 +89,7 @@ namespace {
void AddKeyValuePairs(absl::Span<const absl::string_view> keys,
absl::Span<const absl::string_view> values,
std::vector<std::string>* key_value_pairs) {
GPR_ASSERT(keys.size() == values.size());
CHECK(keys.size() == values.size());
for (size_t i = 0; i < keys.size(); ++i) {
key_value_pairs->push_back(absl::StrCat(keys[i], "=", values[i]));
}

@ -23,6 +23,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@ -78,13 +79,13 @@ FakeUdpAndTcpServer::FakeUdpAndTcpServer(
udp_socket_ = socket(AF_INET6, SOCK_DGRAM, 0);
if (udp_socket_ == BAD_SOCKET_RETURN_VAL) {
gpr_log(GPR_ERROR, "Failed to create UDP ipv6 socket: %d", ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
accept_socket_ = socket(AF_INET6, SOCK_STREAM, 0);
address_ = absl::StrCat("[::1]:", port_);
if (accept_socket_ == BAD_SOCKET_RETURN_VAL) {
gpr_log(GPR_ERROR, "Failed to create TCP IPv6 socket: %d", ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
#ifdef GPR_WINDOWS
char val = 1;
@ -94,35 +95,35 @@ FakeUdpAndTcpServer::FakeUdpAndTcpServer(
"Failed to set SO_REUSEADDR on TCP ipv6 socket to [::1]:%d, "
"errno: %d",
port_, ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
grpc_error_handle set_non_block_error;
set_non_block_error = grpc_tcp_set_non_block(udp_socket_);
if (!set_non_block_error.ok()) {
gpr_log(GPR_ERROR, "Failed to configure non-blocking socket: %s",
StatusToString(set_non_block_error).c_str());
GPR_ASSERT(0);
CHECK(0);
}
set_non_block_error = grpc_tcp_set_non_block(accept_socket_);
if (!set_non_block_error.ok()) {
gpr_log(GPR_ERROR, "Failed to configure non-blocking socket: %s",
StatusToString(set_non_block_error).c_str());
GPR_ASSERT(0);
CHECK(0);
}
#else
int val = 1;
if (setsockopt(accept_socket_, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) !=
0) {
gpr_log(GPR_ERROR, "Failed to set SO_REUSEADDR on socket [::1]:%d", port_);
GPR_ASSERT(0);
CHECK(0);
}
if (fcntl(udp_socket_, F_SETFL, O_NONBLOCK) != 0) {
gpr_log(GPR_ERROR, "Failed to set O_NONBLOCK on socket: %d", ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
if (fcntl(accept_socket_, F_SETFL, O_NONBLOCK) != 0) {
gpr_log(GPR_ERROR, "Failed to set O_NONBLOCK on socket: %d", ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
#endif
sockaddr_in6 addr;
@ -139,18 +140,18 @@ FakeUdpAndTcpServer::FakeUdpAndTcpServer(
if (bind(udp_socket_, reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)) != 0) {
gpr_log(GPR_ERROR, "Failed to bind UDP socket to [::1]:%d", port_);
GPR_ASSERT(0);
CHECK(0);
}
if (bind(accept_socket_, reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)) != 0) {
gpr_log(GPR_ERROR, "Failed to bind TCP socket to [::1]:%d : %d", port_,
ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
if (listen(accept_socket_, 100)) {
gpr_log(GPR_ERROR, "Failed to listen on socket bound to [::1]:%d : %d",
port_, ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
gpr_event_init(&stop_ev_);
run_server_loop_thd_ = std::make_unique<std::thread>(
@ -176,7 +177,7 @@ FakeUdpAndTcpServer::CloseSocketUponReceivingBytesFromPeer(
if (bytes_received_size < 0 && !ErrorIsRetryable(read_error)) {
gpr_log(GPR_ERROR, "Failed to receive from peer socket: %d. errno: %d", s,
read_error);
GPR_ASSERT(0);
CHECK(0);
}
if (bytes_received_size >= 0) {
gpr_log(GPR_DEBUG,
@ -195,7 +196,7 @@ FakeUdpAndTcpServer::CloseSocketUponCloseFromPeer(int bytes_received_size,
if (bytes_received_size < 0 && !ErrorIsRetryable(read_error)) {
gpr_log(GPR_ERROR, "Failed to receive from peer socket: %d. errno: %d", s,
read_error);
GPR_ASSERT(0);
CHECK(0);
}
if (bytes_received_size == 0) {
// The peer has shut down the connection.
@ -215,7 +216,7 @@ FakeUdpAndTcpServer::SendThreeAllZeroBytes(int bytes_received_size,
if (bytes_received_size < 0 && !ErrorIsRetryable(read_error)) {
gpr_log(GPR_ERROR, "Failed to receive from peer socket: %d. errno: %d", s,
read_error);
GPR_ASSERT(0);
CHECK(0);
}
if (bytes_received_size == 0) {
// The peer has shut down the connection.
@ -257,10 +258,10 @@ void FakeUdpAndTcpServer::FakeUdpAndTcpServerPeer::
"Fake TCP server encountered unexpected error:%d "
"sending %d bytes on fd:%d",
ERRNO, bytes_to_send, fd_);
GPR_ASSERT(0);
CHECK(0);
} else if (bytes_sent > 0) {
total_bytes_sent_ += bytes_sent;
GPR_ASSERT(total_bytes_sent_ <= int(kEmptyHttp2SettingsFrame.size()));
CHECK(total_bytes_sent_ <= int(kEmptyHttp2SettingsFrame.size()));
}
}
}
@ -283,13 +284,13 @@ void FakeUdpAndTcpServer::RunServerLoop() {
if (!set_non_block_error.ok()) {
gpr_log(GPR_ERROR, "Failed to configure non-blocking socket: %s",
StatusToString(set_non_block_error).c_str());
GPR_ASSERT(0);
CHECK(0);
}
#else
if (fcntl(p, F_SETFL, O_NONBLOCK) != 0) {
gpr_log(GPR_ERROR, "Failed to configure non-blocking socket, errno: %d",
ERRNO);
GPR_ASSERT(0);
CHECK(0);
}
#endif
peers.insert(std::make_unique<FakeUdpAndTcpServerPeer>(p));
@ -307,8 +308,7 @@ void FakeUdpAndTcpServer::RunServerLoop() {
if (r == FakeUdpAndTcpServer::ProcessReadResult::kCloseSocket) {
it = peers.erase(it);
} else {
GPR_ASSERT(r ==
FakeUdpAndTcpServer::ProcessReadResult::kContinueReading);
CHECK(r == FakeUdpAndTcpServer::ProcessReadResult::kContinueReading);
it++;
}
}

@ -27,6 +27,7 @@
#include <vector>
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/types/optional.h"
#include "gtest/gtest.h"
@ -109,7 +110,7 @@ class ExampleGenerator
}
// Make sure we don't succeed without doing anything, which caused
// us to be blind to our fuzzers not running for 9 months.
GPR_ASSERT(!examples_.empty());
CHECK(!examples_.empty());
// Get a consistent ordering of examples so problems don't just show up on
// CI
std::sort(examples_.begin(), examples_.end());

@ -21,6 +21,8 @@
#include <math.h>
#include <stddef.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -63,7 +65,7 @@ static size_t bucket_for_unchecked(grpc_histogram* h, double x) {
static size_t bucket_for(grpc_histogram* h, double x) {
size_t bucket =
bucket_for_unchecked(h, grpc_core::Clamp(x, 1.0, h->max_possible));
GPR_ASSERT(bucket < h->num_buckets);
CHECK(bucket < h->num_buckets);
return bucket;
}
@ -76,8 +78,8 @@ grpc_histogram* grpc_histogram_create(double resolution,
double max_bucket_start) {
grpc_histogram* h =
static_cast<grpc_histogram*>(gpr_malloc(sizeof(grpc_histogram)));
GPR_ASSERT(resolution > 0.0);
GPR_ASSERT(max_bucket_start > resolution);
CHECK(resolution > 0.0);
CHECK(max_bucket_start > resolution);
h->sum = 0.0;
h->sum_of_squares = 0.0;
h->multiplier = 1.0 + resolution;
@ -87,8 +89,8 @@ grpc_histogram* grpc_histogram_create(double resolution,
h->min_seen = max_bucket_start;
h->max_seen = 0.0;
h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1;
GPR_ASSERT(h->num_buckets > 1);
GPR_ASSERT(h->num_buckets < 100000000);
CHECK_GT(h->num_buckets, 1u);
CHECK_LT(h->num_buckets, 100000000ul);
h->buckets =
static_cast<uint32_t*>(gpr_zalloc(sizeof(uint32_t) * h->num_buckets));
return h;
@ -129,7 +131,7 @@ void grpc_histogram_merge_contents(grpc_histogram* histogram,
double min_seen, double max_seen, double sum,
double sum_of_squares, double count) {
size_t i;
GPR_ASSERT(histogram->num_buckets == data_count);
CHECK(histogram->num_buckets == data_count);
histogram->sum += sum;
histogram->sum_of_squares += sum_of_squares;
histogram->count += count;
@ -198,7 +200,7 @@ double grpc_histogram_percentile(grpc_histogram* h, double percentile) {
}
double grpc_histogram_mean(grpc_histogram* h) {
GPR_ASSERT(h->count != 0);
CHECK_NE(h->count, 0);
return h->sum / h->count;
}

@ -18,6 +18,7 @@
#include "test/core/util/mock_endpoint.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
@ -153,7 +154,7 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice)) {
void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) {
mock_endpoint* m = reinterpret_cast<mock_endpoint*>(ep);
gpr_mu_lock(&m->mu);
GPR_ASSERT(!m->put_reads_done);
CHECK(!m->put_reads_done);
if (m->on_read != nullptr) {
grpc_slice_buffer_add(m->on_read_out, slice);
grpc_core::ExecCtx::Run(DEBUG_LOCATION, m->on_read, absl::OkStatus());

@ -18,6 +18,8 @@
#include <stdbool.h>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@ -33,7 +35,7 @@ extern bool leak_check;
int main(int argc, char** argv) {
squelch = false;
leak_check = false;
GPR_ASSERT(argc > 1); // Make sure that we have a filename argument
CHECK_GT(argc, 1); // Make sure that we have a filename argument
std::string buffer = grpc_core::testing::GetFileContents(argv[1]);
LLVMFuzzerTestOneInput(buffer.data(), buffer.size());
return 0;

@ -21,6 +21,8 @@
#include <stddef.h>
#include <stdint.h>
#include "absl/log/check.h"
#include <grpc/slice.h>
#include <grpc/support/log.h>
@ -35,7 +37,7 @@ Slice ParseHexstring(absl::string_view hexstring) {
nibbles += (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
}
GPR_ASSERT((nibbles & 1) == 0);
CHECK_EQ((nibbles & 1), 0u);
slice = grpc_slice_malloc(nibbles / 2);
out = GRPC_SLICE_START_PTR(slice);

@ -23,6 +23,8 @@
#include <utility>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -49,7 +51,7 @@ static int free_chosen_port_locked(int port) {
// freed.
for (i = 0; i < num_chosen_ports; i++) {
if (chosen_ports[i] == port) {
GPR_ASSERT(found == 0);
CHECK_EQ(found, 0);
found = 1;
found_at = i;
}
@ -110,7 +112,7 @@ static int grpc_pick_unused_port_or_die_impl(void) {
static void grpc_recycle_unused_port_impl(int port) {
gpr_once_init(&g_default_port_picker_init, init_default_port_picker);
grpc_core::MutexLock lock(g_default_port_picker_mu);
GPR_ASSERT(free_chosen_port_locked(port));
CHECK(free_chosen_port_locked(port));
}
namespace {
@ -131,7 +133,7 @@ void grpc_recycle_unused_port(int port) {
grpc_pick_port_functions grpc_set_pick_port_functions(
grpc_pick_port_functions new_functions) {
GPR_ASSERT(new_functions.pick_unused_port_or_die_fn != nullptr);
GPR_ASSERT(new_functions.recycle_unused_port_fn != nullptr);
CHECK_NE(new_functions.pick_unused_port_or_die_fn, nullptr);
CHECK_NE(new_functions.recycle_unused_port_fn, nullptr);
return std::exchange(functions(), new_functions);
}

@ -24,6 +24,8 @@
//
#include <stdlib.h>
#include "absl/log/check.h"
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
@ -49,7 +51,7 @@ static gpr_atm s_pick_counter = 0;
static int grpc_pick_unused_port_or_die_impl(void) {
int orig_counter_val =
static_cast<int>(gpr_atm_full_fetch_add(&s_pick_counter, 1));
GPR_ASSERT(orig_counter_val < (MAX_PORT - MIN_PORT + 1));
CHECK(orig_counter_val < (MAX_PORT - MIN_PORT + 1));
return MIN_PORT +
(s_initial_offset + orig_counter_val) % (MAX_PORT - MIN_PORT + 1);
}

@ -27,6 +27,7 @@
#include <string>
#include <utility>
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
@ -101,7 +102,7 @@ void grpc_free_port_using_server(int port) {
std::string path = absl::StrFormat("/drop/%d", port);
auto uri = grpc_core::URI::Create("https", GRPC_PORT_SERVER_ADDRESS, path,
{} /* query params */, "" /* fragment */);
GPR_ASSERT(uri.ok());
CHECK_OK(uri);
auto http_request = grpc_core::HttpRequest::Get(
std::move(*uri), nullptr /* channel args */, &pr.pops, &req,
grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(30),
@ -173,7 +174,7 @@ static void got_port_from_server(void* arg, grpc_error_handle error) {
gpr_mu_unlock(pr->mu);
return;
}
GPR_ASSERT(pr->retries < 10);
CHECK(pr->retries < 10);
gpr_sleep_until(gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_millis(
@ -185,7 +186,7 @@ static void got_port_from_server(void* arg, grpc_error_handle error) {
pr->response = {};
auto uri = grpc_core::URI::Create("http", pr->server, "/get",
{} /* query params */, "" /* fragment */);
GPR_ASSERT(uri.ok());
CHECK_OK(uri);
pr->http_request = grpc_core::HttpRequest::Get(
std::move(*uri), nullptr /* channel args */, &pr->pops, &req,
grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(30),
@ -197,13 +198,14 @@ static void got_port_from_server(void* arg, grpc_error_handle error) {
pr->http_request->Start();
return;
}
GPR_ASSERT(response);
GPR_ASSERT(response->status == 200);
CHECK(response);
CHECK_EQ(response->status, 200);
for (i = 0; i < response->body_length; i++) {
GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
CHECK(response->body[i] >= '0');
CHECK(response->body[i] <= '9');
port = port * 10 + response->body[i] - '0';
}
GPR_ASSERT(port > 1024);
CHECK(port > 1024);
gpr_mu_lock(pr->mu);
pr->port = port;
GRPC_LOG_IF_ERROR(
@ -232,7 +234,7 @@ int grpc_pick_port_using_server(void) {
pr.server = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS);
auto uri = grpc_core::URI::Create("http", GRPC_PORT_SERVER_ADDRESS, "/get",
{} /* query params */, "" /* fragment */);
GPR_ASSERT(uri.ok());
CHECK_OK(uri);
auto http_request = grpc_core::HttpRequest::Get(
std::move(*uri), nullptr /* channel args */, &pr.pops, &req,
grpc_core::Timestamp::Now() + grpc_core::Duration::Seconds(30),

@ -21,6 +21,7 @@
#include <memory>
#include <vector>
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@ -41,7 +42,7 @@ gpr_once g_resolve_localhost_ipv46 = GPR_ONCE_INIT;
void InitResolveLocalhost() {
absl::StatusOr<std::vector<grpc_resolved_address>> addresses_or =
GetDNSResolver()->LookupHostnameBlocking("localhost", "https");
GPR_ASSERT(addresses_or.ok());
CHECK_OK(addresses_or);
for (const auto& addr : *addresses_or) {
const grpc_sockaddr* sock_addr =
reinterpret_cast<const grpc_sockaddr*>(&addr);

@ -21,6 +21,7 @@
#include <memory>
#include <string>
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/variant.h"
@ -83,7 +84,7 @@ class ForwardingLoadBalancingPolicy : public LoadBalancingPolicy {
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
Json::FromArray({Json::FromObject(
{{std::string(delegate_->name()), Json::FromObject({})}})}));
GPR_ASSERT(config.ok());
CHECK_OK(config);
args.config = *config;
return delegate_->UpdateLocked(std::move(args));
}
@ -417,7 +418,7 @@ class FixedAddressLoadBalancingPolicy : public ForwardingLoadBalancingPolicy {
EndpointAddressesList addresses;
if (uri.ok()) {
grpc_resolved_address address;
GPR_ASSERT(grpc_parse_uri(*uri, &address));
CHECK(grpc_parse_uri(*uri, &address));
addresses.emplace_back(address, ChannelArgs());
} else {
gpr_log(GPR_ERROR,

@ -23,6 +23,8 @@
#include <algorithm>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -82,11 +84,11 @@ void test_tcp_server_start(test_tcp_server* server, int port) {
&server->shutdown_complete,
grpc_event_engine::experimental::ChannelArgsEndpointConfig(args),
server->on_connect, server->cb_data, &server->tcp_server);
GPR_ASSERT(error.ok());
CHECK_OK(error);
error =
grpc_tcp_server_add_port(server->tcp_server, &resolved_addr, &port_added);
GPR_ASSERT(error.ok());
GPR_ASSERT(port_added == port);
CHECK_OK(error);
CHECK(port_added == port);
grpc_tcp_server_start(server->tcp_server, &server->pollset);
gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port);

@ -17,6 +17,7 @@
#include <stdio.h>
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include <grpc/slice.h>
@ -37,34 +38,33 @@ namespace testing {
TmpFile::TmpFile(absl::string_view data) {
name_ = CreateTmpFileAndWriteData(data);
GPR_ASSERT(!name_.empty());
CHECK(!name_.empty());
}
TmpFile::~TmpFile() { GPR_ASSERT(remove(name_.c_str()) == 0); }
TmpFile::~TmpFile() { CHECK_EQ(remove(name_.c_str()), 0); }
void TmpFile::RewriteFile(absl::string_view data) {
// Create a new file containing new data.
std::string new_name = CreateTmpFileAndWriteData(data);
GPR_ASSERT(!new_name.empty());
CHECK(!new_name.empty());
#ifdef GPR_WINDOWS
// Remove the old file.
// On Windows rename requires that the new name not exist, whereas
// on posix systems rename does an atomic replacement of the new
// name.
GPR_ASSERT(remove(name_.c_str()) == 0);
CHECK_EQ(remove(name_.c_str()), 0);
#endif
// Rename the new file to the original name.
GPR_ASSERT(rename(new_name.c_str(), name_.c_str()) == 0);
CHECK_EQ(rename(new_name.c_str(), name_.c_str()), 0);
}
std::string TmpFile::CreateTmpFileAndWriteData(absl::string_view data) {
char* name = nullptr;
FILE* file_descriptor = gpr_tmpfile("test", &name);
GPR_ASSERT(fwrite(data.data(), 1, data.size(), file_descriptor) ==
data.size());
GPR_ASSERT(fclose(file_descriptor) == 0);
GPR_ASSERT(file_descriptor != nullptr);
GPR_ASSERT(name != nullptr);
CHECK(fwrite(data.data(), 1, data.size(), file_descriptor) == data.size());
CHECK_EQ(fclose(file_descriptor), 0);
CHECK_NE(file_descriptor, nullptr);
CHECK_NE(name, nullptr);
std::string name_to_return = name;
gpr_free(name);
return name_to_return;

Loading…
Cancel
Save