|
60 | 60 | except ImportError: |
61 | 61 | INT_MAX = PY_SSIZE_T_MAX = sys.maxsize |
62 | 62 |
|
| 63 | +try: |
| 64 | + import select |
| 65 | +except ImportError: |
| 66 | + select = None |
| 67 | + |
63 | 68 | from test.support.script_helper import assert_python_ok |
64 | 69 | from test.support import unix_shell |
65 | 70 | from test.support.os_helper import FakePath |
@@ -3589,6 +3594,31 @@ def test_eventfd_semaphore(self): |
3589 | 3594 | with self.assertRaises(BlockingIOError): |
3590 | 3595 | os.eventfd_read(fd) |
3591 | 3596 |
|
| 3597 | + @unittest.skipUnless( |
| 3598 | + hasattr(select, "select"), reason="test needs select.select" |
| 3599 | + ) |
| 3600 | + def test_eventfd_select(self): |
| 3601 | + flags = os.EFD_CLOEXEC | os.EFD_NONBLOCK |
| 3602 | + fd = os.eventfd(0, flags) |
| 3603 | + self.assertNotEqual(fd, -1) |
| 3604 | + self.addCleanup(os.close, fd) |
| 3605 | + |
| 3606 | + # counter is zero, only writeable |
| 3607 | + rfd, wfd, xfd = select.select([fd], [fd], [fd], 0) |
| 3608 | + self.assertEqual((rfd, wfd, xfd), ([], [fd], [])) |
| 3609 | + |
| 3610 | + # counter is non-zero, read and writeable |
| 3611 | + os.eventfd_write(fd, 23) |
| 3612 | + rfd, wfd, xfd = select.select([fd], [fd], [fd], 0) |
| 3613 | + self.assertEqual((rfd, wfd, xfd), ([fd], [fd], [])) |
| 3614 | + self.assertEqual(os.eventfd_read(fd), 23) |
| 3615 | + |
| 3616 | + # counter at max, only readable |
| 3617 | + os.eventfd_write(fd, (2**64) - 2) |
| 3618 | + rfd, wfd, xfd = select.select([fd], [fd], [fd], 0) |
| 3619 | + self.assertEqual((rfd, wfd, xfd), ([fd], [], [])) |
| 3620 | + os.eventfd_read(fd) |
| 3621 | + |
3592 | 3622 |
|
3593 | 3623 | class OSErrorTests(unittest.TestCase): |
3594 | 3624 | def setUp(self): |
|
0 commit comments