Skip to content

Commit 00b9633

Browse files
committed
gh-108297: Update test_crashers
* Rename Lib/test/crashers/ to Lib/test/test_crashers/. * Move Lib/test/test_crashers.py to Lib/test/test_crashers/__init__.py. * test_crashers is no longer skipped and makes sure that scripts do crash, and no simply fail with a non-zero exit code. * Update bogus_code_obj.py to use CodeType.replace(). * Scripts crashing Python now uses SuppressCrashReport of test.support to not create coredump files. * Remove Lib/test/crashers/ scripts which no longer crash: * recursive_call.py: fixed by gh-89419 * mutation_inside_cyclegc.py: fixed by gh-97922 * trace_at_recursion_limit.py: fixed by Python 3.7
1 parent 6541fe4 commit 00b9633

10 files changed

+42
-96
lines changed

Lib/test/crashers/mutation_inside_cyclegc.py

-31
This file was deleted.

Lib/test/crashers/recursive_call.py

-15
This file was deleted.

Lib/test/crashers/trace_at_recursion_limit.py

-27
This file was deleted.

Lib/test/crashers/README renamed to Lib/test/test_crashers/README

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ too obscure to invest the effort.
55

66
Each test should fail when run from the command line:
77

8-
./python Lib/test/crashers/weakref_in_del.py
8+
./python Lib/test/test_crashers/bogus_code_obj.py
99

1010
Put as much info into a docstring or comments to help determine the cause of the
1111
failure, as well as a bugs.python.org issue number if it exists. Particularly
@@ -15,6 +15,6 @@ Once the crash is fixed, the test case should be moved into an appropriate test
1515
(even if it was originally from the test suite). This ensures the regression
1616
doesn't happen again. And if it does, it should be easier to track down.
1717

18-
Also see Lib/test_crashers.py which exercises the crashers in this directory.
19-
In particular, make sure to add any new infinite loop crashers to the black
20-
list so it doesn't try to run them.
18+
Also see Lib/test/test_crashers/__init__.py which exercises the crashers in
19+
this directory. In particular, make sure to add any new infinite loop crashers
20+
to the black list so it doesn't try to run them.

Lib/test/test_crashers.py renamed to Lib/test/test_crashers/__init__.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,40 @@
44
# If a crasher is fixed, it should be moved elsewhere in the test suite to
55
# ensure it continues to work correctly.
66

7-
import unittest
87
import glob
98
import os.path
10-
import test.support
9+
import unittest
10+
from test import support
1111
from test.support.script_helper import assert_python_failure
1212

13-
CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers")
13+
14+
CRASHER_DIR = os.path.abspath(os.path.dirname(__file__))
1415
CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py")
16+
infinite_loops = frozenset(["infinite_loop_re.py"])
1517

16-
infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"]
1718

1819
class CrasherTest(unittest.TestCase):
19-
20-
@unittest.skip("these tests are too fragile")
21-
@test.support.cpython_only
20+
@support.cpython_only
2221
def test_crashers_crash(self):
22+
if support.verbose:
23+
print()
2324
for fname in glob.glob(CRASHER_FILES):
24-
if os.path.basename(fname) in infinite_loops:
25+
script = os.path.basename(fname)
26+
if script == "__init__.py":
27+
continue
28+
if script in infinite_loops:
2529
continue
2630
# Some "crashers" only trigger an exception rather than a
2731
# segfault. Consider that an acceptable outcome.
28-
if test.support.verbose:
29-
print("Checking crasher:", fname)
30-
assert_python_failure(fname)
32+
if support.verbose:
33+
print(f"Checking crasher: {script}", flush=True)
34+
proc = assert_python_failure(fname)
35+
self.assertLess(proc.rc, 0, proc)
3136

3237

3338
def tearDownModule():
34-
test.support.reap_children()
39+
support.reap_children()
40+
3541

3642
if __name__ == "__main__":
3743
unittest.main()

Lib/test/crashers/bogus_code_obj.py renamed to Lib/test/test_crashers/bogus_code_obj.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
1313
"""
1414

15-
import types
15+
from test.support import SuppressCrashReport
1616

17-
co = types.CodeType(0, 0, 0, 0, 0, 0, b'\x04\x00\x71\x00',
18-
(), (), (), '', '', 1, b'')
19-
exec(co)
17+
def func():
18+
pass
19+
20+
invalid_code = b'\x04\x00\x71\x00'
21+
func.__code__ = func.__code__.replace(co_code=invalid_code)
22+
23+
with SuppressCrashReport():
24+
func()

Lib/test/crashers/gc_inspection.py renamed to Lib/test/test_crashers/gc_inspection.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
fixes to the documentation for extension module writers. It's unlikely
1616
to happen, though. So this is currently classified as
1717
"gc.get_referrers() is dangerous, use only for debugging".
18+
19+
* https://github.com/python/cpython/issues/39117
20+
* https://github.com/python/cpython/issues/59313
21+
* https://github.com/python/cpython/pull/107183
1822
"""
1923

2024
import gc
25+
from test.support import SuppressCrashReport
2126

2227

2328
def g():
@@ -29,4 +34,5 @@ def g():
2934
print(tup[1])
3035

3136

32-
tuple(g())
37+
with SuppressCrashReport():
38+
tuple(g())

Lib/test/crashers/underlying_dict.py renamed to Lib/test/test_crashers/underlying_dict.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from test.support import SuppressCrashReport
12
import gc
23

34
thingy = object()
@@ -17,4 +18,5 @@ def f(self):
1718
a.f()
1819
dct["f"] = lambda self: 2
1920

20-
print(a.f()) # should print 1
21+
with SuppressCrashReport():
22+
print(a.f()) # should print 1

Makefile.pre.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,6 @@ TESTSUBDIRS= idlelib/idle_test \
21442144
test/audiodata \
21452145
test/capath \
21462146
test/cjkencodings \
2147-
test/crashers \
21482147
test/data \
21492148
test/decimaltestdata \
21502149
test/dtracedata \
@@ -2156,6 +2155,7 @@ TESTSUBDIRS= idlelib/idle_test \
21562155
test/support/_hypothesis_stubs \
21572156
test/test_asyncio \
21582157
test/test_capi \
2158+
test/test_crashers \
21592159
test/test_ctypes \
21602160
test/test_email \
21612161
test/test_email/data \

0 commit comments

Comments
 (0)