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