@@ -23,7 +23,7 @@ import (
23
23
)
24
24
25
25
func TestTraceAnnotations (t * testing.T ) {
26
- testTraceProg (t , "annotations.go" , func (t * testing.T , tb , _ []byte , _ bool ) {
26
+ testTraceProg (t , "annotations.go" , func (t * testing.T , tb , _ []byte , _ string ) {
27
27
type evDesc struct {
28
28
kind trace.EventKind
29
29
task trace.TaskID
@@ -98,7 +98,7 @@ func TestTraceCgoCallback(t *testing.T) {
98
98
}
99
99
100
100
func TestTraceCPUProfile (t * testing.T ) {
101
- testTraceProg (t , "cpu-profile.go" , func (t * testing.T , tb , stderr []byte , _ bool ) {
101
+ testTraceProg (t , "cpu-profile.go" , func (t * testing.T , tb , stderr []byte , _ string ) {
102
102
// Parse stderr which has a CPU profile summary, if everything went well.
103
103
// (If it didn't, we shouldn't even make it here.)
104
104
scanner := bufio .NewScanner (bytes .NewReader (stderr ))
@@ -211,7 +211,7 @@ func TestTraceCPUProfile(t *testing.T) {
211
211
}
212
212
213
213
func TestTraceFutileWakeup (t * testing.T ) {
214
- testTraceProg (t , "futile-wakeup.go" , func (t * testing.T , tb , _ []byte , _ bool ) {
214
+ testTraceProg (t , "futile-wakeup.go" , func (t * testing.T , tb , _ []byte , _ string ) {
215
215
// Check to make sure that no goroutine in the "special" trace region
216
216
// ends up blocking, unblocking, then immediately blocking again.
217
217
//
@@ -312,7 +312,7 @@ func TestTraceGOMAXPROCS(t *testing.T) {
312
312
}
313
313
314
314
func TestTraceStacks (t * testing.T ) {
315
- testTraceProg (t , "stacks.go" , func (t * testing.T , tb , _ []byte , stress bool ) {
315
+ testTraceProg (t , "stacks.go" , func (t * testing.T , tb , _ []byte , godebug string ) {
316
316
type frame struct {
317
317
fn string
318
318
line int
@@ -403,11 +403,19 @@ func TestTraceStacks(t *testing.T) {
403
403
{"runtime.GOMAXPROCS" , 0 },
404
404
{"main.main" , 0 },
405
405
}},
406
- {trace .EventStateTransition , "Goroutine Running->Runnable" , []frame {
406
+ }
407
+ asyncPreemptOff := strings .Contains (godebug , "asyncpreemptoff=1" )
408
+ if asyncPreemptOff {
409
+ // Only check for syncPreemptPoint if asynchronous preemption is disabled.
410
+ // Otherwise, the syncPreemptPoint goroutine might be exclusively async
411
+ // preempted, causing this test to flake.
412
+ syncPreemptEv := evDesc {trace .EventStateTransition , "Goroutine Running->Runnable" , []frame {
407
413
{"main.syncPreemptPoint" , 0 },
408
414
{"main.main.func12" , 0 },
409
- }},
415
+ }}
416
+ want = append (want , syncPreemptEv )
410
417
}
418
+ stress := strings .Contains (godebug , "traceadvanceperiod=0" )
411
419
if ! stress {
412
420
// Only check for this stack if !stress because traceAdvance alone could
413
421
// allocate enough memory to trigger a GC if called frequently enough.
@@ -535,7 +543,7 @@ func TestTraceIterPull(t *testing.T) {
535
543
testTraceProg (t , "iter-pull.go" , nil )
536
544
}
537
545
538
- func checkReaderDeterminism (t * testing.T , tb , _ []byte , _ bool ) {
546
+ func checkReaderDeterminism (t * testing.T , tb , _ []byte , _ string ) {
539
547
events := func () []trace.Event {
540
548
var evs []trace.Event
541
549
@@ -572,7 +580,7 @@ func checkReaderDeterminism(t *testing.T, tb, _ []byte, _ bool) {
572
580
}
573
581
}
574
582
575
- func testTraceProg (t * testing.T , progName string , extra func (t * testing.T , trace , stderr []byte , stress bool )) {
583
+ func testTraceProg (t * testing.T , progName string , extra func (t * testing.T , trace , stderr []byte , godebug string )) {
576
584
testenv .MustHaveGoRun (t )
577
585
578
586
// Check if we're on a builder.
@@ -657,7 +665,7 @@ func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace
657
665
658
666
// Run some extra validation.
659
667
if ! t .Failed () && extra != nil {
660
- extra (t , tb , errBuf .Bytes (), stress )
668
+ extra (t , tb , errBuf .Bytes (), godebug )
661
669
}
662
670
663
671
// Dump some more information on failure.
@@ -686,6 +694,9 @@ func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace
686
694
t .Run ("Default" , func (t * testing.T ) {
687
695
runTest (t , false , "" )
688
696
})
697
+ t .Run ("AsyncPreemptOff" , func (t * testing.T ) {
698
+ runTest (t , false , "asyncpreemptoff=1" )
699
+ })
689
700
t .Run ("Stress" , func (t * testing.T ) {
690
701
if testing .Short () {
691
702
t .Skip ("skipping trace stress tests in short mode" )
0 commit comments