Author: Antonio Cuni <[email protected]>
Branch: refactor-call_release_gil
Changeset: r62830:c5cc557a227f
Date: 2013-03-27 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/c5cc557a227f/
Log: add a (no longer failing) test which is the whole point of the
branch
diff --git a/pypy/module/pypyjit/test_pypy_c/test__ffi.py
b/pypy/module/pypyjit/test_pypy_c/test__ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test__ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test__ffi.py
@@ -110,7 +110,6 @@
loops = log.loops_by_id('sleep')
assert len(loops) == 1 # make sure that we actually JITted the loop
-
def test_ctypes_call(self):
from rpython.rlib.test.test_clibffi import get_libm_name
def main(libm_name):
@@ -209,3 +208,65 @@
# so far just check that call_release_gil() is produced.
# later, also check that the arguments to call_release_gil()
# are constants, and that the numerous raw_mallocs are removed
+
+ def test_cffi_call_guard_not_forced_fails(self):
+ # this is the test_pypy_c equivalent of
+ # rpython/jit/metainterp/test/test_fficall::test_guard_not_forced_fails
+ #
+ # it requires cffi to be installed for pypy in order to run
+ def main():
+ import sys
+ try:
+ import cffi
+ except ImportError:
+ sys.stderr.write('SKIP: cannot import cffi\n')
+ return 0
+
+ ffi = cffi.FFI()
+
+ ffi.cdef("""
+ typedef void (*functype)(int);
+ int foo(int n, functype func);
+ """)
+
+ lib = ffi.verify("""
+ #include <signal.h>
+ typedef void (*functype)(int);
+
+ int foo(int n, functype func) {
+ if (n >= 2000) {
+ func(n);
+ }
+ return n*2;
+ }
+ """)
+
+ @ffi.callback("functype")
+ def mycallback(n):
+ if n < 5000:
+ return
+ # make sure that guard_not_forced fails
+ d = {}
+ f = sys._getframe()
+ while f:
+ d.update(f.f_locals)
+ f = f.f_back
+
+ n = 0
+ while n < 10000:
+ res = lib.foo(n, mycallback) # ID: cfficall
+ # this is the real point of the test: before the
+ # refactor-call_release_gil branch, the assert failed when
+ # res == 5000
+ assert res == n*2
+ n += 1
+ return n
+
+ log = self.run(main, [], import_site=True)
+ assert log.result == 10000
+ loop, = log.loops_by_id('cfficall')
+ assert loop.match_by_id('cfficall', """
+ ...
+ f1 = call_release_gil(..., descr=<Calli 4 ii EF=6 OS=62>)
+ ...
+ """)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit