~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_strace.py

  • Committer: Martin Pool
  • Date: 2010-01-29 10:36:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129103623-hywka5hymo5z13jw
Change url to canonical.com or wiki, plus some doc improvements in passing

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
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
17
17
 
18
18
"""Tests for the strace-invoking support."""
19
19
 
20
20
import errno
21
21
import subprocess
22
 
 
23
 
from bzrlib.strace import StraceFeature, strace, StraceResult
24
 
from bzrlib.tests import TestCaseWithTransport
25
 
 
26
 
 
27
 
class TestStraceFeature(TestCaseWithTransport):
 
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):
28
31
 
29
32
    def test_strace_detection(self):
30
33
        """Strace is available if its runnable."""
43
46
        self.assertEqual(found_strace, StraceFeature.available())
44
47
 
45
48
 
46
 
class TestStrace(TestCaseWithTransport):
 
49
class TestStrace(tests.TestCaseWithTransport):
47
50
 
48
51
    _test_needs_features = [StraceFeature]
49
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
 
50
64
    def test_strace_callable_is_called(self):
 
65
        self._check_threads()
 
66
 
51
67
        output = []
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)
56
73
 
57
74
    def test_strace_callable_result(self):
 
75
        self._check_threads()
 
76
 
58
77
        def function():
59
78
            return "foo"
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)
63
83
 
64
84
    def test_strace_result_has_raw_log(self):
65
85
        """Checks that a reasonable raw strace log was found by strace."""
 
86
        self._check_threads()
 
87
 
66
88
        def function():
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')