From 1dbfd4c9f21c4fcee21df1e7c42ba596ab39aec8 Mon Sep 17 00:00:00 2001 From: Tanvi Jagtap <139093547+tanvi-jagtap@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:11:27 -0700 Subject: [PATCH] [grpc][Gpr_To_Absl_Logging] Deleting multiple instances of gpr_set_log_function (#36833) Deleting multiple instances of gpr_set_log_function . This function will be deleted soon. https://github.com/grpc/proposal/pull/425 Closes #36833 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36833 from tanvi-jagtap:remove_gpr_log_partial_code 17517efee4795eb6e5ff7670252e7329c9cf12d7 PiperOrigin-RevId: 641268299 --- CMakeLists.txt | 43 -------- build_autogenerated.yaml | 11 --- grpc.def | 1 + include/grpc/support/log.h | 3 + src/core/util/log.cc | 5 + src/ruby/ext/grpc/rb_grpc_imports.generated.c | 2 + src/ruby/ext/grpc/rb_grpc_imports.generated.h | 3 + test/core/call/yodel/fuzzer_main.cc | 3 +- test/core/end2end/end2end_test_fuzzer.cc | 3 +- test/core/end2end/fuzzers/api_fuzzer.cc | 4 +- test/core/end2end/fuzzers/client_fuzzer.cc | 4 +- test/core/end2end/fuzzers/server_fuzzer.cc | 4 +- .../resolver_fuzzer.cc | 5 +- test/core/nanopb/fuzzer_response.cc | 7 +- test/core/nanopb/fuzzer_serverlist.cc | 7 +- .../resource_quota/memory_quota_fuzzer.cc | 6 +- test/core/security/alts_credentials_fuzzer.cc | 4 +- test/core/security/ssl_server_fuzzer.cc | 6 +- .../binder/end2end/fuzzers/client_fuzzer.cc | 6 +- .../binder/end2end/fuzzers/server_fuzzer.cc | 6 +- .../chttp2/hpack_parser_fuzzer_test.cc | 6 +- .../transport/chttp2/hpack_sync_fuzzer.cc | 6 +- test/core/util/BUILD | 17 ---- test/core/util/log_test.cc | 99 ------------------- test/cpp/interop/BUILD | 2 + test/cpp/interop/metrics_client.cc | 5 +- test/cpp/interop/stress_test.cc | 58 ++++++----- tools/run_tests/generated/tests.json | 24 ----- 28 files changed, 83 insertions(+), 267 deletions(-) delete mode 100644 test/core/util/log_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 103973737699d..92d752bafb2f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 06418da333688..25a4cf13493c3 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -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 diff --git a/grpc.def b/grpc.def index 154e8eee94dfb..acee3331a7404 100644 --- a/grpc.def +++ b/grpc.def @@ -236,6 +236,7 @@ EXPORTS gpr_log_message gpr_set_log_verbosity gpr_log_verbosity_init + gpr_disable_all_logs gpr_set_log_function gpr_assertion_failed gpr_format_message diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index 2cba30164ff67..1d51ffd9b8505 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -69,6 +69,8 @@ GPRAPI void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print); GPRAPI void gpr_log_verbosity_init(void); +GPRAPI void gpr_disable_all_logs(void); + /** Log overrides: applications can use this API to intercept logging calls and use their own implementations */ @@ -82,6 +84,7 @@ struct gpr_log_func_args { typedef struct gpr_log_func_args gpr_log_func_args; typedef void (*gpr_log_func)(gpr_log_func_args* args); + GPRAPI void gpr_set_log_function(gpr_log_func func); GPRAPI void gpr_assertion_failed(const char* filename, int line, diff --git a/src/core/util/log.cc b/src/core/util/log.cc index 58ba0562c0001..484bb7feb032a 100644 --- a/src/core/util/log.cc +++ b/src/core/util/log.cc @@ -187,3 +187,8 @@ void gpr_log_verbosity_init() { void gpr_set_log_function(gpr_log_func f) { gpr_atm_no_barrier_store(&g_log_func, (gpr_atm)(f ? f : gpr_default_log)); } + +void gpr_disable_all_logs() { + absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfinity); + absl::SetVLogLevel("*grpc*/*", -1); +} diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index e4607ce6d00d6..664a8f0148201 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -259,6 +259,7 @@ gpr_should_log_type gpr_should_log_import; gpr_log_message_type gpr_log_message_import; gpr_set_log_verbosity_type gpr_set_log_verbosity_import; gpr_log_verbosity_init_type gpr_log_verbosity_init_import; +gpr_disable_all_logs_type gpr_disable_all_logs_import; gpr_set_log_function_type gpr_set_log_function_import; gpr_assertion_failed_type gpr_assertion_failed_import; gpr_format_message_type gpr_format_message_import; @@ -549,6 +550,7 @@ void grpc_rb_load_imports(HMODULE library) { gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity"); gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init"); + gpr_disable_all_logs_import = (gpr_disable_all_logs_type) GetProcAddress(library, "gpr_disable_all_logs"); gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function"); gpr_assertion_failed_import = (gpr_assertion_failed_type) GetProcAddress(library, "gpr_assertion_failed"); gpr_format_message_import = (gpr_format_message_type) GetProcAddress(library, "gpr_format_message"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 42fb67dface15..3b3b401a257d2 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -753,6 +753,9 @@ extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import; typedef void(*gpr_log_verbosity_init_type)(void); extern gpr_log_verbosity_init_type gpr_log_verbosity_init_import; #define gpr_log_verbosity_init gpr_log_verbosity_init_import +typedef void(*gpr_disable_all_logs_type)(void); +extern gpr_disable_all_logs_type gpr_disable_all_logs_import; +#define gpr_disable_all_logs gpr_disable_all_logs_import typedef void(*gpr_set_log_function_type)(gpr_log_func func); extern gpr_set_log_function_type gpr_set_log_function_import; #define gpr_set_log_function gpr_set_log_function_import diff --git a/test/core/call/yodel/fuzzer_main.cc b/test/core/call/yodel/fuzzer_main.cc index 8eb9502a9638d..96c3917a36015 100644 --- a/test/core/call/yodel/fuzzer_main.cc +++ b/test/core/call/yodel/fuzzer_main.cc @@ -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,7 @@ 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); + gpr_disable_all_logs(); } grpc_core::ConfigVars::Overrides overrides = diff --git a/test/core/end2end/end2end_test_fuzzer.cc b/test/core/end2end/end2end_test_fuzzer.cc index 0df0feda71c28..be79482d7e2a6 100644 --- a/test/core/end2end/end2end_test_fuzzer.cc +++ b/test/core/end2end/end2end_test_fuzzer.cc @@ -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,7 @@ 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); + gpr_disable_all_logs(); } // TODO(ctiller): make this per fixture? diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index b3fde2b995472..02f296ec19f08 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -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,7 @@ 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); + gpr_disable_all_logs(); } grpc_core::ApplyFuzzConfigVars(msg.config_vars()); grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); diff --git a/test/core/end2end/fuzzers/client_fuzzer.cc b/test/core/end2end/fuzzers/client_fuzzer.cc index defc274c1f39c..eb20355a31a89 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/end2end/fuzzers/client_fuzzer.cc @@ -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,7 @@ 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); + gpr_disable_all_logs(); } if (msg.network_input().size() != 1) return; grpc_core::ApplyFuzzConfigVars(msg.config_vars()); diff --git a/test/core/end2end/fuzzers/server_fuzzer.cc b/test/core/end2end/fuzzers/server_fuzzer.cc index c151c8b30b80c..3e310fa6cee90 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/end2end/fuzzers/server_fuzzer.cc @@ -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,7 @@ void RunServerFuzzer( absl::FunctionRef server_setup) { if (squelch && !GetEnv("GRPC_TRACE_FUZZER").has_value()) { - gpr_set_log_function(dont_log); + gpr_disable_all_logs(); } static const int once = []() { ForceEnableExperiment("event_engine_client", true); diff --git a/test/core/ext/filters/event_engine_client_channel_resolver/resolver_fuzzer.cc b/test/core/ext/filters/event_engine_client_channel_resolver/resolver_fuzzer.cc index e0b3b3f7c5645..ed7d60e33975f 100644 --- a/test/core/ext/filters/event_engine_client_channel_resolver/resolver_fuzzer.cc +++ b/test/core/ext/filters/event_engine_client_channel_resolver/resolver_fuzzer.cc @@ -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,9 @@ 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) { + gpr_disable_all_logs(); + } bool done_resolving = false; grpc_core::ApplyFuzzConfigVars(msg.config_vars()); grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); diff --git a/test/core/nanopb/fuzzer_response.cc b/test/core/nanopb/fuzzer_response.cc index 72d72039396ac..93537339e3a18 100644 --- a/test/core/nanopb/fuzzer_response.cc +++ b/test/core/nanopb/fuzzer_response.cc @@ -25,12 +25,13 @@ 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) { + gpr_disable_all_logs(); + } + // TODO(veblush): Convert this to upb. // // grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); diff --git a/test/core/nanopb/fuzzer_serverlist.cc b/test/core/nanopb/fuzzer_serverlist.cc index 5d36655a9723f..8f83c0a32a11d 100644 --- a/test/core/nanopb/fuzzer_serverlist.cc +++ b/test/core/nanopb/fuzzer_serverlist.cc @@ -25,12 +25,13 @@ 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) { + gpr_disable_all_logs(); + } + // TODO(veblush): Convert this to upb. // // grpc_slice slice = grpc_slice_from_copied_buffer((const char*)data, size); diff --git a/test/core/resource_quota/memory_quota_fuzzer.cc b/test/core/resource_quota/memory_quota_fuzzer.cc index 912e3508065a1..6c3a1f4badbc6 100644 --- a/test/core/resource_quota/memory_quota_fuzzer.cc +++ b/test/core/resource_quota/memory_quota_fuzzer.cc @@ -187,10 +187,10 @@ 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) { + gpr_disable_all_logs(); + } grpc_core::ApplyFuzzConfigVars(msg.config_vars()); grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); gpr_log_verbosity_init(); diff --git a/test/core/security/alts_credentials_fuzzer.cc b/test/core/security/alts_credentials_fuzzer.cc index 4ad08a367ba4f..2d01d66012c94 100644 --- a/test/core/security/alts_credentials_fuzzer.cc +++ b/test/core/security/alts_credentials_fuzzer.cc @@ -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,7 @@ 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); + gpr_disable_all_logs(); } input_stream inp = {data, data + size}; grpc_init(); diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc index d5310112c90b1..a7498f6d7cd0e 100644 --- a/test/core/security/ssl_server_fuzzer.cc +++ b/test/core/security/ssl_server_fuzzer.cc @@ -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,9 @@ 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) { + gpr_disable_all_logs(); + } grpc_init(); { grpc_core::ExecCtx exec_ctx; diff --git a/test/core/transport/binder/end2end/fuzzers/client_fuzzer.cc b/test/core/transport/binder/end2end/fuzzers/client_fuzzer.cc index fb194663f5825..a5fa9905d81b4 100644 --- a/test/core/transport/binder/end2end/fuzzers/client_fuzzer.cc +++ b/test/core/transport/binder/end2end/fuzzers/client_fuzzer.cc @@ -35,10 +35,10 @@ bool leak_check = true; static void* tag(intptr_t t) { return reinterpret_cast(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) { + gpr_disable_all_logs(); + } grpc_init(); { // Copied and modified from grpc/test/core/end2end/fuzzers/client_fuzzer.cc diff --git a/test/core/transport/binder/end2end/fuzzers/server_fuzzer.cc b/test/core/transport/binder/end2end/fuzzers/server_fuzzer.cc index 68996f1020fbc..38bc3add000e7 100644 --- a/test/core/transport/binder/end2end/fuzzers/server_fuzzer.cc +++ b/test/core/transport/binder/end2end/fuzzers/server_fuzzer.cc @@ -30,10 +30,10 @@ bool leak_check = true; static void* tag(intptr_t t) { return reinterpret_cast(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) { + gpr_disable_all_logs(); + } grpc_init(); { // Copied and modified from grpc/test/core/end2end/fuzzers/server_fuzzer.cc diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index 1b21b22893537..61dfc6a43ad02 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -50,10 +50,10 @@ 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) { + gpr_disable_all_logs(); + } grpc_core::ProtoBitGen proto_bit_src(msg.random_numbers()); grpc_core::ApplyFuzzConfigVars(msg.config_vars()); grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); diff --git a/test/core/transport/chttp2/hpack_sync_fuzzer.cc b/test/core/transport/chttp2/hpack_sync_fuzzer.cc index 230ddc8a5cb56..b79953a780564 100644 --- a/test/core/transport/chttp2/hpack_sync_fuzzer.cc +++ b/test/core/transport/chttp2/hpack_sync_fuzzer.cc @@ -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,9 @@ 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) { + gpr_disable_all_logs(); + } grpc_core::ApplyFuzzConfigVars(msg.config_vars()); grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); grpc_core::FuzzOneInput(msg); diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 728ef6bd167f7..8337de838eb16 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -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"], diff --git a/test/core/util/log_test.cc b/test/core/util/log_test.cc deleted file mode 100644 index fa39d2c28edba..0000000000000 --- a/test/core/util/log_test.cc +++ /dev/null @@ -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 - -#include - -#include - -#include "absl/log/check.h" - -#include - -#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; -} diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 21d86d049710e..28624783556a4 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -206,6 +206,8 @@ grpc_cc_binary( external_deps = [ "absl/flags:flag", "absl/log:check", + "absl/log:globals", + "absl/log:log", ], deps = [ ":client_helper_lib", diff --git a/test/cpp/interop/metrics_client.cc b/test/cpp/interop/metrics_client.cc index 853c04a9c17c8..739764db17ed1 100644 --- a/test/cpp/interop/metrics_client.cc +++ b/test/cpp/interop/metrics_client.cc @@ -44,9 +44,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 stub, bool total_only, @@ -93,7 +90,7 @@ int main(int argc, char** argv) { // 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); + gpr_disable_all_logs(); std::shared_ptr channel( grpc::CreateChannel(absl::GetFlag(FLAGS_metrics_server_address), diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index b37c608a369e5..9dc306cdba8f6 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -16,6 +16,8 @@ // is % allowed in string // +#include + #include #include #include @@ -24,6 +26,7 @@ #include "absl/flags/flag.h" #include "absl/log/check.h" +#include "absl/log/globals.h" #include "absl/log/log.h" #include @@ -93,11 +96,14 @@ 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( + int32_t, absl_min_log_level, + static_cast(absl::LogSeverityAtLeast::kInfo), + "Severity level of messages that should be logged by absl::SetMinLogLevel"); + +ABSL_FLAG(int32_t, absl_vlog_level, -1, + "Severity level of messages that should be logged. Set using " + "absl::SetVLogLevel"); ABSL_FLAG(bool, do_not_abort_on_transient_failures, true, "If set to 'true', abort() is not called in case of transient " @@ -123,15 +129,9 @@ 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 absl_vlog_level = -1; +static absl::LogSeverityAtLeast absl_min_log_level = + absl::LogSeverityAtLeast::kInfo; TestCaseType GetTestTypeFromName(const std::string& test_name) { TestCaseType test_case = UNKNOWN_TEST; @@ -208,7 +208,9 @@ void LogParameterInfo(const std::vector& addresses, << absl::GetFlag(FLAGS_num_channels_per_server); LOG(INFO) << "num_stubs_per_channel: " << absl::GetFlag(FLAGS_num_stubs_per_channel); - LOG(INFO) << "log_level: " << absl::GetFlag(FLAGS_log_level); + LOG(INFO) << "absl_vlog_level: " << absl::GetFlag(FLAGS_absl_vlog_level); + LOG(INFO) << "absl_min_log_level: " + << absl::GetFlag(FLAGS_absl_min_log_level); LOG(INFO) << "do_not_abort_on_transient_failures: " << (absl::GetFlag(FLAGS_do_not_abort_on_transient_failures) ? "true" @@ -228,21 +230,23 @@ void LogParameterInfo(const std::vector& addresses, } } +void SetLogLevels() { + absl_vlog_level = absl::GetFlag(FLAGS_absl_vlog_level); + CHECK_LE(-1, absl_vlog_level); + CHECK_LE(absl_vlog_level, (INT_MAX - 1)); + absl::SetVLogLevel("*grpc*/*", absl_vlog_level); + + absl_min_log_level = static_cast( + absl::GetFlag(FLAGS_absl_min_log_level)); + CHECK_LE(absl::LogSeverityAtLeast::kInfo, absl_min_log_level); + CHECK_LE(absl_min_log_level, absl::LogSeverityAtLeast::kInfinity); + absl::SetMinLogLevel(absl_min_log_level); +} + 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); - + SetLogLevels(); srand(time(nullptr)); // Parse the server addresses diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 1be46fa624c12..ff41de58ef879 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -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,