From 18dd0df5af140f2640953cd094e0453798e1fa22 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 26 Feb 2011 14:29:24 +0000 Subject: [PATCH] Issue #11323: fix sendfile tests under 64-bit Solaris. --- Lib/test/test_os.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 0b65bbd3cf1..a2e2ee805cd 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1374,7 +1374,7 @@ class SendfileTestServer(asyncore.dispatcher, threading.Thread): @unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()") class TestSendfile(unittest.TestCase): - DATA = b"12345abcde" * 1024 * 1024 # 10 Mb + DATA = b"12345abcde" * 16 * 1024 # 160 KB SUPPORT_HEADERS_TRAILERS = not sys.platform.startswith("linux") and \ not sys.platform.startswith("solaris") and \ not sys.platform.startswith("sunos") @@ -1432,7 +1432,7 @@ class TestSendfile(unittest.TestCase): total_sent = 0 offset = 0 nbytes = 4096 - while 1: + while total_sent < len(self.DATA): sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes) if sent == 0: break @@ -1445,14 +1445,15 @@ class TestSendfile(unittest.TestCase): self.client.close() self.server.wait() data = self.server.handler_instance.get_data() - self.assertEqual(hash(data), hash(self.DATA)) + self.assertEqual(data, self.DATA) def test_send_at_certain_offset(self): # start sending a file at a certain offset total_sent = 0 - offset = len(self.DATA) / 2 + offset = len(self.DATA) // 2 + must_send = len(self.DATA) - offset nbytes = 4096 - while 1: + while total_sent < must_send: sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes) if sent == 0: break @@ -1463,15 +1464,21 @@ class TestSendfile(unittest.TestCase): self.client.close() self.server.wait() data = self.server.handler_instance.get_data() - expected = self.DATA[int(len(self.DATA) / 2):] + expected = self.DATA[len(self.DATA) // 2:] self.assertEqual(total_sent, len(expected)) - self.assertEqual(hash(data), hash(expected)) + self.assertEqual(data, expected) def test_offset_overflow(self): # specify an offset > file size offset = len(self.DATA) + 4096 - sent = os.sendfile(self.sockno, self.fileno, offset, 4096) - self.assertEqual(sent, 0) + try: + sent = os.sendfile(self.sockno, self.fileno, offset, 4096) + except OSError as e: + # Solaris can raise EINVAL if offset >= file length, ignore. + if e.errno != errno.EINVAL: + raise + else: + self.assertEqual(sent, 0) self.client.close() self.server.wait() data = self.server.handler_instance.get_data()