MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / main

Function main

src/test/fuzz/fuzz.cpp:227–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225
226#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
227int main(int argc, char** argv)
228{
229 initialize();
230#ifdef __AFL_LOOP
231 // Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
232 // See fuzzing.md for details.
233 const uint8_t* buffer = __AFL_FUZZ_TESTCASE_BUF;
234 while (__AFL_LOOP(100000)) {
235 size_t buffer_len = __AFL_FUZZ_TESTCASE_LEN;
236 test_one_input({buffer, buffer_len});
237 }
238#else
239 std::vector<uint8_t> buffer;
240 if (argc <= 1) {
241 if (!read_stdin(buffer)) {
242 return 0;
243 }
244 test_one_input(buffer);
245 return 0;
246 }
247 std::signal(SIGABRT, signal_handler);
248 const auto start_time{Now<SteadySeconds>()};
249 int tested = 0;
250 for (int i = 1; i < argc; ++i) {
251 fs::path input_path(*(argv + i));
252 if (fs::is_directory(input_path)) {
253 std::vector<fs::path> files;
254 for (fs::directory_iterator it(input_path); it != fs::directory_iterator(); ++it) {
255 if (!fs::is_regular_file(it->path())) continue;
256 files.emplace_back(it->path());
257 }
258 std::ranges::shuffle(files, std::mt19937{std::random_device{}()});
259 for (const auto& input_path : files) {
260 g_input_path = input_path;
261 Assert(read_file(input_path, buffer));
262 test_one_input(buffer);
263 ++tested;
264 buffer.clear();
265 }
266 } else {
267 g_input_path = input_path;
268 Assert(read_file(input_path, buffer));
269 test_one_input(buffer);
270 ++tested;
271 buffer.clear();
272 }
273 }
274 const auto end_time{Now<SteadySeconds>()};
275 std::cout << g_fuzz_target << ": succeeded against " << tested << " files in " << count_seconds(end_time - start_time) << "s." << std::endl;
276#endif
277 return 0;
278}
279#endif

Callers

nothing calls this directly

Calls 9

test_one_inputFunction · 0.85
read_stdinFunction · 0.85
signalClass · 0.85
read_fileFunction · 0.85
count_secondsFunction · 0.85
pathMethod · 0.80
initializeFunction · 0.70
emplace_backMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected