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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Restore tests
  • Loading branch information
vstinner committed Apr 16, 2024
commit 14d1a1138975fcdbdad040c0c1a1c850cae47dbc
62 changes: 1 addition & 61 deletions Lib/test/test_bigaddrspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,9 @@
from test import support
from test.support import bigaddrspacetest, MAX_Py_ssize_t

import contextlib
import unittest
import operator
import os
import sys
import unittest


@contextlib.contextmanager
def ignore_stderr():
fd = 2
old_stderr = os.dup(fd)
try:
# Redirect stderr to /dev/null
with open(os.devnull, 'wb') as null:
os.dup2(null.fileno(), fd)
yield
finally:
os.dup2(old_stderr, fd)
os.close(old_stderr)


class BytesTest(unittest.TestCase):
Expand Down Expand Up @@ -68,50 +52,6 @@ def test_repeat(self):
finally:
x = None

@unittest.skipUnless(sys.maxsize >= 0x7FFFFFFF_FFFFFFFF,
'need 64-bit size')
def test_large_alloc(self):
debug_bytes = 0
if support.check_impl_detail(cpython=True) and support.Py_DEBUG:
try:
from _testcapi import SIZEOF_SIZE_T
except ImportError:
if sys.maxsize > 0xffff_ffff:
SIZEOF_SIZE_T = 8
else:
SIZEOF_SIZE_T = 4

# The debug hook on memory allocator adds 3 size_t per memory block
# See PYMEM_DEBUG_EXTRA_BYTES in Objects/obmalloc.c.
debug_bytes = SIZEOF_SIZE_T * 3

try:
from _testinternalcapi import pymem_getallocatorsname
if not pymem_getallocatorsname().endswith('_debug'):
# PYTHONMALLOC env var is used and disables the debug hook
debug_bytes = 0
except (ImportError, RuntimeError):
pass

def allocate(size):
length = size - sys.getsizeof(b'') - debug_bytes
# allocate 'size' bytes
return b'x' * length

# 64-bit size which cannot be allocated on any reasonable hardware
# (in 2024) and must fail immediately with MemoryError.
for size in (
# gh-114331: test_decimal.test_maxcontext_exact_arith()
0x0BAFC246_72035E58,
# gh-117755: test_io.test_constructor()
0x7FFFFFFF_FFFFFFFF,
):
with self.subTest(size=size):
with self.assertRaises(MemoryError):
# ignore "mimalloc: error: unable to allocate memory"
with ignore_stderr():
allocate(size)


class StrTest(unittest.TestCase):

Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
check_disallow_instantiation)
from test.support import (TestFailed,
run_with_locale, cpython_only,
darwin_malloc_err_warning, is_emscripten)
darwin_malloc_err_warning, is_emscripten,
skip_on_s390x)
from test.support.import_helper import import_fresh_module
from test.support import threading_helper
from test.support import warnings_helper
Expand Down Expand Up @@ -5650,6 +5651,9 @@ def __abs__(self):
@unittest.skipIf(check_sanitizer(address=True, memory=True),
"ASAN/MSAN sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-114331: The test allocates 784 271 641 GiB and mimalloc does not fail
# to allocate it when using mimalloc on s390x.
@skip_on_s390x
def test_maxcontext_exact_arith(self):

# Make sure that exact operations do not raise MemoryError due
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
assert_python_ok, assert_python_failure, run_python_until_end)
from test.support import (
import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper,
skip_on_s390x
)
from test.support.os_helper import FakePath

Expand Down Expand Up @@ -1700,6 +1701,9 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedReaderTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down Expand Up @@ -2068,6 +2072,9 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedWriterTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down Expand Up @@ -2590,6 +2597,9 @@ class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
@skip_if_sanitizer(memory=True, address=True, thread=True,
reason="sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
# gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
# (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
@skip_on_s390x
def test_constructor(self):
BufferedRandomTest.test_constructor(self)
# The allocation can succeed on 32-bit builds, e.g. with more
Expand Down