(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestPollMod(t *testing.T) { |
| 55 | var rn, wn, hn int32 |
| 56 | read := func(p Poll) error { |
| 57 | atomic.AddInt32(&rn, 1) |
| 58 | return nil |
| 59 | } |
| 60 | write := func(p Poll) error { |
| 61 | atomic.AddInt32(&wn, 1) |
| 62 | return nil |
| 63 | } |
| 64 | hup := func(p Poll) error { |
| 65 | atomic.AddInt32(&hn, 1) |
| 66 | return nil |
| 67 | } |
| 68 | stop := make(chan error) |
| 69 | p, err := openDefaultPoll() |
| 70 | MustNil(t, err) |
| 71 | go func() { |
| 72 | stop <- p.Wait() |
| 73 | }() |
| 74 | |
| 75 | rfd, wfd := GetSysFdPairs() |
| 76 | rop := &FDOperator{FD: rfd, OnRead: read, OnWrite: write, OnHup: hup, poll: p} |
| 77 | wop := &FDOperator{FD: wfd, OnRead: read, OnWrite: write, OnHup: hup, poll: p} |
| 78 | var r, w, h int32 |
| 79 | r, w, h = atomic.LoadInt32(&rn), atomic.LoadInt32(&wn), atomic.LoadInt32(&hn) |
| 80 | Assert(t, r == 0 && w == 0 && h == 0, r, w, h) |
| 81 | err = p.Control(rop, PollReadable) |
| 82 | MustNil(t, err) |
| 83 | r, w, h = atomic.LoadInt32(&rn), atomic.LoadInt32(&wn), atomic.LoadInt32(&hn) |
| 84 | Assert(t, r == 0 && w == 0 && h == 0, r, w, h) |
| 85 | |
| 86 | err = p.Control(wop, PollWritable) // trigger one shot |
| 87 | MustNil(t, err) |
| 88 | for atomic.LoadInt32(&wn) == 0 { |
| 89 | runtime.Gosched() |
| 90 | } |
| 91 | r, w, h = atomic.LoadInt32(&rn), atomic.LoadInt32(&wn), atomic.LoadInt32(&hn) |
| 92 | Assert(t, r == 0 && w >= 1 && h == 0, r, w, h) |
| 93 | |
| 94 | err = p.Control(rop, PollR2RW) // trigger write |
| 95 | MustNil(t, err) |
| 96 | for atomic.LoadInt32(&wn) <= 1 { |
| 97 | runtime.Gosched() |
| 98 | } |
| 99 | r, w, h = atomic.LoadInt32(&rn), atomic.LoadInt32(&wn), atomic.LoadInt32(&hn) |
| 100 | Assert(t, r == 0 && w >= 2 && h == 0, r, w, h) |
| 101 | |
| 102 | // close wfd, then trigger hup rfd |
| 103 | err = syscall.Close(wfd) // trigger hup |
| 104 | MustNil(t, err) |
| 105 | for atomic.LoadInt32(&hn) == 0 { |
| 106 | runtime.Gosched() |
| 107 | } |
| 108 | w, h = atomic.LoadInt32(&wn), atomic.LoadInt32(&hn) |
| 109 | Assert(t, w >= 2 && h >= 1, r, w, h) |
| 110 | |
| 111 | p.Close() |
nothing calls this directly
no test coverage detected
searching dependent graphs…