diff options
| author | Jay Conrod <jayconrod@google.com> | 2020-12-17 17:25:42 -0500 |
|---|---|---|
| committer | Jay Conrod <jayconrod@google.com> | 2020-12-23 16:33:50 +0000 |
| commit | a1646595e63cc0bf7f566bb9b657f826cbda22a1 (patch) | |
| tree | 56f50513d0ee0e56fda0125cd38c72bc12ded09a /src/testing/fuzz.go | |
| parent | 3ea342eb2e2f65a02bc84e206a4e7615747df49a (diff) | |
| download | go-a1646595e63cc0bf7f566bb9b657f826cbda22a1.tar.xz | |
[dev.fuzz] cmd/go: implement -fuzztime flag and support cancellation
fuzz.CoordinateFuzzing and RunFuzzWorker now accept a context.Context
parameter. They should terminate gracefully when the context is
cancelled. The worker should exit quickly without processing more
inputs. The coordinator should save interesting inputs to the cache.
The testing package can't import context directly, so it provides a
timeout argument to testdeps.CoordinateFuzzing instead. The testdeps
wrapper sets the timeout and installs an interrupt handler (for SIGINT
on POSIX and the equivalent on Windows) that cancels the context when
^C is pressed.
Note that on POSIX platforms, pressing ^C causes the shell to deliver
SIGINT to all processes in the active group: so 'go test', the
coordinator, and the workers should all react to that. On Windows,
pressing ^C only interrupts 'go test'. We may want to look at that
separately.
Change-Id: I924d3be2905f9685dae82ff3c047ca3d6b5e2357
Reviewed-on: https://go-review.googlesource.com/c/go/+/279487
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Trust: Katie Hockman <katie@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/testing/fuzz.go')
| -rw-r--r-- | src/testing/fuzz.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go index 996e361300..4351704b58 100644 --- a/src/testing/fuzz.go +++ b/src/testing/fuzz.go @@ -16,12 +16,14 @@ import ( func initFuzzFlags() { matchFuzz = flag.String("test.fuzz", "", "run the fuzz target matching `regexp`") + fuzzDuration = flag.Duration("test.fuzztime", 0, "time to spend fuzzing; default (0) is to run indefinitely") fuzzCacheDir = flag.String("test.fuzzcachedir", "", "directory where interesting fuzzing inputs are stored") isFuzzWorker = flag.Bool("test.fuzzworker", false, "coordinate with the parent process to fuzz random values") } var ( matchFuzz *string + fuzzDuration *time.Duration fuzzCacheDir *string isFuzzWorker *bool @@ -136,7 +138,7 @@ func (f *F) Fuzz(ff interface{}) { } corpusTargetDir := filepath.Join(corpusDir, f.name) cacheTargetDir := filepath.Join(*fuzzCacheDir, f.name) - err := f.context.coordinateFuzzing(*parallel, seed, corpusTargetDir, cacheTargetDir) + err := f.context.coordinateFuzzing(*fuzzDuration, *parallel, seed, corpusTargetDir, cacheTargetDir) if err != nil { f.Fail() f.result = FuzzResult{Error: err} @@ -279,7 +281,7 @@ func (r FuzzResult) String() string { type fuzzContext struct { runMatch *matcher fuzzMatch *matcher - coordinateFuzzing func(int, [][]byte, string, string) error + coordinateFuzzing func(time.Duration, int, [][]byte, string, string) error runFuzzWorker func(func([]byte) error) error readCorpus func(string) ([][]byte, error) } |
