| 1 |
import os |
| 2 |
import py |
| 3 |
import pytest |
| 4 |
|
| 5 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 6 |
from rpython.jit.backend.detect_cpu import getcpuclass |
| 7 |
from rpython.jit.metainterp.test import support |
| 8 |
from rpython.rlib.jit import JitDriver |
| 9 |
|
| 10 |
class JitARMMixin(support.LLJitMixin): |
| 11 |
CPUClass = getcpuclass() |
| 12 |
|
| 13 |
enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap" |
| 14 |
basic = False |
| 15 |
|
| 16 |
def check_jumps(self, maxcount): |
| 17 |
pass |
| 18 |
|
| 19 |
if not getattr(os, 'uname', None): |
| 20 |
pytest.skip('cannot run arm tests on non-posix platform') |
| 21 |
|
| 22 |
if os.uname()[1] == 'llaima.local': |
| 23 |
AS = '~/Code/arm-jit/android/android-ndk-r4b//build/prebuilt/darwin-x86/arm-eabi-4.4.0/arm-eabi/bin/as' |
| 24 |
else: |
| 25 |
AS = 'as' |
| 26 |
|
| 27 |
def run_asm(asm): |
| 28 |
BOOTSTRAP_TP = lltype.FuncType([], lltype.Signed) |
| 29 |
addr = asm.mc.materialize(asm.cpu, [], None) |
| 30 |
assert addr % 8 == 0 |
| 31 |
func = rffi.cast(lltype.Ptr(BOOTSTRAP_TP), addr) |
| 32 |
asm.mc._dump_trace(addr, 'test.asm') |
| 33 |
return func() |
| 34 |
|
| 35 |
def skip_unless_run_slow_tests(): |
| 36 |
if not pytest.config.option.run_slow_tests: |
| 37 |
py.test.skip("use --slow to execute this long-running test") |
| 38 |
|
| 39 |
def requires_arm_as(): |
| 40 |
import commands |
| 41 |
i = commands.getoutput("%s -version </dev/null -o /dev/null 2>&1" % AS) |
| 42 |
check_skip(i) |
| 43 |
|
| 44 |
def get_as_version(): |
| 45 |
import commands |
| 46 |
i = commands.getoutput("%s -v </dev/null -o /dev/null 2>&1" % AS) |
| 47 |
return tuple([int(j) for j in i.split()[-1].split('.')]) |
| 48 |
|
| 49 |
def check_skip(inp, search='arm', msg='only for arm'): |
| 50 |
skip = True |
| 51 |
try: |
| 52 |
if inp.index(search) >= 0: |
| 53 |
skip = False |
| 54 |
finally: |
| 55 |
if skip: |
| 56 |
py.test.skip(msg) |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
def gen_test_function(name, asm, args, kwargs=None, asm_ext=None): |
| 61 |
if kwargs is None: |
| 62 |
kwargs = {} |
| 63 |
if asm_ext is None: |
| 64 |
asm_ext = '' |
| 65 |
def f(self): |
| 66 |
func = getattr(self.cb, name) |
| 67 |
func(*args, **kwargs) |
| 68 |
try: |
| 69 |
f_name = name[:name.index('_')] |
| 70 |
except ValueError as e: |
| 71 |
f_name = name |
| 72 |
self.assert_equal('%s%s %s' % (f_name, asm_ext, asm)) |
| 73 |
return f |
| 74 |
|
| 75 |
def define_test(cls, name, test_case, base_name=None): |
| 76 |
import types |
| 77 |
if base_name is None: |
| 78 |
base_name = '' |
| 79 |
templ = 'test_generated_%s_%s' |
| 80 |
test_name = templ % (base_name, name) |
| 81 |
if hasattr(cls, test_name): |
| 82 |
i = 1 |
| 83 |
new_test_name = test_name |
| 84 |
while hasattr(cls, new_test_name): |
| 85 |
new_test_name = '%s_%d' % (test_name, i) |
| 86 |
i += 1 |
| 87 |
test_name = new_test_name |
| 88 |
if not isinstance(test_case, types.FunctionType): |
| 89 |
asm, sig = test_case[0:2] |
| 90 |
kw_args = None |
| 91 |
asm_ext = None |
| 92 |
if len(test_case) > 2: |
| 93 |
kw_args = test_case[2] |
| 94 |
if len(test_case) > 3: |
| 95 |
asm_ext = test_case[3] |
| 96 |
f = gen_test_function(name, asm, sig, kw_args, asm_ext) |
| 97 |
else: |
| 98 |
f = test_case |
| 99 |
setattr(cls, test_name, f) |