From 0c823b97ae02f0fcdfaa20dbfd53435b53ee2c94 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 Nov 2021 15:34:11 -0800 Subject: [PATCH] unix: avoid depending on consistent Revents type in TestPoll For golang/go#49380 Change-Id: Ie1d370681962d9f69ef54b33ddf38e4c74a2e298 Reviewed-on: https://go-review.googlesource.com/c/sys/+/363660 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Michael Knyszek --- unix/syscall_unix_test.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index 259098b0..81db934e 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -522,20 +522,25 @@ func TestPoll(t *testing.T) { t.Errorf("Poll: wrong number of events: got %v, expected %v", n, 0) // Identify which event(s) caused Poll to return. - for _, ev := range []struct { - name string - bits int16 - }{ - {"POLLIN", unix.POLLIN}, - {"POLLPRI", unix.POLLPRI}, - {"POLLOUT", unix.POLLOUT}, - {"POLLERR", unix.POLLERR}, - {"POLLHUP", unix.POLLHUP}, - {"POLLNVAL", unix.POLLNVAL}, - } { - if fds[0].Revents&ev.bits != 0 { - t.Logf("Poll: found event %s", ev.name) - } + // We can't trivially use a table here because Revents + // isn't the same type on all systems. + if fds[0].Revents&unix.POLLIN != 0 { + t.Log("found POLLIN event") + } + if fds[0].Revents&unix.POLLPRI != 0 { + t.Log("found POLLPRI event") + } + if fds[0].Revents&unix.POLLOUT != 0 { + t.Log("found POLLOUT event") + } + if fds[0].Revents&unix.POLLERR != 0 { + t.Log("found POLLERR event") + } + if fds[0].Revents&unix.POLLHUP != 0 { + t.Log("found POLLHUP event") + } + if fds[0].Revents&unix.POLLNVAL != 0 { + t.Log("found POLLNVAL event") } } break