Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r44775:65c409578ec8
Date: 2011-06-07 11:27 +0200
http://bitbucket.org/pypy/pypy/changeset/65c409578ec8/
Log: port the last two tests from test_pypy_c to test_pypy_c_new
diff --git a/pypy/module/pypyjit/test/test_pypy_c.py
b/pypy/module/pypyjit/test/test_pypy_c.py
--- a/pypy/module/pypyjit/test/test_pypy_c.py
+++ b/pypy/module/pypyjit/test/test_pypy_c.py
@@ -210,56 +210,6 @@
([], 42))
- def test_overflow_checking(self):
- startvalue = sys.maxint - 2147483647
- self.run_source('''
- def main():
- def f(a,b):
- if a < 0: return -1
- return a-b
- total = %d
- for i in range(100000):
- total += f(i, 5)
- return total
- ''' % startvalue, 170, ([], startvalue + 4999450000L))
-
-
- def test_mod(self):
- avalues = ('a', 'b', 7, -42, 8)
- bvalues = ['b'] + range(-10, 0) + range(1,10)
- code = ''
- a1, b1, res1 = 10, 20, 0
- a2, b2, res2 = 10, -20, 0
- a3, b3, res3 = -10, -20, 0
- def dd(a, b, aval, bval):
- m = {'a': aval, 'b': bval}
- if not isinstance(a, int):
- a=m[a]
- if not isinstance(b, int):
- b=m[b]
- return a % b
- for a in avalues:
- for b in bvalues:
- code += ' sa += %s %% %s\n' % (a, b)
- res1 += dd(a, b, a1, b1)
- res2 += dd(a, b, a2, b2)
- res3 += dd(a, b, a3, b3)
- # The purpose of this test is to check that we get
- # the correct results, not really to count operations.
- self.run_source('''
- def main(a, b):
- i = sa = 0
- while i < 2000:
- if a > 0: pass
- if 1 < b < 2: pass
-%s
- i += 1
- return sa
- ''' % code, sys.maxint, ([a1, b1], 2000 * res1),
- ([a2, b2], 2000 * res2),
- ([a3, b3], 2000 * res3))
-
-
class AppTestJIT(PyPyCJITTests):
def setup_class(cls):
if not option.runappdirect:
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -1791,8 +1791,33 @@
i += 1
return sa
""" % code
- self.run_and_check(src, [ 10, 20], threshold=200)
- self.run_and_check(src, [ 10, -20], threshold=200)
+ self.run_and_check(src, [ 10, 20], threshold=200)
+ self.run_and_check(src, [ 10, -20], threshold=200)
+ self.run_and_check(src, [-10, -20], threshold=200)
+
+ def test_mod(self):
+ """
+ This test only checks that we get the expected result, not that any
+ optimization has been applied.
+ """
+ avalues = ('a', 'b', 7, -42, 8)
+ bvalues = ['b'] + range(-10, 0) + range(1,10)
+ code = ''
+ for a in avalues:
+ for b in bvalues:
+ code += ' sa += %s %% %s\n' % (a, b)
+ src = """
+ def main(a, b):
+ i = sa = 0
+ while i < 2000:
+ if a > 0: pass
+ if 1 < b < 2: pass
+%s
+ i += 1
+ return sa
+ """ % code
+ self.run_and_check(src, [ 10, 20], threshold=200)
+ self.run_and_check(src, [ 10, -20], threshold=200)
self.run_and_check(src, [-10, -20], threshold=200)
def test_shift_allcases(self):
@@ -1949,3 +1974,22 @@
log = self.run(main, [], threshold=200)
loop, = log.loops_by_filename(self.filepath)
assert loop.match_by_id("compare", "") # optimized away
+
+ def test_overflow_checking(self):
+ """
+ This test only checks that we get the expected result, not that any
+ optimization has been applied.
+ """
+ def main():
+ import sys
+ def f(a,b):
+ if a < 0: return -1
+ return a-b
+ #
+ total = sys.maxint - 2147483647
+ for i in range(100000):
+ total += f(i, 5)
+ #
+ return total
+ #
+ self.run_and_check(main, [])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit