aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2021-06-23 16:23:37 -0700
committerJay Conrod <jayconrod@google.com>2021-06-24 17:45:48 +0000
commitcc04ab463dd6c86ad8d22bbadba4d325fffa2131 (patch)
tree676f7f2a85804950dca1ff0865bae6a43e05e89c /src/testing
parentdf99a270b36fe9f0b8bd43ba05e305fa738d2de6 (diff)
downloadgo-cc04ab463dd6c86ad8d22bbadba4d325fffa2131.tar.gz
go-cc04ab463dd6c86ad8d22bbadba4d325fffa2131.zip
[dev.fuzz] testing: report T.Deadline when running seed values
T.Deadline should return the test deadline, set with -timeout. When fuzz targets are run with seed values as unit tests, either with or without -fuzz, T.Deadline should work inside the fuzz function. There is no deadline when fuzzing, even if -fuzztime is set, since workers may have much shorter deadlines, and fuzz function behavior shouldn't be time-dependent anyway. Fixes #46220 Change-Id: I84aaeb9d7bfdc12bdcb6f1ab3fe67b3067ad2dfe Reviewed-on: https://go-review.googlesource.com/c/go/+/330509 Trust: Jay Conrod <jayconrod@google.com> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/fuzz.go3
-rw-r--r--src/testing/testing.go2
2 files changed, 3 insertions, 2 deletions
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go
index fc1212b142..55e5397193 100644
--- a/src/testing/fuzz.go
+++ b/src/testing/fuzz.go
@@ -491,13 +491,14 @@ type fuzzContext struct {
// runFuzzTargets runs the fuzz targets matching the pattern for -run. This will
// only run the f.Fuzz function for each seed corpus without using the fuzzing
// engine to generate or mutate inputs.
-func runFuzzTargets(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran, ok bool) {
+func runFuzzTargets(deps testDeps, fuzzTargets []InternalFuzzTarget, deadline time.Time) (ran, ok bool) {
ok = true
if len(fuzzTargets) == 0 || *isFuzzWorker {
return ran, ok
}
m := newMatcher(deps.MatchString, *match, "-test.run")
tctx := newTestContext(*parallel, m)
+ tctx.deadline = deadline
fctx := &fuzzContext{
importPath: deps.ImportPath,
readCorpus: deps.ReadCorpus,
diff --git a/src/testing/testing.go b/src/testing/testing.go
index fa92dbb005..581271e748 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1595,7 +1595,7 @@ func (m *M) Run() (code int) {
deadline := m.startAlarm()
haveExamples = len(m.examples) > 0
testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline)
- fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets)
+ fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets, deadline)
exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples)
m.stopAlarm()
if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" {