aboutsummaryrefslogtreecommitdiff
path: root/src/internal/fuzz/fuzz.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/fuzz/fuzz.go')
-rw-r--r--src/internal/fuzz/fuzz.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/internal/fuzz/fuzz.go b/src/internal/fuzz/fuzz.go
index 8e0425c0c4..293cb48d4d 100644
--- a/src/internal/fuzz/fuzz.go
+++ b/src/internal/fuzz/fuzz.go
@@ -18,6 +18,7 @@ import (
"reflect"
"runtime"
"strings"
+ "time"
)
// CoordinateFuzzing creates several worker processes and communicates with
@@ -27,6 +28,9 @@ import (
// with the same arguments as the coordinator, except with the -test.fuzzworker
// flag prepended to the argument list.
//
+// timeout is the amount of wall clock time to spend fuzzing after the corpus
+// has loaded.
+//
// parallel is the number of worker processes to run in parallel. If parallel
// is 0, CoordinateFuzzing will run GOMAXPROCS workers.
//
@@ -43,7 +47,7 @@ import (
//
// If a crash occurs, the function will return an error containing information
// about the crash, which can be reported to the user.
-func CoordinateFuzzing(ctx context.Context, parallel int, seed []CorpusEntry, types []reflect.Type, corpusDir, cacheDir string) (err error) {
+func CoordinateFuzzing(ctx context.Context, timeout time.Duration, parallel int, seed []CorpusEntry, types []reflect.Type, corpusDir, cacheDir string) (err error) {
if err := ctx.Err(); err != nil {
return err
}
@@ -69,6 +73,12 @@ func CoordinateFuzzing(ctx context.Context, parallel int, seed []CorpusEntry, ty
corpus.entries = append(corpus.entries, CorpusEntry{Data: marshalCorpusFile(vals...), Values: vals})
}
+ if timeout > 0 {
+ var cancel func()
+ ctx, cancel = context.WithTimeout(ctx, timeout)
+ defer cancel()
+ }
+
// TODO(jayconrod): do we want to support fuzzing different binaries?
dir := "" // same as self
binPath := os.Args[0]