Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4847e4e

Browse files
Issue #19886: Use better estimated memory requirements for bigmem tests.
Incorrect requirements can cause memory swapping.
1 parent f451112 commit 4847e4e

6 files changed

Lines changed: 20 additions & 28 deletions

File tree

Lib/test/pickletester.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
# kind of outer loop.
2020
protocols = range(pickle.HIGHEST_PROTOCOL + 1)
2121

22-
ascii_char_size = 1
23-
2422

2523
# Return True if opcode code appears in the pickle, else False.
2624
def opcode_in_pickle(code, pickle):
@@ -1331,7 +1329,7 @@ class BigmemPickleTests(unittest.TestCase):
13311329

13321330
# Binary protocols can serialize longs of up to 2GB-1
13331331

1334-
@bigmemtest(size=_2G, memuse=1 + 1, dry_run=False)
1332+
@bigmemtest(size=_2G, memuse=3.6, dry_run=False)
13351333
def test_huge_long_32b(self, size):
13361334
data = 1 << (8 * size)
13371335
try:
@@ -1347,7 +1345,7 @@ def test_huge_long_32b(self, size):
13471345
# (older protocols don't have a dedicated opcode for bytes and are
13481346
# too inefficient)
13491347

1350-
@bigmemtest(size=_2G, memuse=1 + 1, dry_run=False)
1348+
@bigmemtest(size=_2G, memuse=2.5, dry_run=False)
13511349
def test_huge_bytes_32b(self, size):
13521350
data = b"abcd" * (size // 4)
13531351
try:
@@ -1363,7 +1361,7 @@ def test_huge_bytes_32b(self, size):
13631361
finally:
13641362
data = None
13651363

1366-
@bigmemtest(size=_4G, memuse=1 + 1, dry_run=False)
1364+
@bigmemtest(size=_4G, memuse=2.5, dry_run=False)
13671365
def test_huge_bytes_64b(self, size):
13681366
data = b"a" * size
13691367
try:
@@ -1378,7 +1376,7 @@ def test_huge_bytes_64b(self, size):
13781376
# All protocols use 1-byte per printable ASCII character; we add another
13791377
# byte because the encoded form has to be copied into the internal buffer.
13801378

1381-
@bigmemtest(size=_2G, memuse=2 + ascii_char_size, dry_run=False)
1379+
@bigmemtest(size=_2G, memuse=8, dry_run=False)
13821380
def test_huge_str_32b(self, size):
13831381
data = "abcd" * (size // 4)
13841382
try:
@@ -1395,7 +1393,7 @@ def test_huge_str_32b(self, size):
13951393
# BINUNICODE (protocols 1, 2 and 3) cannot carry more than
13961394
# 2**32 - 1 bytes of utf-8 encoded unicode.
13971395

1398-
@bigmemtest(size=_4G, memuse=1 + ascii_char_size, dry_run=False)
1396+
@bigmemtest(size=_4G, memuse=8, dry_run=False)
13991397
def test_huge_str_64b(self, size):
14001398
data = "a" * size
14011399
try:

Lib/test/test_bz2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def testEOFError(self):
679679
self.assertRaises(EOFError, bz2d.decompress, b"anything")
680680
self.assertRaises(EOFError, bz2d.decompress, b"")
681681

682-
@bigmemtest(size=_4G + 100, memuse=3)
682+
@bigmemtest(size=_4G + 100, memuse=3.3)
683683
def testDecompress4G(self, size):
684684
# "Test BZ2Decompressor.decompress() with >4GiB input"
685685
blocksize = 10 * 1024 * 1024

Lib/test/test_hashlib.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,15 @@ def test_case_md5_2(self):
235235
b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
236236
'd174ab98d277d9f5a5611c2c9f419d9f')
237237

238-
@bigmemtest(size=_4G + 5, memuse=1)
238+
@unittest.skipIf(sys.maxsize < _4G + 5, 'test cannot run on 32-bit systems')
239+
@bigmemtest(size=_4G + 5, memuse=1, dry_run=False)
239240
def test_case_md5_huge(self, size):
240-
if size == _4G + 5:
241-
try:
242-
self.check('md5', b'A'*size, 'c9af2dff37468ce5dfee8f2cfc0a9c6d')
243-
except OverflowError:
244-
pass # 32-bit arch
241+
self.check('md5', b'A'*size, 'c9af2dff37468ce5dfee8f2cfc0a9c6d')
245242

246-
@bigmemtest(size=_4G - 1, memuse=1)
243+
@unittest.skipIf(sys.maxsize < _4G - 1, 'test cannot run on 32-bit systems')
244+
@bigmemtest(size=_4G - 1, memuse=1, dry_run=False)
247245
def test_case_md5_uintmax(self, size):
248-
if size == _4G - 1:
249-
try:
250-
self.check('md5', b'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
251-
except OverflowError:
252-
pass # 32-bit arch
246+
self.check('md5', b'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
253247

254248
# use the three examples from Federal Information Processing Standards
255249
# Publication 180-1, Secure Hash Standard, 1995 April 17

Lib/test/test_marshal.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,19 @@ class LargeValuesTestCase(unittest.TestCase):
303303
def check_unmarshallable(self, data):
304304
self.assertRaises(ValueError, marshal.dump, data, NullWriter())
305305

306-
@support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
306+
@support.bigmemtest(size=LARGE_SIZE, memuse=2, dry_run=False)
307307
def test_bytes(self, size):
308308
self.check_unmarshallable(b'x' * size)
309309

310-
@support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
310+
@support.bigmemtest(size=LARGE_SIZE, memuse=2, dry_run=False)
311311
def test_str(self, size):
312312
self.check_unmarshallable('x' * size)
313313

314-
@support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False)
314+
@support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size + 1, dry_run=False)
315315
def test_tuple(self, size):
316316
self.check_unmarshallable((None,) * size)
317317

318-
@support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False)
318+
@support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size + 1, dry_run=False)
319319
def test_list(self, size):
320320
self.check_unmarshallable([None] * size)
321321

@@ -331,7 +331,7 @@ def test_set(self, size):
331331
def test_frozenset(self, size):
332332
self.check_unmarshallable(frozenset(range(size)))
333333

334-
@support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
334+
@support.bigmemtest(size=LARGE_SIZE, memuse=2, dry_run=False)
335335
def test_bytearray(self, size):
336336
self.check_unmarshallable(bytearray(size))
337337

Lib/test/test_xml_etree_c.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
class MiscTests(unittest.TestCase):
1414
# Issue #8651.
15-
@support.bigmemtest(size=support._2G + 100, memuse=1)
15+
@support.bigmemtest(size=support._2G + 100, memuse=1, dry_run=False)
1616
def test_length_overflow(self, size):
17-
if size < support._2G + 100:
18-
self.skipTest("not enough free memory, need at least 2 GB")
1917
data = b'x' * size
2018
parser = cET.XMLParser()
2119
try:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ IDLE
234234
Tests
235235
-----
236236

237+
- Issue #19886: Use better estimated memory requirements for bigmem tests.
238+
237239
- Issue #20055: Fix test_shutil under Windows with symlink privileges held.
238240
Patch by Vajrasky Kok.
239241

0 commit comments

Comments
 (0)