summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-09-08 09:53:09 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-09-08 09:53:09 (GMT)
commita3c18d0f1423b192f82bd785cea09346942cf18e (patch)
tree085963340809aa198b6ff3c0cff3facf920c44d1 /Lib
parent7ba6b0f943ed9fc1782ec5813a07440d98d64554 (diff)
downloadcpython-a3c18d0f1423b192f82bd785cea09346942cf18e.zip
cpython-a3c18d0f1423b192f82bd785cea09346942cf18e.tar.gz
cpython-a3c18d0f1423b192f82bd785cea09346942cf18e.tar.bz2
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 6205768..fc478b6 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -26,6 +26,10 @@ try:
import multiprocessing
except ImportError:
multiprocessing = False
+try:
+ import fcntl
+except ImportError:
+ fcntl = None
HOST = support.HOST
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') ## test unicode string and carriage return
@@ -4804,6 +4808,32 @@ class InheritanceTest(unittest.TestCase):
sock.set_inheritable(False)
self.assertEqual(sock.get_inheritable(), False)
+ if fcntl:
+ def test_get_inheritable_cloexec(self):
+ sock = socket.socket()
+ with sock:
+ fd = sock.fileno()
+ self.assertEqual(sock.get_inheritable(), False)
+
+ # clear FD_CLOEXEC flag
+ flags = fcntl.fcntl(fd, fcntl.F_GETFD)
+ flags &= ~fcntl.FD_CLOEXEC
+ fcntl.fcntl(fd, fcntl.F_SETFD, flags)
+
+ self.assertEqual(sock.get_inheritable(), True)
+
+ def test_set_inheritable_cloexec(self):
+ sock = socket.socket()
+ with sock:
+ fd = sock.fileno()
+ self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
+ fcntl.FD_CLOEXEC)
+
+ sock.set_inheritable(True)
+ self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
+ 0)
+
+
@unittest.skipUnless(hasattr(socket, "socketpair"),
"need socket.socketpair()")
def test_socketpair(self):