Commits

Maciej Fijalkowski committed 09ee47c Draft

(alex, arigo, fijal) fix some tests

Comments (0)

Files changed (4)

pypy/rpython/rint.py

     # version picked by specialisation based on which
     # type system rtyping is using, from <type_system>.ll_str module
     def ll_str(self, i):
-        pass
+        raise NotImplementedError
     ll_str._annspecialcase_ = "specialize:ts('ll_str.ll_int_str')"
 
     def rtype_hex(self, hop):

pypy/translator/c/test/test_backendoptimized.py

 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.translator.backendopt.all import backend_optimizations
 from pypy.translator.c.test.test_typed import TestTypedTestCase as _TestTypedTestCase
+from pypy.translator.c.test.test_genc import compile
 
 
 class TestTypedOptimizedTestCase(_TestTypedTestCase):
-
-    def process(self, t):
-        _TestTypedTestCase.process(self, t)
-        self.t = t
-        backend_optimizations(t, merge_if_blocks=False)
-        if conftest.option.view:
-            t.view()
+    getcompiled = staticmethod(compile)
 
     def test_remove_same_as(self):
         def f(n):

pypy/translator/c/test/test_genc.py

 
 from pypy.rlib.entrypoint import entrypoint
 from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, intmask
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.rpython.lltypesystem.rstr import STR
 from pypy.translator.interactive import Translation
 from pypy.translator.translator import TranslationContext, graphof
 
+def llrepr(v):
+    if isinstance(v, r_ulonglong):
+        return "%d:%d" % (intmask(v >> 32), intmask(v & 0xffffffff))
+    elif isinstance(v, r_longlong):
+        return "%d:%d" % (intmask(v >> 32), intmask(v & 0xffffffff))
+    return str(v)
+
+def parse_longlong(a):
+    p0, p1 = a.split(":")
+    return (r_longlong(int(p0)) << 32) + (r_longlong(int(p1)) & 0xffffffff)
+
+def parse_ulonglong(a):
+    p0, p1 = a.split(":")
+    return (r_ulonglong(int(p0)) << 32) + (r_ulonglong(int(p1)) & 0xffffffff)
 
 def compile(fn, argtypes, view=False, gcpolicy="none", backendopt=True,
             annotatorpolicy=None, thread=False):
     argtypes_unroll = unrolling_iterable(enumerate(argtypes))
 
     for argtype in argtypes:
-        if argtype not in [int, float, str, bool]:
+        if argtype not in [int, float, str, bool, r_ulonglong, r_longlong]:
             raise Exception("Unsupported argtype, %r" % (argtype,))
 
     def entry_point(argv):
         args = ()
         for i, argtype in argtypes_unroll:
+            a = argv[i + 1]
             if argtype is int:
-                args += (int(argv[i + 1]),)
+                args += (int(a),)
+            elif argtype is r_longlong:
+                args += (parse_longlong(a),)
+            elif argtype is r_ulonglong:
+                args += (parse_ulonglong(a),)
             elif argtype is bool:
-                if argv[i + 1] == 'True':
+                if a == 'True':
                     args += (True,)
                 else:
-                    assert argv[i + 1] == 'False'
+                    assert a == 'False'
                     args += (False,)
             elif argtype is float:
-                args += (float(argv[i + 1]),)
+                args += (float(a),)
             else:
-                args += (argv[i + 1],)
+                args += (a,)
         res = fn(*args)
         print "THE RESULT IS:", res, ";"
         return 0
         assert len(args) == len(argtypes)
         for arg, argtype in zip(args, argtypes):
             assert isinstance(arg, argtype)
-        stdout = t.driver.cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
+        stdout = t.driver.cbuilder.cmdexec(" ".join([llrepr(arg) for arg in args]))
         assert stdout.endswith(' ;\n')
         pos = stdout.rindex('THE RESULT IS: ')
         res = stdout[pos + len('THE RESULT IS: '):-3]
-        if ll_res == lltype.Signed:
+        if ll_res in [lltype.Signed, lltype.Unsigned, lltype.SignedLongLong,
+                      lltype.UnsignedLongLong]:
             return int(res)
         elif ll_res == lltype.Bool:
             return bool(int(res))

pypy/translator/c/test/test_typed.py

 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.translator.test import snippet
 from pypy.translator.c.test.test_genc import compile
-from pypy.translator.translator import TranslationContext
 
 
-class CompilationTestCase:
-
-    def annotatefunc(self, func, argtypes=None):
-        from pypy.config.pypyoption import get_pypy_config
-        config = get_pypy_config(translating=True)
-        config.translation.gc = "ref"
-        config.translation.simplifying = True
-        t = TranslationContext(config=config)
-        if argtypes is None:
-            argtypes = []
-        a = t.buildannotator()
-        a.build_types(func, argtypes)
-        a.simplify()
-        return t
-
-    def compilefunc(self, t, func):
-        from pypy.translator.c import genc
-        self.builder = builder = genc.CExtModuleBuilder(t, func, config=t.config)
-        if hasattr(self, 'include_also_eci'):
-            builder.merge_eci(self.include_also_eci)
-        builder.generate_source()
-        builder.compile()
-        return builder.get_entry_point()
-
-    def getcompiled(self, func, argtypes=[], view=False):
-        return compile(func, argtypes, view=view)
-
-    def process(self, t):
-        t.buildrtyper().specialize()
-        #raisingop2direct_call(t)
-
-
-class TestTypedTestCase(CompilationTestCase):
+class TestTypedTestCase(object):
+    def getcompiled(self, func, argtypes):
+        return compile(func, argtypes, backendopt=False)
 
     def test_set_attr(self):
         set_attr = self.getcompiled(snippet.set_attr)
                 x = x - 1
             return z == (6, 'a')
         fn = self.getcompiled(tuple_repr, [int, str])
-        assert fn()
+        assert fn(6, "a")
+        assert not fn(6, "xyz")
 
     def test_classattribute(self):
         fn = self.getcompiled(snippet.classattribute, [int])
             g2.next = g1
             g3.next = g2
             return g3.next.next.value
-        fn = self.getcompiled(do_things)
+        fn = self.getcompiled(do_things, [])
         assert fn() == 1
 
     def test_float_ops(self):
         assert fn(4.5) == 90.125
 
     def test_memoryerror(self):
+        def g(i):
+            return [0] * i
+        
         def f(i):
-            lst = [0] * i
-            lst[-1] = 5
-            return lst[0]
+            try:
+                lst = g(i)
+                lst[-1] = 5
+                return lst[0]
+            except MemoryError:
+                return -1
         fn = self.getcompiled(f, [int])
         assert fn(1) == 5
         assert fn(2) == 0
-        py.test.raises(MemoryError, fn, sys.maxint // 2 + 1)
-        py.test.raises(MemoryError, fn, sys.maxint)
+        assert fn(sys.maxint // 2 + 1) == -1
+        assert fn(sys.maxint) == -1
 
     def test_chr(self):
         def f(x):
         def f(i):
             return 4 * i
         fn = self.getcompiled(f, [r_ulonglong], view=False)
-        assert fn(2147483647) == 4 * 2147483647
+        assert fn(r_ulonglong(2147483647)) == 4 * 2147483647
 
         def g(i):
             return 4 * i
         gn = self.getcompiled(g, [r_longlong], view=False)
-        assert gn(2147483647) == 4 * 2147483647
+        assert gn(r_longlong(2147483647)) == 4 * 2147483647
 
         def g(i):
             return i << 12
         gn = self.getcompiled(g, [r_longlong])
-        assert gn(2147483647) == 2147483647 << 12
+        assert gn(r_longlong(2147483647)) == 2147483647 << 12
 
         def g(i):
             return i >> 12
         gn = self.getcompiled(g, [r_longlong])
-        assert gn(-2147483647) == (-2147483647) >> 12
+        assert gn(r_longlong(-2147483647)) == (-2147483647) >> 12
 
         def g(i):
             return i >> 12
         gn = self.getcompiled(g, [r_ulonglong])
-        assert gn(2 ** 64 - 12345678) == (2 ** 64 - 12345678) >> 12
+        assert gn(r_ulonglong(2 ** 64 - 12345678)) == (2 ** 64 - 12345678) >> 12
 
     def test_specializing_int_functions(self):
         def f(i):
         def f(i):
             return int(i)
         fn = self.getcompiled(f, [r_longlong])
-        assert fn(0) == 0
+        assert fn(r_longlong(0)) == 0
 
     def test_upcast_int(self):
         def f(v):
         def wrapper():
             lst = snippet.call_five()
             return (len(lst), lst[0]) == (1, 5)
-        call_five = self.getcompiled(wrapper)
+        call_five = self.getcompiled(wrapper, [])
         result = call_five()
         assert result
 
             list_3_c = l[:2]
             list_9 = l[5:]
             list_11_h = l[3:5]
-            return (len(l), l[0], l[1], l[2], l[3], l[4], l[5],
+            return str((len(l), l[0], l[1], l[2], l[3], l[4], l[5],
                     len(list_3_c),  list_3_c[0],  list_3_c[1],
                     len(list_9),    list_9[0],
-                    len(list_11_h), list_11_h[0], list_11_h[1])
-        fn = self.getcompiled(get_set_del_nonneg_slice)
+                    len(list_11_h), list_11_h[0], list_11_h[1]))
+        fn = self.getcompiled(get_set_del_nonneg_slice, [])
         result = fn()
-        assert result == (6, 3, ord('c'), 8, 11, ord('h'), 9,
-                          2, 3, ord('c'),
-                          1, 9,
-                          2, 11, ord('h'))
+        assert result == str((6, 3, ord('c'), 8, 11, ord('h'), 9,
+                              2, 3, ord('c'),
+                              1, 9,
+                              2, 11, ord('h')))
 
     def test_is(self):
         def testfn():
             l1 = []
             return l1 is l1
-        fn = self.getcompiled(testfn)
+        fn = self.getcompiled(testfn, [])
         result = fn()
         assert result is True
         def testfn():
             l1 = []
             return l1 is None
-        fn = self.getcompiled(testfn)
+        fn = self.getcompiled(testfn, [])
         result = fn()
         assert result is False
 
         m = r.meth
         def fn():
             return m()
-        res = self.getcompiled(fn)()
+        res = self.getcompiled(fn, [])()
         assert res == 0
 
     def test_constant_return_disagreement(self):
         r = R()
         def fn():
             return r.meth()
-        res = self.getcompiled(fn)()
+        res = self.getcompiled(fn, [])()
         assert res == 0
 
     def test_stringformatting(self):
                     compute_hash(d),
                     compute_hash(("Hi", None, (7.5, 2, d))))
 
-        f = self.getcompiled(fn)
+        f = self.getcompiled(fn, [])
         res = f()
 
         # xxx the next line is too precise, checking the exact implementation
             r = range(10, 37, 4)
             r.reverse()
             return r[0]
-        f = self.getcompiled(fn)
+        f = self.getcompiled(fn, [])
         assert f() == fn()
 
     def test_range_idx(self):
             for ii in range(1):
                 a1.append_to_list(X())
             return a1.check_list_is_true()
-        fn = self.getcompiled(f)
+        fn = self.getcompiled(f, [])
         assert fn() == 1
 
     def test_recursion_detection(self):
             except Exception:
                 return 42
             return x
-        fn = self.getcompiled(f)
+        fn = self.getcompiled(f, [])
         res = fn()
         assert res == 42
 
             except TypeError:
                 return 42
             return x
-        fn = self.getcompiled(f)
+        fn = self.getcompiled(f, [])
         res = fn()
         assert res == 42
 
             except TypeError:
                 return 42
             return 0
-        fn = self.getcompiled(f)
+        fn = self.getcompiled(f, [])
         res = fn()
         assert res == 42