~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_strace.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
#   Authors: Robert Collins <robert.collins@canonical.com>
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
 
18
 
"""Tests for the strace-invoking support."""
19
 
 
20
 
import errno
21
 
import subprocess
22
 
import threading
23
 
 
24
 
from bzrlib import (
25
 
    tests,
26
 
    )
27
 
from bzrlib.strace import StraceFeature, strace_detailed, StraceResult
28
 
 
29
 
 
30
 
class TestStraceFeature(tests.TestCaseWithTransport):
31
 
 
32
 
    def test_strace_detection(self):
33
 
        """Strace is available if its runnable."""
34
 
        try:
35
 
            proc = subprocess.Popen(['strace'],
36
 
                stderr=subprocess.PIPE,
37
 
                stdout=subprocess.PIPE)
38
 
            proc.communicate()
39
 
            found_strace = True
40
 
        except OSError, e:
41
 
            if e.errno == errno.ENOENT:
42
 
                # strace is not installed
43
 
                found_strace = False
44
 
            else:
45
 
                raise
46
 
        self.assertEqual(found_strace, StraceFeature.available())
47
 
 
48
 
 
49
 
class TestStrace(tests.TestCaseWithTransport):
50
 
 
51
 
    _test_needs_features = [StraceFeature]
52
 
 
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
58
 
        # restriction.
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)
63
 
 
64
 
    def test_strace_callable_is_called(self):
65
 
        self._check_threads()
66
 
 
67
 
        output = []
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)
73
 
 
74
 
    def test_strace_callable_result(self):
75
 
        self._check_threads()
76
 
 
77
 
        def function():
78
 
            return "foo"
79
 
        result, strace_result = strace_detailed(function,[], {},
80
 
                                                follow_children=False)
81
 
        self.assertEqual("foo", result)
82
 
        self.assertIsInstance(strace_result, StraceResult)
83
 
 
84
 
    def test_strace_result_has_raw_log(self):
85
 
        """Checks that a reasonable raw strace log was found by strace."""
86
 
        self._check_threads()
87
 
 
88
 
        def function():
89
 
            self.build_tree(['myfile'])
90
 
        unused, result = strace_detailed(function, [], {},
91
 
                                         follow_children=False)
92
 
        self.assertContainsRe(result.raw_log, 'myfile')