[pypy-svn] r33408 - in pypy/dist/pypy/jit/codegen: ppc/test test

mwh at codespeak.net mwh at codespeak.net
Wed Oct 18 16:16:08 CEST 2006


Author: mwh
Date: Wed Oct 18 16:16:06 2006
New Revision: 33408

Added:
   pypy/dist/pypy/jit/codegen/test/
   pypy/dist/pypy/jit/codegen/test/__init__.py   (contents, props changed)
   pypy/dist/pypy/jit/codegen/test/rgenop_tests.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/codegen/ppc/test/test_rppcgenop.py
Log:
start refactoring the backend specific rgenop tests.


Modified: pypy/dist/pypy/jit/codegen/ppc/test/test_rppcgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/test/test_rppcgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/test/test_rppcgenop.py	Wed Oct 18 16:16:06 2006
@@ -1,90 +1,5 @@
 from pypy.jit.codegen.ppc.rppcgenop import RPPCGenOp
-from ctypes import c_void_p, cast, CFUNCTYPE, c_int
-from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.objectmodel import keepalive_until_here
-from pypy.rpython.annlowlevel import MixLevelAnnotatorPolicy
-import py
+from pypy.jit.codegen.test.rgenop_tests import AbstractRGenOpTests
 
-# XXX clean up
-class PseudoAnnhelper(object):
-    rtyper = None
-GENOP_POLICY = MixLevelAnnotatorPolicy(PseudoAnnhelper())
-
-FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
-
-def compile(func, inputtypes):
-    from pypy.translator.c.test.test_genc import compile
-    return compile(func, inputtypes,
-                   annotatorpolicy=GENOP_POLICY,
-                   gcpolicy='boehm')
-
-def make_adder(rgenop, n):
-    # 'return x+n'
-    sigtoken = rgenop.sigToken(FUNC)
-    builder, entrypoint, [gv_x] = rgenop.newgraph(sigtoken)
-    gv_result = builder.genop2("int_add", gv_x, rgenop.genconst(n))
-    builder.finish_and_return(sigtoken, gv_result)
-    gv_add_one = rgenop.gencallableconst(sigtoken, "adder", entrypoint)
-    return gv_add_one
-
-def test_adder_direct():
-    rgenop = RPPCGenOp()
-    gv_add_5 = make_adder(rgenop, 5)
-    print gv_add_5.value
-    fnptr = cast(c_void_p(gv_add_5.value), CFUNCTYPE(c_int, c_int))
-    res = fnptr(37)
-    assert res == 42
-
-def runner(x, y):
-    rgenop = RPPCGenOp()
-    gv_add_x = make_adder(rgenop, x)
-    add_x = gv_add_x.revealconst(lltype.Ptr(FUNC))
-    res = add_x(y)
-    keepalive_until_here(rgenop)    # to keep the code blocks alive
-    return res
-
-def test_adder_compile():
-    fn = compile(runner, [int, int])
-    res = fn(9080983, -9080941)
-    assert res == 42
-
-FUNC2 = lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed)
-
-def make_dummy(rgenop):
-    # 'return x - (y - (x-1))'
-    signed_kind = rgenop.kindToken(lltype.Signed)
-    sigtoken = rgenop.sigToken(FUNC2)
-    builder, entrypoint, [gv_x, gv_y] = rgenop.newgraph(sigtoken)
-    gv_z = builder.genop2("int_sub", gv_x, rgenop.genconst(1))
-
-    args_gv = [gv_y, gv_z, gv_x]
-    builder.enter_next_block([signed_kind, signed_kind, signed_kind], args_gv)
-    [gv_y2, gv_z2, gv_x2] = args_gv
-
-    gv_s2 = builder.genop2("int_sub", gv_y2, gv_z2)
-    gv_t2 = builder.genop2("int_sub", gv_x2, gv_s2)
-    builder.finish_and_return(sigtoken, gv_t2)
-
-    gv_dummyfn = rgenop.gencallableconst(sigtoken, "dummy", entrypoint)
-    return gv_dummyfn
-
-def dummy_runner(x, y):
-    rgenop = RPPCGenOp()
-    gv_dummyfn = make_dummy(rgenop)
-    dummyfn = gv_dummyfn.revealconst(lltype.Ptr(FUNC2))
-    res = dummyfn(x, y)
-    keepalive_until_here(rgenop)    # to keep the code blocks alive
-    return res
-
-def test_dummy_direct():
-    rgenop = RPPCGenOp()
-    gv_dummyfn = make_dummy(rgenop)
-    print gv_dummyfn.value
-    fnptr = cast(c_void_p(gv_dummyfn.value), CFUNCTYPE(c_int, c_int, c_int))
-    res = fnptr(30, 17)    # <== the segfault is here
-    assert res == 42
-
-def test_dummy_compile():
-    fn = compile(dummy_runner, [int, int])
-    res = fn(40, 37)
-    assert res == 42
+class TestRPPCGenop(AbstractRGenOpTests):
+    RGenOp = RPPCGenOp

Added: pypy/dist/pypy/jit/codegen/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/test/__init__.py	Wed Oct 18 16:16:06 2006
@@ -0,0 +1 @@
+#

Added: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	Wed Oct 18 16:16:06 2006
@@ -0,0 +1,50 @@
+from pypy.rpython.annlowlevel import MixLevelAnnotatorPolicy
+from pypy.rpython.objectmodel import keepalive_until_here
+from pypy.rpython.lltypesystem import lltype
+from pypy.translator.c.test import test_boehm
+from ctypes import c_void_p, cast, CFUNCTYPE, c_int
+
+class PseudoAnnhelper(object):
+    rtyper = None
+GENOP_POLICY = MixLevelAnnotatorPolicy(PseudoAnnhelper())
+
+FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
+
+def make_adder(rgenop, n):
+    # 'return x+n'
+    sigtoken = rgenop.sigToken(FUNC)
+    builder, entrypoint, [gv_x] = rgenop.newgraph(sigtoken)
+    gv_result = builder.genop2("int_add", gv_x, rgenop.genconst(n))
+    builder.finish_and_return(sigtoken, gv_result)
+    gv_add_one = rgenop.gencallableconst(sigtoken, "adder", entrypoint)
+    return gv_add_one
+
+def get_adder_runner(RGenOp):
+    def runner(x, y):
+        rgenop = RGenOp()
+        gv_add_x = make_adder(rgenop, x)
+        add_x = gv_add_x.revealconst(lltype.Ptr(FUNC))
+        res = add_x(y)
+        keepalive_until_here(rgenop)    # to keep the code blocks alive
+        return res
+    return runner
+
+class AbstractRGenOpTests(test_boehm.AbstractGCTestClass):
+    RGenOp = None
+
+    def compile(self, runner, argtypes):
+        return self.getcompiled(runner, argtypes,
+                                annotatorpolicy = GENOP_POLICY)
+
+    def test_adder_direct(self):
+        rgenop = self.RGenOp()
+        gv_add_5 = make_adder(rgenop, 5)
+        fnptr = cast(c_void_p(gv_add_5.value), CFUNCTYPE(c_int, c_int))
+        res = fnptr(37)
+        assert res == 42
+
+    def test_adder_compile(self):
+        fn = self.compile(get_adder_runner(self.RGenOp), [int, int])
+        res = fn(9080983, -9080941)
+        assert res == 42
+



More information about the Pypy-commit mailing list