[pypy-svn] r64756 - in pypy/branch/pyjitpl5/pypy/jit/backend: minimal/test test x86/test

antocuni at codespeak.net antocuni at codespeak.net
Tue Apr 28 11:16:00 CEST 2009


Author: antocuni
Date: Tue Apr 28 11:16:00 2009
New Revision: 64756

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
Log:
start writing the ootype version of runner tests


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/minimal/test/test_runner.py	Tue Apr 28 11:16:00 2009
@@ -1,13 +1,13 @@
 import py
 from pypy.jit.backend.minimal.test.test_basic import LLJitMixin, OOJitMixin
-from pypy.jit.backend.test.runner import BaseBackendTest
+from pypy.jit.backend.test.runner import LLtypeBackendTest, OOtypeBackendTest
 
 class FakeStats(object):
     pass
 
 # ____________________________________________________________
 
-class MinimalTest(BaseBackendTest):
+class MinimalTestMixin(object):
 
     # for the individual tests see
     # ====> ../../test/runner.py
@@ -22,9 +22,14 @@
     test_failing_guards = _skip      # GUARD_CLASS
 
 
-## class TestOOtype(OOJitMixin, MinimalTest):
-##     pass
+class TestOOtype(OOJitMixin, MinimalTestMixin, OOtypeBackendTest):
+    def skip(self):
+        py.test.skip('in-progress')
 
-class TestLLtype(LLJitMixin, MinimalTest):
+    test_executor = skip
+    test_ooops_non_gc = skip
+
+
+class TestLLtype(LLJitMixin, MinimalTestMixin, LLtypeBackendTest):
     pass
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py	Tue Apr 28 11:16:00 2009
@@ -3,23 +3,14 @@
 from pypy.jit.metainterp.history import (BoxInt, Box, BoxPtr, TreeLoop,
                                          ConstInt, ConstPtr, BoxObj)
 from pypy.jit.metainterp.resoperation import ResOperation, rop
+from pypy.jit.metainterp.typesystem import deref
 from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi, rclass
+from pypy.rpython.ootypesystem import ootype
 from pypy.jit.metainterp.executor import execute
 from pypy.rlib.rarithmetic import r_uint, intmask
 
-MY_VTABLE = rclass.OBJECT_VTABLE    # for tests only
-
-S = lltype.GcForwardReference()
-S.become(lltype.GcStruct('S', ('parent', rclass.OBJECT),
-                              ('value', lltype.Signed),
-                              ('next', lltype.Ptr(S))))
-T = lltype.GcStruct('T', ('parent', S),
-                         ('next', lltype.Ptr(S)))
-U = lltype.GcStruct('U', ('parent', T),
-                         ('next', lltype.Ptr(S)))
-
 class Runner(object):
-        
+
     def execute_operation(self, opname, valueboxes, result_type, descr=None):
         loop = self.get_compiled_single_operation(opname, result_type,
                                                   valueboxes, descr)
@@ -43,6 +34,8 @@
             return BoxInt(self.cpu.get_latest_value_int(0))
         elif result_type == 'ptr':
             return BoxPtr(self.cpu.get_latest_value_ptr(0))
+        else:
+            assert False
 
     def get_compiled_single_operation(self, opnum, result_type, valueboxes,
                                       descr):
@@ -70,6 +63,7 @@
         self.cpu.compile_operations(loop)
         return loop
 
+
 class BaseBackendTest(Runner):
     
     def test_do_call(self):
@@ -78,11 +72,11 @@
         #
         def func(c):
             return chr(ord(c) + 1)
-        FPTR = lltype.Ptr(lltype.FuncType([lltype.Char], lltype.Char))
+        FPTR = self.Ptr(self.FuncType([lltype.Char], lltype.Char))
         func_ptr = llhelper(FPTR, func)
-        calldescr = cpu.calldescrof(FPTR.TO, (lltype.Char,), lltype.Char)
+        calldescr = cpu.calldescrof(deref(FPTR), (lltype.Char,), lltype.Char)
         x = cpu.do_call(
-            [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(func_ptr))),
+            [self.get_funcbox(cpu, func_ptr),
              BoxInt(ord('A'))],
             calldescr)
         assert x.value == ord('B')
@@ -94,17 +88,6 @@
         s = execute(cpu, rop.NEWSTR, [BoxInt(8)])
         assert len(s.getptr(lltype.Ptr(rstr.STR)).chars) == 8
 
-    def test_casts(self):
-        from pypy.rpython.lltypesystem import lltype, llmemory
-        TP = lltype.GcStruct('x')
-        x = lltype.malloc(TP)        
-        x = lltype.cast_opaque_ptr(llmemory.GCREF, x)
-        res = self.execute_operation(rop.CAST_PTR_TO_INT,
-                                     [BoxPtr(x)],  'int').value
-        res2 = self.execute_operation(rop.CAST_INT_TO_PTR,
-                                      [BoxInt(res)], 'ptr').value
-        assert res2 == x
-
     def test_lshift(self):
         res = execute(self.cpu, rop.INT_LSHIFT, [BoxInt(10), ConstInt(4)])
         assert res.value == 10 << 4
@@ -268,7 +251,8 @@
 
 
     def test_passing_guards(self):
-        vtable_for_T = lltype.malloc(MY_VTABLE, immortal=True)
+        T = self.T
+        vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
         vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
         cpu = self.cpu
         cpu._cache_gcstruct2vtable = {T: vtable_for_T}
@@ -291,9 +275,11 @@
         #                       'void')
 
     def test_failing_guards(self):
-        vtable_for_T = lltype.malloc(MY_VTABLE, immortal=True)
+        T = self.T
+        U = self.U
+        vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
         vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
-        vtable_for_U = lltype.malloc(MY_VTABLE, immortal=True)
+        vtable_for_U = lltype.malloc(self.MY_VTABLE, immortal=True)
         vtable_for_U_addr = llmemory.cast_ptr_to_adr(vtable_for_U)
         cpu = self.cpu
         cpu._cache_gcstruct2vtable = {T: vtable_for_T, U: vtable_for_U}
@@ -317,3 +303,49 @@
             assert self.guard_failed
 
             
+class LLtypeBackendTest(BaseBackendTest):
+
+    Ptr = lltype.Ptr
+    FuncType = lltype.FuncType
+    malloc = staticmethod(lltype.malloc)
+    nullptr = staticmethod(lltype.nullptr)
+
+    @classmethod
+    def get_funcbox(cls, cpu, func_ptr):
+        addr = llmemory.cast_ptr_to_adr(func_ptr)
+        return BoxInt(cpu.cast_adr_to_int(addr))
+
+    
+    MY_VTABLE = rclass.OBJECT_VTABLE    # for tests only
+
+    S = lltype.GcForwardReference()
+    S.become(lltype.GcStruct('S', ('parent', rclass.OBJECT),
+                                  ('value', lltype.Signed),
+                                  ('next', lltype.Ptr(S))))
+    T = lltype.GcStruct('T', ('parent', S),
+                             ('next', lltype.Ptr(S)))
+    U = lltype.GcStruct('U', ('parent', T),
+                             ('next', lltype.Ptr(S)))
+
+    def test_casts(self):
+        from pypy.rpython.lltypesystem import lltype, llmemory
+        TP = lltype.GcStruct('x')
+        x = lltype.malloc(TP)        
+        x = lltype.cast_opaque_ptr(llmemory.GCREF, x)
+        res = self.execute_operation(rop.CAST_PTR_TO_INT,
+                                     [BoxPtr(x)],  'int').value
+        res2 = self.execute_operation(rop.CAST_INT_TO_PTR,
+                                      [BoxInt(res)], 'ptr').value
+        assert res2 == x
+
+
+class OOtypeBackendTest(BaseBackendTest):
+
+    Ptr = lambda x: x
+    FuncType = ootype.StaticMethod
+    malloc = staticmethod(ootype.new)
+    nullptr = staticmethod(ootype.null)
+
+    @classmethod
+    def get_funcbox(cls, cpu, func_ptr):
+        return ootype.cast_to_object(func_ptr)

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	Tue Apr 28 11:16:00 2009
@@ -8,16 +8,19 @@
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.executor import execute
-from pypy.jit.backend.test.runner import BaseBackendTest, U, S
+from pypy.jit.backend.test.runner import LLtypeBaseBackendTest
 import ctypes
 import sys
 
 class FakeStats(object):
     pass
 
+U = LLtypeBaseBackendTest.U
+S = LLtypeBaseBackendTest.S
+
 # ____________________________________________________________
 
-class TestX86(BaseBackendTest):
+class TestX86(LLtypeBaseBackendTest):
 
     # for the individual tests see
     # ====> ../../test/runner.py



More information about the Pypy-commit mailing list