[pypy-commit] pypy default: revert test_pypy_c from rev b31644e85091: it seems that merging jitypes2 resurrected a lot of tests that were already moved to test_pypy_c_new

antocuni noreply at buildbot.pypy.org
Mon Jun 6 15:11:37 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r44744:0fadb6d3e664
Date: 2011-06-06 15:12 +0200
http://bitbucket.org/pypy/pypy/changeset/0fadb6d3e664/

Log:	revert test_pypy_c from rev b31644e85091: it seems that merging
	jitypes2 resurrected a lot of tests that were already moved to
	test_pypy_c_new

diff --git a/pypy/module/pypyjit/test/test_pypy_c.py b/pypy/module/pypyjit/test/test_pypy_c.py
--- a/pypy/module/pypyjit/test/test_pypy_c.py
+++ b/pypy/module/pypyjit/test/test_pypy_c.py
@@ -11,9 +11,9 @@
                     if op.getopname().startswith(prefix)]
 
     def __repr__(self):
-        return "%s%s" % (self.opcode, list.__repr__(self))
+        return "%s%s" % (self.bytecode, list.__repr__(self))
 
-ZERO_OP_OPCODES = [
+ZERO_OP_BYTECODES = [
     'POP_TOP',
     'ROT_TWO',
     'ROT_THREE',
@@ -85,13 +85,11 @@
         threshold = kwds.pop('threshold', 3)
         self.count_debug_merge_point = \
                                      kwds.pop('count_debug_merge_point', True)
-        filter_loops = kwds.pop('filter_loops', False) # keep only the loops beginning from case%d.py
         if kwds:
             raise TypeError, 'Unsupported keyword arguments: %s' % kwds.keys()
         source = py.code.Source(source)
         filepath = self.tmpdir.join('case%d.py' % self.counter)
         logfilepath = filepath.new(ext='.log')
-        self.logfilepath = logfilepath
         self.__class__.counter += 1
         f = filepath.open('w')
         print >> f, source
@@ -129,7 +127,7 @@
         if result.strip().startswith('SKIP:'):
             py.test.skip(result.strip())
         assert result.splitlines()[-1].strip() == 'OK :-)'
-        self.parse_loops(logfilepath, filepath, filter_loops)
+        self.parse_loops(logfilepath)
         self.print_loops()
         print logfilepath
         if self.total_ops > expected_max_ops:
@@ -137,21 +135,21 @@
                 self.total_ops, expected_max_ops)
         return result
 
-    def parse_loops(self, opslogfile, filepath, filter_loops):
+    def parse_loops(self, opslogfile):
         from pypy.tool import logparser
         assert opslogfile.check()
         log = logparser.parse_log_file(str(opslogfile))
         parts = logparser.extract_category(log, 'jit-log-opt-')
         self.rawloops = [part for part in parts
                          if not from_entry_bridge(part, parts)]
-        self.loops, self.all_bytecodes, self.bytecode_by_loop, self.total_ops = \
-                                   self.parse_rawloops(self.rawloops, filepath, filter_loops)
+        self.loops, self.sliced_loops, self.total_ops = \
+                                           self.parse_rawloops(self.rawloops)
         self.check_0_op_bytecodes()
         self.rawentrybridges = [part for part in parts
                                 if from_entry_bridge(part, parts)]
-        _, self.all_bytecodes_entrybridges, _, _ = \
-                                    self.parse_rawloops(self.rawentrybridges, filepath, filter_loops)
-        #
+        _, self.sliced_entrybridge, _ = \
+                                    self.parse_rawloops(self.rawentrybridges)
+
         from pypy.jit.tool.jitoutput import parse_prof
         summaries  = logparser.extract_category(log, 'jit-summary')
         if len(summaries) > 0:
@@ -159,59 +157,37 @@
         else:
             self.jit_summary = None
         
-    def parse_rawloops(self, rawloops, filepath, filter_loops):
+
+    def parse_rawloops(self, rawloops):
         from pypy.jit.tool.oparser import parse
         loops = [parse(part, no_namespace=True) for part in rawloops]
-        if filter_loops:
-            loops = self.filter_loops(filepath, loops)
-        all_bytecodes = []    # contains all bytecodes of all loops
-        bytecode_by_loop = {} # contains all bytecodes divided by loops
+        sliced_loops = [] # contains all bytecodes of all loops
         total_ops = 0
         for loop in loops:
-            loop_bytecodes = []
-            bytecode_by_loop[loop] = loop_bytecodes
-            total_ops = 0
             for op in loop.operations:
                 if op.getopname() == "debug_merge_point":
-                    bytecode = BytecodeTrace()
-                    bytecode.opcode = op.getarg(0)._get_str().rsplit(" ", 1)[1]
-                    bytecode.debug_merge_point = op
-                    loop_bytecodes.append(bytecode)
-                    all_bytecodes.append(bytecode)
+                    sliced_loop = BytecodeTrace()
+                    sliced_loop.bytecode = op.getarg(0)._get_str().rsplit(" ", 1)[1]
+                    sliced_loops.append(sliced_loop)
                     if self.count_debug_merge_point:
                         total_ops += 1
                 else:
-                    bytecode.append(op)
+                    sliced_loop.append(op)
                     total_ops += 1
-        return loops, all_bytecodes, bytecode_by_loop, total_ops
-        
-
-    def filter_loops(self, filepath, loops):
-        newloops = []
-        for loop in loops:
-            op = loop.operations[0]
-            # if the first op is not debug_merge_point, it's a bridge: for
-            # now, we always include them
-            if (op.getopname() != 'debug_merge_point' or 
-                str(filepath) in str(op.getarg(0))):
-                newloops.append(loop)
-        return newloops
+        return loops, sliced_loops, total_ops
 
     def check_0_op_bytecodes(self):
-        for bytecodetrace in self.all_bytecodes:
-            if bytecodetrace.opcode not in ZERO_OP_OPCODES:
+        for bytecodetrace in self.sliced_loops:
+            if bytecodetrace.bytecode not in ZERO_OP_BYTECODES:
                 continue
             assert not bytecodetrace
 
-    def get_by_bytecode(self, name, from_entry_bridge=False, loop=None):
+    def get_by_bytecode(self, name, from_entry_bridge=False):
         if from_entry_bridge:
-            assert loop is None
-            bytecodes = self.all_bytecodes_entrybridges
-        elif loop:
-            bytecodes = self.bytecode_by_loop[loop]
+            sliced_loops = self.sliced_entrybridge
         else:
-            bytecodes = self.all_bytecodes
-        return [ops for ops in bytecodes if ops.opcode == name]
+            sliced_loops = self.sliced_loops
+        return [ops for ops in sliced_loops if ops.bytecode == name]
 
     def print_loops(self):
         for rawloop in self.rawloops:
@@ -247,576 +223,6 @@
             return total
         ''' % startvalue, 170, ([], startvalue + 4999450000L))
 
-    def test_boolrewrite_invers(self):
-        for a, b, res, ops in (('2000', '2000', 20001000, 51),
-                               ( '500',  '500', 15001500, 81),
-                               ( '300',  '600', 16001700, 83),
-                               (   'a',    'b', 16001700, 89),
-                               (   'a',    'a', 13001700, 85)):
-
-            self.run_source('''
-            def main():
-                sa = 0
-                a = 300
-                b = 600
-                for i in range(1000):
-                    if i < %s: sa += 1
-                    else: sa += 2
-                    if i >= %s: sa += 10000
-                    else: sa += 20000
-                return sa
-            '''%(a, b), ops, ([], res))
-
-    def test_boolrewrite_reflex(self):
-        for a, b, res, ops in (('2000', '2000', 10001000, 51),
-                               ( '500',  '500', 15001500, 81),
-                               ( '300',  '600', 14001700, 83),
-                               (   'a',    'b', 14001700, 89),
-                               (   'a',    'a', 17001700, 85)):
-
-            self.run_source('''
-            def main():
-                sa = 0
-                a = 300
-                b = 600
-                for i in range(1000):
-                    if i < %s: sa += 1
-                    else: sa += 2
-                    if %s > i: sa += 10000
-                    else: sa += 20000
-                return sa
-            '''%(a, b), ops, ([], res))
-
-
-    def test_boolrewrite_correct_invers(self):
-        def opval(i, op, a):
-            if eval('%d %s %d' % (i, op, a)): return 1
-            return 2
-
-        ops = ('<', '>', '<=', '>=', '==', '!=')        
-        for op1 in ops:
-            for op2 in ops:
-                for a,b in ((500, 500), (300, 600)):
-                    res = 0
-                    res += opval(a-1, op1, a) * (a)
-                    res += opval(  a, op1, a) 
-                    res += opval(a+1, op1, a) * (1000 - a - 1)
-                    res += opval(b-1, op2, b) * 10000 * (b)
-                    res += opval(  b, op2, b) * 10000 
-                    res += opval(b+1, op2, b) * 10000 * (1000 - b - 1)
-
-                    self.run_source('''
-                    def main():
-                        sa = 0
-                        for i in range(1000):
-                            if i %s %d: sa += 1
-                            else: sa += 2
-                            if i %s %d: sa += 10000
-                            else: sa += 20000
-                        return sa
-                    '''%(op1, a, op2, b), 83, ([], res))
-
-                    self.run_source('''
-                    def main():
-                        sa = 0
-                        i = 0.0
-                        while i < 250.0:
-                            if i %s %f: sa += 1
-                            else: sa += 2
-                            if i %s %f: sa += 10000
-                            else: sa += 20000
-                            i += 0.25
-                        return sa
-                    '''%(op1, float(a)/4.0, op2, float(b)/4.0), 156, ([], res))
-                    
-
-    def test_boolrewrite_correct_reflex(self):
-        def opval(i, op, a):
-            if eval('%d %s %d' % (i, op, a)): return 1
-            return 2
-
-        ops = ('<', '>', '<=', '>=', '==', '!=')        
-        for op1 in ops:
-            for op2 in ops:
-                for a,b in ((500, 500), (300, 600)):
-                    res = 0
-                    res += opval(a-1, op1, a) * (a)
-                    res += opval(  a, op1, a) 
-                    res += opval(a+1, op1, a) * (1000 - a - 1)
-                    res += opval(b, op2, b-1) * 10000 * (b)
-                    res += opval(b, op2,   b) * 10000
-                    res += opval(b, op2, b+1) * 10000 * (1000 - b - 1)
-
-                    self.run_source('''
-                    def main():
-                        sa = 0
-                        for i in range(1000):
-                            if i %s %d: sa += 1
-                            else: sa += 2
-                            if %d %s i: sa += 10000
-                            else: sa += 20000
-                        return sa
-                    '''%(op1, a, b, op2), 83, ([], res))
-
-                    self.run_source('''
-                    def main():
-                        sa = 0
-                        i = 0.0
-                        while i < 250.0:
-                            if i %s %f: sa += 1
-                            else: sa += 2
-                            if %f %s i: sa += 10000
-                            else: sa += 20000
-                            i += 0.25
-                        return sa
-                    '''%(op1, float(a)/4.0, float(b)/4.0, op2), 156, ([], res))
-
-    def test_boolrewrite_ptr(self):
-        # XXX this test is way too imprecise in what it is actually testing
-        # it should count the number of guards instead
-        compares = ('a == b', 'b == a', 'a != b', 'b != a', 'a == c', 'c != b')
-        for e1 in compares:
-            for e2 in compares:
-                a, b, c = 1, 2, 3
-                if eval(e1): res = 752 * 1 
-                else: res = 752 * 2 
-                if eval(e2): res += 752 * 10000 
-                else: res += 752 * 20000 
-                a = b
-                if eval(e1): res += 248 * 1
-                else: res += 248 * 2
-                if eval(e2): res += 248 * 10000
-                else: res += 248 * 20000
-
-
-                if 'c' in e1 or 'c' in e2:
-                    n = 337
-                else:
-                    n = 215
-
-                print
-                print 'Test:', e1, e2, n, res
-                self.run_source('''
-                class tst(object):
-                    pass
-                def main():
-                    a = tst()
-                    b = tst()
-                    c = tst()
-                    sa = 0
-                    for i in range(1000):
-                        if %s: sa += 1
-                        else: sa += 2
-                        if %s: sa += 10000
-                        else: sa += 20000
-                        if i > 750: a = b
-                    return sa
-                '''%(e1, e2), n, ([], res))
-
-    def test_array_sum(self):
-        for tc, maxops in zip('bhilBHILfd', (38,) * 6 + (40, 40, 41, 38)):
-            res = 19352859
-            if tc == 'L':
-                res = long(res)
-            elif tc in 'fd':
-                res = float(res)
-            elif tc == 'I' and sys.maxint == 2147483647:
-                res = long(res)
-                # note: in CPython we always get longs here, even on 64-bits
-
-            self.run_source('''
-            from array import array
-
-            def main():
-                img = array("%s", range(127) * 5) * 484
-                l, i = 0, 0
-                while i < 640 * 480:
-                    l += img[i]
-                    i += 1
-                return l
-            ''' % tc, maxops, ([], res))
-
-    def test_array_sum_char(self):
-        self.run_source('''
-            from array import array
-
-            def main():
-                img = array("c", "Hello") * 130 * 480
-                l, i = 0, 0
-                while i < 640 * 480:
-                    l += ord(img[i])
-                    i += 1
-                return l
-            ''', 60, ([], 30720000))
-
-    def test_array_sum_unicode(self):
-        self.run_source('''
-            from array import array
-
-            def main():
-                img = array("u", u"Hello") * 130 * 480
-                l, i = 0, 0
-                while i < 640 * 480:
-                    if img[i] == u"l":
-                        l += 1
-                    i += 1
-                return l
-            ''', 65, ([], 122880))
-
-    def test_array_intimg(self):
-        # XXX this test is way too imprecise in what it is actually testing
-        # it should count the number of guards instead
-        for tc, maxops in zip('ilILd', (67, 67, 70, 70, 61)):
-            print
-            print '='*65
-            print '='*20, 'running test for tc=%r' % (tc,), '='*20
-            res = 73574560
-            if tc == 'L':
-                res = long(res)
-            elif tc in 'fd':
-                res = float(res)
-            elif tc == 'I' and sys.maxint == 2147483647:
-                res = long(res)
-                # note: in CPython we always get longs here, even on 64-bits
-
-            self.run_source('''
-            from array import array
-
-            def main(tc):
-                img = array(tc, range(3)) * (350 * 480)
-                intimg = array(tc, (0,)) * (640 * 480)
-                l, i = 0, 640
-                while i < 640 * 480:
-                    l = l + img[i]
-                    intimg[i] = (intimg[i-640] + l) 
-                    i += 1
-                return intimg[i - 1]
-            ''', maxops, ([tc], res))
-
-    def test_unpackiterable(self):
-        self.run_source('''
-        from array import array
-
-        def main():
-            i = 0
-            t = array('l', (1, 2))
-            while i < 2000:
-                a, b = t
-                i += 1
-            return 3
-
-        ''', 100, ([], 3))
-        bytecode, = self.get_by_bytecode("UNPACK_SEQUENCE")
-        # we allocate virtual ref and frame, we don't want block
-        assert len(bytecode.get_opnames('call_may_force')) == 0
-        
-
-    def test_intbound_simple(self):
-        ops = ('<', '>', '<=', '>=', '==', '!=')
-        nbr = (3, 7)
-        for o1 in ops:
-            for o2 in ops:
-                for n1 in nbr:
-                    for n2 in nbr:
-                        src = '''
-                        def f(i):
-                            a, b = 3, 3
-                            if i %s %d:
-                                a = 0
-                            else:
-                                a = 1
-                            if i %s %d:
-                                b = 0
-                            else:
-                                b = 1
-                            return a + b * 2
-
-                        def main():
-                            res = [0] * 4
-                            idx = []
-                            for i in range(15):
-                                idx.extend([i] * 1500)
-                            for i in idx:
-                                res[f(i)] += 1
-                            return res
-
-                        ''' % (o1, n1, o2, n2)
-
-                        exec(str(py.code.Source(src)))
-                        res = [0] * 4
-                        for i in range(15):
-                            res[f(i)] += 1500
-                        self.run_source(src, 268, ([], res))
-
-    def test_intbound_addsub_mix(self):
-        tests = ('i > 4', 'i > 2', 'i + 1 > 2', '1 + i > 4',
-                 'i - 1 > 1', '1 - i > 1', '1 - i < -3',
-                 'i == 1', 'i == 5', 'i != 1', '-2 * i < -4')
-        for t1 in tests:
-            for t2 in tests:
-                print t1, t2
-                src = '''
-                def f(i):
-                    a, b = 3, 3
-                    if %s:
-                        a = 0
-                    else:
-                        a = 1
-                    if %s:
-                        b = 0
-                    else:
-                        b = 1
-                    return a + b * 2
-
-                def main():
-                    res = [0] * 4
-                    idx = []
-                    for i in range(15):
-                        idx.extend([i] * 1500)
-                    for i in idx:
-                        res[f(i)] += 1
-                    return res
-
-                ''' % (t1, t2)
-
-                exec(str(py.code.Source(src)))
-                res = [0] * 4
-                for i in range(15):
-                    res[f(i)] += 1500
-                self.run_source(src, 280, ([], res))
-
-    def test_intbound_gt(self):
-        self.run_source('''
-        def main():
-            i, a, b = 0, 0, 0
-            while i < 2000:
-                if i > -1:
-                    a += 1
-                if i > -2:
-                    b += 1
-                i += 1
-            return (a, b)
-        ''', 48, ([], (2000, 2000)))
-
-    def test_intbound_sub_lt(self):
-        self.run_source('''
-        def main():
-            i, a, b = 0, 0, 0
-            while i < 2000:
-                if i - 10 < 1995:
-                    a += 1
-                i += 1
-            return (a, b)
-        ''', 38, ([], (2000, 0)))
-
-    def test_intbound_addsub_ge(self):
-        self.run_source('''
-        def main():
-            i, a, b = 0, 0, 0
-            while i < 2000:
-                if i + 5 >= 5:
-                    a += 1
-                if i - 1 >= -1:
-                    b += 1
-                i += 1
-            return (a, b)
-        ''', 56, ([], (2000, 2000)))
-
-    def test_intbound_addmul_ge(self):
-        self.run_source('''
-        def main():
-            i, a, b = 0, 0, 0
-            while i < 2000:
-                if i + 5 >= 5:
-                    a += 1
-                if 2 * i >= 0:
-                    b += 1
-                i += 1
-            return (a, b)
-        ''', 53, ([], (2000, 2000)))
-
-    def test_intbound_eq(self):
-        self.run_source('''
-        def main(a):
-            i, s = 0, 0
-            while i < 1500:
-                if a == 7:
-                    s += a + 1
-                elif i == 10:
-                    s += i
-                else:
-                    s += 1
-                i += 1
-            return s
-        ''', 69, ([7], 12000), ([42], 1509), ([10], 1509))
-        
-    def test_intbound_mul(self):
-        self.run_source('''
-        def main(a):
-            i, s = 0, 0
-            while i < 1500:
-                assert i >= 0
-                if 2 * i < 30000:
-                    s += 1
-                else:
-                    s += a
-                i += 1
-            return s
-        ''', 43, ([7], 1500))
-        
-    def test_assert(self):
-        self.run_source('''
-        def main(a):
-            i, s = 0, 0
-            while i < 1500:
-                assert a == 7
-                s += a + 1
-                i += 1
-            return s
-        ''', 38, ([7], 8*1500))
-        
-    def test_zeropadded(self):
-        self.run_source('''
-        from array import array
-        class ZeroPadded(array):
-            def __new__(cls, l):
-                self = array.__new__(cls, 'd', range(l))
-                return self
-
-            def __getitem__(self, i):
-                if i < 0 or i >= self.__len__():
-                    return 0
-                return array.__getitem__(self, i)
-
-
-        def main():
-            buf = ZeroPadded(2000)
-            i = 10
-            sa = 0
-            while i < 2000 - 10:
-                sa += buf[i-2] + buf[i-1] + buf[i] + buf[i+1] + buf[i+2]
-                i += 1
-            return sa
-
-        ''', 232, ([], 9895050.0))
-
-    def test_circular(self):
-        self.run_source('''
-        from array import array
-        class Circular(array):
-            def __new__(cls):
-                self = array.__new__(cls, 'd', range(256))
-                return self
-            def __getitem__(self, i):
-                # assert self.__len__() == 256 (FIXME: does not improve)
-                return array.__getitem__(self, i & 255)
-
-        def main():
-            buf = Circular()
-            i = 10
-            sa = 0
-            while i < 2000 - 10:
-                sa += buf[i-2] + buf[i-1] + buf[i] + buf[i+1] + buf[i+2]
-                i += 1
-            return sa
-
-        ''', 170, ([], 1239690.0))
-
-    def test_min_max(self):
-        self.run_source('''
-        def main():
-            i=0
-            sa=0
-            while i < 2000: 
-                sa+=min(max(i, 3000), 4000)
-                i+=1
-            return sa
-        ''', 51, ([], 2000*3000))
-
-    def test_silly_max(self):
-        self.run_source('''
-        def main():
-            i=2
-            sa=0
-            while i < 2000: 
-                sa+=max(*range(i))
-                i+=1
-            return sa
-        ''', 125, ([], 1997001))
-
-    def test_iter_max(self):
-        self.run_source('''
-        def main():
-            i=2
-            sa=0
-            while i < 2000: 
-                sa+=max(range(i))
-                i+=1
-            return sa
-        ''', 88, ([], 1997001))
-
-    def test__ffi_call(self):
-        from pypy.rlib.test.test_libffi import get_libm_name
-        libm_name = get_libm_name(sys.platform)
-        out = self.run_source('''
-        def main():
-            try:
-                from _ffi import CDLL, types
-            except ImportError:
-                sys.stdout.write('SKIP: cannot import _ffi')
-                return 0
-
-            libm = CDLL('%(libm_name)s')
-            pow = libm.getfunc('pow', [types.double, types.double],
-                               types.double)
-            print pow.getaddr()
-            i = 0
-            res = 0
-            while i < 2000:
-                res += pow(2, 3)
-                i += 1
-            return res
-        ''' % locals(),
-                              76, ([], 8.0*2000), threshold=1000)
-        pow_addr = int(out.splitlines()[0])
-        ops = self.get_by_bytecode('CALL_FUNCTION')
-        assert len(ops) == 1
-        call_function = ops[0]
-        last_ops = [op.getopname() for op in call_function[-5:]]
-        assert last_ops == ['force_token',
-                            'setfield_gc',
-                            'call_release_gil',
-                            'guard_not_forced',
-                            'guard_no_exception']
-        call = call_function[-3]
-        assert call.getarg(0).value == pow_addr
-        assert call.getarg(1).value == 2.0
-        assert call.getarg(2).value == 3.0
-
-    def test_xor(self):
-        values = (-4, -3, -2, -1, 0, 1, 2, 3, 4)
-        for a in values:
-            for b in values:
-                if a^b >= 0:
-                    r = 2000
-                else:
-                    r = 0
-                ops = 46
-                
-                self.run_source('''
-                def main(a, b):
-                    i = sa = 0
-                    while i < 2000:
-                        if a > 0: # Specialises the loop
-                            pass
-                        if b > 1:
-                            pass
-                        if a^b >= 0:
-                            sa += 1
-                        i += 1
-                    return sa
-                ''', ops, ([a, b], r))
-        
     def test_shift(self):
         from sys import maxint
         maxvals = (-maxint-1, -maxint, maxint-1, maxint)
@@ -957,7 +363,6 @@
         _, compare = self.get_by_bytecode("COMPARE_OP")
         assert "call" not in compare.get_opnames()
 
-            
 class AppTestJIT(PyPyCJITTests):
     def setup_class(cls):
         if not option.runappdirect:


More information about the pypy-commit mailing list