示例#1
0
def test_nested_remember_forget_2():
    p2 = leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    py.test.raises(leakfinder.MallocMismatch,
                   leakfinder.stop_tracking_allocations, True, prev=p2)
    leakfinder.stop_tracking_allocations(True)
示例#2
0
def test_start_stop_nested():
    leakfinder.start_tracking_allocations()
    p2 = leakfinder.start_tracking_allocations()
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True, prev=p2)
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True)
    assert not leakfinder.TRACK_ALLOCATIONS
示例#3
0
def test_nested_remember_forget_1():
    leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    p2 = leakfinder.start_tracking_allocations()
    leakfinder.stop_tracking_allocations(True, prev=p2)
    py.test.raises(leakfinder.MallocMismatch,
                   leakfinder.stop_tracking_allocations, True)
示例#4
0
def test_start_stop_nested():
    leakfinder.start_tracking_allocations()
    p2 = leakfinder.start_tracking_allocations()
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True, prev=p2)
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True)
    assert not leakfinder.TRACK_ALLOCATIONS
示例#5
0
def interpret(func,
              values,
              view='auto',
              viewbefore='auto',
              policy=None,
              someobjects=False,
              type_system="lltype",
              backendopt=False,
              config=None,
              malloc_check=True,
              **kwargs):
    interp, graph = get_interpreter(func,
                                    values,
                                    view,
                                    viewbefore,
                                    policy,
                                    someobjects,
                                    type_system=type_system,
                                    backendopt=backendopt,
                                    config=config,
                                    **kwargs)
    if not malloc_check:
        result = interp.eval_graph(graph, values)
    else:
        prev = leakfinder.start_tracking_allocations()
        try:
            result = interp.eval_graph(graph, values)
        finally:
            leaks = leakfinder.stop_tracking_allocations(False, prev)
        if leaks:
            raise leakfinder.MallocMismatch(leaks)
    return result
示例#6
0
    def check_and_print_leaks(self):
        # check for sane refcnts
        import gc

        if not self.enable_leak_checking:
            leakfinder.stop_tracking_allocations(check=False)
            return False

        leaking = False
        state = self.space.fromcache(RefcountState)
        gc.collect()
        lost_objects_w = identity_dict()
        lost_objects_w.update(
            (key, None) for key in self.frozen_refcounts.keys())

        for w_obj, obj in state.py_objects_w2r.iteritems():
            base_refcnt = self.frozen_refcounts.get(w_obj)
            delta = obj.c_ob_refcnt
            if base_refcnt is not None:
                delta -= base_refcnt
                lost_objects_w.pop(w_obj)
            if delta != 0:
                leaking = True
                print >> sys.stderr, "Leaking %r: %i references" % (w_obj,
                                                                    delta)
                try:
                    weakref.ref(w_obj)
                except TypeError:
                    lifeline = None
                else:
                    lifeline = state.lifeline_dict.get(w_obj)
                if lifeline is not None:
                    refcnt = lifeline.pyo.c_ob_refcnt
                    if refcnt > 0:
                        print >> sys.stderr, "\tThe object also held by C code."
                    else:
                        referrers_repr = []
                        for o in gc.get_referrers(w_obj):
                            try:
                                repr_str = repr(o)
                            except TypeError, e:
                                repr_str = "%s (type of o is %s)" % (str(e),
                                                                     type(o))
                            referrers_repr.append(repr_str)
                        referrers = ", ".join(referrers_repr)
                        print >>sys.stderr, "\tThe object is referenced by these objects:", \
                                referrers
示例#7
0
文件: test_cpyext.py 项目: ieure/pypy
    def check_and_print_leaks(self):
        # check for sane refcnts
        import gc

        if not self.enable_leak_checking:
            leakfinder.stop_tracking_allocations(check=False)
            return False

        leaking = False
        state = self.space.fromcache(RefcountState)
        gc.collect()
        lost_objects_w = identity_dict()
        lost_objects_w.update((key, None) for key in self.frozen_refcounts.keys())

        for w_obj, obj in state.py_objects_w2r.iteritems():
            base_refcnt = self.frozen_refcounts.get(w_obj)
            delta = obj.c_ob_refcnt
            if base_refcnt is not None:
                delta -= base_refcnt
                lost_objects_w.pop(w_obj)
            if delta != 0:
                leaking = True
                print >>sys.stderr, "Leaking %r: %i references" % (w_obj, delta)
                try:
                    weakref.ref(w_obj)
                except TypeError:
                    lifeline = None
                else:
                    lifeline = state.lifeline_dict.get(w_obj)
                if lifeline is not None:
                    refcnt = lifeline.pyo.c_ob_refcnt
                    if refcnt > 0:
                        print >>sys.stderr, "\tThe object also held by C code."
                    else:
                        referrers_repr = []
                        for o in gc.get_referrers(w_obj):
                            try:
                                repr_str = repr(o)
                            except TypeError, e:
                                repr_str = "%s (type of o is %s)" % (str(e), type(o))
                            referrers_repr.append(repr_str)
                        referrers = ", ".join(referrers_repr)
                        print >>sys.stderr, "\tThe object is referenced by these objects:", \
                                referrers
示例#8
0
def test_traceback():
    leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    res = leakfinder.stop_tracking_allocations(check=False)
    assert res.keys() == [x]
    print res[x]
    assert isinstance(res[x], str)
    assert 'test_traceback' in res[x]
    assert 'leakfinder.remember_malloc(x)' in res[x]
示例#9
0
def test_traceback():
    leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    res = leakfinder.stop_tracking_allocations(check=False)
    assert res.keys() == [x]
    print res[x]
    assert isinstance(res[x], str)
    assert 'test_traceback' in res[x]
    assert 'leakfinder.remember_malloc(x)' in res[x]
示例#10
0
def pytest_runtest_teardown(__multicall__, item):
    __multicall__.execute()

    if isinstance(item, py.test.collect.Function):
        if (not getattr(item.obj, 'dont_track_allocations', False)
            and leakfinder.TRACK_ALLOCATIONS):
            item._pypytest_leaks = leakfinder.stop_tracking_allocations(False)
        else:            # stop_tracking_allocations() already called
            item._pypytest_leaks = None

        # check for leaks, but only if the test passed so far
        if getattr(item, '_success', False) and item._pypytest_leaks:
            raise leakfinder.MallocMismatch(item._pypytest_leaks)

    if 'pygame' in sys.modules:
        assert option.view, ("should not invoke Pygame "
                             "if conftest.option.view is False")
示例#11
0
文件: conftest.py 项目: njues/Sypy
def pytest_runtest_teardown(__multicall__, item):
    __multicall__.execute()

    if isinstance(item, py.test.collect.Function):
        if (not getattr(item.obj, 'dont_track_allocations', False)
                and leakfinder.TRACK_ALLOCATIONS):
            item._pypytest_leaks = leakfinder.stop_tracking_allocations(False)
        else:  # stop_tracking_allocations() already called
            item._pypytest_leaks = None

        # check for leaks, but only if the test passed so far
        if getattr(item, '_success', False) and item._pypytest_leaks:
            raise leakfinder.MallocMismatch(item._pypytest_leaks)

    if 'pygame' in sys.modules:
        assert option.view, ("should not invoke Pygame "
                             "if conftest.option.view is False")
示例#12
0
def interpret(func, values, view='auto', viewbefore='auto', policy=None,
              someobjects=False, type_system="lltype", backendopt=False,
              config=None, malloc_check=True, **kwargs):
    interp, graph = get_interpreter(func, values, view, viewbefore, policy,
                                    someobjects, type_system=type_system,
                                    backendopt=backendopt, config=config,
                                    **kwargs)
    if not malloc_check:
        result = interp.eval_graph(graph, values)
    else:
        prev = leakfinder.start_tracking_allocations()
        try:
            result = interp.eval_graph(graph, values)
        finally:
            leaks = leakfinder.stop_tracking_allocations(False, prev)
        if leaks:
            raise leakfinder.MallocMismatch(leaks)
    return result
示例#13
0
def test_start_stop():
    leakfinder.start_tracking_allocations()
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True)
    assert not leakfinder.TRACK_ALLOCATIONS
示例#14
0
def test_remember_free():
    leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    leakfinder.remember_free(x)
    leakfinder.stop_tracking_allocations(True)
示例#15
0
def test_start_stop():
    leakfinder.start_tracking_allocations()
    assert leakfinder.TRACK_ALLOCATIONS
    leakfinder.stop_tracking_allocations(True)
    assert not leakfinder.TRACK_ALLOCATIONS
示例#16
0
def test_remember_free():
    leakfinder.start_tracking_allocations()
    x = 1234
    leakfinder.remember_malloc(x)
    leakfinder.remember_free(x)
    leakfinder.stop_tracking_allocations(True)