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

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Jul 21 15:29:32 CEST 2005


Author: ericvrp
Date: Thu Jul 21 15:29:30 2005
New Revision: 14861

Added:
   pypy/dist/pypy/translator/llvm2/test/test_class.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py
   pypy/dist/pypy/translator/llvm2/test/test_seq.py
   pypy/dist/pypy/translator/llvm2/test/test_snippet.py
Modified:
   pypy/dist/pypy/translator/llvm2/build_llvm_module.py
   pypy/dist/pypy/translator/llvm2/test/llvmsnippet.py
Log:
Added llvm(1) tests to see how much functionality llvm2 is still missing.


Modified: pypy/dist/pypy/translator/llvm2/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/build_llvm_module.py	(original)
+++ pypy/dist/pypy/translator/llvm2/build_llvm_module.py	Thu Jul 21 15:29:30 2005
@@ -8,8 +8,6 @@
 from py import path 
 import py
 
-from pypy.tool.udir import udir
-from pypy.translator.pyrex.genpyrex import GenPyrex
 from pypy.translator.tool.buildpyxmodule import make_c_from_pyxfile
 from pypy.translator.tool import stdoutcapture
 from pypy.translator.llvm2.genllvm import use_boehm_gc

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	Thu Jul 21 15:29:30 2005
@@ -1,7 +1,34 @@
-
 #function snippets
+def simple1():
+    return 1
+
+def simple2():
+    return False
 
+def simple3(i):
+    c = "Hello, Stars!"
+    return c[i]
+
+def simple4():
+    return 3 + simple1()
+
+def simple5(b):
+    if b:
+        x = 12
+    else:
+        x = 13
+    return x
+
+def simple6():
+    simple4()
+    return 1
 
+def ackermann(n, m):
+    if n == 0:
+        return m + 1
+    if m == 0:
+        return ackermann(n - 1, 1)
+    return ackermann(n - 1, ackermann(n, m - 1))
 
 def calling1(m):
     if m > 1:

Added: pypy/dist/pypy/translator/llvm2/test/test_class.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/test/test_class.py	Thu Jul 21 15:29:30 2005
@@ -0,0 +1,66 @@
+from __future__ import division
+import py
+
+from pypy.translator.translator import Translator
+from pypy.objspace.flow.model import Constant, Variable
+from pypy.translator.llvm2.genllvm import compile_function
+from pypy.translator.llvm2.test import llvmsnippet
+
+class TestClass(object):
+    def test_classsimple(self):
+        f = compile_function(llvmsnippet.class_simple, [])
+        assert f() == 14
+
+    def test_classsimple1(self):
+        f = compile_function(llvmsnippet.class_simple1, [int])
+        assert f(2) == 10
+
+    def test_id_int(self):
+        f = compile_function(llvmsnippet.id_int, [int])
+        for i in range(1, 20):
+            assert f(i) == i
+
+    def test_classsimple2(self):
+        f = compile_function(llvmsnippet.class_simple2, [int])
+        assert f(2) == 10
+
+    def test_method_of_base_class(self):
+        f = compile_function(llvmsnippet.method_of_base_class, [])
+        assert f() == 14
+
+    def test_attribute_from_base_class(self):
+        f = compile_function(llvmsnippet.attribute_from_base_class, [])
+        assert f() == 4
+
+    def test_direct_call_of_virtual_method(self):
+        f = compile_function(llvmsnippet.direct_call_of_virtual_method, [])
+        assert f() == 14
+
+    def test_flow_type(self):
+        f = compile_function(llvmsnippet.flow_type, [])
+        assert f() == 16
+
+    def test_merge_class(self):
+        f = compile_function(llvmsnippet.merge_classes, [bool])
+        assert f(True) == 1
+        assert f(False) == 2
+
+    def test_attribute_instance(self):
+        f = compile_function(llvmsnippet.attribute_instance, [bool])
+        assert f(True) == 1
+        assert f(False) == 2
+
+    def test_global_instance(self):
+        f = compile_function(llvmsnippet.global_instance, [int])
+        assert f(-1) == 41
+        for i in range(20):
+            assert f(i) == 2 * i
+
+    def test_call_degrading_func(self):
+        f = compile_function(llvmsnippet.call_degrading_func, [bool])
+        assert f(True) == -36
+        assert f(False) == 14
+    
+    def DONOTtest_circular_classdef(self):
+        f = compile_function(llvmsnippet.circular_classdef, [])
+        assert f() == 10

Added: pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm1.py	Thu Jul 21 15:29:30 2005
@@ -0,0 +1,144 @@
+from __future__ import division
+import sys
+
+import py
+
+from pypy.translator.translator import Translator
+from pypy.objspace.flow.model import Constant, Variable
+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, [])
+        assert f() == 1
+
+    def test_simple2(self):
+        f = compile_function(llvmsnippet.simple2, [])
+        assert f() == 0
+
+    def test_simple4(self):
+        f = compile_function(llvmsnippet.simple4, [])
+        assert f() == 4
+
+    def test_simple5(self):
+        f = compile_function(llvmsnippet.simple5, [int])
+        assert f(1) == 12
+        assert f(0) == 13
+
+    def test_ackermann(self):
+        f = compile_function(llvmsnippet.ackermann, [int, int])
+        for i in range(10):
+            assert f(0, i) == i + 1
+            assert f(1, i) == i + 2
+            assert f(2, i) == 2 * i + 3
+            assert f(3, i) == 2 ** (i + 3) - 3
+
+    def test_calling(self):
+        f = compile_function(llvmsnippet.calling1, [int])
+        assert f(10) == 1
+
+    def DONOTtest_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):
+        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])
+        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])
+        assert f(1.0) == 2.2
+
+    def test_float_int_bool(self):
+        f = compile_function(llvmsnippet.float_int_bool, [float])
+        assert f(3.0) == 9.0
+
+
+class TestString(object):
+    def test_f2(self):
+        f = compile_function(llvmsnippet.string_f2, [int, int])
+        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])
+        assert f(0) == 2
+        assert f(1) == 4
+        assert f(2) == 6
+        assert f(3) == 8
+
+    def DONOTtest_pbc_function2(self):
+        f = compile_function(llvmsnippet.pbc_function2, [int])
+        assert f(0) == 13
+        assert f(1) == 15
+        assert f(2) == 17
+        assert f(3) == 19
+

Added: pypy/dist/pypy/translator/llvm2/test/test_seq.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/test/test_seq.py	Thu Jul 21 15:29:30 2005
@@ -0,0 +1,112 @@
+from __future__ import division
+import py
+
+from pypy.translator.translator import Translator
+from pypy.objspace.flow.model import Constant, Variable
+from pypy.translator.llvm2.genllvm import compile_function
+from pypy.translator.llvm2.test import llvmsnippet
+
+class TestLLVMArray(object):
+    def test_array(self):
+        f = compile_function(llvmsnippet.array_simple, [])
+        assert f() == 42
+
+    def test_array1(self):
+        f = compile_function(llvmsnippet.array_simple1, [int])
+        assert f(1) == 10
+        assert f(-42) == -420
+
+    def test_array_setitem(self):
+        f = compile_function(llvmsnippet.array_setitem, [int])
+        print f(1), f(2), f(3)
+        assert f(1) == 12
+        assert f(2) == 13
+        assert f(3) == 3
+
+    def test_array_add(self):
+        f = compile_function(llvmsnippet.array_add, [int, int, int, int, int])
+        assert f(1,2,3,4,0) == 1
+        assert f(1,2,3,4,1) == 2
+        assert f(1,2,3,4,2) == 3
+        assert f(1,2,5,6,3) == 6
+
+    def test_array_double(self):
+        f = compile_function(llvmsnippet.double_array, [])
+        assert f() == 15
+
+    def test_bool_array(self):
+        f = compile_function(llvmsnippet.bool_array, [])
+        assert f() == 1
+
+    def test_array_arg(self):
+        f = compile_function(llvmsnippet.array_arg, [int])
+        assert f(5) == 0
+
+    def test_array_len(self):
+        f = compile_function(llvmsnippet.array_len, [])
+        assert f() == 10
+
+    def test_array_append(self):
+        f = compile_function(llvmsnippet.array_append, [int])
+        for i in range(3):
+            assert f(i) == 0
+        assert f(3) == 10
+
+    def test_array_reverse(self):
+        f = compile_function(llvmsnippet.array_reverse, [int])
+        assert f(0) == 1
+        assert f(1) == 0
+
+    def test_range(self):
+        f = compile_function(llvmsnippet.rangetest, [int])
+        for i in range(10):
+            assert f(i) == i
+
+    def test_array_pop(self):
+        f = compile_function(llvmsnippet.array_pop, [int])
+        assert f(0) == 6
+        assert f(1) == 7
+        assert f(2) == 8
+
+    def test_newlist_zero_arg(self):
+        f = compile_function(llvmsnippet.newlist_zero_arg, [int])
+        assert f(10) == 11
+        assert f(-41) == -40
+
+    def test_big_array(self):
+        f = compile_function(llvmsnippet.big_array, [int])
+        for i in range(18):
+            assert f(i) == i
+
+    def test_access_global_array(self):
+        f = compile_function(llvmsnippet.access_global_array, [int, int, int])
+        for i in range(5):
+            for j in range(5):
+                assert f(i, j, i + j) == i
+        for i in range(5):
+            for j in range(5):
+                assert f(i, j, 0) == i + j
+
+    def test_circular_list(self):
+        f = compile_function(llvmsnippet.circular_list, [int])
+        assert f(0) == 0
+        assert f(1) == 1
+        assert f(10) == 1
+
+
+class TestTuple(object):
+    def test_f1(self):
+        f = compile_function(llvmsnippet.tuple_f1, [int])
+        assert f(10) == 10
+        assert f(15) == 15
+
+    def test_f3(self):
+        f = compile_function(llvmsnippet.tuple_f3, [int])
+        assert f(10) == 10
+        assert f(15) == 15
+        assert f(30) == 30
+
+    def test_constant_tuple(self):
+        f = compile_function(llvmsnippet.constant_tuple, [int])
+        for i in range(3, 7):
+            assert f(i) == i + 3

Added: pypy/dist/pypy/translator/llvm2/test/test_snippet.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm2/test/test_snippet.py	Thu Jul 21 15:29:30 2005
@@ -0,0 +1,96 @@
+from __future__ import division
+import py
+
+from pypy.translator.translator import Translator
+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):
+        f = compile_function(test.if_then_else, [int, int, int])
+        assert f(0, 12, 13) == 13
+        assert f(13, 12, 13) == 12
+        
+    def test_my_gcd(self):
+        f = compile_function(test.my_gcd, [int, int])
+        assert f(15, 5) == 5
+        assert f(18, 42) == 6
+
+    def test_is_perfect_number(self):
+        f = compile_function(test.is_perfect_number, [int])
+        assert f(28) == 1
+        assert f(123) == 0
+        assert f(496) == 1
+
+    def test_my_bool(self):
+        f = compile_function(test.my_bool, [int])
+        assert f(10) == 1
+        assert f(1) == 1
+        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
+
+    def test_simple_func(self):
+        f = compile_function(test.simple_func, [int])
+        assert f(1027) == 1028
+        
+    def test_while_func(self):
+        while_func = compile_function(test.while_func, [int])
+        assert while_func(10) == 55
+
+    def test_time_waster(self):
+        f = compile_function(test.time_waster, [int])
+        assert f(1) == 1
+        assert f(2) == 2
+        assert f(3) == 6
+        assert f(4) == 12
+
+    def test_int_id(self):
+        f = compile_function(test.int_id, [int])
+        assert f(1027) == 1027
+
+    def test_factorial2(self):
+        factorial2 = compile_function(test.factorial2, [int])
+        assert factorial2(5) == 120
+
+    def test_factorial(self):
+        factorial = compile_function(test.factorial, [int])
+        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):
+        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