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() |
|
2527.1.1
by Martin Pool
Fix race in test_breakin_harder that can cause test suite hang. |
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
|
|
66 |
# going to work.
|
|
67 |
for i in range(100): |
|
68 |
time.sleep(0.1) |
|
69 |
os.kill(proc.pid, signal.SIGQUIT) |
|
70 |
# note: waitpid is different on win32, but this test only runs on
|
|
71 |
# unix
|
|
72 |
r = os.waitpid(proc.pid, os.WNOHANG) |
|
73 |
if r != (0, 0): |
|
74 |
# high bit says if core was dumped; we don't care
|
|
75 |
self.assertEquals(r[1] & 0x7f, signal.SIGQUIT) |
|
76 |
break
|
|
77 |
else: |
|
78 |
self.fail("subprocess wasn't terminated by repeated SIGQUIT") |
|
2423.3.7
by Martin Pool
Add BZR_SIGQUIT_PDB=0 option to disable breakin. |
79 |
|
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) |
|
87 |
proc.wait() |