@@ -78,16 +78,17 @@ func copyFieldUsingPointersWithConversion[V any](source any, target any, fieldNa
7878
7979// commonPrivateFields is collection of required private fields from testing.common
8080type commonPrivateFields struct {
81- mu * sync.RWMutex
82- output * []byte // Output generated by test or benchmark.
83- level * int
84- name * string // Name of test or benchmark.
85- failed * bool // Test or benchmark has failed.
86- skipped * bool // Test or benchmark has been skipped.
87- parent * unsafe.Pointer // Parent common
88- barrier * chan bool // Barrier for parallel tests
89- signal * chan bool // Signal channel for test completion
90- sub * []* testing.T // Queue of subtests to be run in parallel.
81+ mu * sync.RWMutex
82+ output * []byte // Output generated by test or benchmark.
83+ level * int
84+ name * string // Name of test or benchmark.
85+ failed * bool // Test or benchmark has failed.
86+ skipped * bool // Test or benchmark has been skipped.
87+ isParallel * bool // Whether the test has called testing.T.Parallel.
88+ parent * unsafe.Pointer // Parent common.
89+ barrier * chan bool // Barrier for parallel tests.
90+ signal * chan bool // Signal channel for test completion.
91+ sub * []* testing.T // Queue of subtests to be run in parallel.
9192}
9293
9394// AddLevel increase or decrease the testing.common.level field value, used by
@@ -188,16 +189,17 @@ func getTestPrivateFieldsFast(t *testing.T, layout *testingInternalsLayout) *com
188189 return nil
189190 }
190191 fields := & commonPrivateFields {
191- mu : fieldPtr [sync.RWMutex ](commonBase , layout .common .mu ),
192- output : fieldPtr [[]byte ](commonBase , layout .common .output ),
193- level : fieldPtr [int ](commonBase , layout .common .level ),
194- name : fieldPtr [string ](commonBase , layout .common .name ),
195- failed : fieldPtr [bool ](commonBase , layout .common .failed ),
196- skipped : fieldPtr [bool ](commonBase , layout .common .skipped ),
197- parent : (* unsafe .Pointer )(fieldRawPtr (commonBase , layout .common .parent .unsafeField )),
198- barrier : fieldPtr [chan bool ](commonBase , layout .common .barrier ),
199- signal : fieldPtr [chan bool ](commonBase , layout .common .signal ),
200- sub : fieldPtr [[]* testing.T ](commonBase , layout .common .sub ),
192+ mu : fieldPtr [sync.RWMutex ](commonBase , layout .common .mu ),
193+ output : fieldPtr [[]byte ](commonBase , layout .common .output ),
194+ level : fieldPtr [int ](commonBase , layout .common .level ),
195+ name : fieldPtr [string ](commonBase , layout .common .name ),
196+ failed : fieldPtr [bool ](commonBase , layout .common .failed ),
197+ skipped : fieldPtr [bool ](commonBase , layout .common .skipped ),
198+ isParallel : fieldPtr [bool ](commonBase , layout .common .isParallel ),
199+ parent : (* unsafe .Pointer )(fieldRawPtr (commonBase , layout .common .parent .unsafeField )),
200+ barrier : fieldPtr [chan bool ](commonBase , layout .common .barrier ),
201+ signal : fieldPtr [chan bool ](commonBase , layout .common .signal ),
202+ sub : fieldPtr [[]* testing.T ](commonBase , layout .common .sub ),
201203 }
202204 runtime .KeepAlive (t )
203205 return fields
@@ -227,6 +229,9 @@ func getTestPrivateFieldsReflect(t *testing.T) *commonPrivateFields {
227229 if ptr , err := getFieldPointerFrom (t , "skipped" ); err == nil && ptr != nil {
228230 testFields .skipped = (* bool )(ptr )
229231 }
232+ if ptr , err := getFieldPointerFrom (t , "isParallel" ); err == nil && ptr != nil {
233+ testFields .isParallel = (* bool )(ptr )
234+ }
230235 if ptr , err := getFieldPointerFrom (t , "parent" ); err == nil && ptr != nil {
231236 testFields .parent = (* unsafe .Pointer )(ptr )
232237 }
@@ -243,6 +248,32 @@ func getTestPrivateFieldsReflect(t *testing.T) *commonPrivateFields {
243248 return testFields
244249}
245250
251+ // testingTestState is an opaque handle for testing.testState. The real type is
252+ // private to the standard library; callers must only pass values obtained from
253+ // a *testing.T's private tstate field.
254+ type testingTestState struct {}
255+
256+ // getTestState returns the private testing.testState pointer used by Go's
257+ // parallel-test scheduler. A nil result means this Go runtime layout is not
258+ // supported by the scheduler-slot helper.
259+ func getTestState (t * testing.T ) * testingTestState {
260+ layout := getTestingInternalsLayout ()
261+ if layout != nil && ! layout .disabled && layout .tstate .available {
262+ ptr := fieldRawPtr (unsafe .Pointer (t ), layout .tstate .unsafeField )
263+ if ptr == nil {
264+ return nil
265+ }
266+ state := * (* * testingTestState )(ptr )
267+ runtime .KeepAlive (t )
268+ return state
269+ }
270+
271+ if ptr , err := getFieldPointerFrom (t , "tstate" ); err == nil && ptr != nil {
272+ return * (* * testingTestState )(ptr )
273+ }
274+ return nil
275+ }
276+
246277// getTestParentPrivateFields is a method to retrieve all required parent privates field from
247278// testing.T.parent, returning a commonPrivateFields instance
248279func getTestParentPrivateFields (t * testing.T ) * commonPrivateFields {
0 commit comments