|
30 | 30 | "record_original_stdout", "get_original_stdout", "captured_stdout", |
31 | 31 | "captured_stdin", "captured_stderr", "captured_output", |
32 | 32 | # unittest |
33 | | - "is_resource_enabled", "requires", "requires_freebsd_version", |
| 33 | + "is_resource_enabled", "get_resource_value", "requires", "requires_resource", |
| 34 | + "requires_freebsd_version", |
34 | 35 | "requires_gil_enabled", "requires_linux_version", "requires_mac_ver", |
35 | 36 | "check_syntax_error", |
36 | 37 | "requires_gzip", "requires_bz2", "requires_lzma", "requires_zstd", |
|
43 | 44 | "check__all__", "skip_if_buggy_ucrt_strfptime", |
44 | 45 | "check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer", |
45 | 46 | "requires_limited_api", "requires_specialization", "thread_unsafe", |
| 47 | + "skip_if_unlimited_stack_size", |
46 | 48 | # sys |
47 | 49 | "MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi", |
48 | 50 | "is_apple_mobile", "check_impl_detail", "unix_shell", "setswitchinterval", |
@@ -184,7 +186,7 @@ def get_attribute(obj, name): |
184 | 186 | return attribute |
185 | 187 |
|
186 | 188 | verbose = 1 # Flag set to 0 by regrtest.py |
187 | | -use_resources = None # Flag set to [] by regrtest.py |
| 189 | +use_resources = None # Flag set to {} by regrtest.py |
188 | 190 | max_memuse = 0 # Disable bigmem tests (they will still be run with |
189 | 191 | # small sizes, to make sure they work.) |
190 | 192 | real_max_memuse = 0 |
@@ -299,6 +301,16 @@ def is_resource_enabled(resource): |
299 | 301 | """ |
300 | 302 | return use_resources is None or resource in use_resources |
301 | 303 |
|
| 304 | +def get_resource_value(resource): |
| 305 | + """Test whether a resource is enabled. |
| 306 | +
|
| 307 | + Known resources are set by regrtest.py. If not running under regrtest.py, |
| 308 | + all resources are assumed enabled unless use_resources has been set. |
| 309 | + """ |
| 310 | + if use_resources is None: |
| 311 | + return None |
| 312 | + return use_resources.get(resource) |
| 313 | + |
302 | 314 | def requires(resource, msg=None): |
303 | 315 | """Raise ResourceDenied if the specified resource is not available.""" |
304 | 316 | if not is_resource_enabled(resource): |
@@ -1669,6 +1681,25 @@ def skip_if_pgo_task(test): |
1669 | 1681 | return test if ok else unittest.skip(msg)(test) |
1670 | 1682 |
|
1671 | 1683 |
|
| 1684 | +def skip_if_unlimited_stack_size(test): |
| 1685 | + """Skip decorator for tests not run when an unlimited stack size is configured. |
| 1686 | +
|
| 1687 | + Tests using support.infinite_recursion([...]) may otherwise run into |
| 1688 | + an infinite loop, running until the memory on the system is filled and |
| 1689 | + crashing due to OOM. |
| 1690 | +
|
| 1691 | + See https://github.com/python/cpython/issues/143460. |
| 1692 | + """ |
| 1693 | + if is_emscripten or is_wasi or os.name == "nt": |
| 1694 | + return test |
| 1695 | + |
| 1696 | + import resource |
| 1697 | + curlim, maxlim = resource.getrlimit(resource.RLIMIT_STACK) |
| 1698 | + unlimited_stack_size_cond = curlim == maxlim and curlim in (-1, 0xFFFF_FFFF_FFFF_FFFF) |
| 1699 | + reason = "Not run due to unlimited stack size" |
| 1700 | + return unittest.skipIf(unlimited_stack_size_cond, reason)(test) |
| 1701 | + |
| 1702 | + |
1672 | 1703 | def detect_api_mismatch(ref_api, other_api, *, ignore=()): |
1673 | 1704 | """Returns the set of items in ref_api not in other_api, except for a |
1674 | 1705 | defined list of items to be ignored in this check. |
@@ -3184,3 +3215,10 @@ def linked_to_musl(): |
3184 | 3215 | return _linked_to_musl |
3185 | 3216 | _linked_to_musl = tuple(map(int, version.split('.'))) |
3186 | 3217 | return _linked_to_musl |
| 3218 | + |
| 3219 | + |
| 3220 | +def control_characters_c0() -> list[str]: |
| 3221 | + """Returns a list of C0 control characters as strings. |
| 3222 | + C0 control characters defined as the byte range 0x00-0x1F, and 0x7F. |
| 3223 | + """ |
| 3224 | + return [chr(c) for c in range(0x00, 0x20)] + ["\x7F"] |
0 commit comments