Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit 6ff4188

Browse files
committed
sub test and sub benchmark auto instrumentation
1 parent c9a1d3c commit 6ff4188

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

instrumentation/testing/go_benchmark.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
The purpose with this file is to clone the struct alignment of the testing.B struct so we can assign a *testing.B
33
pointer to the *goB to have access to the internal private fields.
44
5-
We use this to create a Run clone method to be called from the subtest auto instrumentation
5+
We use this to create a Run clone method to be called from the sub benchmark auto instrumentation (because the original
6+
method is replaced with the Patch)
67
*/
78

89
package testing

instrumentation/testing/go_testing.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
The purpose with this file is to clone the struct alignment of the testing.T struct so we can assign a *testing.T
33
pointer to the *goT to have access to the internal private fields.
44
5-
We use this to create a Run clone method to be called from the subtest auto instrumentation
5+
We use this to create a Run clone method to be called from the sub test auto instrumentation (because the original
6+
method is replaced with the Patch)
67
*/
78
package testing
89

@@ -61,8 +62,8 @@ const maxStackLen = 50
6162
//go:linkname matchMutex testing.matchMutex
6263
var matchMutex sync.Mutex
6364

64-
//go:linkname goTRunner testing.tRunner
65-
func goTRunner(t *testing.T, fn func(t *testing.T))
65+
//go:linkname tRunner testing.tRunner
66+
func tRunner(t *testing.T, fn func(t *testing.T))
6667

6768
//go:linkname rewrite testing.rewrite
6869
func rewrite(s string) string
@@ -73,14 +74,9 @@ func shouldFailFast() bool
7374
//go:linkname (*goMatcher).fullName testing.(*matcher).fullName
7475
func (m *goMatcher) fullName(c *goCommon, subname string) (name string, ok, partial bool)
7576

76-
// this method calls the original testing.tRunner by converting *goT to *testing.T
77-
func tRunner(t *goT, fn func(t *goT)) {
78-
goTRunner(t.ToTestingT(), func(t *testing.T) { fn(FromTestingT(t)) })
79-
}
80-
8177
// we clone the same (*testing.T).Run implementation because the Patch
8278
// overwrites the original implementation with the jump
83-
func (t *goT) Run(name string, f func(t *goT)) bool {
79+
func (t *goT) Run(name string, f func(t *testing.T)) bool {
8480
atomic.StoreInt32(&t.hasSub, 1)
8581
testName, ok, _ := t.context.match.fullName(&t.goCommon, name)
8682
if !ok || shouldFailFast() {
@@ -110,7 +106,7 @@ func (t *goT) Run(name string, f func(t *goT)) bool {
110106
fmt.Fprintf(root.w, "=== RUN %s\n", t.name)
111107
root.mu.Unlock()
112108
}
113-
go tRunner(t, f)
109+
go tRunner(t.ToTestingT(), f)
114110
if !<-t.signal {
115111
runtime.Goexit()
116112
}

instrumentation/testing/init.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ func Init(m *testing.M) {
7373
_, err := mpatch.PatchMethodByReflect(tRunMethod, func(t *testing.T, name string, f func(t *testing.T)) bool {
7474
pc, _, _, _ := runtime.Caller(1)
7575
gT := FromTestingT(t)
76-
return gT.Run(name, func(childGoT *goT) {
77-
childT := childGoT.ToTestingT()
76+
return gT.Run(name, func(childT *testing.T) {
7877
addAutoInstrumentedTest(childT)
7978
childTest := StartTestFromCaller(childT, pc)
8079
defer childTest.end()

0 commit comments

Comments
 (0)