aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlicia Boya García <aboya@igalia.com>2018-03-02 19:16:29 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2018-03-05 00:04:28 +0200
commit70270d874d7479253b2ffe8fd20d9199a29f202c (patch)
tree1ff46142c3975687e75d760c33f0b0fd19518055
parent0744601fda65c2cd3e02c6705533493ed7b4e501 (diff)
downloadmeson-70270d874d7479253b2ffe8fd20d9199a29f202c.zip
meson-70270d874d7479253b2ffe8fd20d9199a29f202c.tar.gz
meson-70270d874d7479253b2ffe8fd20d9199a29f202c.tar.bz2
meson test: let gdb handle ^C instead of us
Fixes https://github.com/mesonbuild/meson/issues/3156
-rw-r--r--mesonbuild/mtest.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 85fe943..fbd6e8b 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -283,22 +283,35 @@ class TestHarness:
if ('MALLOC_PERTURB_' not in test_env or not test_env['MALLOC_PERTURB_']) and not self.options.benchmark:
test_env['MALLOC_PERTURB_'] = str(random.randint(1, 255))
- setsid = None
stdout = None
stderr = None
if not self.options.verbose:
stdout = subprocess.PIPE
stderr = subprocess.PIPE if self.options and self.options.split else subprocess.STDOUT
- if not is_windows():
- setsid = os.setsid
+ # Let gdb handle ^C instead of us
+ if test_opts.gdb:
+ previous_sigint_handler = signal.getsignal(signal.SIGINT)
+ # Make the meson executable ignore SIGINT while gdb is running.
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
+
+ def preexec_fn():
+ if test_opts.gdb:
+ # Restore the SIGINT handler for the child process to
+ # ensure it can handle it.
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+ else:
+ # We don't want setsid() in gdb because gdb needs the
+ # terminal in order to handle ^C and not show tcsetpgrp()
+ # errors avoid not being able to use the terminal.
+ os.setsid()
p = subprocess.Popen(cmd,
stdout=stdout,
stderr=stderr,
env=test_env,
cwd=test.workdir,
- preexec_fn=setsid)
+ preexec_fn=preexec_fn if not is_windows() else None)
timed_out = False
kill_test = False
if test.timeout is None:
@@ -316,6 +329,10 @@ class TestHarness:
except KeyboardInterrupt:
mlog.warning("CTRL-C detected while running %s" % (test.name))
kill_test = True
+ finally:
+ if test_opts.gdb:
+ # Let us accept ^C again
+ signal.signal(signal.SIGINT, previous_sigint_handler)
if kill_test or timed_out:
# Python does not provide multiplatform support for