aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2021-05-19 11:43:58 -0700
committerRoland Shoemaker <roland@golang.org>2021-05-27 02:14:18 +0000
commit5fcd18bc9bd89bad5270434f99d40e820affbd82 (patch)
tree10df22a9eba3f771c7f4a3d8d27b18b11c011264 /src/testing/testing.go
parentff0164cf736b12740bf5837111e93130da6d612c (diff)
downloadgo-5fcd18bc9bd89bad5270434f99d40e820affbd82.tar.xz
[dev.fuzz] internal/fuzz,testing: treat panics as recoverable
And only log the last panic, not all of them, during minimization. This change makes the worker processes quiet, so now the only process that logs anything is the coordinator. This hides all of the panics caused during minimization of an input which causes a panic. This change also alters the usage of tRunner such that we now recover from recoverable panics instead of terminating the process. This results in larger stack traces, since we include a bit more of the trace within testing. There is a TODO to see if it's possible to slice the stack up so that it is somewhat more informative. Change-Id: Ic85eabd2e70b078412fbb88adf424a8da25af876 Reviewed-on: https://go-review.googlesource.com/c/go/+/321230 Trust: Roland Shoemaker <roland@golang.org> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 07ef625538..82b422a414 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -448,6 +448,7 @@ type common struct {
chatty *chattyPrinter // A copy of chattyPrinter, if the chatty flag is set.
bench bool // Whether the current test is a benchmark.
+ fuzzing bool // Whether the current test is a fuzzing target.
hasSub int32 // Written atomically.
raceErrors int // Number of races detected during test.
runner string // Function name of tRunner running the test.
@@ -655,6 +656,20 @@ func (c *common) flushToParent(testName, format string, args ...interface{}) {
}
}
+// isFuzzing returns whether the current context, or any of the parent contexts,
+// are a fuzzing target
+func (c *common) isFuzzing() bool {
+ if c.fuzzing {
+ return true
+ }
+ for parent := c.parent; parent != nil; parent = parent.parent {
+ if parent.fuzzing {
+ return true
+ }
+ }
+ return false
+}
+
type indenter struct {
c *common
}
@@ -1221,10 +1236,11 @@ func tRunner(t *T, fn func(t *T)) {
// complete even if a cleanup function calls t.FailNow. See issue 41355.
didPanic := false
defer func() {
- if didPanic {
+ isFuzzing := t.common.isFuzzing()
+ if didPanic && !isFuzzing {
return
}
- if err != nil {
+ if err != nil && !isFuzzing {
panic(err)
}
// Only report that the test is complete if it doesn't panic,
@@ -1250,6 +1266,12 @@ func tRunner(t *T, fn func(t *T)) {
}
}
didPanic = true
+ if t.common.fuzzing {
+ for root := &t.common; root.parent != nil; root = root.parent {
+ fmt.Fprintf(root.parent.w, "panic: %s\n%s\n", err, string(debug.Stack()))
+ }
+ return
+ }
panic(err)
}
if err != nil {