[pypy-svn] r37673 - in pypy/dist/pypy/jit/timeshifter: . test
ac at codespeak.net
ac at codespeak.net
Wed Jan 31 15:25:41 CET 2007
Author: ac
Date: Wed Jan 31 15:25:40 2007
New Revision: 37673
Modified:
pypy/dist/pypy/jit/timeshifter/rtimeshift.py
pypy/dist/pypy/jit/timeshifter/test/test_portal.py
pypy/dist/pypy/jit/timeshifter/test/test_promotion.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
Log:
(pedronis, arre) Some more tests.
Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py Wed Jan 31 15:25:40 2007
@@ -16,6 +16,7 @@
debug_view = lloperation.llop.debug_view
debug_print = lloperation.llop.debug_print
+debug_pdb = lloperation.llop.debug_pdb
# ____________________________________________________________
# emit ops
Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py Wed Jan 31 15:25:40 2007
@@ -106,7 +106,6 @@
return residual_graph
def check_insns(self, expected=None, **counts):
- # XXX only works if the portal is the same as the main
residual_graph = self.get_residual_graph()
self.insns = summary(residual_graph)
if expected is not None:
@@ -115,6 +114,23 @@
assert self.insns.get(opname, 0) == count
+ def check_oops(self, expected=None, **counts):
+ if not self.on_llgraph:
+ return
+ oops = {}
+ residual_graph = self.get_residual_graph()
+ for block in residual_graph.iterblocks():
+ for op in block.operations:
+ if op.opname == 'direct_call':
+ f = getattr(op.args[0].value._obj, "_callable", None)
+ if hasattr(f, 'oopspec'):
+ name, _ = f.oopspec.split('(', 1)
+ oops[name] = oops.get(name, 0) + 1
+ if expected is not None:
+ assert oops == expected
+ for name, count in counts.items():
+ assert oops.get(name, 0) == count
+
def count_direct_calls(self):
residual_graph = self.get_residual_graph()
calls = {}
Modified: pypy/dist/pypy/jit/timeshifter/test/test_promotion.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_promotion.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_promotion.py Wed Jan 31 15:25:40 2007
@@ -2,6 +2,7 @@
from pypy.rpython.lltypesystem import lltype
from pypy.jit.timeshifter.test.test_timeshift import TimeshiftingTests
from pypy.jit.timeshifter.test.test_timeshift import P_NOVIRTUAL
+from pypy.jit.timeshifter.test.test_vlist import P_OOPSPEC
from pypy.rlib.objectmodel import hint
@@ -256,3 +257,21 @@
res = self.timeshift(ll_function, ["20", 0], [], policy=P_NOVIRTUAL)
assert res == 42
self.check_flexswitches(1)
+
+ def test_virtual_list_copy(self):
+ def ll_function(x, y):
+ hint(None, global_merge_point=True)
+ l = [y] * x
+ size = len(l)
+ size = hint(size, promote=True)
+ vl = [0] * size
+ i = 0
+ while i < size:
+ hint(i, concrete=True)
+ vl[i] = l[i]
+ i = i + 1
+ return len(vl)
+ res = self.timeshift(ll_function, [6, 5], [], policy=P_OOPSPEC)
+ assert res == 6
+ self.check_oops(**{'newlist': 1, 'list.len': 1})
+
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Wed Jan 31 15:25:40 2007
@@ -17,6 +17,7 @@
from pypy.translator.backendopt.inline import auto_inlining
from pypy import conftest
from pypy.jit.conftest import Benchmark
+from pypy.jit.codegen.llgraph.rgenop import RGenOp as LLRGenOp
P_NOVIRTUAL = HintAnnotatorPolicy(novirtualcontainer=True)
@@ -59,12 +60,13 @@
return hs, hannotator, rtyper
class TimeshiftingTests(object):
- from pypy.jit.codegen.llgraph.rgenop import RGenOp
+ RGenOp = LLRGenOp
small = True
def setup_class(cls):
from pypy.jit.timeshifter.test.conftest import option
+ cls.on_llgraph = cls.RGenOp is LLRGenOp
if option.use_dump_backend:
from pypy.jit.codegen.dump.rgenop import RDumpGenOp
cls.RGenOp = RDumpGenOp
@@ -325,6 +327,22 @@
for opname, count in counts.items():
assert self.insns.get(opname, 0) == count
+ def check_oops(self, expected=None, **counts):
+ if not self.on_llgraph:
+ return
+ oops = {}
+ for block in self.residual_graph.iterblocks():
+ for op in block.operations:
+ if op.opname == 'direct_call':
+ f = getattr(op.args[0].value._obj, "_callable", None)
+ if hasattr(f, 'oopspec'):
+ name, _ = f.oopspec.split('(', 1)
+ oops[name] = oops.get(name, 0) + 1
+ if expected is not None:
+ assert oops == expected
+ for name, count in counts.items():
+ assert oops.get(name, 0) == count
+
def check_flexswitches(self, expected_count):
count = 0
for block in self.residual_graph.iterblocks():
Modified: pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py Wed Jan 31 15:25:40 2007
@@ -1139,3 +1139,72 @@
res = self.timeshift_from_portal(main, f, [], policy=StopAtXPolicy(g))
assert res == main()
+ def test_simple_interpreter_with_frame_with_stack(self):
+ class Log:
+ stack = None
+ log = Log()
+ class Frame(object):
+ _virtualizable_ = True
+ def __init__(self, code, *args):
+ self.code = code
+ self.pc = 0
+ self.stack = list(args)
+
+ def run(self):
+ return self.interpret(self.code)
+
+ def interpret(self, s):
+ hint(None, global_merge_point=True)
+ n = len(s)
+ pc = 0
+ origstack = self.stack
+ stacklen = len(origstack)
+ stacklen = hint(stacklen, promote=True)
+ curstack = [0] * stacklen
+ i = 0
+ while i < stacklen:
+ hint(i, concrete=True)
+ curstack[i] = origstack[i]
+ i += 1
+ self.stack = curstack
+ while pc < n:
+ hint(None, global_merge_point=True)
+ self.pc = pc
+ op = s[pc]
+ pc += 1
+ op = hint(op, concrete=True)
+ if op == 'P':
+ arg = s[pc]
+ pc += 1
+ hint(arg, concrete=True)
+ self.stack.append(ord(arg) - ord('0'))
+ elif op == 'p':
+ self.stack.pop()
+ elif op == '+':
+ arg = self.stack.pop()
+ self.stack[-1] += arg
+ elif op == '-':
+ arg = self.stack.pop()
+ self.stack[-1] -= arg
+ elif op == 'd':
+ self.debug()
+ else:
+ raise NotImplementedError
+ result = self.stack.pop()
+ self.stack = None
+ return result
+
+ def debug(self):
+ log.stack = self.stack[:]
+
+ def main(x):
+ code = 'P2+P5+P3-'
+ f = Frame(code, x)
+ return f.run()
+
+ res = self.timeshift_from_portal(main, Frame.interpret.im_func,
+ [38],
+ policy=StopAtXPolicy(Frame.debug.im_func))
+ assert res == 42
+ self.check_oops(newlist=0)
+
Modified: pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_vlist.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_vlist.py Wed Jan 31 15:25:40 2007
@@ -101,3 +101,12 @@
res = self.timeshift(ll_function, [], [], policy=P_OOPSPEC)
assert res == 30185379
self.check_insns({})
+
+ def test_alloc_and_set(self):
+ def ll_function():
+ lst = [0] * 9
+ return len(lst)
+ res = self.timeshift(ll_function, [], [], policy=P_OOPSPEC)
+ assert res == 9
+ self.check_insns({})
+
More information about the Pypy-commit
mailing list