[pypy-svn] r14947 - in pypy/dist/pypy/translator/llvm2: . test

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Jul 23 00:49:32 CEST 2005


Author: ericvrp
Date: Sat Jul 23 00:49:31 2005
New Revision: 14947

Added:
   pypy/dist/pypy/translator/llvm2/test/test_exception.py
Modified:
   pypy/dist/pypy/translator/llvm2/funcnode.py
   pypy/dist/pypy/translator/llvm2/test/llvmsnippet.py
   pypy/dist/pypy/translator/llvm2/test/test_class.py
   pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py
   pypy/dist/pypy/translator/llvm2/test/test_lltype.py
   pypy/dist/pypy/translator/llvm2/test/test_snippet.py
Log:
Lots more test pass now (107 passed, 17 failed, of which 11 are exceptions tests).


Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py	Sat Jul 23 00:49:31 2005
@@ -68,6 +68,12 @@
     def writeimpl(self, codewriter):
         assert self._issetup 
         graph = self.graph
+        #dir(graph)==['__class__', '__delattr__', '__dict__', '__doc__',
+        #             '__getattribute__', '__hash__', '__init__', '__module__',
+        #             '__new__', '__reduce__', '__reduce_ex__', '__repr__',
+        #             '__setattr__', '__str__', '__weakref__', 'exceptblock',
+        #             'func', 'getargs', 'getreturnvar', 'name', 'returnblock',
+        #             'show', 'source', 'startblock']
         log.writeimpl(graph.name)
         codewriter.openfunc(self.getdecl())
         nextblock = graph.startblock

Modified: pypy/dist/pypy/translator/llvm2/test/llvmsnippet.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/llvmsnippet.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/llvmsnippet.py	Sat Jul 23 00:49:31 2005
@@ -1,3 +1,5 @@
+from __future__ import division
+
 #function snippets
 def simple1():
     return 1
@@ -375,52 +377,6 @@
     return len((1, 2, "asdf")) + i
 
 
-#exception snippets:
-def simple_exception(n):
-    lst = range(10)
-    try:
-        lst[n]
-    except IndexError:
-        return 2
-    return 4
-    
-def two_exceptions(n):
-    lst = range(10)
-    try:
-        lst[n]
-    except IndexError:
-        return 2
-    except KeyError:
-        return 3
-    return 4
-
-def catch_base_exception(n):
-    lst = range(10)
-    try:
-        lst[n]
-    except LookupError:
-        return 2
-    return 4
-
-class MyException(Exception):
-    def __init__(self, n):
-        self.n = n
-
-def raises(i):
-    if i == 3:
-        raise MyException, 12
-    if i == 4:
-        raise IndexError
-    if i > 5:
-        raise MyException(i)
-    return 1
-
-def catches(i):
-    try:
-        return raises(i)
-    except MyException, e:
-        return e.n
-
 #PBC snippets
 
 class PBCClass(object):

Modified: pypy/dist/pypy/translator/llvm2/test/test_class.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_class.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_class.py	Sat Jul 23 00:49:31 2005
@@ -52,15 +52,15 @@
 
     def test_global_instance(self):
         f = compile_function(llvmsnippet.global_instance, [int])
-        assert f(-1) == 41
+        assert f(-1) == llvmsnippet.global_instance(-1)
         for i in range(20):
-            assert f(i) == 2 * i
+            assert f(i) == llvmsnippet.global_instance(i)
 
     def test_call_degrading_func(self):
         f = compile_function(llvmsnippet.call_degrading_func, [bool])
-        assert f(True) == -36
-        assert f(False) == 14
+        assert f(True) == llvmsnippet.call_degrading_func(True)     #-36
+        assert f(False) == llvmsnippet.call_degrading_func(False)   #14
     
-    def DONOTtest_circular_classdef(self):
+    def test_circular_classdef(self):
         f = compile_function(llvmsnippet.circular_classdef, [])
         assert f() == 10

Added: pypy/dist/pypy/translator/llvm2/test/test_exception.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/test/test_exception.py	Sat Jul 23 00:49:31 2005
@@ -0,0 +1,159 @@
+from pypy.translator.llvm2.genllvm import compile_function
+from pypy.translator.test.snippet import try_raise_choose
+
+class TestException(Exception):
+    pass
+
+class MyException(Exception):
+    def __init__(self, n):
+        self.n = n
+
+def test_simple1():
+    def raise_(i):
+        if i:
+            raise TestException()
+        else:
+            return 1
+    def fn(i):
+        try:
+            return raise_(i)
+        except TestException: 
+            return 0
+    f = compile_function(fn, [int])
+    assert f(0) == fn(0)
+    assert f(1) == fn(1)
+
+def test_simple2():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except:
+            return 2
+        return 4
+    f = compile_function(fn, [int])
+    assert f(-1) == fn(-1)
+    assert f( 0) == fn( 0)
+    assert f(10) == fn(10)
+
+def test_pass_exc():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except:
+            pass
+        return 4
+    f = compile_function(fn, [int])
+    assert f(-1) == fn(-1)
+    assert f( 0) == fn( 0)
+    assert f(10) == fn(10)
+
+def test_divzero():
+    def fn(n):
+        try:
+            n/0
+        except:
+            return 2
+        return 4
+    f = compile_function(fn, [int])
+    assert f(0) == fn(0)
+    
+def test_reraise1():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except:
+            raise
+        return 4
+    f = compile_function(fn, [int])
+    assert f(-1) == fn(-1)
+    assert f( 0) == fn( 0)
+    assert f(10) == fn(10)
+
+def test_reraise2():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except e:
+            raise e
+        return 4
+    f = compile_function(fn, [int])
+    assert f(-1) == fn(-1)
+    assert f( 0) == fn( 0)
+    assert f(10) == fn(10)
+
+def test_simple_exception():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except IndexError:
+            return 2
+        return 4
+    f = compile_function(fn, [int])
+    for i in range(10):
+        assert f(i) == fn(i)
+    for i in range(10, 20):
+        assert f(i) == fn(i)
+
+def test_two_exceptions():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except IndexError:
+            return 2
+        except KeyError:
+            return 3
+        return 4
+    f = compile_function(fn, [int])
+    for i in range(10):
+        assert f(i) == fn(i)
+    for i in range(10, 20):
+        assert f(i) == fn(i)
+
+def test_catch_base_exception():
+    def fn(n):
+        lst = range(10)
+        try:
+            lst[n]
+        except LookupError:
+            return 2
+        return 4
+    f = compile_function(fn, [int])
+    for i in range(10):
+        assert f(i) == fn(i)
+    for i in range(10, 20):
+        assert f(i) == fn(i)
+
+
+def test_catches():
+    def raises(i):
+        if i == 3:
+            raise MyException, 12
+        if i == 4:
+            raise IndexError
+        if i > 5:
+            raise MyException(i)
+        return 1
+    def fn(i):
+        try:
+            return raises(i)
+        except MyException, e:
+            return e.n
+    f = compile_function(fn, [int])
+    assert f(1) == fn(1)
+    assert f(2) == fn(2)
+    assert f(3) == fn(3)
+    py.test.raises(RuntimeError, "f(4)")
+    assert f(5) == fn(5)
+    assert f(6) == fn(6)
+    assert f(13) == fn(13)
+
+def test_try_raise_choose():
+    f = compile_function(try_raise_choose, [int])
+    for i in [-1, 0, 1, 2]:
+        assert f(i) == i

Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	Sat Jul 23 00:49:31 2005
@@ -20,14 +20,14 @@
     import time
     def fn():
         return time.time()
-    f = compile_function(fn, [], view=False)
+    f = compile_function(fn, [])
     assert abs(f()-fn()) < 10.0
 
 def test_external_function_ll_time_clock():
     import time
     def fn():
         return time.clock()
-    f = compile_function(fn, [], view=False)
+    f = compile_function(fn, [])
     assert abs(f()-fn()) < 10.0
 
 def test_external_function_ll_time_sleep():
@@ -35,7 +35,7 @@
     def fn(t):
         time.sleep(t)
         return 666
-    f = compile_function(fn, [float], view=False)
+    f = compile_function(fn, [float])
     start_time = time.time()
     delay_time = 2.0
     d = f(delay_time)

Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	Sat Jul 23 00:49:31 2005
@@ -15,7 +15,7 @@
     f = compile_function(simple1, [])
     assert f() == 1
 
-def DONTtest_simple_function_pointer(): 
+def test_simple_function_pointer(): 
     def f1(x): 
         return x + 1
     def f2(x): 
@@ -331,28 +331,12 @@
     f = compile_function(method_call, [])
     assert f() == 4
 
-class TestException(Exception):
-    pass
-
-def DONTtest_exception():
-    def raise_(i):
-        if i:
-            raise TestException()
-        else:
-            return 1
-    def catch(i):
-        try:
-            return raise_(i)
-        except TestException:
-            return 0
-    f = compile_function(catch, [int])
-
-def Xtest_dict_creation(): 
+def test_dict_creation(): 
     d = {'hello' : 23,
          'world' : 21}
     l = ["hello", "world"]
     def createdict(i, j):
         return d[l[i]] + d[l[j]]
-    f = compile_function(createdict, [int, int], view=True)
-
-    assert createdict(0, 1) == 43
+    assert createdict(0,1) == 44
+    f = compile_function(createdict, [int, int])
+    assert f(0,1) == createdict(0,1)

Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py	Sat Jul 23 00:49:31 2005
@@ -8,25 +8,6 @@
 from pypy.translator.llvm2.genllvm import compile_function
 from pypy.translator.llvm2.test import llvmsnippet
 
-class TestLLVMRepr(object):
-    def DONTtest_simple1(self):
-        t = Translator(llvmsnippet.simple1)
-        a = t.annotate([])
-        gen = LLVMGenerator(t)
-        l_repr = gen.get_repr(t.getflowgraph().startblock.exits[0].args[0])
-        assert l_repr.llvmname() == "1"
-        assert l_repr.typed_name() == "int 1"
-
-    def DONTtest_simple2(self):
-        t = Translator(llvmsnippet.simple2)
-        a = t.annotate([])
-        gen = LLVMGenerator(t)
-        print gen
-        print t.getflowgraph().startblock.exits[0].args[0]
-        l_repr = gen.get_repr(t.getflowgraph().startblock.exits[0].args[0])
-        assert l_repr.llvmname() == "false"
-        assert l_repr.typed_name() == "bool false"
-
 class TestGenLLVM(object):
     def test_simple1(self):
         f = compile_function(llvmsnippet.simple1, [])
@@ -57,28 +38,31 @@
         f = compile_function(llvmsnippet.calling1, [int])
         assert f(10) == 1
 
-    def DONOTtest_call_default_arguments(self):
+    def test_call_default_arguments(self):
         f = compile_function(llvmsnippet.call_default_arguments, [int, int])
         for i in range(3):
             assert f(i + 3, i) == llvmsnippet.call_default_arguments(i + 3, i)
 
-    def DONOTtest_call_list_default_argument(self):
+    def test_call_list_default_argument(self):
         f = compile_function(llvmsnippet.call_list_default_argument, [int])
         for i in range(20):
             assert f(i) == llvmsnippet.call_list_default_argument(i)
 
-    def DONOTtest_return_none(self):
-        f = compile_function(llvmsnippet.return_none, [])
-        assert f() is None
-
     def test_shift(self):
         shl = compile_function(llvmsnippet.shiftleft, [int, int])
         shr = compile_function(llvmsnippet.shiftright, [int, int])
+        assert shl(42,2) == llvmsnippet.shiftleft(42, 2)
+        assert shr(42,2) == llvmsnippet.shiftright(42,2)
+
+    def test_shift_with_overflow(self):
+        shl = compile_function(llvmsnippet.shiftleft, [int, int])
+        shr = compile_function(llvmsnippet.shiftright, [int, int])
         for i in [1, 2, 3, 100000, 2000000, sys.maxint - 1]:
             for j in [1, 2, 3, 100000, 2000000, sys.maxint - 1]:
                 assert shl(i, j) == i << j
                 assert shr(i, j) == i >> j
 
+
 class TestFloat(object):
     def test_float_f1(self):
         f = compile_function(llvmsnippet.float_f1, [float])
@@ -95,38 +79,6 @@
         assert chr(f(1, 0)) == "a"
 
 
-class TestException(object):
-    def test_simple_exception(self):
-        f = compile_function(llvmsnippet.simple_exception, [int])
-        for i in range(10):
-            assert f(i) == 4
-        for i in range(10, 20):
-            assert f(i) == 2
-        
-    def test_two_exception(self):
-        f = compile_function(llvmsnippet.two_exceptions, [int])
-        for i in range(10):
-            assert f(i) == 4
-        for i in range(10, 20):
-            assert f(i) == 2
-
-    def test_catch_base_exception(self):
-        f = compile_function(llvmsnippet.catch_base_exception, [int])
-        for i in range(10):
-            assert f(i) == 4
-        for i in range(10, 20):
-            assert f(i) == 2
-
-    def DONOT_test_catch_instance(self):
-        f = compile_function(llvmsnippet.catches, [int])
-        assert f(1) == 1
-        assert f(2) == 1
-        assert f(3) == 12
-        py.test.raises(RuntimeError, "f(4)")
-        assert f(5) == 1
-        assert f(6) == 6
-        assert f(13) == 13
-        
 class TestPBC(object):
     def test_pbc_function1(self):
         f = compile_function(llvmsnippet.pbc_function1, [int])
@@ -135,7 +87,7 @@
         assert f(2) == 6
         assert f(3) == 8
 
-    def DONOTtest_pbc_function2(self):
+    def test_pbc_function2(self):
         f = compile_function(llvmsnippet.pbc_function2, [int])
         assert f(0) == 13
         assert f(1) == 15

Modified: pypy/dist/pypy/translator/llvm2/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_lltype.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_lltype.py	Sat Jul 23 00:49:31 2005
@@ -28,8 +28,8 @@
     def struct_constant():
         x1 = s.signed + s.unsigned
         return x1
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == 3
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_struct_constant2():
     S2 = lltype.GcStruct("struct2", ('a', lltype.Signed), ('s1', S), ('s2', S))
@@ -41,8 +41,8 @@
     s.s2.b = 3
     def struct_constant():
         return s.a + s.s2.b + s.s1.a + s.s1.b
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == 14
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_struct_constant3():
     structs = []
@@ -62,8 +62,8 @@
         return (top.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.a -
                 top.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.s.b)
     
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == 5
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_struct_constant4():
     SPTR = lltype.GcStruct('sptr', ('a', lltype.Signed))
@@ -73,8 +73,8 @@
     s.sptr.a = 21
     def struct_constant():
         return s.sptr.a * 2
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == 42
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_struct_constant5():
     SPTR = lltype.GcStruct('sptr', ('a', lltype.Signed), ('b', S))
@@ -86,8 +86,8 @@
     s.sptr.b.b = 10
     def struct_constant():
         return s.sptr.a + s.sptr.b.a + s.sptr.b.b
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == 42
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_struct_constant6():
     U = lltype.Struct('inlined', ('z', lltype.Signed))
@@ -101,8 +101,8 @@
     s.p = s.u
     def struct_constant():
         return s.x.y + s.p.z
-    fn = compile_function(struct_constant, [], embedexterns=False)
-    assert fn() == -58
+    f = compile_function(struct_constant, [], embedexterns=False)
+    assert f() == struct_constant()
 
 def test_array_constant():
     A = lltype.GcArray(lltype.Signed)
@@ -112,8 +112,8 @@
     a[2] = 102
     def array_constant():
         return a[0] + a[1] + a[2]    
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 303
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_array_constant2():
     A = lltype.GcArray(lltype.Signed)
@@ -124,8 +124,8 @@
     def array_constant():
         a[0] = 0
         return a[0] + a[1] + a[2]    
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 203
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_array_constant3():
     A = lltype.GcArray(('x', lltype.Signed))
@@ -135,8 +135,8 @@
     a[2].x = 102
     def array_constant():
         return a[0].x + a[1].x + a[2].x    
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 303
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_struct_array1():
     A = lltype.GcArray(lltype.Signed)
@@ -147,8 +147,8 @@
     a[1] = 101
     def array_constant():
         return s.aptr[1] - a[0]
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 1
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_struct_array2():
     A = lltype.Array(lltype.Signed)
@@ -159,8 +159,8 @@
     s.b[1] = 101
     def array_constant():
         return s.b[1] - s.b[0] + s.a
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 42
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_struct_array3():
     A = lltype.Array(lltype.Signed)
@@ -175,8 +175,8 @@
     def array_constant():
         s = b.p
         return s.b[1] - s.b[0] + s.a
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 42
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()
 
 def test_struct_opaque():
     PRTTI = lltype.Ptr(lltype.RuntimeTypeInfo)
@@ -185,6 +185,5 @@
     s.a = 42
     def array_constant():
         return s.a
-    fn = compile_function(array_constant, [], embedexterns=False)
-    assert fn() == 42
-    
+    f = compile_function(array_constant, [], embedexterns=False)
+    assert f() == array_constant()

Modified: pypy/dist/pypy/translator/llvm2/test/test_snippet.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_snippet.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_snippet.py	Sat Jul 23 00:49:31 2005
@@ -1,9 +1,7 @@
 from __future__ import division
-import py
 
-from pypy.translator.translator import Translator
+from pypy.translator.llvm2.genllvm import compile_function
 from pypy.translator.test import snippet as test
-from pypy.objspace.flow.model import Constant, Variable
 
 class TestSnippet(object):
     def test_if_then_else(self):
@@ -29,12 +27,10 @@
         assert f(0) == 0
 
     def test_two_plus_two(self):
-        py.test.skip("two_plus_two not working yet")
         f = compile_function(test.two_plus_two, [])
         assert f() == 4
 
     def test_sieve_of_eratosthenes(self):
-        py.test.skip("sieve_of_eratosthenes not working yet")
         f = compile_function(test.sieve_of_eratosthenes, [])
         assert f() == 1028
 
@@ -66,31 +62,22 @@
         assert factorial(5) == 120
 
     def test_set_attr(self):
-        py.test.skip("set_attr not working yet")
         set_attr = compile_function(test.set_attr, [])
         assert set_attr() == 2
 
-    def DONOT_test_try_raise_choose(self):
-        try_raise_choose = compile_function(test.try_raise_choose, [int])
-        for i in [-1, 0, 1, 2]:
-            assert try_raise_choose(i) == i
-
     def test_merge_setattr(self):
-        py.test.skip("merge_setattr not working yet")
         merge_setattr = compile_function(test.merge_setattr, [bool])
         assert merge_setattr(1) == 1
 
     def test_simple_method(self):
-        py.test.skip("simple_method not working yet")
         simple_method = compile_function(test.simple_method, [int])
         assert simple_method(65) == 65
 
     def test_with_init(self):
-        py.test.skip("with_init not working yet")
         with_init = compile_function(test.with_init, [int])
         assert with_init(42) == 42
 
-    def DONOT_test_with_more_init(self):
+    def test_with_more_init(self):
         with_more_init = compile_function(test.with_more_init, [int, bool])
         assert with_more_init(42, True) == 42
         assert with_more_init(42, False) == -42



More information about the Pypy-commit mailing list