Пример #1
0
def dash_R(the_module, test, indirect_test, huntrleaks):
    """Run a test multiple times, looking for reference leaks.

    Returns:
        False if the test didn't leak references; True if we detected refleaks.
    """
    # This code is hackish and inelegant, but it seems to do the job.
    import copy_reg, _abcoll, io

    if not hasattr(sys, 'gettotalrefcount'):
        raise Exception("Tracking reference leaks requires a debug build "
                        "of Python")

    # Save current values for dash_R_cleanup() to restore.
    fs = warnings.filters[:]
    ps = copy_reg.dispatch_table.copy()
    pic = sys.path_importer_cache.copy()
    abcs = {}
    modules = _abcoll, io
    for abc in [getattr(mod, a) for mod in modules for a in mod.__all__]:
        # XXX isinstance(abc, ABCMeta) leads to infinite recursion
        if not hasattr(abc, '_abc_registry'):
            continue
        for obj in abc.__subclasses__() + [abc]:
            abcs[obj] = obj._abc_registry.copy()

    if indirect_test:

        def run_the_test():
            indirect_test()
    else:

        def run_the_test():
            reload(the_module)

    deltas = []
    nwarmup, ntracked, fname = huntrleaks
    repcount = nwarmup + ntracked
    print >> sys.stderr, "beginning", repcount, "repetitions"
    print >> sys.stderr, ("1234567890" * (repcount // 10 + 1))[:repcount]
    if _llvm:
        _llvm.set_jit_control("never")
    for i in range(repcount):
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_before = sys.gettotalrefcount()
        run_the_test()
        sys.stderr.write('.')
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_after = sys.gettotalrefcount()
        if i >= nwarmup:
            deltas.append(rc_after - rc_before)
    print >> sys.stderr
    if any(deltas):
        msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas))
        print >> sys.stderr, msg
        refrep = open(fname, "a")
        print >> refrep, msg
        refrep.close()
        return True
    return False
Пример #2
0
def dash_R(the_module, test, indirect_test, huntrleaks):
    """Run a test multiple times, looking for reference leaks.

    Returns:
        False if the test didn't leak references; True if we detected refleaks.
    """
    # This code is hackish and inelegant, but it seems to do the job.
    import copy_reg, _abcoll, io

    if not hasattr(sys, 'gettotalrefcount'):
        raise Exception("Tracking reference leaks requires a debug build "
                        "of Python")

    # Save current values for dash_R_cleanup() to restore.
    fs = warnings.filters[:]
    ps = copy_reg.dispatch_table.copy()
    pic = sys.path_importer_cache.copy()
    abcs = {}
    modules = _abcoll, io
    for abc in [getattr(mod, a) for mod in modules for a in mod.__all__]:
        # XXX isinstance(abc, ABCMeta) leads to infinite recursion
        if not hasattr(abc, '_abc_registry'):
            continue
        for obj in abc.__subclasses__() + [abc]:
            abcs[obj] = obj._abc_registry.copy()

    if indirect_test:
        def run_the_test():
            indirect_test()
    else:
        def run_the_test():
            reload(the_module)

    deltas = []
    nwarmup, ntracked, fname = huntrleaks
    repcount = nwarmup + ntracked
    print >> sys.stderr, "beginning", repcount, "repetitions"
    print >> sys.stderr, ("1234567890"*(repcount//10 + 1))[:repcount]
    if _llvm:
        _llvm.set_jit_control("never")
    for i in range(repcount):
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_before = sys.gettotalrefcount()
        run_the_test()
        sys.stderr.write('.')
        dash_R_cleanup(fs, ps, pic, abcs)
        rc_after = sys.gettotalrefcount()
        if i >= nwarmup:
            deltas.append(rc_after - rc_before)
    print >> sys.stderr
    if any(deltas):
        msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas))
        print >> sys.stderr, msg
        refrep = open(fname, "a")
        print >> refrep, msg
        refrep.close()
        return True
    return False
Пример #3
0
 def tearDown(self):
     if _llvm:
         _llvm.set_jit_control(self.orig_jit_control)
     asyncore.close_all()
Пример #4
0
 def setUp(self):
     # This test is sensitive to random pauses, so we disable the JIT if it
     # is present.
     if _llvm:
         self.orig_jit_control = _llvm.get_jit_control()
         _llvm.set_jit_control("never")
Пример #5
0
 def tearDown(self):
     if _llvm:
         _llvm.set_jit_control(self.orig_jit_control)
     asyncore.close_all()
Пример #6
0
 def setUp(self):
     # This test is sensitive to random pauses, so we disable the JIT if it
     # is present.
     if _llvm:
         self.orig_jit_control = _llvm.get_jit_control()
         _llvm.set_jit_control("never")
Пример #7
0
 def tearDown(self):
     if _llvm:
         _llvm.set_jit_control(self.orig_jit_control)
Пример #8
0
 def setUp(self):
     # TODO(rnk): This test doesn't pass with the background thread under
     # -Xjit=always, so we disable the JIT for the duration of the tests.
     if _llvm:
         self.orig_jit_control = _llvm.get_jit_control()
         _llvm.set_jit_control("never")