Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0e9b4b

Browse files
committed
Add eventfd select test case
Signed-off-by: Christian Heimes <[email protected]>
1 parent 2732046 commit c0e9b4b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lib/test/test_os.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
except ImportError:
6161
INT_MAX = PY_SSIZE_T_MAX = sys.maxsize
6262

63+
try:
64+
import select
65+
except ImportError:
66+
select = None
67+
6368
from test.support.script_helper import assert_python_ok
6469
from test.support import unix_shell
6570
from test.support.os_helper import FakePath
@@ -3589,6 +3594,31 @@ def test_eventfd_semaphore(self):
35893594
with self.assertRaises(BlockingIOError):
35903595
os.eventfd_read(fd)
35913596

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+
35923622

35933623
class OSErrorTests(unittest.TestCase):
35943624
def setUp(self):

0 commit comments

Comments
 (0)