From faf0a1b62c6b439486fd1d914d8185627b99d387 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Fri, 12 Nov 2021 19:14:58 +0000 Subject: [PATCH] unix: identify unexpected events that fired in TestPoll Currently if TestPoll fails because an unexpected event fired, we just print that it happened, not which one fired. #49380 has been difficult to reproduce, so printing more information for this case would be helpful. Updates #49380. Change-Id: I820c4b634536565487ee1474f8afe092a8a4443b Reviewed-on: https://go-review.googlesource.com/c/sys/+/363714 Trust: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills --- unix/syscall_unix_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index cfcdd0e1..259098b0 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -520,6 +520,23 @@ func TestPoll(t *testing.T) { } if n != 0 { 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) + } + } } break }