forked from jsgilmore/ib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal_test.go
91 lines (81 loc) · 1.58 KB
/
signal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ib
import (
"net"
"sync"
"syscall"
"testing"
"time"
)
// Test if random signals cause infiniband errors. Poll did not check for EINTR and could be interrupted causing errors
// to be returned. Needs -cpu=2 or higher to trigger the issue.
func TestConnWithSignals(t *testing.T) {
for i := 0; i < 10; i++ {
testConnWithSignals(t)
}
}
func testConnWithSignals(t *testing.T) {
stop := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go signalSelf(stop, &wg)
connectReadAndWrite(t)
close(stop)
wg.Wait()
}
func signalSelf(stop chan struct{}, wg *sync.WaitGroup) {
ticker := time.NewTicker(10 * time.Millisecond)
for {
select {
case <-ticker.C:
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
case <-stop:
wg.Done()
return
}
}
}
func connectReadAndWrite(t *testing.T) {
laddr, raddr := chooseInterfaces(t)
sendMr, err := AllocateMemory(benchMrLen)
if err != nil {
panic(err)
}
populateRegion(sendMr)
recvMr, err := AllocateMemory(sendMr.Len())
if err != nil {
panic(err)
}
l, err := ListenRC(raddr)
if err != nil {
panic(err)
}
raddr = l.Addr().(*net.TCPAddr)
ch := make(chan *RCConn)
go func() {
c, err := DialRC(laddr, raddr)
if err != nil {
panic(err)
}
ch <- c
}()
srvc, err := l.Accept()
if err != nil {
panic(err)
}
clic := <-ch
var wg sync.WaitGroup
wg.Add(1)
go benchReader(&wg, srvc, recvMr, 1)
wg.Add(1)
go benchWriter(&wg, clic, sendMr, 1)
wg.Wait()
if err := l.Close(); err != nil {
panic(err)
}
if err := recvMr.Close(); err != nil {
panic(err)
}
if err := sendMr.Close(); err != nil {
panic(err)
}
}