summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-08-04 10:25:51 (GMT)
committerGitHub <noreply@github.com>2023-08-04 10:25:51 (GMT)
commit98902d6c0522df022d2f88499faf9774970e2838 (patch)
tree3c5919fae5314286a774ae9ebe8e682a4b5d50c5 /Lib/test
parent58af2293c52a1ad3754d254690c0e54f787c545b (diff)
downloadcpython-98902d6c0522df022d2f88499faf9774970e2838.zip
cpython-98902d6c0522df022d2f88499faf9774970e2838.tar.gz
cpython-98902d6c0522df022d2f88499faf9774970e2838.tar.bz2
[3.12] GH-107263: Increase C stack limit for most functions, except `_PyEval_EvalFrameDefault()` (GH-107535) (#107618)
GH-107263: Increase C stack limit for most functions, except `_PyEval_EvalFrameDefault()` (GH-107535) * Set C recursion limit to 1500, set cost of eval loop to 2 frames, and compiler mutliply to 2. (cherry picked from commit fa45958450aa3489607daf9855ca0474a2a20878) Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/list_tests.py4
-rw-r--r--Lib/test/mapping_tests.py3
-rw-r--r--Lib/test/support/__init__.py10
-rw-r--r--Lib/test/test_ast.py1
-rw-r--r--Lib/test/test_call.py3
-rw-r--r--Lib/test/test_compile.py21
-rw-r--r--Lib/test/test_dict.py4
-rw-r--r--Lib/test/test_dictviews.py3
-rw-r--r--Lib/test/test_exception_group.py4
-rw-r--r--Lib/test/test_zlib.py7
10 files changed, 32 insertions, 28 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index fe3ee80..b1ef332 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -6,7 +6,7 @@ import sys
from functools import cmp_to_key
from test import seq_tests
-from test.support import ALWAYS_EQ, NEVER_EQ
+from test.support import ALWAYS_EQ, NEVER_EQ, C_RECURSION_LIMIT
class CommonTest(seq_tests.CommonTest):
@@ -61,7 +61,7 @@ class CommonTest(seq_tests.CommonTest):
def test_repr_deep(self):
a = self.type2test([])
- for i in range(sys.getrecursionlimit() + 100):
+ for i in range(C_RECURSION_LIMIT + 1):
a = self.type2test([a])
self.assertRaises(RecursionError, repr, a)
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py
index 613206a..5492bbf 100644
--- a/Lib/test/mapping_tests.py
+++ b/Lib/test/mapping_tests.py
@@ -2,6 +2,7 @@
import unittest
import collections
import sys
+from test.support import C_RECURSION_LIMIT
class BasicTestMappingProtocol(unittest.TestCase):
@@ -624,7 +625,7 @@ class TestHashMappingProtocol(TestMappingProtocol):
def test_repr_deep(self):
d = self._empty_mapping()
- for i in range(sys.getrecursionlimit() + 100):
+ for i in range(C_RECURSION_LIMIT + 1):
d0 = d
d = self._empty_mapping()
d[1] = d0
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 3b332f4..c3c3cf0 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -64,7 +64,8 @@ __all__ = [
"run_with_tz", "PGO", "missing_compiler_executable",
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
- "Py_DEBUG", "EXCEEDS_RECURSION_LIMIT",
+ "Py_DEBUG", "EXCEEDS_RECURSION_LIMIT", "C_RECURSION_LIMIT",
+ "skip_on_s390x",
]
@@ -2460,3 +2461,10 @@ def adjust_int_max_str_digits(max_digits):
#For recursion tests, easily exceeds default recursion limit
EXCEEDS_RECURSION_LIMIT = 5000
+
+# The default C recursion limit (from Include/cpython/pystate.h).
+C_RECURSION_LIMIT = 1500
+
+#Windows doesn't have os.uname() but it doesn't support s390x.
+skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
+ 'skipped on s390x')
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index a03fa4c..5346b39 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1084,6 +1084,7 @@ class AST_Tests(unittest.TestCase):
return self
enum._test_simple_enum(_Precedence, ast._Precedence)
+ @unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
@support.cpython_only
def test_ast_recursion_limit(self):
fail_depth = support.EXCEEDS_RECURSION_LIMIT
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index 12759c5..ec8dc29 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -1,5 +1,5 @@
import unittest
-from test.support import cpython_only, requires_limited_api
+from test.support import cpython_only, requires_limited_api, skip_on_s390x
try:
import _testcapi
except ImportError:
@@ -931,6 +931,7 @@ class TestErrorMessagesUseQualifiedName(unittest.TestCase):
@cpython_only
class TestRecursion(unittest.TestCase):
+ @skip_on_s390x
def test_super_deep(self):
def recurse(n):
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 784c055..142d3f5 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -11,10 +11,9 @@ import textwrap
import warnings
from test import support
from test.support import (script_helper, requires_debug_ranges,
- requires_specialization)
+ requires_specialization, C_RECURSION_LIMIT)
from test.support.os_helper import FakePath
-
class TestSpecifics(unittest.TestCase):
def compile_single(self, source):
@@ -112,7 +111,7 @@ class TestSpecifics(unittest.TestCase):
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
def test_extended_arg(self):
- repeat = 2000
+ repeat = int(C_RECURSION_LIMIT * 0.9)
longexpr = 'x = x or ' + '-x' * repeat
g = {}
code = textwrap.dedent('''
@@ -558,16 +557,12 @@ class TestSpecifics(unittest.TestCase):
@support.cpython_only
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
def test_compiler_recursion_limit(self):
- # Expected limit is sys.getrecursionlimit() * the scaling factor
- # in symtable.c (currently 3)
- # We expect to fail *at* that limit, because we use up some of
- # the stack depth limit in the test suite code
- # So we check the expected limit and 75% of that
- # XXX (ncoghlan): duplicating the scaling factor here is a little
- # ugly. Perhaps it should be exposed somewhere...
- fail_depth = sys.getrecursionlimit() * 3
- crash_depth = sys.getrecursionlimit() * 300
- success_depth = int(fail_depth * 0.75)
+ # Expected limit is C_RECURSION_LIMIT * 2
+ # Duplicating the limit here is a little ugly.
+ # Perhaps it should be exposed somewhere...
+ fail_depth = C_RECURSION_LIMIT * 2 + 1
+ crash_depth = C_RECURSION_LIMIT * 100
+ success_depth = int(C_RECURSION_LIMIT * 1.8)
def check_limit(prefix, repeated, mode="single"):
expect_ok = prefix + repeated * success_depth
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 7963834..fbc6ce8 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -8,7 +8,7 @@ import sys
import unittest
import weakref
from test import support
-from test.support import import_helper
+from test.support import import_helper, C_RECURSION_LIMIT
class DictTest(unittest.TestCase):
@@ -596,7 +596,7 @@ class DictTest(unittest.TestCase):
def test_repr_deep(self):
d = {}
- for i in range(sys.getrecursionlimit() + 100):
+ for i in range(C_RECURSION_LIMIT + 1):
d = {1: d}
self.assertRaises(RecursionError, repr, d)
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 924f4a6..2bd9d6e 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -3,6 +3,7 @@ import copy
import pickle
import sys
import unittest
+from test.support import C_RECURSION_LIMIT
class DictSetTest(unittest.TestCase):
@@ -279,7 +280,7 @@ class DictSetTest(unittest.TestCase):
def test_deeply_nested_repr(self):
d = {}
- for i in range(sys.getrecursionlimit() + 100):
+ for i in range(C_RECURSION_LIMIT//2 + 100):
d = {42: d.values()}
self.assertRaises(RecursionError, repr, d)
diff --git a/Lib/test/test_exception_group.py b/Lib/test/test_exception_group.py
index fa159a7..22be3a7 100644
--- a/Lib/test/test_exception_group.py
+++ b/Lib/test/test_exception_group.py
@@ -1,7 +1,7 @@
import collections.abc
import types
import unittest
-
+from test.support import C_RECURSION_LIMIT
class TestExceptionGroupTypeHierarchy(unittest.TestCase):
def test_exception_group_types(self):
@@ -433,7 +433,7 @@ class ExceptionGroupSplitTests(ExceptionGroupTestBase):
class DeepRecursionInSplitAndSubgroup(unittest.TestCase):
def make_deep_eg(self):
e = TypeError(1)
- for i in range(2000):
+ for i in range(C_RECURSION_LIMIT + 1):
e = ExceptionGroup('eg', [e])
return e
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 3dac70e..2113757 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -7,7 +7,7 @@ import os
import pickle
import random
import sys
-from test.support import bigmemtest, _1G, _4G
+from test.support import bigmemtest, _1G, _4G, skip_on_s390x
zlib = import_helper.import_module('zlib')
@@ -44,10 +44,7 @@ requires_Decompress_copy = unittest.skipUnless(
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
#
# Make the assumption that s390x always has an accelerator to simplify the skip
-# condition. Windows doesn't have os.uname() but it doesn't support s390x.
-skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
- 'skipped on s390x')
-
+# condition.
class VersionTestCase(unittest.TestCase):