Skip to content

Commit 9313c4e

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21874: fuzz: Add WRITE_ALL_FUZZ_TARGETS_AND_ABORT
fa5cb6b fuzz: Add WRITE_ALL_FUZZ_TARGETS_AND_ABORT (MarcoFalke) Pull request description: This is needed when stdout is polluted by the fuzz engine. stderr can't be used instead because it is polluted by aborting the program. Top commit has no ACKs. Tree-SHA512: bf0a2a6bcd964ff1f0f3ef6e7e297b4c780430c4d6312332ed99ace0e1c58243c1483fd387e39405837d39b36072dfeb9ae03d2a7aa728ad6955159754fd5766
2 parents eb9a1fe + fa5cb6b commit 9313c4e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/test/fuzz/fuzz.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,24 @@ static TypeTestOneInput* g_test_one_input{nullptr};
2929

3030
void initialize()
3131
{
32+
bool should_abort{false};
3233
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
3334
for (const auto& t : FuzzTargets()) {
3435
if (std::get<2>(t.second)) continue;
3536
std::cout << t.first << std::endl;
3637
}
37-
Assert(false);
38+
should_abort = true;
3839
}
40+
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
41+
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
42+
std::ofstream out_stream(out_path, std::ios::binary);
43+
for (const auto& t : FuzzTargets()) {
44+
if (std::get<2>(t.second)) continue;
45+
out_stream << t.first << std::endl;
46+
}
47+
should_abort = true;
48+
}
49+
Assert(!should_abort);
3950
std::string_view fuzz_target{Assert(std::getenv("FUZZ"))};
4051
const auto it = FuzzTargets().find(fuzz_target);
4152
Assert(it != FuzzTargets().end());

0 commit comments

Comments
 (0)