cpython: 6b536f0516ea (original) (raw)

Mercurial > cpython

changeset 91742:6b536f0516ea

Issue #22018: Add _testcapi.raise_signal() - Use _testcapi.raise_signal() in test_signal - close also os.pipe() file descriptors in some test_signal tests where they were not closed properly - Remove faulthandler._sigill() and faulthandler._sigbus(): reuse _testcapi.raise_signal() in test_faulthandler [#22018]

Victor Stinner victor.stinner@gmail.com
date Mon, 21 Jul 2014 12:30:22 +0200
parents 6fcdeea47cea
children 057a8bd043ea
files Lib/test/test_faulthandler.py Lib/test/test_signal.py Modules/_testcapimodule.c Modules/faulthandler.c
diffstat 4 files changed, 85 insertions(+), 53 deletions(-)[+] [-] Lib/test/test_faulthandler.py 26 Lib/test/test_signal.py 65 Modules/_testcapimodule.c 21 Modules/faulthandler.c 26

line wrap: on

line diff

--- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -16,6 +16,10 @@ try: HAVE_THREADS = True except ImportError: HAVE_THREADS = False +try:

+except ImportError:

TIMEOUT = 0.5 @@ -133,26 +137,32 @@ faulthandler._sigfpe() 3, 'Floating point exception')

+import _testcapi import faulthandler +import signal + faulthandler.enable() -faulthandler._sigbus() +_testcapi.raise_signal(signal.SIGBUS) """.strip(),

+import _testcapi import faulthandler +import signal + faulthandler.enable() -faulthandler._sigill() +_testcapi.raise_signal(signal.SIGILL) """.strip(),

def test_fatal_error(self):

--- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -15,6 +15,10 @@ try: import threading except ImportError: threading = None +try:

+except ImportError:

class HandlerBCalled(Exception): @@ -250,12 +254,27 @@ class WakeupFDTests(unittest.TestCase): fd = support.make_bad_fd() self.assertRaises(ValueError, signal.set_wakeup_fd, fd)

+

+ @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class WakeupSignalTests(unittest.TestCase):

@@ -294,17 +313,18 @@ class WakeupSignalTests(unittest.TestCas assert_python_ok('-c', code)

def handler(signum, frame): @@ -319,8 +339,7 @@ class WakeupSignalTests(unittest.TestCas signal.set_wakeup_fd(r) try: with captured_stderr() as err:

@@ -331,6 +350,9 @@ class WakeupSignalTests(unittest.TestCas raise AssertionError(err) else: raise AssertionError("ZeroDivisionError not raised") +

@@ -394,9 +416,10 @@ class WakeupSignalTests(unittest.TestCas def test_signum(self): self.check_wakeup("""def test():

@unittest.skipUnless(hasattr(signal, 'pthread_sigmask'), @@ -410,8 +433,8 @@ class WakeupSignalTests(unittest.TestCas signal.signal(signum2, handler) signal.pthread_sigmask(signal.SIG_BLOCK, (signum1, signum2))

@@ -447,18 +470,22 @@ class SiginterruptTest(unittest.TestCase sys.stdout.flush() # run the test twice

--- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -11,6 +11,7 @@ #include <float.h> #include "structmember.h" #include "datetime.h" +#include <signal.h> #ifdef WITH_THREAD #include "pythread.h" @@ -3063,6 +3064,24 @@ exit: } #endif /* WITH_THREAD / +static PyObject +test_raise_signal(PyObject* self, PyObject *args) +{

+

+

+

+

+} + static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, @@ -3198,6 +3217,8 @@ static PyMethodDef TestMethods[] = { {"docstring_with_signature_with_defaults", (PyCFunction)test_with_docstring, METH_NOARGS, docstring_with_signature_with_defaults},

#ifdef WITH_THREAD {"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_O, PyDoc_STR("set_error_class(error_class) -> None")},

--- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -874,24 +874,6 @@ faulthandler_sigabrt(PyObject *self, PyO Py_RETURN_NONE; } -#ifdef SIGBUS -static PyObject * -faulthandler_sigbus(PyObject *self, PyObject *args) -{

-} -#endif - -#ifdef SIGILL -static PyObject * -faulthandler_sigill(PyObject *self, PyObject *args) -{

-} -#endif - static PyObject * faulthandler_fatal_error_py(PyObject *self, PyObject *args) { @@ -1012,14 +994,6 @@ static PyMethodDef module_methods[] = { PyDoc_STR("_sigabrt(): raise a SIGABRT signal")}, {"_sigfpe", (PyCFunction)faulthandler_sigfpe, METH_NOARGS, PyDoc_STR("_sigfpe(): raise a SIGFPE signal")}, -#ifdef SIGBUS

-#endif -#ifdef SIGILL

-#endif {"_fatal_error", faulthandler_fatal_error_py, METH_VARARGS, PyDoc_STR("_fatal_error(message): call Py_FatalError(message)")}, #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)