Skip to content

Commit c1f4481

Browse files
committed
unix: add TestEpoll on linux
This tests the epoll functionality on linux and should hopefully help catch GOARCHes where additional padding of EpollEvent is needed (see e.g. CL 189877). Change-Id: Icd19746a60a63016a5d46535a2cc557ca7a0d474 Reviewed-on: https://go-review.googlesource.com/c/sys/+/205398 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent ac3223d commit c1f4481

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

unix/syscall_linux_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,40 @@ func openMountByID(mountID int) (f *os.File, err error) {
659659
}
660660
return nil, errors.New("mountID not found")
661661
}
662+
663+
func TestEpoll(t *testing.T) {
664+
efd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
665+
if err != nil {
666+
t.Fatalf("EpollCreate1: %v", err)
667+
}
668+
defer unix.Close(efd)
669+
670+
r, w, err := os.Pipe()
671+
if err != nil {
672+
t.Fatal(err)
673+
}
674+
defer r.Close()
675+
defer w.Close()
676+
677+
fd := int(r.Fd())
678+
ev := unix.EpollEvent{Events: unix.EPOLLIN, Fd: int32(fd)}
679+
680+
err = unix.EpollCtl(efd, unix.EPOLL_CTL_ADD, fd, &ev)
681+
if err != nil {
682+
t.Fatalf("EpollCtl: %v", err)
683+
}
684+
685+
if _, err := w.Write([]byte("HELLO GOPHER")); err != nil {
686+
t.Fatal(err)
687+
}
688+
689+
events := make([]unix.EpollEvent, 128)
690+
n, err := unix.EpollWait(efd, events, 1)
691+
if err != nil {
692+
t.Fatalf("EpollWait: %v", err)
693+
}
694+
695+
if n != 1 {
696+
t.Logf("EpollWait: wrong number of events: got %v, expected 1", n)
697+
}
698+
}

0 commit comments

Comments
 (0)