[pypy-svn] pypy jitypes2: add a test that fails if we do not emit CALL_RELEASE_GIL for _ffi calls
antocuni
commits-noreply at bitbucket.org
Wed Apr 13 18:29:39 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r43329:489e9af0684e
Date: 2011-04-13 17:09 +0200
http://bitbucket.org/pypy/pypy/changeset/489e9af0684e/
Log: add a test that fails if we do not emit CALL_RELEASE_GIL for _ffi
calls
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -1037,3 +1037,34 @@
--TICK--
jump(p0, p1, p2, p3, p4, i22, i6, i7, p8, p9, descr=<Loop0>)
""")
+
+ def test__ffi_call_releases_gil(self):
+ from pypy.rlib.test.test_libffi import get_libc_name
+ def main(libc_name, n):
+ import time
+ from threading import Thread
+ from _ffi import CDLL, types
+
+ libc = CDLL(libc_name)
+ sleep = libc.getfunc('sleep', [types.uint], types.uint)
+ delays = [0]*n + [1]
+
+ def loop_of_sleeps(i, delays):
+ import time
+ for delay in delays:
+ sleep(delay) # ID: sleep
+
+ threads = [Thread(target=loop_of_sleeps, args=[i, delays]) for i in range(5)]
+ start = time.time()
+ for i, thread in enumerate(threads):
+ thread.start()
+ for thread in threads:
+ thread.join()
+ end = time.time()
+ #
+ return end - start
+ #
+ log = self.run(main, [get_libc_name(), 200], threshold=150)
+ assert 1 <= log.result <= 1.5 # at most 0.5 seconds of overhead
+ loops = log.loops_by_id('sleep')
+ assert len(loops) == 1 # make sure that we actually JITted the loop
More information about the Pypy-commit
mailing list