diff options
author | fanquake <fanquake@gmail.com> | 2023-05-22 11:49:51 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-05-22 12:55:18 +0100 |
commit | 456701420b157f4c02592a2aea6fc32b1620c56a (patch) | |
tree | 0c31995ad971489d1655c99992ff09b866f00be6 /src | |
parent | 09351f51d279612973ecd76811dc075dff08209f (diff) | |
parent | fa1b3abc834a90fb1cfbd5ac63deb28f3990c1fb (diff) | |
download | bitcoin-456701420b157f4c02592a2aea6fc32b1620c56a.tar.xz |
Merge bitcoin/bitcoin#27672: fuzz: Print error message when FUZZ is missing
fa1b3abc834a90fb1cfbd5ac63deb28f3990c1fb ci: Log qa-assets repo last commit (MarcoFalke)
fa22966f3307e22b77ea386e1abb60bf8c606170 fuzz: Print error message when FUZZ is missing (MarcoFalke)
Pull request description:
Some trivial UX improvements.
* Change the exit code for `PRINT_ALL_FUZZ_TARGETS_AND_ABORT` and `WRITE_ALL_FUZZ_TARGETS_AND_ABORT` to `EXIT_SUCCESS` instead of `Aborted (core dumped)`.
* Print readable error message when `FUZZ` is missing instead of `Aborted (core dumped)`.
* Clarify that a fuzz target needs to be compiled into the executable.
ACKs for top commit:
dergoegge:
ACK fa1b3abc834a90fb1cfbd5ac63deb28f3990c1fb
Tree-SHA512: 065ef8920449c64b3516f89a61cb397b505eccf531318c4f3830895d5ff6cd7ae2525cb857320481e3d0ed0b2f8a522cd8f7835e69f021241b6ec297a6102fc8
Diffstat (limited to 'src')
-rw-r--r-- | src/test/fuzz/fuzz.cpp | 27 | ||||
-rw-r--r-- | src/util/fs.h | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 0bbfb206d5..44ba8bc254 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -14,14 +14,19 @@ #include <csignal> #include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <exception> #include <fstream> #include <functional> +#include <iostream> #include <map> #include <memory> #include <string> #include <tuple> #include <unistd.h> +#include <utility> #include <vector> const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; @@ -77,13 +82,13 @@ void initialize() return WrappedGetAddrInfo(name, false); }; - bool should_abort{false}; + bool should_exit{false}; if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) { for (const auto& t : FuzzTargets()) { if (std::get<2>(t.second)) continue; 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")) { 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; 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); 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); } Assert(!g_test_one_input); diff --git a/src/util/fs.h b/src/util/fs.h index 886a30394e..8f79f6cba6 100644 --- a/src/util/fs.h +++ b/src/util/fs.h @@ -8,7 +8,7 @@ #include <tinyformat.h> #include <cstdio> -#include <filesystem> +#include <filesystem> // IWYU pragma: export #include <functional> #include <iomanip> #include <ios> |