~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_strace.py

  • Committer: Martin Pool
  • Date: 2007-04-04 06:17:31 UTC
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404061731-tt2xrzllqhbodn83
Contents of TODO file moved into bug tracker

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""Tests for the strace-invoking support."""
19
19
 
20
 
import errno
21
20
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):
 
21
 
 
22
from bzrlib.strace import StraceFeature, strace, StraceResult
 
23
from bzrlib.tests import TestCaseWithTransport
 
24
 
 
25
 
 
26
class TestStraceFeature(TestCaseWithTransport):
31
27
 
32
28
    def test_strace_detection(self):
33
29
        """Strace is available if its runnable."""
46
42
        self.assertEqual(found_strace, StraceFeature.available())
47
43
 
48
44
 
49
 
class TestStrace(tests.TestCaseWithTransport):
 
45
class TestStrace(TestCaseWithTransport):
50
46
 
51
47
    _test_needs_features = [StraceFeature]
52
48
 
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
49
    def test_strace_callable_is_called(self):
65
 
        self._check_threads()
66
 
 
67
50
        output = []
68
51
        def function(positional, *args, **kwargs):
69
52
            output.append((positional, args, kwargs))
70
 
        strace_detailed(function, ["a", "b"], {"c": "c"},
71
 
                        follow_children=False)
 
53
        strace(function, "a", "b", c="c")
72
54
        self.assertEqual([("a", ("b",), {"c":"c"})], output)
73
55
 
74
56
    def test_strace_callable_result(self):
75
 
        self._check_threads()
76
 
 
77
57
        def function():
78
58
            return "foo"
79
 
        result, strace_result = strace_detailed(function,[], {},
80
 
                                                follow_children=False)
 
59
        result, strace_result = strace(function)
81
60
        self.assertEqual("foo", result)
82
61
        self.assertIsInstance(strace_result, StraceResult)
83
62
 
84
63
    def test_strace_result_has_raw_log(self):
85
64
        """Checks that a reasonable raw strace log was found by strace."""
86
 
        self._check_threads()
87
 
 
88
65
        def function():
89
66
            self.build_tree(['myfile'])
90
 
        unused, result = strace_detailed(function, [], {},
91
 
                                         follow_children=False)
 
67
        _, result = strace(function)
92
68
        self.assertContainsRe(result.raw_log, 'myfile')