diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-21 23:41:12 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-21 23:41:12 (GMT) |
commit | ecc26923cd8a0a3511e1fb89b4b13d74a1391b87 (patch) | |
tree | 217f35056ff9d050976638032576a01edb6c9207 /Lib | |
parent | ce58dc7b166a4859f7e6e3483ac59fa679d78be9 (diff) | |
download | cpython-ecc26923cd8a0a3511e1fb89b4b13d74a1391b87.zip cpython-ecc26923cd8a0a3511e1fb89b4b13d74a1391b87.tar.gz cpython-ecc26923cd8a0a3511e1fb89b4b13d74a1391b87.tar.bz2 |
Issue #4681: Allow mmap() to work on file sizes and offsets larger than
4GB, even on 32-bit builds. Initial patch by Ross Lagerwall, adapted for
32-bit Windows.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_mmap.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 8f20d96..cbef374 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,4 +1,4 @@ -from test.support import TESTFN, run_unittest, import_module +from test.support import TESTFN, run_unittest, import_module, unlink, requires import unittest import os import re @@ -646,9 +646,56 @@ class MmapTests(unittest.TestCase): "wrong exception raised in context manager") self.assertTrue(m.closed, "context manager failed") +class LargeMmapTests(unittest.TestCase): + + def setUp(self): + unlink(TESTFN) + + def tearDown(self): + unlink(TESTFN) + + def _working_largefile(self): + # Only run if the current filesystem supports large files. + f = open(TESTFN, 'wb', buffering=0) + try: + f.seek(0x80000001) + f.write(b'x') + f.flush() + except (IOError, OverflowError): + raise unittest.SkipTest("filesystem does not have largefile support") + finally: + f.close() + unlink(TESTFN) + + def test_large_offset(self): + if sys.platform[:3] == 'win' or sys.platform == 'darwin': + requires('largefile', + 'test requires %s bytes and a long time to run' % str(0x180000000)) + self._working_largefile() + with open(TESTFN, 'wb') as f: + f.seek(0x14FFFFFFF) + f.write(b" ") + + with open(TESTFN, 'rb') as f: + with mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ) as m: + self.assertEqual(m[0xFFFFFFF], 32) + + def test_large_filesize(self): + if sys.platform[:3] == 'win' or sys.platform == 'darwin': + requires('largefile', + 'test requires %s bytes and a long time to run' % str(0x180000000)) + self._working_largefile() + with open(TESTFN, 'wb') as f: + f.seek(0x17FFFFFFF) + f.write(b" ") + + with open(TESTFN, 'rb') as f: + with mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) as m: + self.assertEqual(m.size(), 0x180000000) + def test_main(): - run_unittest(MmapTests) + run_unittest(MmapTests, LargeMmapTests) if __name__ == '__main__': test_main() |