[pypy-svn] r77567 - pypy/branch/jitffi/pypy/jit/metainterp/test

antocuni at codespeak.net antocuni at codespeak.net
Mon Oct 4 13:56:49 CEST 2010


Author: antocuni
Date: Mon Oct  4 13:56:47 2010
New Revision: 77567

Added:
   pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py
      - copied, changed from r77562, pypy/branch/jitffi/pypy/jit/metainterp/test/test_direct_call.py
Removed:
   pypy/branch/jitffi/pypy/jit/metainterp/test/test_direct_call.py
Log:
rename test_direct_call into test_fficall, and add a test for returning floats


Copied: pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py (from r77562, pypy/branch/jitffi/pypy/jit/metainterp/test/test_direct_call.py)
==============================================================================
--- pypy/branch/jitffi/pypy/jit/metainterp/test/test_direct_call.py	(original)
+++ pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py	Mon Oct  4 13:56:47 2010
@@ -8,7 +8,7 @@
 from pypy.translator.platform import platform
 from pypy.rpython.lltypesystem import lltype, rffi
 
-class TestDirectCall(LLJitMixin):
+class TestFfiCall(LLJitMixin):
     def setup_class(cls):
         # prepare C code as an example, so we can load it and call
         # it via rlib.libffi
@@ -16,14 +16,21 @@
         c_file.write(py.code.Source('''
         int sum_xy(int x, double y)
         {
-           return (x + (int)y);
+            return (x + (int)y);
+        }
+
+        float abs(double x)
+        {
+            if (x<0)
+                return -x;
+            return x;
         }
         '''))
         eci = ExternalCompilationInfo(export_symbols=['sum_xy'])
         cls.lib_name = str(platform.compile([c_file], eci, 'x',
                                             standalone=False))
 
-    def test_one(self):
+    def test_simple(self):
         driver = JitDriver(reds = ['n', 'func'], greens = [])        
 
         def f(n):
@@ -48,3 +55,25 @@
                 'guard_true': 1,
                 'jump': 1})
 
+
+    def test_float_result(self):
+        driver = JitDriver(reds = ['n', 'func', 'res'], greens = [])        
+
+        def f(n):
+            cdll = CDLL(self.lib_name)
+            func = cdll.getpointer('abs', [ffi_type_double], ffi_type_double)
+            res = 0.0
+            while n < 10:
+                driver.jit_merge_point(n=n, func=func, res=res)
+                driver.can_enter_jit(n=n, func=func, res=res)
+                func = hint(func, promote=True)
+                argchain = ArgChain()
+                argchain.float(float(-n))
+                res = func.call(argchain, lltype.Float)
+                n += 1
+            return res
+            
+        res = self.meta_interp(f, [0])
+        assert res == 9
+        self.check_loops(call=1)
+



More information about the Pypy-commit mailing list