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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add eventfd select test case
Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran committed Nov 13, 2020
commit c0e9b4bf85b72cfbfe9aa9db4bf933fc75a1aec3
30 changes: 30 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
except ImportError:
INT_MAX = PY_SSIZE_T_MAX = sys.maxsize

try:
import select
except ImportError:
select = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems all other modules / tests don't guard against select not being available. It looks like all platforms should support it (at least select.select).


from test.support.script_helper import assert_python_ok
from test.support import unix_shell
from test.support.os_helper import FakePath
Expand Down Expand Up @@ -3589,6 +3594,31 @@ def test_eventfd_semaphore(self):
with self.assertRaises(BlockingIOError):
os.eventfd_read(fd)

@unittest.skipUnless(
hasattr(select, "select"), reason="test needs select.select"
)
def test_eventfd_select(self):
flags = os.EFD_CLOEXEC | os.EFD_NONBLOCK
fd = os.eventfd(0, flags)
self.assertNotEqual(fd, -1)
self.addCleanup(os.close, fd)

# counter is zero, only writeable
rfd, wfd, xfd = select.select([fd], [fd], [fd], 0)
self.assertEqual((rfd, wfd, xfd), ([], [fd], []))

# counter is non-zero, read and writeable
os.eventfd_write(fd, 23)
rfd, wfd, xfd = select.select([fd], [fd], [fd], 0)
self.assertEqual((rfd, wfd, xfd), ([fd], [fd], []))
self.assertEqual(os.eventfd_read(fd), 23)

# counter at max, only readable
os.eventfd_write(fd, (2**64) - 2)
rfd, wfd, xfd = select.select([fd], [fd], [fd], 0)
self.assertEqual((rfd, wfd, xfd), ([fd], [], []))
os.eventfd_read(fd)


class OSErrorTests(unittest.TestCase):
def setUp(self):
Expand Down