1 // Copyright 2023 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <grpc/event_engine/event_engine.h> 16 #include <gtest/gtest.h> 17 #include <stdio.h> 18 19 #include "absl/log/check.h" 20 #include "src/core/config/config_vars.h" 21 #include "src/core/lib/event_engine/default_event_engine.h" 22 #include "src/core/lib/experiments/config.h" 23 #include "src/core/util/env.h" 24 #include "src/libfuzzer/libfuzzer_macro.h" 25 #include "test/core/call/yodel/fuzzer.pb.h" 26 #include "test/core/call/yodel/yodel_test.h" 27 #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h" 28 #include "test/core/test_util/fuzz_config_vars.h" 29 #include "test/core/test_util/proto_bit_gen.h" 30 #include "test/core/test_util/test_config.h" 31 32 bool squelch = true; 33 DEFINE_PROTO_FUZZER(const transport_test_suite::Msg & msg)34DEFINE_PROTO_FUZZER(const transport_test_suite::Msg& msg) { 35 grpc_core::g_yodel_fuzzing = true; 36 static const grpc_core::NoDestruct< 37 std::vector<grpc_core::yodel_detail::TestRegistry::Test>> 38 tests{grpc_core::yodel_detail::TestRegistry::AllTests()}; 39 CHECK(!tests->empty()); 40 const int test_id = msg.test_id() % tests->size(); 41 42 if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { 43 grpc_disable_all_absl_logs(); 44 } 45 46 grpc_core::ConfigVars::Overrides overrides = 47 grpc_core::OverridesFromFuzzConfigVars(msg.config_vars()); 48 grpc_core::ConfigVars::SetOverrides(overrides); 49 grpc_core::TestOnlyReloadExperimentsFromConfigVariables(); 50 if (!squelch) { 51 LOG(INFO) << "RUN TEST '" << (*tests)[test_id].name << "'"; 52 } 53 grpc_core::ProtoBitGen bitgen(msg.rng()); 54 auto test = (*tests)[test_id].make(msg.event_engine_actions(), bitgen); 55 test->RunTest(); 56 delete test; 57 CHECK(!::testing::Test::HasFailure()); 58 } 59