summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-08-10 10:37:39 (GMT)
committerGitHub <noreply@github.com>2017-08-10 10:37:39 (GMT)
commit7b7c6dcfff6a35333988a3c74c895ed19dff2e09 (patch)
tree4de55c7bfde202d1c27348c5575816286906bcf0 /Modules
parent3b0f620c1a2a21272a9e2aeca6ca1d1ac10f8162 (diff)
downloadcpython-7b7c6dcfff6a35333988a3c74c895ed19dff2e09.zip
cpython-7b7c6dcfff6a35333988a3c74c895ed19dff2e09.tar.gz
cpython-7b7c6dcfff6a35333988a3c74c895ed19dff2e09.tar.bz2
bpo-31173: Rewrite WSTOPSIG test of test_subprocess (#3055)
The current test_child_terminated_in_stopped_state() function test creates a child process which calls ptrace(PTRACE_TRACEME, 0, 0) and then crash (SIGSEGV). The problem is that calling os.waitpid() in the parent process is not enough to close the process: the child process remains alive and so the unit test leaks a child process in a strange state. Closing the child process requires non-trivial code, maybe platform specific. Remove the functional test and replaces it with an unit test which mocks os.waitpid() using a new _testcapi.W_STOPCODE() function to test the WIFSTOPPED() path.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 6556690..95c1018 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -18,6 +18,10 @@
# include <winsock2.h> /* struct timeval */
#endif
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h> /* For W_STOPCODE */
+#endif
+
#ifdef WITH_THREAD
#include "pythread.h"
#endif /* WITH_THREAD */
@@ -4272,6 +4276,7 @@ test_pyobject_fastcallkeywords(PyObject *self, PyObject *args)
return _PyObject_FastCallKeywords(func, stack, nargs, kwnames);
}
+
static PyObject*
stack_pointer(PyObject *self, PyObject *args)
{
@@ -4280,6 +4285,20 @@ stack_pointer(PyObject *self, PyObject *args)
}
+#ifdef W_STOPCODE
+static PyObject*
+py_w_stopcode(PyObject *self, PyObject *args)
+{
+ int sig, status;
+ if (!PyArg_ParseTuple(args, "i", &sig)) {
+ return NULL;
+ }
+ status = W_STOPCODE(sig);
+ return PyLong_FromLong(status);
+}
+#endif
+
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
@@ -4493,6 +4512,9 @@ static PyMethodDef TestMethods[] = {
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
{"pyobject_fastcallkeywords", test_pyobject_fastcallkeywords, METH_VARARGS},
{"stack_pointer", stack_pointer, METH_NOARGS},
+#ifdef W_STOPCODE
+ {"W_STOPCODE", py_w_stopcode, METH_VARARGS},
+#endif
{NULL, NULL} /* sentinel */
};