Skip to content

Commit

Permalink
pythongh-108297: Update test_crashers
Browse files Browse the repository at this point in the history
* 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 pythongh-89419
  * mutation_inside_cyclegc.py: fixed by pythongh-97922
  * trace_at_recursion_limit.py: fixed by Python 3.7
  • Loading branch information
vstinner committed Aug 22, 2023
1 parent 6541fe4 commit 00b9633
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 96 deletions.
31 changes: 0 additions & 31 deletions Lib/test/crashers/mutation_inside_cyclegc.py

This file was deleted.

15 changes: 0 additions & 15 deletions Lib/test/crashers/recursive_call.py

This file was deleted.

27 changes: 0 additions & 27 deletions Lib/test/crashers/trace_at_recursion_limit.py

This file was deleted.

8 changes: 4 additions & 4 deletions Lib/test/crashers/README → Lib/test/test_crashers/README
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ too obscure to invest the effort.

Each test should fail when run from the command line:

./python Lib/test/crashers/weakref_in_del.py
./python Lib/test/test_crashers/bogus_code_obj.py

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

Also see Lib/test_crashers.py which exercises the crashers in this directory.
In particular, make sure to add any new infinite loop crashers to the black
list so it doesn't try to run them.
Also see Lib/test/test_crashers/__init__.py which exercises the crashers in
this directory. In particular, make sure to add any new infinite loop crashers
to the black list so it doesn't try to run them.
30 changes: 18 additions & 12 deletions Lib/test/test_crashers.py → Lib/test/test_crashers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,40 @@
# If a crasher is fixed, it should be moved elsewhere in the test suite to
# ensure it continues to work correctly.

import unittest
import glob
import os.path
import test.support
import unittest
from test import support
from test.support.script_helper import assert_python_failure

CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers")

CRASHER_DIR = os.path.abspath(os.path.dirname(__file__))
CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py")
infinite_loops = frozenset(["infinite_loop_re.py"])

infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"]

class CrasherTest(unittest.TestCase):

@unittest.skip("these tests are too fragile")
@test.support.cpython_only
@support.cpython_only
def test_crashers_crash(self):
if support.verbose:
print()
for fname in glob.glob(CRASHER_FILES):
if os.path.basename(fname) in infinite_loops:
script = os.path.basename(fname)
if script == "__init__.py":
continue
if script in infinite_loops:
continue
# Some "crashers" only trigger an exception rather than a
# segfault. Consider that an acceptable outcome.
if test.support.verbose:
print("Checking crasher:", fname)
assert_python_failure(fname)
if support.verbose:
print(f"Checking crasher: {script}", flush=True)
proc = assert_python_failure(fname)
self.assertLess(proc.rc, 0, proc)


def tearDownModule():
test.support.reap_children()
support.reap_children()


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"""

import types
from test.support import SuppressCrashReport

co = types.CodeType(0, 0, 0, 0, 0, 0, b'\x04\x00\x71\x00',
(), (), (), '', '', 1, b'')
exec(co)
def func():
pass

invalid_code = b'\x04\x00\x71\x00'
func.__code__ = func.__code__.replace(co_code=invalid_code)

with SuppressCrashReport():
func()
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
fixes to the documentation for extension module writers. It's unlikely
to happen, though. So this is currently classified as
"gc.get_referrers() is dangerous, use only for debugging".
* https://github.com/python/cpython/issues/39117
* https://github.com/python/cpython/issues/59313
* https://github.com/python/cpython/pull/107183
"""

import gc
from test.support import SuppressCrashReport


def g():
Expand All @@ -29,4 +34,5 @@ def g():
print(tup[1])


tuple(g())
with SuppressCrashReport():
tuple(g())
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from test.support import SuppressCrashReport
import gc

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

print(a.f()) # should print 1
with SuppressCrashReport():
print(a.f()) # should print 1
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,6 @@ TESTSUBDIRS= idlelib/idle_test \
test/audiodata \
test/capath \
test/cjkencodings \
test/crashers \
test/data \
test/decimaltestdata \
test/dtracedata \
Expand All @@ -2156,6 +2155,7 @@ TESTSUBDIRS= idlelib/idle_test \
test/support/_hypothesis_stubs \
test/test_asyncio \
test/test_capi \
test/test_crashers \
test/test_ctypes \
test/test_email \
test/test_email/data \
Expand Down

0 comments on commit 00b9633

Please sign in to comment.