[pypy-svn] r68660 - in pypy/trunk/pypy/translator/c: gcc/test test

pedronis at codespeak.net pedronis at codespeak.net
Tue Oct 20 14:58:13 CEST 2009


Author: pedronis
Date: Tue Oct 20 14:58:12 2009
New Revision: 68660

Modified:
   pypy/trunk/pypy/translator/c/gcc/test/test_asmgcroot.py
   pypy/trunk/pypy/translator/c/test/test_newgc.py
Log:
make test_newgc compile standalone, also the executable takes the (test) name string not a number anymore as first argument.

adjust test_asmgcroot, there is some more duplication between the two tests setup code, too bad for now



Modified: pypy/trunk/pypy/translator/c/gcc/test/test_asmgcroot.py
==============================================================================
--- pypy/trunk/pypy/translator/c/gcc/test/test_asmgcroot.py	(original)
+++ pypy/trunk/pypy/translator/c/gcc/test/test_asmgcroot.py	Tue Oct 20 14:58:12 2009
@@ -18,19 +18,16 @@
     should_be_moving = False
 
     @classmethod
-    def _makefunc2(cls, func):
+    def _makefunc_str_int(cls, func):
         def main(argv):
-            arg0 = int(argv[1])
+            arg0 = argv[1]
             arg1 = int(argv[2])
             try:
                 res = func(arg0, arg1)
             except MemoryError:
                 print 'Result: MemoryError'
             else:
-                if isinstance(res, int):
-                    print 'Result:', res
-                else:
-                    print 'Result: "%s"' % (res,)
+                print 'Result: "%s"' % (res,)
             return 0
         from pypy.config.pypyoption import get_pypy_config
         config = get_pypy_config(translating=True)
@@ -59,7 +56,7 @@
                 redirect = ' 2> NUL'
             else:
                 redirect = ''
-            g = os.popen('"%s" %d %d%s' % (exe_name, arg0, arg1, redirect), 'r')
+            g = os.popen('"%s" %s %d%s' % (exe_name, arg0, arg1, redirect), 'r')
             for line in g:
                 print >> sys.stderr, 'RUN:', line.rstrip()
                 lines.append(line)

Modified: pypy/trunk/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/trunk/pypy/translator/c/test/test_newgc.py	Tue Oct 20 14:58:12 2009
@@ -24,19 +24,39 @@
     _isolated_func = None
 
     @classmethod
-    def _makefunc2(cls, f):
-        t = Translation(f, [int, int], gc=cls.gcpolicy,
+    def _makefunc_str_int(cls, f):
+        def main(argv):
+            arg0 = argv[1]
+            arg1 = int(argv[2])
+            try:
+                res = f(arg0, arg1)
+            except MemoryError:
+                print "MEMORY-ERROR"
+            else:
+                print res
+            return 0
+        
+        t = Translation(main, standalone=True, gc=cls.gcpolicy,
                         policy=annpolicy.StrictAnnotatorPolicy(),
                         taggedpointers=cls.taggedpointers,
                         removetypeptr=cls.removetypeptr,
                         debugprint=True)
         t.disable(['backendopt'])
-        t.set_backend_extra_options(c_isolated=True, c_debug_defines=True)
+        t.set_backend_extra_options(c_debug_defines=True)
         t.rtype()
         if conftest.option.view:
             t.viewcg()
-        isolated_func = t.compile()
-        return isolated_func
+        exename = t.compile()
+
+        def run(s, i):
+            data = py.process.cmdexec("%s %s %d" % (exename, s, i))
+            data = data.strip()
+            if data == 'MEMORY-ERROR':
+                raise MemoryError
+            return data
+
+        return run
+
 
     def setup_class(cls):
         funcs0 = []
@@ -66,8 +86,8 @@
                     funcs1.append(func)
             assert name not in name_to_func
             name_to_func[name] = len(name_to_func)
-        def allfuncs(num, arg):
-            rgc.collect()
+        def allfuncs(name, arg):
+            num = name_to_func[name]
             func0 = funcs0[num]
             if func0:
                 return str(func0())
@@ -79,7 +99,7 @@
                 return funcstr(arg)
             assert 0, 'unreachable'
         cls.funcsstr = funcsstr
-        cls.c_allfuncs = staticmethod(cls._makefunc2(allfuncs))
+        cls.c_allfuncs = staticmethod(cls._makefunc_str_int(allfuncs))
         cls.allfuncs = staticmethod(allfuncs)
         cls.name_to_func = name_to_func
 
@@ -90,10 +110,9 @@
     def run(self, name, *args):
         if not args:
             args = (-1, )
+        print 'Running %r)' % name
+        res = self.c_allfuncs(name, *args)
         num = self.name_to_func[name]
-        print
-        print 'Running %r (test number %d)' % (name, num)
-        res = self.c_allfuncs(num, *args)
         if self.funcsstr[num]:
             return res
         return int(res)
@@ -101,8 +120,8 @@
     def run_orig(self, name, *args):
         if not args:
             args = (-1, )
-        num = self.name_to_func[name]
-        res = self.allfuncs(num, *args)
+        res = self.allfuncs(name, *args)
+        num = self.name_to_func[name]        
         if self.funcsstr[num]:
             return res
         return int(res)        



More information about the Pypy-commit mailing list