~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_strace.py

  • Committer: Robert Collins
  • Date: 2009-07-07 04:32:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4524.
  • Revision ID: robertc@robertcollins.net-20090707043213-4hjjhgr40iq7gk2d
More informative assertions in xml serialisation.

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
import threading
22
23
 
 
24
from bzrlib import (
 
25
    tests,
 
26
    )
23
27
from bzrlib.strace import StraceFeature, strace_detailed, StraceResult
24
 
from bzrlib.tests import TestCaseWithTransport
25
 
 
26
 
 
27
 
class TestStraceFeature(TestCaseWithTransport):
 
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))
56
72
        self.assertEqual([("a", ("b",), {"c":"c"})], output)
57
73
 
58
74
    def test_strace_callable_result(self):
 
75
        self._check_threads()
 
76
 
59
77
        def function():
60
78
            return "foo"
61
79
        result, strace_result = strace_detailed(function,[], {},
65
83
 
66
84
    def test_strace_result_has_raw_log(self):
67
85
        """Checks that a reasonable raw strace log was found by strace."""
 
86
        self._check_threads()
 
87
 
68
88
        def function():
69
89
            self.build_tree(['myfile'])
70
90
        unused, result = strace_detailed(function, [], {},