| 1 |
""" Test that the math module still behaves even when |
| 2 |
compiled to C with SSE2 enabled. |
| 3 |
""" |
| 4 |
import py, math |
| 5 |
from rpython.translator.c.test.test_genc import compile |
| 6 |
from rpython.jit.backend.x86.support import ensure_sse2_floats |
| 7 |
from rpython.rlib import rfloat |
| 8 |
from rpython.rlib.unroll import unrolling_iterable |
| 9 |
from rpython.rlib.debug import debug_print |
| 10 |
from rpython.rtyper.lltypesystem.module.test.math_cases import (MathTests, |
| 11 |
get_tester) |
| 12 |
|
| 13 |
def get_test_case((fnname, args, expected)): |
| 14 |
try: |
| 15 |
fn = getattr(math, fnname) |
| 16 |
except AttributeError: |
| 17 |
fn = getattr(rfloat, fnname) |
| 18 |
expect_valueerror = (expected == ValueError) |
| 19 |
expect_overflowerror = (expected == OverflowError) |
| 20 |
check = get_tester(expected) |
| 21 |
unroll_args = unrolling_iterable(args) |
| 22 |
|
| 23 |
def testfn(): |
| 24 |
debug_print('calling', fnname, 'with arguments:') |
| 25 |
for arg in unroll_args: |
| 26 |
debug_print('\t', arg) |
| 27 |
try: |
| 28 |
got = fn(*args) |
| 29 |
except ValueError: |
| 30 |
if expect_valueerror: |
| 31 |
return True |
| 32 |
else: |
| 33 |
debug_print('unexpected ValueError!') |
| 34 |
return False |
| 35 |
except OverflowError: |
| 36 |
if expect_overflowerror: |
| 37 |
return True |
| 38 |
else: |
| 39 |
debug_print('unexpected OverflowError!') |
| 40 |
return False |
| 41 |
else: |
| 42 |
if check(got): |
| 43 |
return True |
| 44 |
else: |
| 45 |
debug_print('unexpected result:', got) |
| 46 |
return False |
| 47 |
|
| 48 |
testfn.__name__ = 'test_' + fnname |
| 49 |
return testfn |
| 50 |
|
| 51 |
|
| 52 |
testfnlist = [get_test_case(testcase) |
| 53 |
for testcase in MathTests.TESTCASES] |
| 54 |
|
| 55 |
def fn(): |
| 56 |
ensure_sse2_floats() |
| 57 |
for i in range(len(testfnlist)): |
| 58 |
testfn = testfnlist[i] |
| 59 |
if not testfn(): |
| 60 |
return i |
| 61 |
return -42 |
| 62 |
|
| 63 |
def test_math(): |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
f = compile(fn, [], lldebug=True) |
| 70 |
res = f() |
| 71 |
if res >= 0: |
| 72 |
py.test.fail(repr(MathTests.TESTCASES[res])) |
| 73 |
else: |
| 74 |
assert res == -42 |