mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-20 22:04:19 +02:00
fuzz: Print error message when FUZZ is missing
Also, add missing includes.
This commit is contained in:
parent
17acb2782a
commit
fa22966f33
@ -14,14 +14,19 @@
|
|||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||||
@ -77,13 +82,13 @@ void initialize()
|
|||||||
return WrappedGetAddrInfo(name, false);
|
return WrappedGetAddrInfo(name, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool should_abort{false};
|
bool should_exit{false};
|
||||||
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
||||||
for (const auto& t : FuzzTargets()) {
|
for (const auto& t : FuzzTargets()) {
|
||||||
if (std::get<2>(t.second)) continue;
|
if (std::get<2>(t.second)) continue;
|
||||||
std::cout << t.first << std::endl;
|
std::cout << t.first << std::endl;
|
||||||
}
|
}
|
||||||
should_abort = true;
|
should_exit = true;
|
||||||
}
|
}
|
||||||
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
|
||||||
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
|
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
|
||||||
@ -92,13 +97,23 @@ void initialize()
|
|||||||
if (std::get<2>(t.second)) continue;
|
if (std::get<2>(t.second)) continue;
|
||||||
out_stream << t.first << std::endl;
|
out_stream << t.first << std::endl;
|
||||||
}
|
}
|
||||||
should_abort = true;
|
should_exit= true;
|
||||||
|
}
|
||||||
|
if (should_exit){
|
||||||
|
std::exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
if (const auto* env_fuzz{std::getenv("FUZZ")}) {
|
||||||
|
// To allow for easier fuzz executable binary modification,
|
||||||
|
static std::string g_copy{env_fuzz}; // create copy to avoid compiler optimizations, and
|
||||||
|
g_fuzz_target = g_copy.c_str(); // strip string after the first null-char.
|
||||||
|
} else {
|
||||||
|
std::cerr << "Must select fuzz target with the FUZZ env var." << std::endl;
|
||||||
|
std::cerr << "Hint: Set the PRINT_ALL_FUZZ_TARGETS_AND_ABORT=1 env var to see all compiled targets." << std::endl;
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
Assert(!should_abort);
|
|
||||||
g_fuzz_target = Assert(std::getenv("FUZZ"));
|
|
||||||
const auto it = FuzzTargets().find(g_fuzz_target);
|
const auto it = FuzzTargets().find(g_fuzz_target);
|
||||||
if (it == FuzzTargets().end()) {
|
if (it == FuzzTargets().end()) {
|
||||||
std::cerr << "No fuzzer for " << g_fuzz_target << "." << std::endl;
|
std::cerr << "No fuzz target compiled for " << g_fuzz_target << "." << std::endl;
|
||||||
std::exit(EXIT_FAILURE);
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
Assert(!g_test_one_input);
|
Assert(!g_test_one_input);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <filesystem>
|
#include <filesystem> // IWYU pragma: export
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user