diff options
author | Christian Heimes <christian@cheimes.de> | 2008-03-22 00:47:35 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-03-22 00:47:35 (GMT) |
commit | 4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d (patch) | |
tree | be5ea38e3ef6d53046f90b35d1ea7d0f077aed87 /Lib/test/test_epoll.py | |
parent | 73a22f0500ce713d46fce864e95402c34a45afd9 (diff) | |
download | cpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.zip cpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.tar.gz cpython-4fbc72b4ac7ac32d85f1fe8d465ed4c8736d002d.tar.bz2 |
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61687 | jeffrey.yasskin | 2008-03-21 06:02:44 +0100 (Fri, 21 Mar 2008) | 2 lines
Speed up test_signal from ~24s to 4s by avoiding nearly all of the sleep calls.
........
r61688 | jeffrey.yasskin | 2008-03-21 06:51:37 +0100 (Fri, 21 Mar 2008) | 5 lines
Try to fix test_signal breakages on Linux due to r61687. It appears that at
least two of the linux build bots aren't leaving zombie processes around for
os.waitpid to wait for, causing ECHILD errors. This would be a symptom of a bug
somewhere, but probably not in signal itself.
........
r61696 | georg.brandl | 2008-03-21 15:32:33 +0100 (Fri, 21 Mar 2008) | 2 lines
Mark the descitems in the tutorial as "noindex" so that :meth: cross-refs don't link to them.
........
r61700 | georg.brandl | 2008-03-21 18:19:29 +0100 (Fri, 21 Mar 2008) | 2 lines
Fix markup.
........
r61704 | jeffrey.yasskin | 2008-03-21 19:25:06 +0100 (Fri, 21 Mar 2008) | 3 lines
Try to fix test_signal on FreeBSD. I'm assuming that os.kill is failing to
raise a signal, but switching to subprocess makes the code cleaner anyway.
........
r61705 | jeffrey.yasskin | 2008-03-21 19:48:04 +0100 (Fri, 21 Mar 2008) | 7 lines
Speed test_threading up from 14s to .5s, and avoid a deadlock on certain
failures. The test for enumerate-after-join is now a little less rigorous, but
the bug it references says the error happened in the first couple iterations,
so 100 iterations should still be enough.
cProfile was useful for identifying the slow tests here.
........
r61707 | georg.brandl | 2008-03-21 20:14:38 +0100 (Fri, 21 Mar 2008) | 2 lines
Fix a code block in __future__ docs.
........
r61708 | georg.brandl | 2008-03-21 20:20:21 +0100 (Fri, 21 Mar 2008) | 2 lines
Add docs for __func__ and __self__ on methods.
........
r61709 | georg.brandl | 2008-03-21 20:37:57 +0100 (Fri, 21 Mar 2008) | 2 lines
Add docs for print_function and future_builtins. Fixes #2442.
........
r61711 | georg.brandl | 2008-03-21 20:54:00 +0100 (Fri, 21 Mar 2008) | 2 lines
#2136: allow single quotes in realm spec.
........
r61712 | georg.brandl | 2008-03-21 21:01:51 +0100 (Fri, 21 Mar 2008) | 3 lines
Issue #2432: give DictReader the dialect and line_num attributes
advertised in the docs.
........
r61714 | georg.brandl | 2008-03-21 21:11:46 +0100 (Fri, 21 Mar 2008) | 2 lines
#2358: add py3k warning to sys.exc_clear().
........
r61715 | georg.brandl | 2008-03-21 21:21:46 +0100 (Fri, 21 Mar 2008) | 2 lines
#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
........
r61716 | georg.brandl | 2008-03-21 21:38:24 +0100 (Fri, 21 Mar 2008) | 2 lines
#2348: add py3k warning for file.softspace.
........
r61718 | georg.brandl | 2008-03-21 21:55:20 +0100 (Fri, 21 Mar 2008) | 2 lines
#2160: document PyImport_GetImporter.
........
r61719 | georg.brandl | 2008-03-21 21:55:51 +0100 (Fri, 21 Mar 2008) | 2 lines
Update doc ACKS.
........
r61720 | steven.bethard | 2008-03-21 22:01:18 +0100 (Fri, 21 Mar 2008) | 1 line
Replace hack in regrtest.py with use of sys.py3kwarning.
........
r61721 | georg.brandl | 2008-03-21 22:05:03 +0100 (Fri, 21 Mar 2008) | 2 lines
Add missing versionadded tag.
........
r61722 | christian.heimes | 2008-03-22 00:49:44 +0100 (Sat, 22 Mar 2008) | 3 lines
Applied patch #1657 epoll and kqueue wrappers for the select module
The patch adds wrappers for the Linux epoll syscalls and the BSD kqueue syscalls. Thanks to Thomas Herve and the Twisted people for their support and help.
TODO: Finish documentation documentation
........
Diffstat (limited to 'Lib/test/test_epoll.py')
-rw-r--r-- | Lib/test/test_epoll.py | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py new file mode 100644 index 0000000..877a54e --- /dev/null +++ b/Lib/test/test_epoll.py @@ -0,0 +1,189 @@ +# Copyright (c) 2001-2006 Twisted Matrix Laboratories. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" +Tests for epoll wrapper. +""" +import os +import socket +import errno +import time +import select +import tempfile +import unittest + +from test import test_support +if not hasattr(select, "epoll"): + raise test_support.TestSkipped("test works only on Linux 2.6") + +class TestEPoll(unittest.TestCase): + + def setUp(self): + self.serverSocket = socket.socket() + self.serverSocket.bind(('127.0.0.1', 0)) + self.serverSocket.listen(1) + self.connections = [self.serverSocket] + + + def tearDown(self): + for skt in self.connections: + skt.close() + + def _connected_pair(self): + client = socket.socket() + client.setblocking(False) + try: + client.connect(('127.0.0.1', self.serverSocket.getsockname()[1])) + except socket.error as e: + self.assertEquals(e.args[0], errno.EINPROGRESS) + else: + raise AssertionError("Connect should have raised EINPROGRESS") + server, addr = self.serverSocket.accept() + + self.connections.extend((client, server)) + return client, server + + def test_create(self): + try: + ep = select.epoll(16) + except OSError as e: + raise AssertionError(str(e)) + self.assert_(ep.fileno() > 0, ep.fileno()) + self.assert_(not ep.closed) + ep.close() + self.assert_(ep.closed) + self.assertRaises(ValueError, ep.fileno) + + def test_badcreate(self): + self.assertRaises(TypeError, select.epoll, 1, 2, 3) + self.assertRaises(TypeError, select.epoll, 'foo') + self.assertRaises(TypeError, select.epoll, None) + self.assertRaises(TypeError, select.epoll, ()) + self.assertRaises(TypeError, select.epoll, ['foo']) + self.assertRaises(TypeError, select.epoll, {}) + + def test_add(self): + server, client = self._connected_pair() + + ep = select.epoll(2) + try: + ep.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) + ep.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) + finally: + ep.close() + + def test_fromfd(self): + server, client = self._connected_pair() + + ep = select.epoll(2) + ep2 = select.epoll.fromfd(ep.fileno()) + + ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) + ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) + + events = ep.poll(1, 4) + events2 = ep2.poll(0.9, 4) + self.assertEqual(len(events), 2) + self.assertEqual(len(events2), 2) + + ep.close() + try: + ep2.poll(1, 4) + except IOError as e: + self.failUnlessEqual(e.args[0], errno.EBADF, e) + else: + self.fail("epoll on closed fd didn't raise EBADF") + + def test_control_and_wait(self): + client, server = self._connected_pair() + + ep = select.epoll(16) + ep.register(server.fileno(), + select.EPOLLIN | select.EPOLLOUT | select.EPOLLET) + ep.register(client.fileno(), + select.EPOLLIN | select.EPOLLOUT | select.EPOLLET) + + now = time.time() + events = ep.poll(1, 4) + then = time.time() + self.failIf(then - now > 0.1, then - now) + + events.sort() + expected = [(client.fileno(), select.EPOLLOUT), + (server.fileno(), select.EPOLLOUT)] + expected.sort() + + self.assertEquals(events, expected) + self.failIf(then - now > 0.01, then - now) + + now = time.time() + events = ep.poll(timeout=2.1, maxevents=4) + then = time.time() + self.failIf(events) + + client.send(b"Hello!") + server.send(b"world!!!") + + now = time.time() + events = ep.poll(1, 4) + then = time.time() + self.failIf(then - now > 0.01) + + events.sort() + expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT), + (server.fileno(), select.EPOLLIN | select.EPOLLOUT)] + expected.sort() + + self.assertEquals(events, expected) + + ep.unregister(client.fileno()) + ep.modify(server.fileno(), select.EPOLLOUT) + now = time.time() + events = ep.poll(1, 4) + then = time.time() + self.failIf(then - now > 0.01) + + expected = [(server.fileno(), select.EPOLLOUT)] + self.assertEquals(events, expected) + + def test_errors(self): + self.assertRaises(ValueError, select.epoll, -2) + self.assertRaises(ValueError, select.epoll().register, -1, + select.EPOLLIN) + + def test_unregister_closed(self): + server, client = self._connected_pair() + fd = server.fileno() + ep = select.epoll(16) + ep.register(server) + + now = time.time() + events = ep.poll(1, 4) + then = time.time() + self.failIf(then - now > 0.01) + + server.close() + ep.unregister(fd) + +def test_main(): + test_support.run_unittest(TestEPoll) + +if __name__ == "__main__": + test_main() |