[pypy-svn] r37405 - pypy/dist/pypy/jit/codegen/i386/demo
arigo at codespeak.net
arigo at codespeak.net
Fri Jan 26 18:53:34 CET 2007
Author: arigo
Date: Fri Jan 26 18:53:32 2007
New Revision: 37405
Added:
pypy/dist/pypy/jit/codegen/i386/demo/rerun_failures.py (contents, props changed)
pypy/dist/pypy/jit/codegen/i386/demo/test_random.py (contents, props changed)
Modified:
pypy/dist/pypy/jit/codegen/i386/demo/support.py
pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py
Log:
Split the files in a way that allows "py.test rerun_failures.py" to
rerun all tests listed as "they failed in the past". We don't run them
all by default, because it takes a bit of time.
Added: pypy/dist/pypy/jit/codegen/i386/demo/rerun_failures.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/i386/demo/rerun_failures.py Fri Jan 26 18:53:32 2007
@@ -0,0 +1,21 @@
+from pypy.jit.codegen.i386.demo import test_random
+from pypy.jit.codegen.i386.demo import conftest as demo_conftest
+
+def rerun(seed, *args):
+ prevseed = demo_conftest.option.randomseed
+ try:
+ demo_conftest.option.randomseed = seed
+ test_random.test_random_function(*args)
+ finally:
+ demo_conftest.option.randomseed = prevseed
+
+# ____________________________________________________________
+# These are tests that failed at some point. Run them all with
+# py.test rerun_failures.py.
+
+def test_3888(): rerun(3888)
+def test_2307(): rerun(2307)
+def test_9792(): rerun(9792)
+def test_37(): rerun(37)
+def test_2871_1_100(): rerun(2871, 1, 100)
+def test_6294(): rerun(6294)
Modified: pypy/dist/pypy/jit/codegen/i386/demo/support.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/demo/support.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/demo/support.py Fri Jan 26 18:53:32 2007
@@ -59,14 +59,15 @@
print
print 'Random seed value: %d' % (seed,)
print
- expected = entrypoint(*args)
print 'Running %s(%s)...' % (entrypoint.__name__,
', '.join(map(repr, args)))
+ expected = entrypoint(*args)
+ print 'Python ===>', expected
fp = cast(c_void_p(gv_entrypoint.value),
CFUNCTYPE(c_int, *[c_int] * nb_args))
res = fp(*args)
- print '===>', res
+ print 'i386 ===>', res
print
if res != expected:
raise AssertionError(
Modified: pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py Fri Jan 26 18:53:32 2007
@@ -1,6 +1,5 @@
import py
-from pypy.rlib.rarithmetic import intmask
-from pypy.jit.codegen.i386.demo.support import rundemo, Random
+from pypy.jit.codegen.i386.demo.support import rundemo
# try running this with the following py.test options:
#
@@ -47,83 +46,3 @@
return x
#rundemo(f1, 2117)
rundemo(f1, 217)
-
-def test_random_function(nb_blocks=15, max_block_length=20):
- py.test.skip("in-progress")
- blocklabels = range(nb_blocks)
- r = Random()
- vars = list("abcdefghijklmnopqrstuvwxyz")
- varlist = ', '.join(vars)
- magicsum = '+'.join(['%s*%d' % (v, hash(v)) for v in vars])
- operations = ['%s + %s',
- '%s + %s',
- '%s - %s',
- '%s - %s',
- '%s * %s',
- '%s & %s',
- '%s | %s',
- '%s ^ %s',
- '%s << (%s & 0x1234567f)',
- '%s >> (%s & 0x1234567f)',
- 'abs(%s)',
- '-%s',
- '~%s',
- '%s // ((%s & 0xfffff) + 1)',
- '%s // (-((%s & 0xfffff) + 1))',
- '%s %% ((%s & 0xfffff) + 1)',
- '%s %% (-((%s & 0xfffff) + 1))',
- '!%s or %s',
- '!%s and %s',
- '!not %s',
- '!bool(%s)',
- '!%s < %s',
- '!%s <= %s',
- '!%s == %s',
- '!%s != %s',
- '!%s > %s',
- '!%s >= %s',
- ]
- lines = ["def dummyfn(counter, %(varlist)s):" % locals(),
- " goto = 0",
- " while True:",
- ]
- for i in blocklabels:
- lines.append(" if goto == %d:" % i)
- for j in range(r.randrange(0, max_block_length)):
- v1 = r.choice(vars)
- constbytes = r.randrange(-15, 5)
- if constbytes <= 0:
- v2 = r.choice(vars)
- op = r.choice(operations)
- if op.count('%s') == 1:
- op = op % (v2,)
- else:
- v3 = r.choice(vars)
- op = op % (v2, v3)
- if op.startswith('!'):
- op = op[1:]
- else:
- op = 'intmask(%s)' % op
- lines.append(" %s = %s" % (v1, op))
- else:
- constant = r.randrange(-128, 128)
- for i in range(1, constbytes):
- constant = constant << 8 | r.randrange(0, 256)
- lines.append(" %s = %d" % (v1, constant))
- v1 = r.choice(vars)
- for line in [" if %s:" % v1,
- " else:"]:
- lines.append(line)
- j = r.choice(blocklabels)
- if j <= i:
- lines.append(" counter -= 1")
- lines.append(" if not counter: break")
- lines.append(" goto = %d" % j)
- lines.append(" return intmask(%(magicsum)s)" % locals())
-
- src = py.code.Source('\n'.join(lines))
- print src
- exec src.compile()
-
- args = [r.randrange(-99, 100) for v1 in vars]
- rundemo(dummyfn, 100, *args)
Added: pypy/dist/pypy/jit/codegen/i386/demo/test_random.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/i386/demo/test_random.py Fri Jan 26 18:53:32 2007
@@ -0,0 +1,91 @@
+import py
+from pypy.rlib.rarithmetic import intmask
+from pypy.jit.codegen.i386.demo.support import rundemo, Random, udir
+from pypy.jit.codegen.i386.demo import conftest as demo_conftest
+
+
+def test_random_function(nb_blocks=15, max_block_length=20):
+ #py.test.skip("in-progress")
+ blocklabels = range(nb_blocks)
+ r = Random()
+ vars = list("abcdefghijklmnopqrstuvwxyz")
+ varlist = ', '.join(vars)
+ magicsum = '+'.join(['%s*%d' % (v, hash(v)) for v in vars])
+ operations = ['%s + %s',
+ '%s + %s',
+ '%s - %s',
+ '%s - %s',
+ '%s * %s',
+ '%s & %s',
+ '%s | %s',
+ '%s ^ %s',
+ '%s << (%s & 0x0000067f)',
+ '%s >> (%s & 0x1234567f)',
+ 'abs(%s)',
+ '-%s',
+ '~%s',
+ '%s // ((%s & 0xfffff) + 1)',
+ '%s // (-((%s & 0xfffff) + 1))',
+ '%s %% ((%s & 0xfffff) + 1)',
+ '%s %% (-((%s & 0xfffff) + 1))',
+ '!%s or %s',
+ '!%s and %s',
+ '!not %s',
+ '!bool(%s)',
+ '!%s < %s',
+ '!%s <= %s',
+ '!%s == %s',
+ '!%s != %s',
+ '!%s > %s',
+ '!%s >= %s',
+ ]
+ lines = ["def dummyfn(counter, %(varlist)s):" % locals(),
+ " goto = 0",
+ " while True:",
+ ]
+ for blocklabel in blocklabels:
+ lines.append(" if goto == %d:" % blocklabel)
+ for j in range(r.randrange(0, max_block_length)):
+ v1 = r.choice(vars)
+ constbytes = r.randrange(-15, 5)
+ if constbytes <= 0:
+ v2 = r.choice(vars)
+ op = r.choice(operations)
+ if op.count('%s') == 1:
+ op = op % (v2,)
+ else:
+ v3 = r.choice(vars)
+ op = op % (v2, v3)
+ if op.startswith('!'):
+ op = op[1:]
+ else:
+ op = 'intmask(%s)' % op
+ lines.append(" %s = %s" % (v1, op))
+ else:
+ constant = r.randrange(-128, 128)
+ for i in range(1, constbytes):
+ constant = constant << 8 | r.randrange(0, 256)
+ lines.append(" %s = %d" % (v1, constant))
+ v1 = r.choice(vars)
+ for line in [" if %s:" % v1,
+ " else:"]:
+ lines.append(line)
+ j = r.choice(blocklabels)
+ if j <= blocklabel:
+ lines.append(" counter -= 1")
+ lines.append(" if not counter: break")
+ lines.append(" goto = %d" % j)
+ lines.append(" return intmask(%(magicsum)s)" % locals())
+
+ args = [r.randrange(-99, 100) for v1 in vars]
+
+ src = py.code.Source('\n'.join(lines))
+ print src
+ udir.join('generated.py').write(
+ 'from pypy.rlib.rarithmetic import intmask\n\n'
+ '%s\n\n'
+ 'args=%r\n'
+ 'print dummyfn(10000, *args)\n' % (src, args))
+ exec src.compile()
+
+ rundemo(dummyfn, 10000, *args)
More information about the Pypy-commit
mailing list