mirror of
https://github.com/python/cpython.git
synced 2024-12-12 19:33:52 +08:00
Fix test_faulthandler on Android where raise() exits with 0
This commit is contained in:
parent
f056b04eea
commit
6c5f21945a
@ -90,7 +90,7 @@ __all__ = [
|
|||||||
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
|
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
|
||||||
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
|
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
|
||||||
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
|
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
|
||||||
"check__all__",
|
"check__all__", "requires_android_level",
|
||||||
# sys
|
# sys
|
||||||
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
"is_jython", "is_android", "check_impl_detail", "unix_shell",
|
||||||
# network
|
# network
|
||||||
@ -735,7 +735,8 @@ requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
|
|||||||
|
|
||||||
is_jython = sys.platform.startswith('java')
|
is_jython = sys.platform.startswith('java')
|
||||||
|
|
||||||
is_android = bool(sysconfig.get_config_var('ANDROID_API_LEVEL'))
|
_ANDROID_API_LEVEL = sysconfig.get_config_var('ANDROID_API_LEVEL')
|
||||||
|
is_android = (_ANDROID_API_LEVEL > 0)
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
||||||
@ -1725,6 +1726,13 @@ def requires_resource(resource):
|
|||||||
else:
|
else:
|
||||||
return unittest.skip("resource {0!r} is not enabled".format(resource))
|
return unittest.skip("resource {0!r} is not enabled".format(resource))
|
||||||
|
|
||||||
|
def requires_android_level(level, reason):
|
||||||
|
if is_android and _ANDROID_API_LEVEL < level:
|
||||||
|
return unittest.skip('%s at Android API level %d' %
|
||||||
|
(reason, _ANDROID_API_LEVEL))
|
||||||
|
else:
|
||||||
|
return _id
|
||||||
|
|
||||||
def cpython_only(test):
|
def cpython_only(test):
|
||||||
"""
|
"""
|
||||||
Decorator for tests only applicable on CPython.
|
Decorator for tests only applicable on CPython.
|
||||||
|
@ -7,7 +7,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import script_helper
|
from test.support import script_helper, is_android, requires_android_level
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
@ -42,6 +42,10 @@ def temporary_filename():
|
|||||||
finally:
|
finally:
|
||||||
support.unlink(filename)
|
support.unlink(filename)
|
||||||
|
|
||||||
|
def requires_raise(test):
|
||||||
|
return (test if not is_android else
|
||||||
|
requires_android_level(24, 'raise() is buggy')(test))
|
||||||
|
|
||||||
class FaultHandlerTests(unittest.TestCase):
|
class FaultHandlerTests(unittest.TestCase):
|
||||||
def get_output(self, code, filename=None, fd=None):
|
def get_output(self, code, filename=None, fd=None):
|
||||||
"""
|
"""
|
||||||
@ -141,6 +145,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
3,
|
3,
|
||||||
'access violation')
|
'access violation')
|
||||||
|
|
||||||
|
@requires_raise
|
||||||
def test_sigsegv(self):
|
def test_sigsegv(self):
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
import faulthandler
|
import faulthandler
|
||||||
@ -183,6 +188,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipIf(_testcapi is None, 'need _testcapi')
|
@unittest.skipIf(_testcapi is None, 'need _testcapi')
|
||||||
@unittest.skipUnless(hasattr(signal, 'SIGBUS'), 'need signal.SIGBUS')
|
@unittest.skipUnless(hasattr(signal, 'SIGBUS'), 'need signal.SIGBUS')
|
||||||
|
@requires_raise
|
||||||
def test_sigbus(self):
|
def test_sigbus(self):
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
import _testcapi
|
import _testcapi
|
||||||
@ -197,6 +203,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipIf(_testcapi is None, 'need _testcapi')
|
@unittest.skipIf(_testcapi is None, 'need _testcapi')
|
||||||
@unittest.skipUnless(hasattr(signal, 'SIGILL'), 'need signal.SIGILL')
|
@unittest.skipUnless(hasattr(signal, 'SIGILL'), 'need signal.SIGILL')
|
||||||
|
@requires_raise
|
||||||
def test_sigill(self):
|
def test_sigill(self):
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
import _testcapi
|
import _testcapi
|
||||||
@ -240,6 +247,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
'(?:Segmentation fault|Bus error)',
|
'(?:Segmentation fault|Bus error)',
|
||||||
other_regex='unable to raise a stack overflow')
|
other_regex='unable to raise a stack overflow')
|
||||||
|
|
||||||
|
@requires_raise
|
||||||
def test_gil_released(self):
|
def test_gil_released(self):
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
import faulthandler
|
import faulthandler
|
||||||
@ -249,6 +257,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
3,
|
3,
|
||||||
'Segmentation fault')
|
'Segmentation fault')
|
||||||
|
|
||||||
|
@requires_raise
|
||||||
def test_enable_file(self):
|
def test_enable_file(self):
|
||||||
with temporary_filename() as filename:
|
with temporary_filename() as filename:
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
@ -263,6 +272,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipIf(sys.platform == "win32",
|
@unittest.skipIf(sys.platform == "win32",
|
||||||
"subprocess doesn't support pass_fds on Windows")
|
"subprocess doesn't support pass_fds on Windows")
|
||||||
|
@requires_raise
|
||||||
def test_enable_fd(self):
|
def test_enable_fd(self):
|
||||||
with tempfile.TemporaryFile('wb+') as fp:
|
with tempfile.TemporaryFile('wb+') as fp:
|
||||||
fd = fp.fileno()
|
fd = fp.fileno()
|
||||||
@ -276,6 +286,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
'Segmentation fault',
|
'Segmentation fault',
|
||||||
fd=fd)
|
fd=fd)
|
||||||
|
|
||||||
|
@requires_raise
|
||||||
def test_enable_single_thread(self):
|
def test_enable_single_thread(self):
|
||||||
self.check_fatal_error("""
|
self.check_fatal_error("""
|
||||||
import faulthandler
|
import faulthandler
|
||||||
@ -286,6 +297,7 @@ class FaultHandlerTests(unittest.TestCase):
|
|||||||
'Segmentation fault',
|
'Segmentation fault',
|
||||||
all_threads=False)
|
all_threads=False)
|
||||||
|
|
||||||
|
@requires_raise
|
||||||
def test_disable(self):
|
def test_disable(self):
|
||||||
code = """
|
code = """
|
||||||
import faulthandler
|
import faulthandler
|
||||||
|
Loading…
Reference in New Issue
Block a user