[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log

pull/36833/head
tanvi-jagtap 6 months ago
parent a5ddcaf170
commit 1ed6a862ea
  1. 43
      CMakeLists.txt
  2. 11
      build_autogenerated.yaml
  3. 4
      test/core/call/yodel/fuzzer_main.cc
  4. 4
      test/core/end2end/end2end_test_fuzzer.cc
  5. 5
      test/core/end2end/fuzzers/api_fuzzer.cc
  6. 5
      test/core/end2end/fuzzers/client_fuzzer.cc
  7. 5
      test/core/end2end/fuzzers/server_fuzzer.cc
  8. 6
      test/core/ext/filters/event_engine_client_channel_resolver/resolver_fuzzer.cc
  9. 8
      test/core/nanopb/fuzzer_response.cc
  10. 8
      test/core/nanopb/fuzzer_serverlist.cc
  11. 7
      test/core/resource_quota/memory_quota_fuzzer.cc
  12. 5
      test/core/security/alts_credentials_fuzzer.cc
  13. 7
      test/core/security/ssl_server_fuzzer.cc
  14. 7
      test/core/transport/binder/end2end/fuzzers/client_fuzzer.cc
  15. 7
      test/core/transport/binder/end2end/fuzzers/server_fuzzer.cc
  16. 7
      test/core/transport/chttp2/hpack_parser_fuzzer_test.cc
  17. 7
      test/core/transport/chttp2/hpack_sync_fuzzer.cc
  18. 17
      test/core/util/BUILD
  19. 99
      test/core/util/log_test.cc
  20. 10
      test/cpp/interop/metrics_client.cc
  21. 30
      test/cpp/interop/stress_test.cc
  22. 24
      tools/run_tests/generated/tests.json

43
CMakeLists.txt generated

@ -1212,7 +1212,6 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx lock_free_event_test)
endif()
add_dependencies(buildtests_cxx log_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx log_too_many_open_files_test)
endif()
@ -19643,48 +19642,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
endif()
endif()
if(gRPC_BUILD_TESTS)
add_executable(log_test
test/core/util/log_test.cc
)
if(WIN32 AND MSVC)
if(BUILD_SHARED_LIBS)
target_compile_definitions(log_test
PRIVATE
"GPR_DLL_IMPORTS"
"GRPC_DLL_IMPORTS"
)
endif()
endif()
target_compile_features(log_test PUBLIC cxx_std_14)
target_include_directories(log_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(log_test
${_gRPC_ALLTARGETS_LIBRARIES}
gtest
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)

@ -13615,17 +13615,6 @@ targets:
- linux
- posix
uses_polling: false
- name: log_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/util/log_test.cc
deps:
- gtest
- grpc_test_util
uses_polling: false
- name: log_too_many_open_files_test
gtest: true
build: test

@ -33,7 +33,6 @@
#include "test/core/test_util/proto_bit_gen.h"
bool squelch = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
DEFINE_PROTO_FUZZER(const transport_test_suite::Msg& msg) {
static const grpc_core::NoDestruct<
@ -43,7 +42,8 @@ DEFINE_PROTO_FUZZER(const transport_test_suite::Msg& msg) {
const int test_id = msg.test_id() % tests->size();
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_core::ConfigVars::Overrides overrides =

@ -48,7 +48,6 @@ using ::grpc_event_engine::experimental::FuzzingEventEngine;
using ::grpc_event_engine::experimental::GetDefaultEventEngine;
bool squelch = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
namespace grpc_core {
@ -92,7 +91,8 @@ void RunEnd2endFuzzer(const core_end2end_test_fuzzer::Msg& msg) {
const int test_id = msg.test_id() % tests.size();
if (squelch && !GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
// TODO(ctiller): make this per fixture?

@ -78,8 +78,6 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
////////////////////////////////////////////////////////////////////////////////
// dns resolution
@ -506,7 +504,8 @@ using grpc_core::testing::ApiFuzzer;
DEFINE_PROTO_FUZZER(const api_fuzzer::Msg& msg) {
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_core::ApplyFuzzConfigVars(msg.config_vars());
grpc_core::TestOnlyReloadExperimentsFromConfigVariables();

@ -49,8 +49,6 @@ bool leak_check = true;
static void discard_write(grpc_slice /*slice*/) {}
static void dont_log(gpr_log_func_args* /*args*/) {}
namespace grpc_core {
namespace testing {
@ -101,7 +99,8 @@ class ClientFuzzer final : public BasicFuzzer {
DEFINE_PROTO_FUZZER(const fuzzer_input::Msg& msg) {
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
if (msg.network_input().size() != 1) return;
grpc_core::ApplyFuzzConfigVars(msg.config_vars());

@ -35,8 +35,6 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
namespace grpc_core {
namespace testing {
@ -97,7 +95,8 @@ void RunServerFuzzer(
absl::FunctionRef<void(grpc_server*, int, const ChannelArgs&)>
server_setup) {
if (squelch && !GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
static const int once = []() {
ForceEnableExperiment("event_engine_client", true);

@ -50,7 +50,6 @@
#include "test/core/test_util/fuzzing_channel_args.h"
bool squelch = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
namespace {
@ -254,7 +253,10 @@ grpc_core::ResolverArgs ConstructResolverArgs(
} // namespace
DEFINE_PROTO_FUZZER(const event_engine_client_channel_resolver::Msg& msg) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
bool done_resolving = false;
grpc_core::ApplyFuzzConfigVars(msg.config_vars());
grpc_core::TestOnlyReloadExperimentsFromConfigVariables();

@ -25,12 +25,14 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* /*data*/,
size_t /*size*/) {
grpc_init();
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
// TODO(veblush): Convert this to upb.
//
// grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size);

@ -25,12 +25,14 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* /*data*/,
size_t /*size*/) {
grpc_init();
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
// TODO(veblush): Convert this to upb.
//
// grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size);

@ -187,10 +187,11 @@ class Fuzzer {
} // namespace testing
} // namespace grpc_core
static void dont_log(gpr_log_func_args* /*args*/) {}
DEFINE_PROTO_FUZZER(const memory_quota_fuzzer::Msg& msg) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_core::ApplyFuzzConfigVars(msg.config_vars());
grpc_core::TestOnlyReloadExperimentsFromConfigVariables();
gpr_log_verbosity_init();

@ -42,8 +42,6 @@ using grpc_core::testing::input_stream;
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
// Add a random number of target service accounts to client options.
static void read_target_service_accounts(
input_stream* inp, grpc_alts_credentials_options* options) {
@ -65,7 +63,8 @@ static void read_target_service_accounts(
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
input_stream inp = {data, data + size};
grpc_init();

@ -43,8 +43,6 @@ bool squelch = true;
// Turning this on will fail the leak check.
bool leak_check = false;
static void dont_log(gpr_log_func_args* /*args*/) {}
struct handshake_state {
grpc_core::Notification done_signal;
};
@ -60,7 +58,10 @@ static void on_handshake_done(void* arg, grpc_error_handle error) {
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_init();
{
grpc_core::ExecCtx exec_ctx;

@ -35,10 +35,11 @@ bool leak_check = true;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void dont_log(gpr_log_func_args*) {}
DEFINE_PROTO_FUZZER(const binder_transport_fuzzer::Input& input) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_init();
{
// Copied and modified from grpc/test/core/end2end/fuzzers/client_fuzzer.cc

@ -30,10 +30,11 @@ bool leak_check = true;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static void dont_log(gpr_log_func_args* /*args*/) {}
DEFINE_PROTO_FUZZER(const binder_transport_fuzzer::Input& input) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_init();
{
// Copied and modified from grpc/test/core/end2end/fuzzers/server_fuzzer.cc

@ -50,10 +50,11 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
DEFINE_PROTO_FUZZER(const hpack_parser_fuzzer::Msg& msg) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_core::ProtoBitGen proto_bit_src(msg.random_numbers());
grpc_core::ApplyFuzzConfigVars(msg.config_vars());
grpc_core::TestOnlyReloadExperimentsFromConfigVariables();

@ -52,8 +52,6 @@
bool squelch = true;
bool leak_check = true;
static void dont_log(gpr_log_func_args* /*args*/) {}
namespace grpc_core {
namespace {
@ -170,7 +168,10 @@ void FuzzOneInput(const hpack_sync_fuzzer::Msg& msg) {
} // namespace grpc_core
DEFINE_PROTO_FUZZER(const hpack_sync_fuzzer::Msg& msg) {
if (squelch) gpr_set_log_function(dont_log);
if (squelch) {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
}
grpc_core::ApplyFuzzConfigVars(msg.config_vars());
grpc_core::TestOnlyReloadExperimentsFromConfigVariables();
grpc_core::FuzzOneInput(msg);

@ -60,23 +60,6 @@ grpc_cc_test(
],
)
grpc_cc_test(
name = "log_test",
srcs = ["log_test.cc"],
external_deps = [
"absl/log:check",
"absl/log:log",
"gtest",
],
language = "C++",
uses_event_engine = False,
uses_polling = False,
deps = [
"//:gpr",
"//test/core/test_util:grpc_test_util",
],
)
grpc_cc_test(
name = "spinlock_test",
srcs = ["spinlock_test.cc"],

@ -1,99 +0,0 @@
//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include <string.h>
#include <memory>
#include <gtest/gtest.h>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
#include "test/core/test_util/test_config.h"
static bool log_func_reached = false;
static void test_callback(gpr_log_func_args* args) {
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*/) {
log_func_reached = true;
}
static void test_should_not_log(gpr_log_func_args* /*args*/) {
grpc_core::Crash("unreachable");
}
#define test_log_function_reached(SEVERITY) \
gpr_set_log_function(test_should_log); \
log_func_reached = false; \
gpr_log_message(SEVERITY, "hello 1 2 3"); \
CHECK(log_func_reached); \
log_func_reached = false; \
gpr_log(SEVERITY, "hello %d %d %d", 1, 2, 3); \
CHECK(log_func_reached); \
gpr_set_log_function(nullptr);
#define test_log_function_unreached(SEVERITY) \
gpr_set_log_function(test_should_not_log); \
gpr_log_message(SEVERITY, "hello 1 2 3"); \
gpr_log(SEVERITY, "hello %d %d %d", 1, 2, 3); \
gpr_set_log_function(nullptr);
TEST(LogTest, Basic) {
// test logging at various verbosity levels
gpr_log(GPR_DEBUG, "%s", "hello world");
gpr_log(GPR_INFO, "%s", "hello world");
gpr_log(GPR_ERROR, "%s", "hello world");
// should succeed
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);
gpr_set_log_function(nullptr);
}
TEST(LogTest, LogVerbosity) {
gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
test_log_function_reached(GPR_ERROR);
test_log_function_reached(GPR_INFO);
test_log_function_reached(GPR_DEBUG);
gpr_set_log_verbosity(GPR_LOG_SEVERITY_INFO);
test_log_function_reached(GPR_ERROR);
test_log_function_reached(GPR_INFO);
test_log_function_unreached(GPR_DEBUG);
gpr_set_log_verbosity(GPR_LOG_SEVERITY_ERROR);
test_log_function_reached(GPR_ERROR);
test_log_function_unreached(GPR_INFO);
test_log_function_unreached(GPR_DEBUG);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}

@ -21,6 +21,7 @@
#include "absl/flags/flag.h"
#include <grpc/support/globals.h>
#include <grpc/support/log.h>
#include <grpcpp/grpcpp.h>
@ -44,9 +45,6 @@ using grpc::testing::EmptyMessage;
using grpc::testing::GaugeResponse;
using grpc::testing::MetricsService;
// Do not log anything
void BlackholeLogger(gpr_log_func_args* /*args*/) {}
// Prints the values of all Gauges (unless total_only is set to 'true' in which
// case this only prints the sum of all gauge values).
bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only,
@ -90,10 +88,8 @@ bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only,
int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true);
// The output of metrics client is in some cases programmatically parsed (for
// example by the stress test framework). So, we do not want any of the log
// from the grpc library appearing on stdout.
gpr_set_log_function(BlackholeLogger);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity);
absl::SetVLogLevel("*grpc*/*", -1);
std::shared_ptr<grpc::Channel> channel(
grpc::CreateChannel(absl::GetFlag(FLAGS_metrics_server_address),

@ -93,12 +93,6 @@ ABSL_FLAG(std::string, test_cases, "",
" 'large_unary', 10% of the time and 'empty_stream' the remaining"
" 70% of the time");
ABSL_FLAG(int32_t, log_level, GPR_LOG_SEVERITY_INFO,
"Severity level of messages that should be logged. Any messages "
"greater than or equal to the level set here will be logged. "
"The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 "
"(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR)");
ABSL_FLAG(bool, do_not_abort_on_transient_failures, true,
"If set to 'true', abort() is not called in case of transient "
"failures like temporary connection failures.");
@ -123,15 +117,7 @@ using grpc::testing::transport_security;
using grpc::testing::UNKNOWN_TEST;
using grpc::testing::WeightedRandomTestSelector;
static int log_level = GPR_LOG_SEVERITY_DEBUG;
// A simple wrapper to grp_default_log() function. This only logs messages at or
// above the current log level (set in 'log_level' variable)
void TestLogFunction(gpr_log_func_args* args) {
if (args->severity >= log_level) {
gpr_default_log(args);
}
}
static int log_level = 2;
TestCaseType GetTestTypeFromName(const std::string& test_name) {
TestCaseType test_case = UNKNOWN_TEST;
@ -231,17 +217,11 @@ void LogParameterInfo(const std::vector<std::string>& addresses,
int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true);
if (absl::GetFlag(FLAGS_log_level) > GPR_LOG_SEVERITY_ERROR ||
absl::GetFlag(FLAGS_log_level) < GPR_LOG_SEVERITY_DEBUG) {
LOG(ERROR) << "log_level should be an integer between "
<< GPR_LOG_SEVERITY_DEBUG << " and " << GPR_LOG_SEVERITY_ERROR;
return 1;
}
// Change the default log function to TestLogFunction which respects the
// log_level setting.
log_level = absl::GetFlag(FLAGS_log_level);
gpr_set_log_function(TestLogFunction);
CHECK(-1 <= log_level && log_level <= 10);
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo);
absl::SetVLogLevel("*grpc*/*", log_level);
srand(time(nullptr));

@ -5657,30 +5657,6 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "log_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save