[2.7] bpo-30283: Backport test_regrtest from master to 2.7 (#1513)

* bpo-30283: regrtest: add --testdir option

* bpo-30283: Backport _testcapi.raise_signal()

Function used by test_regrtest to simulate an interrupted unit test.

* bpo-30283: Backport test_regrtest from master
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index f306b1c..e742541 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -10,6 +10,7 @@
 #include "structmember.h"
 #include "datetime.h"
 #include "marshal.h"
+#include <signal.h>
 
 #ifdef WITH_THREAD
 #include "pythread.h"
@@ -2481,6 +2482,24 @@
     return Py_BuildValue("Nl", obj, pos);
 }
 
+static PyObject*
+test_raise_signal(PyObject* self, PyObject *args)
+{
+    int signum, err;
+
+    if (PyArg_ParseTuple(args, "i:raise_signal", &signum) < 0)
+        return NULL;
+
+    err = raise(signum);
+    if (err)
+        return PyErr_SetFromErrno(PyExc_OSError);
+
+    if (PyErr_CheckSignals() < 0)
+        return NULL;
+
+    Py_RETURN_NONE;
+}
+
 
 static PyMethodDef TestMethods[] = {
     {"raise_exception",         raise_exception,                 METH_VARARGS},
@@ -2593,6 +2612,7 @@
         pymarshal_read_last_object_from_file, METH_VARARGS},
     {"pymarshal_read_object_from_file",
         pymarshal_read_object_from_file, METH_VARARGS},
+    {"raise_signal", (PyCFunction)test_raise_signal, METH_VARARGS},
     {NULL, NULL} /* sentinel */
 };