[pypy-svn] r40607 - pypy/branch/jit-virtual-world/pypy/module/pypyjit/test

arigo at codespeak.net arigo at codespeak.net
Fri Mar 16 19:25:02 CET 2007


Author: arigo
Date: Fri Mar 16 19:25:00 2007
New Revision: 40607

Added:
   pypy/branch/jit-virtual-world/pypy/module/pypyjit/test/test_pypy_c.py   (contents, props changed)
Log:
(pedronis, arigo, arre)

Starting to write tests aimed at a pypy-c with a jit.



Added: pypy/branch/jit-virtual-world/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-virtual-world/pypy/module/pypyjit/test/test_pypy_c.py	Fri Mar 16 19:25:00 2007
@@ -0,0 +1,81 @@
+from pypy.conftest import gettestobjspace, option
+from pypy.tool.udir import udir
+import py
+import sys, os
+
+def setup_module(mod):
+    if not option.runappdirect:
+        py.test.skip("meant only for pypy-c")
+    mod.space = gettestobjspace(usemodules=['pypyjit'])
+    mod.tmpdir = udir.join('pypy-jit')
+    mod.tmpdir.ensure(dir=1)
+    mod.counter = 0
+
+
+def run_source(source, testcases):
+    global counter
+    source = py.code.Source(source)
+    filepath = tmpdir.join('case%d.py' % counter)
+    logfilepath = filepath.new(ext='.log')
+    counter += 1
+    f = filepath.open('w')
+    print >> f, source
+    # some support code...
+    print >> f, py.code.Source("""
+        import pypyjit
+        pypyjit.enable(main.func_code)
+
+        def check(args, expected):
+            print 'trying:', args
+            result = main(*args)
+            print 'got:', repr(result)
+            assert result == expected
+            assert type(result) is type(expected)
+    """)
+    for testcase in testcases * 2:
+        print >> f, "check(%r, %r)" % testcase
+    print >> f, "print 'OK :-)'"
+    f.close()
+
+    # we don't have os.popen() yet on pypy-c...
+    if sys.platform.startswith('win'):
+        py.test.skip("XXX this is not Windows-friendly")
+    child_stdin, child_stdout = os.popen2('PYPYJITLOG="%s" "%s" "%s"' % (
+        logfilepath, sys.executable, filepath))
+    child_stdin.close()
+    result = child_stdout.read()
+    child_stdout.close()
+    assert result
+    assert result.splitlines()[-1].strip() == 'OK :-)'
+    assert logfilepath.check()
+
+
+def app_test_f():
+    run_source("""
+        def main(n):
+            return (n+5)+6
+    """,
+               [([100], 111),
+                ([-5], 6),
+                ([sys.maxint], sys.maxint+11),
+                ([-sys.maxint-5], long(-sys.maxint+6)),
+                ])
+
+def app_test_f1():
+    run_source('''
+        def main(n):
+            "Arbitrary test function."
+            i = 0
+            x = 1
+            while i<n:
+                j = 0   #ZERO
+                while j<=i:
+                    j = j + 1
+                    x = x + (i&j)
+                i = i + 1
+            return x
+    ''',
+               [([2117], 1083876708)])
+
+##def test_richards():
+##    xxx



More information about the Pypy-commit mailing list