[pygobject] setup.py: add option to run under gdb



commit 8e80469a008fb1da5a667203362f9881005f9229
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Thu Mar 15 15:59:59 2018 +0100

    setup.py: add option to run under gdb
    
    setup.py test --gdb
    
    Also sets an env var so we can disable one test which uses
    SIGINT on the test process, which makes gdb break.

 setup.py               | 13 ++++++++++---
 tests/test_mainloop.py |  1 +
 2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/setup.py b/setup.py
index 57009158..1620c4a7 100755
--- a/setup.py
+++ b/setup.py
@@ -444,16 +444,19 @@ class test(Command):
     user_options = [
         ("valgrind", None, "run tests under valgrind"),
         ("valgrind-log-file=", None, "save logs instead of printing them"),
+        ("gdb", None, "run tests under gdb"),
     ]
 
     def initialize_options(self):
         self.valgrind = None
         self.valgrind_log_file = None
+        self.gdb = None
 
     def finalize_options(self):
         self.valgrind = bool(self.valgrind)
         if self.valgrind_log_file and not self.valgrind:
             raise DistutilsOptionError("valgrind not enabled")
+        self.gdb = bool(self.gdb)
 
     def run(self):
         cmd = self.reinitialize_command("build_tests")
@@ -479,20 +482,24 @@ class test(Command):
                 sys.prefix, "share", "glib-2.0", "valgrind", "glib.supp"))
             return [f for f in files if os.path.isfile(f)]
 
+        pre_args = []
+
         if self.valgrind:
             env["G_SLICE"] = "always-malloc"
             env["G_DEBUG"] = "gc-friendly"
             env["PYTHONMALLOC"] = "malloc"
 
-            pre_args = [
+            pre_args += [
                 "valgrind", "--leak-check=full", "--show-possibly-lost=no",
                 "--num-callers=20", "--child-silent-after-fork=yes",
             ] + ["--suppressions=" + f for f in get_suppression_files()]
 
             if self.valgrind_log_file:
                 pre_args += ["--log-file=" + self.valgrind_log_file]
-        else:
-            pre_args = []
+
+        if self.gdb:
+            env["PYGI_TEST_GDB"] = "1"
+            pre_args += ["gdb", "--args"]
 
         if pre_args:
             log.info(" ".join(pre_args))
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 2d9fbd57..40a8b97b 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -44,6 +44,7 @@ class TestMainLoop(unittest.TestCase):
         assert exc[0].value.args[0] == "deadbabe"
 
     @unittest.skipUnless(hasattr(os, "fork"), "no os.fork available")
+    @unittest.skipIf(os.environ.get("PYGI_TEST_GDB"), "SIGINT stops gdb")
     def test_sigint(self):
         r, w = os.pipe()
         pid = os.fork()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]