diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-27 16:48:17 (GMT) |
---|---|---|
committer | Antoine Pitrou <antoine@python.org> | 2019-05-27 16:48:16 (GMT) |
commit | 02db696732c031d9a0265dc9bbf4f5b1fad042b3 (patch) | |
tree | e98de473936501302c683c984a9f8b4fdccf6dd2 /Lib/test/test_mmap.py | |
parent | 331a6a56e9a9c72f3e4605987fabdaec72677702 (diff) | |
download | cpython-02db696732c031d9a0265dc9bbf4f5b1fad042b3.zip cpython-02db696732c031d9a0265dc9bbf4f5b1fad042b3.tar.gz cpython-02db696732c031d9a0265dc9bbf4f5b1fad042b3.tar.bz2 |
bpo-32941: Add madvise() for mmap objects (GH-6172)
Allow mmap objects to access the madvise() system call.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r-- | Lib/test/test_mmap.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 495d24a..7b2b100 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -739,6 +739,25 @@ class MmapTests(unittest.TestCase): # See bpo-34754 for details. self.assertRaises(OSError, mm.flush, 1, len(b'python')) + @unittest.skipUnless(hasattr(mmap.mmap, 'madvise'), 'needs madvise') + def test_madvise(self): + size = 8192 + m = mmap.mmap(-1, size) + + with self.assertRaisesRegex(ValueError, "madvise start out of bounds"): + m.madvise(mmap.MADV_NORMAL, size) + with self.assertRaisesRegex(ValueError, "madvise start out of bounds"): + m.madvise(mmap.MADV_NORMAL, -1) + with self.assertRaisesRegex(ValueError, "madvise length invalid"): + m.madvise(mmap.MADV_NORMAL, 0, -1) + with self.assertRaisesRegex(OverflowError, "madvise length too large"): + m.madvise(mmap.MADV_NORMAL, PAGESIZE, sys.maxsize) + self.assertEqual(m.madvise(mmap.MADV_NORMAL), None) + self.assertEqual(m.madvise(mmap.MADV_NORMAL, PAGESIZE), None) + self.assertEqual(m.madvise(mmap.MADV_NORMAL, PAGESIZE, size), None) + self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, 2), None) + self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, size), None) + class LargeMmapTests(unittest.TestCase): |