[pypy-svn] r52088 - in pypy/branch/jit-refactoring/pypy/jit: codegen/i386/test rainbow/test

arigo at codespeak.net arigo at codespeak.net
Mon Mar 3 14:10:06 CET 2008


Author: arigo
Date: Mon Mar  3 14:10:00 2008
New Revision: 52088

Modified:
   pypy/branch/jit-refactoring/pypy/jit/codegen/i386/test/test_genc_portal.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_portal.py
Log:
Adapt the portal test for the i386 backend.  Most or all tests pass.


Modified: pypy/branch/jit-refactoring/pypy/jit/codegen/i386/test/test_genc_portal.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/codegen/i386/test/test_genc_portal.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/codegen/i386/test/test_genc_portal.py	Mon Mar  3 14:10:00 2008
@@ -1,33 +1,63 @@
-import py, os
+import py, os, sys
 from pypy.annotation import model as annmodel
-from pypy.annotation.listdef import s_list_of_strings
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.translator.c.genc import CStandaloneBuilder
-from pypy.jit.timeshifter.test import test_portal
+from pypy.jit.rainbow.test import test_portal
 from pypy.jit.codegen.i386.rgenop import RI386GenOp
 from pypy.rpython.annlowlevel import PseudoHighLevelCallable
 
 class I386PortalTestMixin(object):
     RGenOp = RI386GenOp
+    translate_support_code = True
 
-    def postprocess_timeshifting(self):
-        annhelper = self.hrtyper.annhelper
-        convert_result = getattr(self.main, 'convert_result', str)
-        annotator = self.rtyper.annotator
-        args_s = [annmodel.lltype_to_annotation(v.concretetype)
-                  for v in self.maingraph.getargs()]
-        retvar = self.maingraph.getreturnvar()
-        s_result = annmodel.lltype_to_annotation(retvar.concretetype)
-        main_fnptr = self.rtyper.type_system.getcallable(self.maingraph)
-        main = PseudoHighLevelCallable(main_fnptr, args_s, s_result)
-        
-        if hasattr(self.main, 'convert_arguments'):
-            decoders = self.main.convert_arguments
-            assert len(decoders) == len(args_s)
+    def timeshift_from_portal(self, main, portal, main_args,
+                              inline=None, policy=None,
+                              backendoptimize=False):
+        self.testname = sys._getframe(1).f_code.co_name
+
+        # ---------- translate main() and the support code ----------
+        self._timeshift_from_portal(main, portal=portal, main_args=main_args,
+                                    inline=inline, policy=policy,
+                                    backendoptimize=backendoptimize)
+
+        # ---------- run the stand-alone executable ----------
+        cmdargs = ' '.join([str(arg) for arg in main_args])
+        output = self.cbuilder.cmdexec(cmdargs)
+        lines = output.split()
+        lastline = lines[-1]
+        assert not lastline.startswith('EXCEPTION:')
+        if hasattr(main, 'convert_result'):
+            return lastline
+        else:
+            return int(lastline)    # assume an int
+
+
+    # The following function is called by _timeshift_from_portal() unless
+    # its results are already in the cache from a previous call
+    def _serialize(self, main, main_args, portal,
+                   policy=None, inline=None,
+                   backendoptimize=False):
+
+        # ---------- prepare a stand-alone main() function ----------
+        convert_result = getattr(main, 'convert_result', str)
+        if hasattr(main, 'convert_arguments'):
+            decoders = main.convert_arguments
+            assert len(decoders) == len(main_args)
         else:
-            decoders = [int] * len(args_s)
+            decoders = [int] * len(main_args)
         decoders = unrolling_iterable(decoders)
+        numargs = len(main_args)
+        USAGE = '%s: %d arguments expected\n' % (self.testname, numargs)
+
+        def usage():
+            os.write(2, USAGE)
+            return 2
+
         def ll_main(argv):
+            if len(argv) != 1 + numargs:
+                return usage()
+            if len(argv) > 1 and argv[1] == '--help':
+                return usage()
             args = ()
             i = 1
             for decoder in decoders:
@@ -41,38 +71,30 @@
             os.write(1, convert_result(res) + '\n')
             return 0
 
-        annhelper.getgraph(ll_main, [s_list_of_strings],
-                           annmodel.SomeInteger())
-        annhelper.finish()
+        # ---------- rewire portal and translate everything ----------
+        super(I386PortalTestMixin, self)._serialize(
+            ll_main, None, portal=portal,
+            inline=inline, policy=policy,
+            backendoptimize=backendoptimize)
+
+        # ---------- generate a stand-alone executable ----------
         t = self.rtyper.annotator.translator
         t.config.translation.gc = 'boehm'
         self.cbuilder = CStandaloneBuilder(t, ll_main, config=t.config)
         self.cbuilder.generate_source()
-        self.cbuilder.compile()
-        
-    def timeshift_from_portal(self, main, portal, main_args,
-                              inline=None, policy=None,
-                              backendoptimize=False):
-        self.main = main
-        self._timeshift_from_portal(main, portal, main_args,
-                                    inline=inline, policy=policy,
-                                    backendoptimize=backendoptimize)
-        cmdargs = ' '.join([str(arg) for arg in main_args])
-        output = self.cbuilder.cmdexec(cmdargs)
-        lines = output.split()
-        lastline = lines[-1]
-        assert not lastline.startswith('EXCEPTION:')
-        if hasattr(main, 'convert_result'):
-            return lastline
-        else:
-            return int(lastline)    # assume an int
-        
+        exename = self.cbuilder.compile()
+        print '-'*60
+        print 'Generated executable for %s: %s', (self.testname, exename)
+        print '-'*60
+
+
     def check_insns(self, expected=None, **counts):
         "Cannot check instructions in the generated assembler."
-    
+
+
 class TestPortal(I386PortalTestMixin,
                  test_portal.TestPortal):
 
     # for the individual tests see
-    # ====> ../../../timeshifter/test/test_portal.py
+    # ====> ../../../rainbow/test/test_portal.py
     pass

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	Mon Mar  3 14:10:00 2008
@@ -29,6 +29,9 @@
                                           entrypoint_returns_red=False)
 
 def getargtypes(annotator, values):
+    if values is None:    # for backend tests producing stand-alone exe's
+        from pypy.annotation.listdef import s_list_of_strings
+        return [s_list_of_strings]
     return [annotation(annotator, x) for x in values]
 
 def annotation(a, x):

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_portal.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_portal.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_portal.py	Mon Mar  3 14:10:00 2008
@@ -2,9 +2,9 @@
 
 from pypy import conftest
 from pypy.translator.translator import graphof
-from pypy.jit.timeshifter.test.test_timeshift import TestLLType as TSTestLLType, getargtypes
 from pypy.jit.rainbow.test.test_interpreter import P_NOVIRTUAL, StopAtXPolicy
 from pypy.jit.rainbow.test.test_interpreter import hannotate, InterpretationTest
+from pypy.jit.rainbow.test.test_interpreter import getargtypes
 from pypy.jit.rainbow.test.test_vlist import P_OOPSPEC
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.lltypesystem import lltype


More information about the pypy-svn mailing list