/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2423.3.7 by Martin Pool
Add BZR_SIGQUIT_PDB=0 option to disable breakin.
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
17
"""Blackbox tests for debugger breakin"""
18
19
import os
20
import signal
21
import subprocess
22
import sys
23
import time
24
25
from bzrlib.tests import TestCase, TestSkipped
26
27
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.
31
32
    def setUp(self):
33
        if sys.platform == 'win32':
34
            raise TestSkipped('breakin signal not tested on win32')
35
        super(TestBreakin, self).setUp()
36
37
    # port 0 means to allocate any port
38
    _test_process_args = ['serve', '--port', 'localhost:0']
39
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")
51
        time.sleep(.5)
52
        err = proc.stderr.readline()
53
        self.assertContainsRe(err, r'entering debugger')
54
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
        # another hit gives the default behaviour of terminating it
61
        os.kill(proc.pid, signal.SIGQUIT)
62
        # wait for it to go into pdb
63
        time.sleep(.5)
64
        os.kill(proc.pid, signal.SIGQUIT)
65
        proc.wait()
66
67
    def test_breakin_disabled(self):
68
        proc = self.start_bzr_subprocess(self._test_process_args,
69
                env_changes=dict(BZR_SIGQUIT_PDB='0'))
70
        # wait for it to get started, and print the 'listening' line
71
        proc.stdout.readline()
72
        # first hit should just kill it
73
        os.kill(proc.pid, signal.SIGQUIT)
74
        proc.wait()