Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(127184)

Side by Side Diff: Lib/test/test_socket.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_site.py ('k') | Lib/test/test_socketserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 3
4 import errno 4 import errno
5 import io 5 import io
6 import itertools 6 import itertools
7 import socket 7 import socket
8 import select 8 import select
9 import tempfile 9 import tempfile
10 import time 10 import time
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) 776 hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
777 except OSError: 777 except OSError:
778 # Probably a similar problem as above; skip this test 778 # Probably a similar problem as above; skip this test
779 self.skipTest('name lookup failure') 779 self.skipTest('name lookup failure')
780 all_host_names = [hostname, hname] + aliases 780 all_host_names = [hostname, hname] + aliases
781 fqhn = socket.getfqdn(ip) 781 fqhn = socket.getfqdn(ip)
782 if not fqhn in all_host_names: 782 if not fqhn in all_host_names:
783 self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) 783 self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names)))
784 784
785 def test_host_resolution(self): 785 def test_host_resolution(self):
786 for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2', 786 for addr in ['0.1.1.~1', '1+.1.1.1']:
787 '1:1:1:1:1:1:1:1:1']:
788 self.assertRaises(OSError, socket.gethostbyname, addr) 787 self.assertRaises(OSError, socket.gethostbyname, addr)
789 self.assertRaises(OSError, socket.gethostbyaddr, addr) 788 self.assertRaises(OSError, socket.gethostbyaddr, addr)
790 789
791 for addr in [support.HOST, '10.0.0.1', '255.255.255.255']: 790 for addr in [support.HOST, '10.0.0.1', '255.255.255.255']:
792 self.assertEqual(socket.gethostbyname(addr), addr) 791 self.assertEqual(socket.gethostbyname(addr), addr)
793 792
794 # we don't test support.HOSTv6 because there's a chance it doesn't have 793 # we don't test support.HOSTv6 because there's a chance it doesn't have
795 # a matching name entry (e.g. 'ip6-localhost') 794 # a matching name entry (e.g. 'ip6-localhost')
796 for host in [support.HOST]: 795 for host in [support.HOST]:
797 self.assertIn(host, socket.gethostbyaddr(host)[2]) 796 self.assertIn(host, socket.gethostbyaddr(host)[2])
798 797
798 @unittest.skipUnless(socket.has_ipv6, "test needs IPv6 support")
799 def test_host_resolution_ipv6(self):
800 for addr in ['::1q', '::1::2', '1:1:1:1:1:1:1:1:1']:
801 self.assertRaises(OSError, socket.gethostbyname, addr)
802 self.assertRaises(OSError, socket.gethostbyaddr, addr)
803
799 @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.seth ostname()") 804 @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.seth ostname()")
800 @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.geth ostname()") 805 @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.geth ostname()")
801 def test_sethostname(self): 806 def test_sethostname(self):
802 oldhn = socket.gethostname() 807 oldhn = socket.gethostname()
803 try: 808 try:
804 socket.sethostname('new') 809 socket.sethostname('new')
805 except OSError as e: 810 except OSError as e:
806 if e.errno == errno.EPERM: 811 if e.errno == errno.EPERM:
807 self.skipTest("test should be run as root") 812 self.skipTest("test should be run as root")
808 else: 813 else:
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 self.doRecvmsg(self.serv_sock, len(MSG), 2760 self.doRecvmsg(self.serv_sock, len(MSG),
2756 socket.CMSG_LEN(4 * SIZEOF_INT)), 2761 socket.CMSG_LEN(4 * SIZEOF_INT)),
2757 # RFC 3542 says implementations may set 2762 # RFC 3542 says implementations may set
2758 # MSG_CTRUNC if there isn't enough space 2763 # MSG_CTRUNC if there isn't enough space
2759 # for trailing padding. 2764 # for trailing padding.
2760 ignoreflags=socket.MSG_CTRUNC) 2765 ignoreflags=socket.MSG_CTRUNC)
2761 2766
2762 def _testFDPassCMSG_LEN(self): 2767 def _testFDPassCMSG_LEN(self):
2763 self.createAndSendFDs(1) 2768 self.createAndSendFDs(1)
2764 2769
2765 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") 2770 @unittest.skipIf(sys.platform in ("darwin", "ios"), "skipping, see issue #12 958")
2766 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ") 2771 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ")
2767 @requireAttrs(socket, "CMSG_SPACE") 2772 @requireAttrs(socket, "CMSG_SPACE")
2768 def testFDPassSeparate(self): 2773 def testFDPassSeparate(self):
2769 # Pass two FDs in two separate arrays. Arrays may be combined 2774 # Pass two FDs in two separate arrays. Arrays may be combined
2770 # into a single control message by the OS. 2775 # into a single control message by the OS.
2771 self.checkRecvmsgFDs(2, 2776 self.checkRecvmsgFDs(2,
2772 self.doRecvmsg(self.serv_sock, len(MSG), 10240), 2777 self.doRecvmsg(self.serv_sock, len(MSG), 10240),
2773 maxcmsgs=2) 2778 maxcmsgs=2)
2774 2779
2775 @testFDPassSeparate.client_skip 2780 @testFDPassSeparate.client_skip
2776 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") 2781 @unittest.skipIf(sys.platform in ("darwin", "ios"), "skipping, see issue #12 958")
2777 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ") 2782 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ")
2778 def _testFDPassSeparate(self): 2783 def _testFDPassSeparate(self):
2779 fd0, fd1 = self.newFDs(2) 2784 fd0, fd1 = self.newFDs(2)
2780 self.assertEqual( 2785 self.assertEqual(
2781 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET, 2786 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET,
2782 socket.SCM_RIGHTS, 2787 socket.SCM_RIGHTS,
2783 array.array("i", [fd0])), 2788 array.array("i", [fd0])),
2784 (socket.SOL_SOCKET, 2789 (socket.SOL_SOCKET,
2785 socket.SCM_RIGHTS, 2790 socket.SCM_RIGHTS,
2786 array.array("i", [fd1]))]), 2791 array.array("i", [fd1]))]),
2787 len(MSG)) 2792 len(MSG))
2788 2793
2789 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") 2794 @unittest.skipIf(sys.platform in ("darwin", "ios"), "skipping, see issue #12 958")
2790 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ") 2795 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ")
2791 @requireAttrs(socket, "CMSG_SPACE") 2796 @requireAttrs(socket, "CMSG_SPACE")
2792 def testFDPassSeparateMinSpace(self): 2797 def testFDPassSeparateMinSpace(self):
2793 # Pass two FDs in two separate arrays, receiving them into the 2798 # Pass two FDs in two separate arrays, receiving them into the
2794 # minimum space for two arrays. 2799 # minimum space for two arrays.
2795 self.checkRecvmsgFDs(2, 2800 self.checkRecvmsgFDs(2,
2796 self.doRecvmsg(self.serv_sock, len(MSG), 2801 self.doRecvmsg(self.serv_sock, len(MSG),
2797 socket.CMSG_SPACE(SIZEOF_INT) + 2802 socket.CMSG_SPACE(SIZEOF_INT) +
2798 socket.CMSG_LEN(SIZEOF_INT)), 2803 socket.CMSG_LEN(SIZEOF_INT)),
2799 maxcmsgs=2, ignoreflags=socket.MSG_CTRUNC) 2804 maxcmsgs=2, ignoreflags=socket.MSG_CTRUNC)
2800 2805
2801 @testFDPassSeparateMinSpace.client_skip 2806 @testFDPassSeparateMinSpace.client_skip
2802 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") 2807 @unittest.skipIf(sys.platform in ("darwin", "ios"), "skipping, see issue #12 958")
2803 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ") 2808 @unittest.skipIf(sys.platform.startswith("aix"), "skipping, see issue #22397 ")
2804 def _testFDPassSeparateMinSpace(self): 2809 def _testFDPassSeparateMinSpace(self):
2805 fd0, fd1 = self.newFDs(2) 2810 fd0, fd1 = self.newFDs(2)
2806 self.assertEqual( 2811 self.assertEqual(
2807 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET, 2812 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET,
2808 socket.SCM_RIGHTS, 2813 socket.SCM_RIGHTS,
2809 array.array("i", [fd0])), 2814 array.array("i", [fd0])),
2810 (socket.SOL_SOCKET, 2815 (socket.SOL_SOCKET,
2811 socket.SCM_RIGHTS, 2816 socket.SCM_RIGHTS,
2812 array.array("i", [fd1]))]), 2817 array.array("i", [fd1]))]),
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
3565 raise 3570 raise
3566 self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876" ) 3571 self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876" )
3567 3572
3568 3573
3569 class SendrecvmsgUnixStreamTestBase(SendrecvmsgConnectedBase, 3574 class SendrecvmsgUnixStreamTestBase(SendrecvmsgConnectedBase,
3570 ConnectedStreamTestMixin, UnixStreamBase): 3575 ConnectedStreamTestMixin, UnixStreamBase):
3571 pass 3576 pass
3572 3577
3573 @requireAttrs(socket.socket, "sendmsg") 3578 @requireAttrs(socket.socket, "sendmsg")
3574 @requireAttrs(socket, "AF_UNIX") 3579 @requireAttrs(socket, "AF_UNIX")
3580 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't fully support UNIX sockets. ")
3575 @unittest.skipUnless(thread, 'Threading required for this test.') 3581 @unittest.skipUnless(thread, 'Threading required for this test.')
3576 class SendmsgUnixStreamTest(SendmsgStreamTests, SendrecvmsgUnixStreamTestBase): 3582 class SendmsgUnixStreamTest(SendmsgStreamTests, SendrecvmsgUnixStreamTestBase):
3577 pass 3583 pass
3578 3584
3579 @requireAttrs(socket.socket, "recvmsg") 3585 @requireAttrs(socket.socket, "recvmsg")
3580 @requireAttrs(socket, "AF_UNIX") 3586 @requireAttrs(socket, "AF_UNIX")
3587 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't fully support UNIX sockets. ")
3581 @unittest.skipUnless(thread, 'Threading required for this test.') 3588 @unittest.skipUnless(thread, 'Threading required for this test.')
3582 class RecvmsgUnixStreamTest(RecvmsgTests, RecvmsgGenericStreamTests, 3589 class RecvmsgUnixStreamTest(RecvmsgTests, RecvmsgGenericStreamTests,
3583 SendrecvmsgUnixStreamTestBase): 3590 SendrecvmsgUnixStreamTestBase):
3584 pass 3591 pass
3585 3592
3586 @requireAttrs(socket.socket, "recvmsg_into") 3593 @requireAttrs(socket.socket, "recvmsg_into")
3587 @requireAttrs(socket, "AF_UNIX") 3594 @requireAttrs(socket, "AF_UNIX")
3595 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't fully support UNIX sockets. ")
3588 @unittest.skipUnless(thread, 'Threading required for this test.') 3596 @unittest.skipUnless(thread, 'Threading required for this test.')
3589 class RecvmsgIntoUnixStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, 3597 class RecvmsgIntoUnixStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests,
3590 SendrecvmsgUnixStreamTestBase): 3598 SendrecvmsgUnixStreamTestBase):
3591 pass 3599 pass
3592 3600
3593 @requireAttrs(socket.socket, "sendmsg", "recvmsg") 3601 @requireAttrs(socket.socket, "sendmsg", "recvmsg")
3594 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS") 3602 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS")
3603 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't fully support UNIX sockets. ")
3595 @unittest.skipUnless(thread, 'Threading required for this test.') 3604 @unittest.skipUnless(thread, 'Threading required for this test.')
3596 class RecvmsgSCMRightsStreamTest(SCMRightsTest, SendrecvmsgUnixStreamTestBase): 3605 class RecvmsgSCMRightsStreamTest(SCMRightsTest, SendrecvmsgUnixStreamTestBase):
3597 pass 3606 pass
3598 3607
3599 @requireAttrs(socket.socket, "sendmsg", "recvmsg_into") 3608 @requireAttrs(socket.socket, "sendmsg", "recvmsg_into")
3600 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS") 3609 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS")
3610 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't fully support UNIX sockets. ")
3601 @unittest.skipUnless(thread, 'Threading required for this test.') 3611 @unittest.skipUnless(thread, 'Threading required for this test.')
3602 class RecvmsgIntoSCMRightsStreamTest(RecvmsgIntoMixin, SCMRightsTest, 3612 class RecvmsgIntoSCMRightsStreamTest(RecvmsgIntoMixin, SCMRightsTest,
3603 SendrecvmsgUnixStreamTestBase): 3613 SendrecvmsgUnixStreamTestBase):
3604 pass 3614 pass
3605 3615
3606 3616
3607 # Test interrupting the interruptible send/receive methods with a 3617 # Test interrupting the interruptible send/receive methods with a
3608 # signal when a timeout is set. These tests avoid having multiple 3618 # signal when a timeout is set. These tests avoid having multiple
3609 # threads alive during the test so that the OS cannot deliver the 3619 # threads alive during the test so that the OS cannot deliver the
3610 # signal to the wrong one. 3620 # signal to the wrong one.
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
5354 SendfileUsingSendTest, 5364 SendfileUsingSendTest,
5355 SendfileUsingSendfileTest, 5365 SendfileUsingSendfileTest,
5356 ]) 5366 ])
5357 5367
5358 thread_info = support.threading_setup() 5368 thread_info = support.threading_setup()
5359 support.run_unittest(*tests) 5369 support.run_unittest(*tests)
5360 support.threading_cleanup(*thread_info) 5370 support.threading_cleanup(*thread_info)
5361 5371
5362 if __name__ == "__main__": 5372 if __name__ == "__main__":
5363 test_main() 5373 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_site.py ('k') | Lib/test/test_socketserver.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+