Skip to content

Commit 4567014

Browse files
committed
Merge bitcoin/bitcoin#27672: fuzz: Print error message when FUZZ is missing
fa1b3ab ci: Log qa-assets repo last commit (MarcoFalke) fa22966 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 fa1b3ab Tree-SHA512: 065ef8920449c64b3516f89a61cb397b505eccf531318c4f3830895d5ff6cd7ae2525cb857320481e3d0ed0b2f8a522cd8f7835e69f021241b6ec297a6102fc8
2 parents 09351f5 + fa1b3ab commit 4567014

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

ci/test/06_script_b.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ if [ "$RUN_FUZZ_TESTS" = "true" ]; then
2424
if [ ! -d "$DIR_FUZZ_IN" ]; then
2525
git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"
2626
fi
27+
(
28+
cd "${DIR_QA_ASSETS}"
29+
echo "Using qa-assets repo from commit ..."
30+
git log -1
31+
)
2732
elif [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
2833
export DIR_UNIT_TEST_DATA=${DIR_QA_ASSETS}/unit_test_data/
2934
if [ ! -d "$DIR_UNIT_TEST_DATA" ]; then

src/test/fuzz/fuzz.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515
#include <csignal>
1616
#include <cstdint>
17+
#include <cstdio>
18+
#include <cstdlib>
19+
#include <cstring>
1720
#include <exception>
1821
#include <fstream>
1922
#include <functional>
23+
#include <iostream>
2024
#include <map>
2125
#include <memory>
2226
#include <string>
2327
#include <tuple>
2428
#include <unistd.h>
29+
#include <utility>
2530
#include <vector>
2631

2732
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
@@ -77,13 +82,13 @@ void initialize()
7782
return WrappedGetAddrInfo(name, false);
7883
};
7984

80-
bool should_abort{false};
85+
bool should_exit{false};
8186
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
8287
for (const auto& t : FuzzTargets()) {
8388
if (std::get<2>(t.second)) continue;
8489
std::cout << t.first << std::endl;
8590
}
86-
should_abort = true;
91+
should_exit = true;
8792
}
8893
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
8994
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
@@ -92,13 +97,23 @@ void initialize()
9297
if (std::get<2>(t.second)) continue;
9398
out_stream << t.first << std::endl;
9499
}
95-
should_abort = true;
100+
should_exit= true;
101+
}
102+
if (should_exit){
103+
std::exit(EXIT_SUCCESS);
104+
}
105+
if (const auto* env_fuzz{std::getenv("FUZZ")}) {
106+
// To allow for easier fuzz executable binary modification,
107+
static std::string g_copy{env_fuzz}; // create copy to avoid compiler optimizations, and
108+
g_fuzz_target = g_copy.c_str(); // strip string after the first null-char.
109+
} else {
110+
std::cerr << "Must select fuzz target with the FUZZ env var." << std::endl;
111+
std::cerr << "Hint: Set the PRINT_ALL_FUZZ_TARGETS_AND_ABORT=1 env var to see all compiled targets." << std::endl;
112+
std::exit(EXIT_FAILURE);
96113
}
97-
Assert(!should_abort);
98-
g_fuzz_target = Assert(std::getenv("FUZZ"));
99114
const auto it = FuzzTargets().find(g_fuzz_target);
100115
if (it == FuzzTargets().end()) {
101-
std::cerr << "No fuzzer for " << g_fuzz_target << "." << std::endl;
116+
std::cerr << "No fuzz target compiled for " << g_fuzz_target << "." << std::endl;
102117
std::exit(EXIT_FAILURE);
103118
}
104119
Assert(!g_test_one_input);

src/util/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <tinyformat.h>
99

1010
#include <cstdio>
11-
#include <filesystem>
11+
#include <filesystem> // IWYU pragma: export
1212
#include <functional>
1313
#include <iomanip>
1414
#include <ios>

0 commit comments

Comments
 (0)