Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions test/fuzz/halide_fuzz_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "fuzz_helpers.h"

#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <iostream>
Expand All @@ -25,7 +26,7 @@ void print_usage(const char *argv0) {
<< "Options:\n"
<< " -runs=N Number of fuzz iterations (default: 10000)\n"
<< " -timeout=N (ignored, accepted for libFuzzer compatibility)\n"
<< " -max_total_time=N (ignored, accepted for libFuzzer compatibility)\n"
<< " -max_total_time=N Stop after N seconds (0 = unlimited)\n"
<< " -help Print this help message and exit\n"
<< "\n"
<< "If a single non-option argument is given, it is used as the RNG seed.\n"
Expand Down Expand Up @@ -71,6 +72,7 @@ namespace Halide {

int fuzz_main(int argc, char **argv, FuzzFunction main_fn) {
int runs = 10000;
int max_total_time = 0;
FuzzingContext::SeedType explicit_seed = 0;
bool has_explicit_seed = false;

Expand All @@ -94,8 +96,7 @@ int fuzz_main(int argc, char **argv, FuzzFunction main_fn) {
std::cerr << "Warning: -timeout is accepted but ignored.\n";
continue;
}
if (parse_positive_int_flag(body, "max_total_time", &dummy)) {
std::cerr << "Warning: -max_total_time is accepted but ignored.\n";
if (parse_positive_int_flag(body, "max_total_time", &max_total_time)) {
continue;
}
std::cerr << "Error: unknown option '" << argv[i] << "'\n\n";
Expand Down Expand Up @@ -128,7 +129,17 @@ int fuzz_main(int argc, char **argv, FuzzFunction main_fn) {

auto seed_generator = initialize_rng<FuzzingContext::RandomEngine>();

using Clock = std::chrono::steady_clock;
const auto start = Clock::now();

for (int i = 0; i < runs; i++) {
if (max_total_time > 0) {
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(Clock::now() - start).count();
if (elapsed >= max_total_time) {
std::cerr << "Reached -max_total_time=" << max_total_time << "s after " << i << " iterations.\n";
break;
}
}
auto seed = seed_generator();
std::cerr << "Seed: " << seed << "\n"
<< std::flush;
Expand Down
Loading