History log of /src/tests/lib/libc/sys/t_poll.c |
Revision | | Date | Author | Comments |
1.12 |
| 10-Feb-2025 |
riastradh | t_poll: Extend the hangup tests to ptys too.
Of course, ptys work slightly differently from pipes and fifos and sockets, presumably for hysterical raisins...
While here: add a more detailed comment to each xfail for the reason why I think it is broken.
PR kern/59056: poll POLLHUP bugs
|
1.11 |
| 09-Feb-2025 |
riastradh | t_poll: Expand tests of polling when other endpoint is closed.
This covers fifos, pipes, and sockets; reads and writes; and polling when the endpoint is already closed as well as sleeping until the endpoint is closed after a delay.
Unfortunately, there is disagreement right now between:
(a) POSIX, (b) our poll(2) man page, and (c) our implementation,
for many of these cases. And we recently changed the behaviour of poll(2) on fifos between 9 and 10 (PR kern/56429: poll(2) should yield POLLHUP when last writer to a fifo close()'s it) but didn't get it quite right.
So I've annotated these test cases with xfails for all the cases I think we're currently doing wrong -- under a justification from some combination of POSIX, our own documentation, and/or a reasonable interpretation of what the semantics _should_ be based on how read(2) and write(2) will behave. These are mostly edge cases:
1. [pollclosed_pipe_*_write*] When the read side of a pipe is closed, poll(2) on the write side currently returns POLLHUP|POLLOUT, which POSIX forbids because it requires POLLHUP to be mutually exclusive with POLLOUT. And our man page concurs with POSIX on this rule, and has for a long time (going as far back as NetBSD 1.3 or earlier, judging by https://man.NetBSD.org/NetBSD-1.3/poll.2).
=> Fixing this won't change whether anything wakes up earlier or later -- it will only change which bits are set when the wakeups happen.
2. [pollclosed_fifo*_immediate_readsome] When the write side of a fifo was previously open with the read side, and has since been closed before calling poll(2), poll(2) on the read side returns 0 instead of POLLHUP|POLLIN as it is expected to, even though read(2) will return EOF without blocking.
=> Fixing this may lead to more wakeups than before, but only in cases where read(2) would actually return immediately anyway.
3. [pollclosed_fifo*_delayed_*_read] When the write side of a fifo is closed, poll(2) on the read side returns POLLHUP|POLLIN, as it is expected to. But this state currently isn't persistent, even though the behaviour of read(2) in returning EOF without blocking is persistent.
=> Fixing this may lead to more wakeups than before, but only in cases where read(2) would actually return immediately anyway.
That said, it turns out that we are correct, according to POSIX, in not setting POLLHUP on a socket whose peer has been closed: POLLHUP is only for devices, pipes, and FIFOs. So one of the issues I reported in PR 59056 turns out to be bogus. (Also POLLHUP is only for the reader side anyway, not for the writer side.)
https://pubs.opengroup.org/onlinepubs/9799919799/functions/poll.html
PR kern/59056: poll POLLHUP bugs
|
1.10 |
| 09-Feb-2025 |
riastradh | t_poll: Tweak to improve diagnostics.
PR kern/59056: poll POLLHUP bugs
|
1.9 |
| 09-Feb-2025 |
riastradh | t_poll: Make sure POLLOUT is clear when testing POLLHUP.
POLLOUT and POLLHUP are mutually exclusive in POSIX. Also, we're only polling for POLLIN anyway.
PR kern/59056: poll POLLHUP bugs
|
1.8 |
| 02-Oct-2021 |
thorpej | branches: 1.8.4; - Strenghen the poll(2) fifo_inout test to ensure that once the reader has read enough that exactly PIPE_BUF space is available that the FIFO becomes writable again. - When creating a FIFO, ensure that the receive low water mark is 1 (a FIFO must be readable when at least 1 byte is available); this was already the case implicitly, but this makes it explicit. - Similarly, set the send low water mark to PIPE_BUF to ensure that the pipe is writable when at least PIPE_BUF bytes of space are available in the send buffer. Without this change, the strengthened test case above does not pass (the default send low water mark is larger than PIPE_BUF; see soreserve()). - Make the same low water mark changes to the PIPE_SOCKETPAIR case.
|
1.7 |
| 02-Oct-2021 |
thorpej | Add a fifo_inout test case that validates the expected POLLIN / POLLOUT behavior for FIFOs: - A FIFO is readable so long as at least 1 byte is available. - A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF) space is avaiable.
This will be cloned for a forthcoming kevent test case.
|
1.6 |
| 02-Oct-2021 |
thorpej | In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a new writer appears.
|
1.5 |
| 02-Oct-2021 |
thorpej | - fifo_poll(): If the last writer has disappeared, detect this and return POLLHUP, per POSIX. - fifo_close(): Use the new fifo_socantrcvmore(), which is like the garden-variety socantrcvmore(), except it specifies POLL_HUP rather than POLL_IN (so the correct code for SIGIO is sent). - sowakeup(): Allow POLL_HUP as a code (notifies poll'ers with POLLHUP). - Add test cases for correct POLLHUP behavior with FIFOs.
Fixes PR kern/56429.
|
1.4 |
| 17-Jul-2020 |
kamil | Add ppoll() a compatibility wrapper around pollts(2)
Submitted by Apurva Nandan.
|
1.3 |
| 18-Mar-2012 |
jruoho | branches: 1.3.34; Move the references to PRs from code comments to the test description. Once ATF has the ability to output the metadata in the HTML reports, it should be easy to traverse between releng and gnats -reports via links.
|
1.2 |
| 15-Oct-2011 |
jruoho | branches: 1.2.2; Follow the design principles of tests(7) by merging 't_poll3w' to 't_poll' as a test case instead of separate file.
|
1.1 |
| 07-Jul-2011 |
jruoho | Add the syscall tests back. Couple of files and tests were also renamed for consistency. All of these now mimic the libc structure.
|
1.2.2.1 |
| 17-Apr-2012 |
yamt | sync with head
|
1.3.34.2 |
| 04-Oct-2021 |
martin | Pull up following revision(s) (requested by thorpej in ticket #1351):
sys/miscfs/fifofs/fifo_vnops.c: revision 1.88 sys/kern/uipc_syscalls.c: revision 1.201 tests/lib/libc/sys/t_poll.c: revision 1.6 tests/lib/libc/sys/t_poll.c: revision 1.7 tests/lib/libc/sys/t_poll.c: revision 1.8
- Strenghen the poll(2) fifo_inout test to ensure that once the reader has read enough that exactly PIPE_BUF space is available that the FIFO becomes writable again. - When creating a FIFO, ensure that the receive low water mark is 1 (a FIFO must be readable when at least 1 byte is available); this was already the case implicitly, but this makes it explicit. - Similarly, set the send low water mark to PIPE_BUF to ensure that the pipe is writable when at least PIPE_BUF bytes of space are available in the send buffer. Without this change, the strengthened test case above does not pass (the default send low water mark is larger than PIPE_BUF; see soreserve()). - Make the same low water mark changes to the PIPE_SOCKETPAIR case.
In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a new writer appears.
Add a fifo_inout test case that validates the expected POLLIN / POLLOUT behavior for FIFOs: - A FIFO is readable so long as at least 1 byte is available. - A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF) space is avaiable. This will be cloned for a forthcoming kevent test case.
|
1.3.34.1 |
| 02-Oct-2021 |
martin | Pull up following revision(s) (requested by thorpej in ticket #1350):
sys/kern/uipc_socket2.c: revision 1.140 tests/lib/libc/sys/t_poll.c: revision 1.5 sys/miscfs/fifofs/fifo_vnops.c: revision 1.87
- fifo_poll(): If the last writer has disappeared, detect this and return POLLHUP, per POSIX. - fifo_close(): Use the new fifo_socantrcvmore(), which is like the garden-variety socantrcvmore(), except it specifies POLL_HUP rather than POLL_IN (so the correct code for SIGIO is sent). - sowakeup(): Allow POLL_HUP as a code (notifies poll'ers with POLLHUP). - Add test cases for correct POLLHUP behavior with FIFOs.
Fixes PR kern/56429.
|
1.8.4.1 |
| 02-Aug-2025 |
perseant | Sync with HEAD
|