14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for the strace-invoking support."""
23
from bzrlib.strace import StraceFeature, strace, StraceResult
24
from bzrlib.tests import TestCaseWithTransport
27
class TestStraceFeature(TestCaseWithTransport):
27
from bzrlib.strace import StraceFeature, strace_detailed, StraceResult
30
class TestStraceFeature(tests.TestCaseWithTransport):
29
32
def test_strace_detection(self):
30
33
"""Strace is available if its runnable."""
43
46
self.assertEqual(found_strace, StraceFeature.available())
46
class TestStrace(TestCaseWithTransport):
49
class TestStrace(tests.TestCaseWithTransport):
48
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)
50
64
def test_strace_callable_is_called(self):
52
68
def function(positional, *args, **kwargs):
53
69
output.append((positional, args, kwargs))
54
strace(function, "a", "b", c="c")
70
strace_detailed(function, ["a", "b"], {"c": "c"},
71
follow_children=False)
55
72
self.assertEqual([("a", ("b",), {"c":"c"})], output)
57
74
def test_strace_callable_result(self):
60
result, strace_result = strace(function)
79
result, strace_result = strace_detailed(function,[], {},
80
follow_children=False)
61
81
self.assertEqual("foo", result)
62
82
self.assertIsInstance(strace_result, StraceResult)
64
84
def test_strace_result_has_raw_log(self):
65
85
"""Checks that a reasonable raw strace log was found by strace."""
67
89
self.build_tree(['myfile'])
68
_, result = strace(function)
90
unused, result = strace_detailed(function, [], {},
91
follow_children=False)
69
92
self.assertContainsRe(result.raw_log, 'myfile')