diff options
| author | Jay Conrod <jayconrod@google.com> | 2021-02-26 10:54:11 -0500 |
|---|---|---|
| committer | Jay Conrod <jayconrod@google.com> | 2021-03-09 18:36:29 +0000 |
| commit | f251d1fbb69156627379df28a150343c08a29474 (patch) | |
| tree | b4c993db785b5b504df60b709daecae483255a40 /src/testing | |
| parent | b89483497a7349bb8dba9110e765f5ff1189f69d (diff) | |
| download | go-f251d1fbb69156627379df28a150343c08a29474.tar.xz | |
[dev.fuzz] testing, internal/fuzz: multiple small fixes
* Run gofmt with go1.17 build constraint changes.
* Tighten regular expressions used in tests. "ok" got some false
positives with verbose output, so make sure it appears at the start
of a line.
* Return err in deps.RunFuzzWorker instead of nil.
* Call common.Helper from F methods. This prevents F methods from
appearing in stack traces.
Change-Id: I839c70ec8a9f313c1a4ea68e6bb34a4d801dd36f
Reviewed-on: https://go-review.googlesource.com/c/go/+/297032
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.go | 31 | ||||
| -rw-r--r-- | src/testing/internal/testdeps/deps.go | 2 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go index f670ef4546..1a634dbe8b 100644 --- a/src/testing/fuzz.go +++ b/src/testing/fuzz.go @@ -70,6 +70,7 @@ func (f *F) Cleanup(fn func()) { if f.inFuzzFn { panic("testing: f.Cleanup was called inside the f.Fuzz function") } + f.common.Helper() f.common.Cleanup(fn) } @@ -78,6 +79,7 @@ func (f *F) Error(args ...interface{}) { if f.inFuzzFn { panic("testing: f.Error was called inside the f.Fuzz function") } + f.common.Helper() f.common.Error(args...) } @@ -86,6 +88,7 @@ func (f *F) Errorf(format string, args ...interface{}) { if f.inFuzzFn { panic("testing: f.Errorf was called inside the f.Fuzz function") } + f.common.Helper() f.common.Errorf(format, args...) } @@ -94,6 +97,7 @@ func (f *F) Fail() { if f.inFuzzFn { panic("testing: f.Fail was called inside the f.Fuzz function") } + f.common.Helper() f.common.Fail() } @@ -109,6 +113,7 @@ func (f *F) FailNow() { if f.inFuzzFn { panic("testing: f.FailNow was called inside the f.Fuzz function") } + f.common.Helper() f.common.FailNow() } @@ -117,6 +122,7 @@ func (f *F) Fatal(args ...interface{}) { if f.inFuzzFn { panic("testing: f.Fatal was called inside the f.Fuzz function") } + f.common.Helper() f.common.Fatal(args...) } @@ -125,6 +131,7 @@ func (f *F) Fatalf(format string, args ...interface{}) { if f.inFuzzFn { panic("testing: f.Fatalf was called inside the f.Fuzz function") } + f.common.Helper() f.common.Fatalf(format, args...) } @@ -135,7 +142,25 @@ func (f *F) Helper() { if f.inFuzzFn { panic("testing: f.Helper was called inside the f.Fuzz function") } - f.common.Helper() + + // common.Helper is inlined here. + // If we called it, it would mark F.Helper as the helper + // instead of the caller. + f.mu.Lock() + defer f.mu.Unlock() + if f.helperPCs == nil { + f.helperPCs = make(map[uintptr]struct{}) + } + // repeating code from callerName here to save walking a stack frame + var pc [1]uintptr + n := runtime.Callers(2, pc[:]) // skip runtime.Callers + Helper + if n == 0 { + panic("testing: zero callers found") + } + if _, found := f.helperPCs[pc[0]]; !found { + f.helperPCs[pc[0]] = struct{}{} + f.helperNames = nil // map will be recreated next time it is needed + } } // Skip is equivalent to Log followed by SkipNow. @@ -143,6 +168,7 @@ func (f *F) Skip(args ...interface{}) { if f.inFuzzFn { panic("testing: f.Skip was called inside the f.Fuzz function") } + f.common.Helper() f.common.Skip(args...) } @@ -158,6 +184,7 @@ func (f *F) SkipNow() { if f.inFuzzFn { panic("testing: f.SkipNow was called inside the f.Fuzz function") } + f.common.Helper() f.common.SkipNow() } @@ -166,6 +193,7 @@ func (f *F) Skipf(format string, args ...interface{}) { if f.inFuzzFn { panic("testing: f.Skipf was called inside the f.Fuzz function") } + f.common.Helper() f.common.Skipf(format, args...) } @@ -178,6 +206,7 @@ func (f *F) TempDir() string { if f.inFuzzFn { panic("testing: f.TempDir was called inside the f.Fuzz function") } + f.common.Helper() return f.common.TempDir() } diff --git a/src/testing/internal/testdeps/deps.go b/src/testing/internal/testdeps/deps.go index d5481d6608..8f587b2e1d 100644 --- a/src/testing/internal/testdeps/deps.go +++ b/src/testing/internal/testdeps/deps.go @@ -166,7 +166,7 @@ func (TestDeps) RunFuzzWorker(fn func(fuzz.CorpusEntry) error) error { if err == ctx.Err() { return nil } - return nil + return err } func (TestDeps) ReadCorpus(dir string, types []reflect.Type) ([]fuzz.CorpusEntry, error) { |
