1
# Copyright (C) 2007 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests for the strace-invoking support."""
27
from bzrlib.strace import StraceFeature, strace_detailed, StraceResult
30
class TestStraceFeature(tests.TestCaseWithTransport):
32
def test_strace_detection(self):
33
"""Strace is available if its runnable."""
35
proc = subprocess.Popen(['strace'],
36
stderr=subprocess.PIPE,
37
stdout=subprocess.PIPE)
41
if e.errno == errno.ENOENT:
42
# strace is not installed
46
self.assertEqual(found_strace, StraceFeature.available())
49
class TestStrace(tests.TestCaseWithTransport):
51
_test_needs_features = [StraceFeature]
53
def _check_threads(self):
54
# For bug #226769, it was decided that the strace tests should not be
55
# run when more than one thread is active. A lot of tests are currently
56
# leaking threads for good or bad reasons, once they are fixed or
57
# strace itself is fixed (bug #103133), we can get rid of the
59
active = threading.activeCount()
60
if active > 1: # There is always the main thread at least
61
raise tests.KnownFailure(
62
'%d active threads, bug #103133 needs to be fixed.' % active)
64
def test_strace_callable_is_called(self):
68
def function(positional, *args, **kwargs):
69
output.append((positional, args, kwargs))
70
strace_detailed(function, ["a", "b"], {"c": "c"},
71
follow_children=False)
72
self.assertEqual([("a", ("b",), {"c":"c"})], output)
74
def test_strace_callable_result(self):
79
result, strace_result = strace_detailed(function,[], {},
80
follow_children=False)
81
self.assertEqual("foo", result)
82
self.assertIsInstance(strace_result, StraceResult)
84
def test_strace_result_has_raw_log(self):
85
"""Checks that a reasonable raw strace log was found by strace."""
89
self.build_tree(['myfile'])
90
unused, result = strace_detailed(function, [], {},
91
follow_children=False)
92
self.assertContainsRe(result.raw_log, 'myfile')