...
Source file
src/runtime/runtime_unix_test.go
Documentation: runtime
1
2
3
4
5
6
7
8
9
10
11 package runtime_test
12
13 import (
14 "runtime"
15 "sync"
16 "sync/atomic"
17 "syscall"
18 "testing"
19 )
20
21 func TestGoroutineProfile(t *testing.T) {
22
23
24
25 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(100))
26
27 var stop uint32
28 defer atomic.StoreUint32(&stop, 1)
29
30 var wg sync.WaitGroup
31 for i := 0; i < 4; i++ {
32 wg.Add(1)
33 go func() {
34 for atomic.LoadUint32(&stop) == 0 {
35 syscall.Close(-1)
36 }
37 wg.Done()
38 }()
39 }
40
41 max := 10000
42 if testing.Short() {
43 max = 100
44 }
45 stk := make([]runtime.StackRecord, 128)
46 for n := 0; n < max; n++ {
47 _, ok := runtime.GoroutineProfile(stk)
48 if !ok {
49 t.Fatalf("GoroutineProfile failed")
50 }
51 }
52
53
54 atomic.StoreUint32(&stop, 1)
55 wg.Wait()
56 }
57
View as plain text