]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merge: #11277: Add tests for mmap crash when using large sparse files on OS X.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sat, 7 May 2011 11:08:54 +0000 (13:08 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sat, 7 May 2011 11:08:54 +0000 (13:08 +0200)
Also, reduce code duplication in LargeMmapTests.

Original patch by Steffen Daode Nurpmeso.

1  2 
Lib/test/test_mmap.py

index e62a046c0112f0d07cfa3e9e4d8f2d097bb0e955,fbc34ed7894c230a5c67d1faeb3f4713cb826eb6..be588cfb99bf32c25dfd62dd3ced0a5729d512ae
@@@ -1,10 -1,7 +1,11 @@@
- from test.support import TESTFN, run_unittest, import_module, unlink, requires
+ from test.support import (TESTFN, run_unittest, import_module, unlink,
+                           requires, _2G, _4G)
  import unittest
 -import os, re, itertools, socket, sys
 +import os
 +import re
 +import itertools
 +import socket
 +import sys
  
  # Skip test if we can't import mmap.
  mmap = import_module('mmap')
@@@ -679,28 -658,54 +667,45 @@@ class LargeMmapTests(unittest.TestCase)
          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" ")
+             try:
+                 f.seek(num_zeroes)
+                 f.write(tail)
+                 f.flush()
+             except (IOError, OverflowError):
+                 raise unittest.SkipTest("filesystem does not have largefile support")
  
+     def test_large_offset(self):
+         self._create_test_file(0x14FFFFFFF, b" ")
          with open(TESTFN, 'rb') as f:
 -            m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
 -            try:
 +            with mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ) as m:
                  self.assertEqual(m[0xFFFFFFF], 32)
 -            finally:
 -                m.close()
  
      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" ")
+         self._create_test_file(0x17FFFFFFF, b" ")
          with open(TESTFN, 'rb') as f:
 -            m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
 -            try:
 +            with mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) as m:
                  self.assertEqual(m.size(), 0x180000000)
 -            finally:
 -                m.close()
  
 -            m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
 -            try:
+     # Issue 11277: mmap() with large (~4GB) sparse files crashes on OS X.
+     def _test_around_boundary(self, boundary):
+         tail = b'  DEARdear  '
+         start = boundary - len(tail) // 2
+         end = start + len(tail)
+         self._create_test_file(start, tail)
+         with open(TESTFN, 'rb') as f:
 -            finally:
 -                m.close()
++            with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
+                 self.assertEqual(m[start:end], tail)
+     @unittest.skipUnless(sys.maxsize > _4G, "test cannot run on 32-bit systems")
+     def test_around_2GB(self):
+         self._test_around_boundary(_2G)
+     @unittest.skipUnless(sys.maxsize > _4G, "test cannot run on 32-bit systems")
+     def test_around_4GB(self):
+         self._test_around_boundary(_4G)
  
  def test_main():
      run_unittest(MmapTests, LargeMmapTests)