Skip to content

Commit

Permalink
fix: fuzzing timeout calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
erikburt committed Nov 7, 2024
1 parent 09497d3 commit 9934f37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
26 changes: 15 additions & 11 deletions fuzz/fuzz_all_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import subprocess
import sys
import time

def main():
parser = argparse.ArgumentParser(
Expand All @@ -22,37 +23,40 @@ def main():

# use float for remaining_seconds so we can represent infinity
if args.seconds:
remaining_seconds = float(args.seconds)
total_time = float(args.seconds)
else:
remaining_seconds = float("inf")
total_time = float("inf")

start_time = time.time()
remaining_seconds = total_time

fuzzers = discover_fuzzers(args.go_module_root)
print(f"🐝 Discovered fuzzers:", file=sys.stderr)
for fuzzfn, path in fuzzers.items():
print(f"{fuzzfn} in {path}", file=sys.stderr)

# run forever or until --seconds, with increasingly longer durations per fuzz run
durations_seconds = itertools.chain([5, 10, 30, 90, 270], itertools.repeat(600))
if args.ci:
if env.GITHUB_EVENT_NAME == 'scheduled':
if os.getenv('GITHUB_EVENT_NAME') == 'scheduled':
durations_seconds = [60]
else:
duration_seconds = [45]
else:
# run forever or until --seconds, with increasingly longer durations per fuzz run
durations_seconds = itertools.chain([5, 10, 30, 90, 270], itertools.repeat(600))
durations_seconds = [45]

for duration_seconds in durations_seconds:
print(f"🐝 Running each fuzzer for {duration_seconds}s before switching to next fuzzer", file=sys.stderr)
for fuzzfn, path in fuzzers.items():
elapsed_time = time.time() - start_time
remaining_seconds = total_time - elapsed_time

if remaining_seconds <= 0:
print(f"🐝 Time budget of {args.seconds}s is exhausted. Exiting.", file=sys.stderr)
return

next_duration_seconds = min(remaining_seconds, duration_seconds)
remaining_seconds -= next_duration_seconds

print(f"🐝 Running {fuzzfn} in {path} for {next_duration_seconds}s before switching to next fuzzer", file=sys.stderr)
print(f"🐝 Running {fuzzfn} in {path} for {next_duration_seconds}s (Elapsed: {elapsed_time:.2f}s, Remaining: {remaining_seconds:.2f}s)", file=sys.stderr)
run_fuzzer(fuzzfn, path, next_duration_seconds, args.go_module_root)
print(f"🐝 Completed running {fuzzfn} in {path} for {next_duration_seconds}s. Total remaining time is {remaining_seconds}s", file=sys.stderr)
print(f"🐝 Completed running {fuzzfn} in {path} for {next_duration_seconds}s.", file=sys.stderr)

def discover_fuzzers(go_module_root):
fuzzers = {}
Expand Down
8 changes: 4 additions & 4 deletions tools/bin/go_core_fuzz
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ OUTPUT_FILE=${OUTPUT_FILE:-"./output.txt"}
FUZZ_TIMEOUT_MINUTES=${FUZZ_TIMEOUT_MINUTES:-"6"}

TOTAL_SECONDS=$((FUZZ_TIMEOUT_MINUTES * 60))
if (( TOTAL_SECONDS >= 180 )); then
# Allow for a 120 second buffer between the timeout, and fuzz test runtime
FUZZ_SECONDS=$((TOTAL_SECONDS - 120))
if (( TOTAL_SECONDS >= 60 )); then
# Allow for a 60 second buffer between the timeout, and fuzz test runtime
FUZZ_SECONDS=$((TOTAL_SECONDS - 60))
else
echo "Increase FUZZ_TIMEOUT_MINUTES to >=3, received $FUZZ_TIMEOUT_MINUTES"
echo "Increase FUZZ_TIMEOUT_MINUTES to >=2, received $FUZZ_TIMEOUT_MINUTES"
exit 1
fi

Expand Down

0 comments on commit 9934f37

Please sign in to comment.