Skip to content

Commit

Permalink
Add execution duration flag
Browse files Browse the repository at this point in the history
Add flag for automatic shutdown after a specified duration.

It seems there can be advantages of restarting fuzzing at regular intervals as seen in dvyukov#257

Also it can be useful to run fuzz tests for a short period to check for regressions.

To facilitate this, add a `-duration` parameter. After the fuzzer has been running this duration it will do a regular exit.

This will always exit with code 0. It could make sense to exit with non-zero if there it one or more crashers.
  • Loading branch information
klauspost committed Oct 13, 2019
1 parent fdaa9b1 commit 25bee80
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion go-fuzz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
flagWorkdir = flag.String("workdir", ".", "dir with persistent work data")
flagProcs = flag.Int("procs", runtime.NumCPU(), "parallelism level")
flagTimeout = flag.Int("timeout", 10, "test timeout, in seconds")
flagDuration = flag.String("duration", "", "exit after this duration")
flagMinimize = flag.Duration("minimize", 1*time.Minute, "time limit for input minimization")
flagCoordinator = flag.String("coordinator", "", "coordinator mode (value is coordinator address)")
flagWorker = flag.String("worker", "", "worker mode (value is coordinator address)")
Expand Down Expand Up @@ -57,8 +58,8 @@ func main() {
log.Fatalf("both -http and -worker are specified")
}

c := make(chan os.Signal, 1)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT)
<-c
atomic.StoreUint32(&shutdown, 1)
Expand All @@ -71,6 +72,18 @@ func main() {
os.Exit(0)
}()

if *flagDuration != "" {
d, err := time.ParseDuration(*flagDuration)
if err != nil {
log.Fatalf("unable to parse duration: %v", err)
}
go func() {
<-time.After(d)
log.Print("execution duration reached. starting shutdown...")
c <- syscall.SIGINT
}()
}

runtime.GOMAXPROCS(min(*flagProcs, runtime.NumCPU()))
debug.SetGCPercent(50) // most memory is in large binary blobs
lowerProcessPrio()
Expand Down

0 comments on commit 25bee80

Please sign in to comment.