1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Tests stack symbolization.
22 if err := trace.Start(os.Stdout); err != nil {
23 log.Fatalf("failed to start tracing: %v", err)
25 defer trace.Stop() // in case of early return
27 // Now we will do a bunch of things for which we verify stacks later.
28 // It is impossible to ensure that a goroutine has actually blocked
29 // on a channel, in a select or otherwise. So we kick off goroutines
30 // that need to block first in the hope that while we are executing
31 // the rest of the test, they will block.
43 done1 := make(chan bool)
47 done2 := make(chan bool)
70 cv := sync.NewCond(&sync.Mutex{})
76 ln, err := net.Listen("tcp", "127.0.0.1:0")
78 log.Fatalf("failed to listen: %v", err)
83 log.Printf("failed to accept: %v", err)
88 rp, wp, err := os.Pipe()
90 log.Fatalf("failed to create a pipe: %v", err)
94 pipeReadDone := make(chan bool)
101 time.Sleep(100 * time.Millisecond)
104 time.Sleep(100 * time.Millisecond) // the last chance for the goroutines above to block
114 c, err := net.Dial("tcp", ln.Addr().String())
116 log.Fatalf("failed to dial: %v", err)
123 oldGoMaxProcs := runtime.GOMAXPROCS(0)
124 runtime.GOMAXPROCS(oldGoMaxProcs + 1)
128 runtime.GOMAXPROCS(oldGoMaxProcs)