[pypy-commit] pypy default: A failing test: keepalive_until_there is not really

arigo noreply at buildbot.pypy.org
Fri Dec 9 08:36:52 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r50319:1edf7af77df6
Date: 2011-12-09 08:36 +0100
http://bitbucket.org/pypy/pypy/changeset/1edf7af77df6/

Log:	A failing test: keepalive_until_there is not really strong enough.

diff --git a/pypy/jit/metainterp/test/test_del.py b/pypy/jit/metainterp/test/test_del.py
--- a/pypy/jit/metainterp/test/test_del.py
+++ b/pypy/jit/metainterp/test/test_del.py
@@ -1,5 +1,7 @@
 import py
-from pypy.rlib.jit import JitDriver
+from pypy.rlib.jit import JitDriver, dont_look_inside
+from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib import rgc
 from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin
 
 
@@ -80,6 +82,55 @@
         assert res == 1
         self.check_resops(call=1)   # for the case B(), but not for the case A()
 
+    def test_keepalive(self):
+        # Fails for now, bcause the keepalive operation doesn't become
+        # anything more than a '-live-' in the jitcodes.  We end up with
+        # operations that are reordered as follows:
+        #    - x = ll_alloc_with_del()
+        #    - setfield(x.state, state)
+        #    - setfield(state.num, 1000)
+        # but when run on CPython with reference counting, __del__ is
+        # invoked between the 2nd and the 3rd line, i.e. too early.
+        py.test.skip("XXX fails")
+        #
+        mydriver = JitDriver(reds = ['n', 'states'], greens = [])
+        class State:
+            num = 1
+        class X:
+            def __init__(self, state):
+                self.state = state
+            def __del__(self):
+                self.state.num += 1
+        @dont_look_inside
+        def do_stuff():
+            pass
+        def f(n):
+            states = []
+            while n > 0:
+                mydriver.jit_merge_point(n=n, states=states)
+                state = State()
+                states.append(state)
+                x = X(state)
+                do_stuff()
+                state.num *= 1000
+                do_stuff()
+                keepalive_until_here(x)
+                n -= 1
+            return states
+        def main(n):
+            states = f(n)
+            rgc.collect()
+            rgc.collect()
+            err = 1001
+            for state in states:
+                if state.num != 1001:
+                    err = state.num
+                    print 'ERROR:', err
+            return err
+        assert main(20) == 1001
+        res = self.meta_interp(main, [20])
+        assert res == 1001
+
 
 class TestLLtype(DelTests, LLJitMixin):
     def test_signal_action(self):


More information about the pypy-commit mailing list