Skip to content

Commit e05d202

Browse files
authored
gh-117755: Remove tests on huge memory allocations (#117938)
Remove unreliable tests on huge memory allocations: * Remove test_maxcontext_exact_arith() of test_decimal. Stefan Krah, test author, agreed on removing the test: #114331 (comment) * Remove test_constructor() tests of test_io. Sam Gross suggests remove them: #117809 (review) On Linux, depending how overcommit is configured, especially on Linux s390x, a huge memory allocation (half or more of the full address space) can succeed, but then the process will eat the full system swap and make the system slower and slower until the whole system becomes unusable. Moreover, these tests had to be skipped when Python is built with sanitizers.
1 parent 241ed5f commit e05d202

File tree

2 files changed

+2
-97
lines changed

2 files changed

+2
-97
lines changed

Lib/test/test_decimal.py

+1-47
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@
3434
import locale
3535
from test.support import (is_resource_enabled,
3636
requires_IEEE_754, requires_docstrings,
37-
check_sanitizer,
3837
check_disallow_instantiation)
3938
from test.support import (TestFailed,
4039
run_with_locale, cpython_only,
41-
darwin_malloc_err_warning, is_emscripten,
42-
skip_on_s390x)
40+
darwin_malloc_err_warning)
4341
from test.support.import_helper import import_fresh_module
4442
from test.support import threading_helper
4543
from test.support import warnings_helper
@@ -5644,50 +5642,6 @@ def __abs__(self):
56445642
self.assertEqual(Decimal.from_float(cls(101.1)),
56455643
Decimal.from_float(101.1))
56465644

5647-
# Issue 41540:
5648-
@unittest.skipIf(sys.platform.startswith("aix"),
5649-
"AIX: default ulimit: test is flaky because of extreme over-allocation")
5650-
@unittest.skipIf(is_emscripten, "Test is unstable on Emscripten")
5651-
@unittest.skipIf(check_sanitizer(address=True, memory=True),
5652-
"ASAN/MSAN sanitizer defaults to crashing "
5653-
"instead of returning NULL for malloc failure.")
5654-
# gh-114331: The test allocates 784 271 641 GiB and mimalloc does not fail
5655-
# to allocate it when using mimalloc on s390x.
5656-
@skip_on_s390x
5657-
def test_maxcontext_exact_arith(self):
5658-
5659-
# Make sure that exact operations do not raise MemoryError due
5660-
# to huge intermediate values when the context precision is very
5661-
# large.
5662-
5663-
# The following functions fill the available precision and are
5664-
# therefore not suitable for large precisions (by design of the
5665-
# specification).
5666-
MaxContextSkip = ['logical_invert', 'next_minus', 'next_plus',
5667-
'logical_and', 'logical_or', 'logical_xor',
5668-
'next_toward', 'rotate', 'shift']
5669-
5670-
Decimal = C.Decimal
5671-
Context = C.Context
5672-
localcontext = C.localcontext
5673-
5674-
# Here only some functions that are likely candidates for triggering a
5675-
# MemoryError are tested. deccheck.py has an exhaustive test.
5676-
maxcontext = Context(prec=C.MAX_PREC, Emin=C.MIN_EMIN, Emax=C.MAX_EMAX)
5677-
with localcontext(maxcontext):
5678-
self.assertEqual(Decimal(0).exp(), 1)
5679-
self.assertEqual(Decimal(1).ln(), 0)
5680-
self.assertEqual(Decimal(1).log10(), 0)
5681-
self.assertEqual(Decimal(10**2).log10(), 2)
5682-
self.assertEqual(Decimal(10**223).log10(), 223)
5683-
self.assertEqual(Decimal(10**19).logb(), 19)
5684-
self.assertEqual(Decimal(4).sqrt(), 2)
5685-
self.assertEqual(Decimal("40E9").sqrt(), Decimal('2.0E+5'))
5686-
self.assertEqual(divmod(Decimal(10), 3), (3, 1))
5687-
self.assertEqual(Decimal(10) // 3, 3)
5688-
self.assertEqual(Decimal(4) / 2, 2)
5689-
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
5690-
56915645
def test_c_immutable_types(self):
56925646
SignalDict = type(C.Context().flags)
56935647
SignalDictMixin = SignalDict.__bases__[0]

Lib/test/test_io.py

+1-50
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
from test.support.script_helper import (
4141
assert_python_ok, assert_python_failure, run_python_until_end)
4242
from test.support import (
43-
import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper,
44-
skip_on_s390x
43+
import_helper, is_apple, os_helper, threading_helper, warnings_helper,
4544
)
4645
from test.support.os_helper import FakePath
4746

@@ -1698,22 +1697,6 @@ def test_seek_character_device_file(self):
16981697
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
16991698
tp = io.BufferedReader
17001699

1701-
@skip_if_sanitizer(memory=True, address=True, thread=True,
1702-
reason="sanitizer defaults to crashing "
1703-
"instead of returning NULL for malloc failure.")
1704-
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
1705-
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
1706-
@skip_on_s390x
1707-
def test_constructor(self):
1708-
BufferedReaderTest.test_constructor(self)
1709-
# The allocation can succeed on 32-bit builds, e.g. with more
1710-
# than 2 GiB RAM and a 64-bit kernel.
1711-
if sys.maxsize > 0x7FFFFFFF:
1712-
rawio = self.MockRawIO()
1713-
bufio = self.tp(rawio)
1714-
self.assertRaises((OverflowError, MemoryError, ValueError),
1715-
bufio.__init__, rawio, sys.maxsize)
1716-
17171700
def test_initialization(self):
17181701
rawio = self.MockRawIO([b"abc"])
17191702
bufio = self.tp(rawio)
@@ -2069,22 +2052,6 @@ def test_slow_close_from_thread(self):
20692052
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
20702053
tp = io.BufferedWriter
20712054

2072-
@skip_if_sanitizer(memory=True, address=True, thread=True,
2073-
reason="sanitizer defaults to crashing "
2074-
"instead of returning NULL for malloc failure.")
2075-
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
2076-
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
2077-
@skip_on_s390x
2078-
def test_constructor(self):
2079-
BufferedWriterTest.test_constructor(self)
2080-
# The allocation can succeed on 32-bit builds, e.g. with more
2081-
# than 2 GiB RAM and a 64-bit kernel.
2082-
if sys.maxsize > 0x7FFFFFFF:
2083-
rawio = self.MockRawIO()
2084-
bufio = self.tp(rawio)
2085-
self.assertRaises((OverflowError, MemoryError, ValueError),
2086-
bufio.__init__, rawio, sys.maxsize)
2087-
20882055
def test_initialization(self):
20892056
rawio = self.MockRawIO()
20902057
bufio = self.tp(rawio)
@@ -2594,22 +2561,6 @@ def test_interleaved_readline_write(self):
25942561
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
25952562
tp = io.BufferedRandom
25962563

2597-
@skip_if_sanitizer(memory=True, address=True, thread=True,
2598-
reason="sanitizer defaults to crashing "
2599-
"instead of returning NULL for malloc failure.")
2600-
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
2601-
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
2602-
@skip_on_s390x
2603-
def test_constructor(self):
2604-
BufferedRandomTest.test_constructor(self)
2605-
# The allocation can succeed on 32-bit builds, e.g. with more
2606-
# than 2 GiB RAM and a 64-bit kernel.
2607-
if sys.maxsize > 0x7FFFFFFF:
2608-
rawio = self.MockRawIO()
2609-
bufio = self.tp(rawio)
2610-
self.assertRaises((OverflowError, MemoryError, ValueError),
2611-
bufio.__init__, rawio, sys.maxsize)
2612-
26132564
def test_garbage_collection(self):
26142565
CBufferedReaderTest.test_garbage_collection(self)
26152566
CBufferedWriterTest.test_garbage_collection(self)

0 commit comments

Comments
 (0)