Skip to content

gh-108297: Update test_crashers #108299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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.

37 changes: 0 additions & 37 deletions Lib/test/test_crashers.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.
50 changes: 50 additions & 0 deletions Lib/test/test_crashers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Tests that the crashers in the Lib/test/crashers directory actually
# do crash the interpreter as expected
#
# If a crasher is fixed, it should be moved elsewhere in the test suite to
# ensure it continues to work correctly.

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


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"])


@support.skip_if_sanitizer(address=True, memory=True)
@support.cpython_only
class CrasherTest(unittest.TestCase):
def test_crashers_crash(self):
if support.verbose:
print()
for fname in glob.glob(CRASHER_FILES):
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 support.verbose:
print(f"Checking crasher: {script}", flush=True)
proc = assert_python_failure(fname)
if os.name != "nt":
# On Unix, if proc.rc is negative, the process was killed
# by a signal
self.assertLess(proc.rc, 0, proc)
else:
# Windows. For example, C0000005 is an Access Violation
self.assertGreaterEqual(proc.rc, 0xC0000000, proc)


def tearDownModule():
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())
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 @@ -2157,6 +2156,7 @@ TESTSUBDIRS= idlelib/idle_test \
test/test_asyncio \
test/test_capi \
test/test_cppext \
test/test_crashers \
test/test_ctypes \
test/test_email \
test/test_email/data \
Expand Down