Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT #36457

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions test/core/bad_ssl/bad_ssl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <string>

#include "absl/log/check.h"

#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
Expand Down Expand Up @@ -101,12 +103,12 @@ static void run_test(const char* target, size_t nops) {
op++;
error = grpc_call_start_batch(c, ops, nops, grpc_core::CqVerifier::tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
CHECK_EQ(error, GRPC_CALL_OK);

cqv.Expect(grpc_core::CqVerifier::tag(1), true);
cqv.Verify();

GPR_ASSERT(status != GRPC_STATUS_OK);
CHECK(status != GRPC_STATUS_OK);

grpc_call_unref(c);
grpc_slice_unref(details);
Expand Down
6 changes: 6 additions & 0 deletions test/core/bad_ssl/generate_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def grpc_bad_ssl_tests():
name = "bad_ssl_test_server",
srcs = ["server_common.cc"],
hdrs = ["server_common.h"],
external_deps = [
"absl/log:check",
],
deps = [
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
Expand All @@ -48,6 +51,9 @@ def grpc_bad_ssl_tests():
grpc_cc_test(
name = "bad_ssl_%s_test" % t,
srcs = ["bad_ssl_test.cc"],
external_deps = [
"absl/log:check",
],
data = [
":bad_ssl_%s_server" % t,
"//src/core/tsi/test_creds:badserver.key",
Expand Down
22 changes: 12 additions & 10 deletions test/core/bad_ssl/server_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <signal.h>

#include "absl/log/check.h"

#include <grpc/support/log.h>
#include <grpc/support/time.h>

Expand All @@ -42,7 +44,7 @@ const char* bad_ssl_addr(int argc, char** argv) {
gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
gpr_cmdline_parse(cl, argc, argv);
gpr_cmdline_destroy(cl);
GPR_ASSERT(addr);
CHECK(addr);
return addr;
}

Expand All @@ -67,18 +69,18 @@ void bad_ssl_run(grpc_server* server) {
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq,
reinterpret_cast<void*>(1));
GPR_ASSERT(GRPC_CALL_OK == error);
CHECK_EQ(error, GRPC_CALL_OK);

signal(SIGINT, sigint_handler);
while (!shutdown_finished) {
if (got_sigint && !shutdown_started) {
gpr_log(GPR_INFO, "Shutting down due to SIGINT");
shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
grpc_server_shutdown_and_notify(server, shutdown_cq, nullptr);
GPR_ASSERT(grpc_completion_queue_pluck(
shutdown_cq, nullptr, grpc_timeout_seconds_to_deadline(5),
nullptr)
.type == GRPC_OP_COMPLETE);
CHECK(grpc_completion_queue_pluck(shutdown_cq, nullptr,
grpc_timeout_seconds_to_deadline(5),
nullptr)
.type == GRPC_OP_COMPLETE);
grpc_completion_queue_destroy(shutdown_cq);
grpc_completion_queue_shutdown(cq);
shutdown_started = 1;
Expand All @@ -90,19 +92,19 @@ void bad_ssl_run(grpc_server* server) {
nullptr);
switch (ev.type) {
case GRPC_OP_COMPLETE:
GPR_ASSERT(ev.tag == (void*)1);
GPR_ASSERT(ev.success == 0);
CHECK(ev.tag == (void*)1);
CHECK_EQ(ev.success, 0);
break;
case GRPC_QUEUE_SHUTDOWN:
GPR_ASSERT(shutdown_started);
CHECK(shutdown_started);
shutdown_finished = 1;
break;
case GRPC_QUEUE_TIMEOUT:
break;
}
}

GPR_ASSERT(s == nullptr);
CHECK_EQ(s, nullptr);
grpc_call_details_destroy(&call_details);
grpc_metadata_array_destroy(&request_metadata_recv);
}
6 changes: 4 additions & 2 deletions test/core/bad_ssl/servers/alpn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <string.h>

#include "absl/log/check.h"

#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
Expand Down Expand Up @@ -54,7 +56,7 @@ size_t grpc_chttp2_num_alpn_versions(void) {
}

const char* grpc_chttp2_get_alpn_version_index(size_t i) {
GPR_ASSERT(i < GPR_ARRAY_SIZE(fake_versions));
CHECK(i < GPR_ARRAY_SIZE(fake_versions));
return fake_versions[i];
}

Expand All @@ -72,7 +74,7 @@ int main(int argc, char** argv) {
ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1,
0, nullptr);
server = grpc_server_create(nullptr, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(server, addr, ssl_creds));
CHECK(grpc_server_add_http2_port(server, addr, ssl_creds));
grpc_server_credentials_release(ssl_creds);

bad_ssl_run(server);
Expand Down
4 changes: 3 additions & 1 deletion test/core/bad_ssl/servers/cert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//
//

#include "absl/log/check.h"

#include <grpc/credentials.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
Expand Down Expand Up @@ -47,7 +49,7 @@ int main(int argc, char** argv) {
ssl_creds = grpc_ssl_server_credentials_create(nullptr, &pem_key_cert_pair, 1,
0, nullptr);
server = grpc_server_create(nullptr, nullptr);
GPR_ASSERT(grpc_server_add_http2_port(server, addr, ssl_creds));
CHECK(grpc_server_add_http2_port(server, addr, ssl_creds));
grpc_server_credentials_release(ssl_creds);

bad_ssl_run(server);
Expand Down
6 changes: 5 additions & 1 deletion test/core/channel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ grpc_cc_test(
grpc_cc_test(
name = "channel_args_test",
srcs = ["channel_args_test.cc"],
external_deps = ["gtest"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
uses_event_engine = False,
uses_polling = False,
Expand Down Expand Up @@ -82,6 +85,7 @@ grpc_cc_test(
name = "minimal_stack_is_minimal_test",
srcs = ["minimal_stack_is_minimal_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
Expand Down
31 changes: 15 additions & 16 deletions test/core/channel/channel_args_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <string.h>

#include "absl/log/check.h"
#include "gtest/gtest.h"

#include <grpc/credentials.h>
Expand Down Expand Up @@ -254,15 +255,14 @@ TEST(GrpcChannelArgsTest, Create) {
const_cast<char*>("str value"));
ch_args = grpc_channel_args_copy_and_add(nullptr, to_add, 2);

GPR_ASSERT(ch_args->num_args == 2);
GPR_ASSERT(strcmp(ch_args->args[0].key, to_add[0].key) == 0);
GPR_ASSERT(ch_args->args[0].type == to_add[0].type);
GPR_ASSERT(ch_args->args[0].value.integer == to_add[0].value.integer);
CHECK_EQ(ch_args->num_args, 2);
CHECK_EQ(strcmp(ch_args->args[0].key, to_add[0].key), 0);
CHECK(ch_args->args[0].type == to_add[0].type);
CHECK(ch_args->args[0].value.integer == to_add[0].value.integer);

GPR_ASSERT(strcmp(ch_args->args[1].key, to_add[1].key) == 0);
GPR_ASSERT(ch_args->args[1].type == to_add[1].type);
GPR_ASSERT(strcmp(ch_args->args[1].value.string, to_add[1].value.string) ==
0);
CHECK_EQ(strcmp(ch_args->args[1].key, to_add[1].key), 0);
CHECK(ch_args->args[1].type == to_add[1].type);
CHECK(strcmp(ch_args->args[1].value.string, to_add[1].value.string) == 0);

grpc_channel_args_destroy(ch_args);
}
Expand Down Expand Up @@ -318,19 +318,18 @@ TEST(GrpcChannelArgsTest, ChannelCreateWithArgs) {
grpc_channel_args* mutate_channel_args(const char* target,
grpc_channel_args* old_args,
grpc_channel_stack_type /*type*/) {
GPR_ASSERT(old_args != nullptr);
GPR_ASSERT(grpc_channel_args_find(old_args, "arg_int")->value.integer == 0);
GPR_ASSERT(strcmp(grpc_channel_args_find(old_args, "arg_str")->value.string,
"arg_str_val") == 0);
GPR_ASSERT(
grpc_channel_args_find(old_args, "arg_pointer")->value.pointer.vtable ==
&fake_pointer_arg_vtable);
CHECK_NE(old_args, nullptr);
CHECK_EQ(grpc_channel_args_find(old_args, "arg_int")->value.integer, 0);
CHECK(strcmp(grpc_channel_args_find(old_args, "arg_str")->value.string,
"arg_str_val") == 0);
CHECK(grpc_channel_args_find(old_args, "arg_pointer")->value.pointer.vtable ==
&fake_pointer_arg_vtable);

if (strcmp(target, "no_op_mutator") == 0) {
return old_args;
}

GPR_ASSERT(strcmp(target, "minimal_stack_mutator") == 0);
CHECK_EQ(strcmp(target, "minimal_stack_mutator"), 0);
const char* args_to_remove[] = {"arg_int", "arg_str", "arg_pointer"};

grpc_arg no_deadline_filter_arg = grpc_channel_arg_integer_create(
Expand Down
3 changes: 2 additions & 1 deletion test/core/channel/minimal_stack_is_minimal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <string>
#include <vector>

#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -95,7 +96,7 @@ std::vector<std::string> MakeStack(const char* transport_name,
builder.SetTarget("foo.test.google.fr");
{
grpc_core::ExecCtx exec_ctx;
GPR_ASSERT(grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
CHECK(grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
&builder));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ grpc_proto_fuzzer(
size = "enormous",
srcs = ["resolver_fuzzer.cc"],
corpus = "resolver_fuzzer_corpus",
external_deps = ["absl/log:check"],
language = "C++",
proto = "resolver_fuzzer.proto",
proto_deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "absl/base/thread_annotations.h"
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -240,7 +241,7 @@ grpc_core::ResolverArgs ConstructResolverArgs(
std::shared_ptr<grpc_core::WorkSerializer> work_serializer) {
grpc_core::ResolverArgs resolver_args;
auto uri = grpc_core::URI::Parse("dns:localhost");
GPR_ASSERT(uri.ok());
CHECK(uri.ok());
resolver_args.uri = *uri;
resolver_args.args = channel_args;
resolver_args.pollset_set = nullptr;
Expand Down
1 change: 1 addition & 0 deletions test/core/gpr/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ grpc_cc_test(
name = "log_test",
srcs = ["log_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
Expand Down
14 changes: 8 additions & 6 deletions test/core/gpr/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <gtest/gtest.h>

#include "absl/log/check.h"

#include <grpc/support/log.h>

#include "src/core/lib/gprpp/crash.h"
Expand All @@ -30,9 +32,9 @@
static bool log_func_reached = false;

static void test_callback(gpr_log_func_args* args) {
GPR_ASSERT(0 == strcmp(__FILE__, args->file));
GPR_ASSERT(args->severity == GPR_LOG_SEVERITY_INFO);
GPR_ASSERT(0 == strcmp(args->message, "hello 1 2 3"));
CHECK_EQ(strcmp(__FILE__, args->file), 0);
CHECK(args->severity == GPR_LOG_SEVERITY_INFO);
CHECK_EQ(strcmp(args->message, "hello 1 2 3"), 0);
}

static void test_should_log(gpr_log_func_args* /*args*/) {
Expand All @@ -47,10 +49,10 @@ static void test_should_not_log(gpr_log_func_args* /*args*/) {
gpr_set_log_function(test_should_log); \
log_func_reached = false; \
gpr_log_message(SEVERITY, "hello 1 2 3"); \
GPR_ASSERT(log_func_reached); \
CHECK(log_func_reached); \
log_func_reached = false; \
gpr_log(SEVERITY, "hello %d %d %d", 1, 2, 3); \
GPR_ASSERT(log_func_reached); \
CHECK(log_func_reached); \
gpr_set_log_function(nullptr);

#define test_log_function_unreached(SEVERITY) \
Expand All @@ -65,7 +67,7 @@ TEST(LogTest, Basic) {
gpr_log(GPR_INFO, "%s", "hello world");
gpr_log(GPR_ERROR, "%s", "hello world");
// should succeed
GPR_ASSERT(1);
CHECK(1);
gpr_set_log_function(test_callback);
gpr_log_message(GPR_INFO, "hello 1 2 3");
gpr_log(GPR_INFO, "hello %d %d %d", 1, 2, 3);
Expand Down
3 changes: 3 additions & 0 deletions test/core/gprpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ grpc_cc_test(
name = "dual_ref_counted_test",
srcs = ["dual_ref_counted_test.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
language = "C++",
Expand All @@ -234,6 +235,7 @@ grpc_cc_test(
srcs = ["ref_counted_ptr_test.cc"],
external_deps = [
"absl/container:flat_hash_set",
"absl/log:check",
"gtest",
],
language = "C++",
Expand Down Expand Up @@ -337,6 +339,7 @@ grpc_proto_fuzzer(
name = "chunked_vector_fuzzer",
srcs = ["chunked_vector_fuzzer.cc"],
corpus = "chunked_vector_corpora",
external_deps = ["absl/log:check"],
language = "C++",
proto = "chunked_vector_fuzzer.proto",
tags = ["no_windows"],
Expand Down