[pypy-svn] r64078 - in pypy/branch/pyjitpl5-simplify/pypy/jit/tl: . test
benjamin at codespeak.net
benjamin at codespeak.net
Tue Apr 14 23:20:24 CEST 2009
Author: benjamin
Date: Tue Apr 14 23:20:23 2009
New Revision: 64078
Added:
pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/jitcrashers.py (contents, props changed)
pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/test_pypyjit.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/tl/targetpypyjit.py
Log:
make pypyjit_demo.py into a set of tests
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/tl/targetpypyjit.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/tl/targetpypyjit.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/tl/targetpypyjit.py Tue Apr 14 23:20:23 2009
@@ -17,11 +17,19 @@
def entry_point(args):
from pypy.interpreter.pycode import PyCode
- source = readfile('pypyjit_demo.py')
+ if len(args) > 1:
+ filename = args[1]
+ func_to_run = space.wrap(args[2])
+ else:
+ filename = 'pypyjit_demo.py'
+ func_to_run = None
+ source = readfile(filename)
ec = space.getexecutioncontext()
code = ec.compiler.compile(source, '?', 'exec', 0)
assert isinstance(code, PyCode)
code.exec_code(space, w_dict, w_dict)
+ if func_to_run is not None:
+ space.call_function(space.getitem(w_dict, func_to_run))
return 0
def opt_parser(config):
Added: pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/jitcrashers.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/jitcrashers.py Tue Apr 14 23:20:23 2009
@@ -0,0 +1,91 @@
+def jit_simple_loop():
+ print "simple loop"
+
+ i = 0
+ while i < 200:
+ i = i + 3
+ print i
+ s
+ #assert i == 102
+
+def jit_simple_inplace_add():
+ print "simple loop with inplace_add"
+
+ i = 0
+ while i < 200:
+ i += 3
+ print i
+ assert i == 102
+
+def jit_range():
+ print "range object, but outside the loop"
+
+ s = 0
+ for i in range(200):
+ s = s + i
+ print s
+
+def jit_exceptions():
+ try:
+ i = 200
+ while i > 0:
+ if i == 10:
+ raise IndexError
+ i -= 1
+ except IndexError:
+ pass
+ else:
+ raise AssertionError
+
+def jit_simple_bridge():
+ s = 0
+ for i in range(200):
+ if i % 2:
+ s += 1
+ else:
+ s += 2
+ print s
+
+def jit_tuple_indexing():
+ t = (1, 2, 3)
+ i = 0
+ while i < 200:
+ t = t[1], t[2], t[0]
+ i += 1
+ print t
+
+def jit_nested_loop():
+ print "Arbitrary test function."
+ n = 100
+ i = 0
+ x = 1
+ while i<n:
+ j = 0 #ZERO
+ while j<=i:
+ j = j + 1
+ x = x + (i&j)
+ i = i + 1
+ print x
+ return x
+
+def jit_another_loop():
+ n = "hello"
+ i = 0
+ while i < 150:
+ i = i + 1
+ print n
+
+def jit_loop_with_call():
+ i = 0
+ k = 0
+ while i < 20000:
+ k += call(i)
+ i += 1
+
+def call(i):
+ k = 0
+ for j in range(i, i + 2):
+ if j > i + 2:
+ raise Exception("Explode")
+ k += 1
+ return k
Added: pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/test_pypyjit.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/tl/test/test_pypyjit.py Tue Apr 14 23:20:23 2009
@@ -0,0 +1,38 @@
+import os
+import py
+
+from pypy.jit.tl.test import jitcrashers
+
+path = os.path.join(os.path.dirname(__file__), "..", "targetpypyjit-c")
+JIT_EXECUTABLE = py.path.local(path)
+del path
+CRASH_FILE = os.path.abspath(jitcrashers.__file__.rstrip("c"))
+
+if not JIT_EXECUTABLE.check():
+ py.test.skip("no JIT executable")
+
+def setup_module(mod):
+ mod._old_cwd = os.getcwd()
+ os.chdir(str(JIT_EXECUTABLE.dirpath()))
+
+def teardown_module(mod):
+ os.chdir(mod._old_cwd)
+
+def check_crasher(func_name):
+ try:
+ JIT_EXECUTABLE.sysexec(CRASH_FILE, func_name)
+ except py.__.process.cmdexec.ExecutionFailed, e:
+ print "stderr"
+ print "------"
+ print e.err
+ print "stdout"
+ print "------"
+ print e.out
+ raise
+
+def test_jit_crashers():
+ # Iterate in over sorted test functions, so it's always consistent and
+ # reproducible.
+ for func_name in sorted(jitcrashers.__dict__):
+ if func_name.startswith("jit_"):
+ yield check_crasher, func_name
More information about the Pypy-commit
mailing list