From 15f2cbf43752cd69ba7b00a713f5db82fd535f1f Mon Sep 17 00:00:00 2001 From: Diogo Pinela Date: Sun, 22 Apr 2018 22:48:56 +0100 Subject: testing: allow marking subtest and subbenchmark functions as Helpers Since subtests and subbenchmarks run in a separate goroutine, and thus a separate stack, this entails capturing the stack trace at the point tb.Run is called. The work of getting the file and line information from this stack is only done when needed, however. Continuing the search into the parent test also requires temporarily holding its mutex. Since Run does not hold it while waiting for the subtest to complete, there should be no risk of a deadlock due to this. Fixes #24128 Change-Id: If0bb169f3ac96bd48794624e619ade7edb599f83 Reviewed-on: https://go-review.googlesource.com/108658 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Marcel van Lohuizen --- src/testing/benchmark.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/testing/benchmark.go') diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index ac9ca58397..bef1492cd6 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -506,14 +506,17 @@ func (b *B) Run(name string, f func(b *B)) bool { if !ok { return true } + var pc [maxStackLen]uintptr + n := runtime.Callers(2, pc[:]) sub := &B{ common: common{ - signal: make(chan bool), - name: benchName, - parent: &b.common, - level: b.level + 1, - w: b.w, - chatty: b.chatty, + signal: make(chan bool), + name: benchName, + parent: &b.common, + level: b.level + 1, + creator: pc[:n], + w: b.w, + chatty: b.chatty, }, importPath: b.importPath, benchFunc: f, -- cgit v1.3