Skip to content

Commit 51633d7

Browse files
MarcoFalkeknst
authored andcommitted
Merge 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
1 parent a02a2c0 commit 51633d7

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
@@ -46,13 +46,24 @@ void initialize()
4646
return WrappedGetAddrInfo(name, false);
4747
};
4848

49+
bool should_abort{false};
4950
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
5051
for (const auto& t : FuzzTargets()) {
5152
if (std::get<2>(t.second)) continue;
5253
std::cout << t.first << std::endl;
5354
}
54-
Assert(false);
55+
should_abort = true;
5556
}
57+
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
58+
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
59+
std::ofstream out_stream(out_path, std::ios::binary);
60+
for (const auto& t : FuzzTargets()) {
61+
if (std::get<2>(t.second)) continue;
62+
out_stream << t.first << std::endl;
63+
}
64+
should_abort = true;
65+
}
66+
Assert(!should_abort);
5667
std::string_view fuzz_target{Assert(std::getenv("FUZZ"))};
5768
const auto it = FuzzTargets().find(fuzz_target);
5869
Assert(it != FuzzTargets().end());

0 commit comments

Comments
 (0)