36#if defined(PROVIDE_FUZZ_MAIN_FUNCTION) && defined(__AFL_FUZZ_INIT)
49static std::vector<const char*>
g_args;
52 for (
int i = 1; i <
argc; ++i) {
120 if (std::getenv(
"PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
122 if (
t.opts.hidden)
continue;
123 std::cout <<
name << std::endl;
127 if (
const char*
out_path = std::getenv(
"WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
128 std::cout <<
"Writing all fuzz target names to '" <<
out_path <<
"'." << std::endl;
131 if (
t.opts.hidden)
continue;
139 if (
const auto*
env_fuzz{std::getenv(
"FUZZ")}) {
144 std::cerr <<
"Must select fuzz target with the FUZZ env var." << std::endl;
145 std::cerr <<
"Hint: Set the PRINT_ALL_FUZZ_TARGETS_AND_ABORT=1 env var to see all compiled targets." << std::endl;
150 std::cerr <<
"No fuzz target compiled for " <<
g_fuzz_target <<
"." << std::endl;
154 std::cerr <<
"Must compile with -DBUILD_FOR_FUZZING=ON or in Debug mode to execute a fuzz target." << std::endl;
158 if (std::getenv(
"FUZZ_NONDETERMINISM")) {
159 std::cerr <<
"Warning: FUZZ_NONDETERMINISM env var set, results may be inconsistent with fuzz build" << std::endl;
167 it->second.opts.init();
172#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
173static bool read_stdin(std::vector<uint8_t>& data)
175 std::istream::char_type buffer[1024];
176 std::streamsize length;
177 while ((std::cin.read(buffer, 1024), length = std::cin.
gcount()) > 0) {
178 data.insert(
data.end(), buffer, buffer + length);
184#if defined(PROVIDE_FUZZ_MAIN_FUNCTION) && !defined(__AFL_LOOP)
185static bool read_file(fs::path
p, std::vector<uint8_t>& data)
189 if (
f ==
nullptr)
return false;
191 const size_t length =
fread(buffer,
sizeof(
uint8_t),
sizeof(buffer),
f);
193 data.insert(
data.end(), buffer, buffer + length);
200#if defined(PROVIDE_FUZZ_MAIN_FUNCTION) && !defined(__AFL_LOOP)
205 std::cerr <<
"Error processing input " <<
g_input_path << std::endl;
207 std::cerr <<
"Unexpected signal " <<
signal <<
" received\n";
228#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
241 std::vector<uint8_t> buffer;
252 for (
int i = 1; i <
argc; ++i) {
255 std::vector<fs::path>
files;
256 for (fs::directory_iterator it(
input_path); it != fs::directory_iterator(); ++it) {
257 if (!fs::is_regular_file(it->path()))
continue;
258 files.emplace_back(it->path());
260 std::ranges::shuffle(
files, std::mt19937{std::random_device{}()});
std::atomic< bool > g_enable_dynamic_fuzz_determinism
bool EnableFuzzDeterminism()
#define Assert(val)
Identity function.
constexpr bool G_ABORT_ON_FAILED_ASSUME
constexpr bool G_FUZZING_BUILD
void ResetCoverageCounters()
static void test_one_input(FuzzBufferType buffer)
void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts)
static const TypeTestOneInput * g_test_one_input
static void SetArgs(int argc, char **argv)
const std::function< std::vector< const char * >()> G_TEST_COMMAND_LINE_ARGUMENTS
Retrieve the command line arguments.
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
int LLVMFuzzerInitialize(int *argc, char ***argv)
const std::function< void(const std::string &) G_TEST_LOG_FUN)
This is connected to the logger.
static std::string_view g_fuzz_target
static std::vector< const char * > g_args
A copy of the command line arguments that start with --.
const std::function< std::string()> G_TEST_GET_FULL_NAME
Retrieve the unit test name.
std::span< const uint8_t > FuzzBufferType
std::function< void(FuzzBufferType)> TypeTestOneInput
FILE * fopen(const fs::path &p, const char *mode)
std::function< std::unique_ptr< Sock >(int, int, int)> CreateSock
Socket factory.
std::vector< CNetAddr > WrappedGetAddrInfo(const std::string &name, bool allow_lookup)
Wrapper for getaddrinfo(3).
const TypeTestOneInput test_one_input
const FuzzTargetOptions opts
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
constexpr int64_t count_seconds(std::chrono::seconds t)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.