1
# Copyright (C) 2006, 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Blackbox tests for debugger breakin"""
25
from bzrlib.tests import TestCase, TestSkipped
28
class TestBreakin(TestCase):
29
# FIXME: If something is broken, these tests may just hang indefinitely in
30
# wait() waiting for the child to exit when it's not going to.
33
if sys.platform == 'win32':
34
raise TestSkipped('breakin signal not tested on win32')
35
super(TestBreakin, self).setUp()
37
# port 0 means to allocate any port
38
_test_process_args = ['serve', '--port', 'localhost:0']
40
def test_breakin(self):
41
# Break in to a debugger while bzr is running
42
# we need to test against a command that will wait for
43
# a while -- bzr serve should do
44
proc = self.start_bzr_subprocess(self._test_process_args,
45
env_changes=dict(BZR_SIGQUIT_PDB=None))
46
# wait for it to get started, and print the 'listening' line
47
proc.stdout.readline()
48
# first sigquit pops into debugger
49
os.kill(proc.pid, signal.SIGQUIT)
50
proc.stdin.write("q\n")
52
err = proc.stderr.readline()
53
self.assertContainsRe(err, r'entering debugger')
55
def test_breakin_harder(self):
56
proc = self.start_bzr_subprocess(self._test_process_args,
57
env_changes=dict(BZR_SIGQUIT_PDB=None))
58
# wait for it to get started, and print the 'listening' line
59
proc.stdout.readline()
60
# break into the debugger
61
os.kill(proc.pid, signal.SIGQUIT)
62
# now send a second sigquit, which should cause it to exit. That
63
# won't happen until the original signal has been noticed by the
64
# child and it's run its signal handler. We don't know quite how long
65
# this will take, but if it's more than 10s then it's probably not
69
os.kill(proc.pid, signal.SIGQUIT)
70
# note: waitpid is different on win32, but this test only runs on
72
r = os.waitpid(proc.pid, os.WNOHANG)
74
# high bit says if core was dumped; we don't care
75
self.assertEquals(r[1] & 0x7f, signal.SIGQUIT)
78
self.fail("subprocess wasn't terminated by repeated SIGQUIT")
80
def test_breakin_disabled(self):
81
proc = self.start_bzr_subprocess(self._test_process_args,
82
env_changes=dict(BZR_SIGQUIT_PDB='0'))
83
# wait for it to get started, and print the 'listening' line
84
proc.stdout.readline()
85
# first hit should just kill it
86
os.kill(proc.pid, signal.SIGQUIT)