[pypy-commit] pypy default: Move zrpy_* and ztranslation* tests to llsupport and import them correspondingly in the backends
bivab
noreply at buildbot.pypy.org
Thu Apr 11 21:08:27 CEST 2013
Author: David Schneider <david.schneider at picle.org>
Branch:
Changeset: r63241:d69d9958dc92
Date: 2013-04-11 21:01 +0200
http://bitbucket.org/pypy/pypy/changeset/d69d9958dc92/
Log: Move zrpy_* and ztranslation* tests to llsupport and import them
correspondingly in the backends
diff too long, truncating to 2000 out of 2756 lines
diff --git a/rpython/jit/backend/arm/test/test_zrpy_gc.py b/rpython/jit/backend/arm/test/test_zrpy_gc.py
--- a/rpython/jit/backend/arm/test/test_zrpy_gc.py
+++ b/rpython/jit/backend/arm/test/test_zrpy_gc.py
@@ -1,798 +1,4 @@
-"""
-This is a test that translates a complete JIT together with a GC and runs it.
-It is testing that the GC-dependent aspects basically work, mostly the mallocs
-and the various cases of write barrier.
-"""
-
-import weakref
-import py, os
-from rpython.annotator import policy as annpolicy
-from rpython.rlib import rgc
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib.jit import JitDriver, dont_look_inside
-from rpython.rlib.jit import elidable, unroll_safe
-from rpython.jit.backend.llsupport.gc import GcLLDescr_framework
-from rpython.tool.udir import udir
-from rpython.config.translationoption import DEFL_GC
from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
skip_unless_run_slow_tests()
-
-class X(object):
- def __init__(self, x=0):
- self.x = x
-
- next = None
-
-class CheckError(Exception):
- pass
-
-def check(flag):
- if not flag:
- raise CheckError
-
-def get_g(main):
- main._dont_inline_ = True
- def g(name, n):
- x = X()
- x.foo = 2
- main(n, x)
- x.foo = 5
- return weakref.ref(x)
- g._dont_inline_ = True
- return g
-
-
-def get_entry(g):
-
- def entrypoint(args):
- name = ''
- n = 2000
- argc = len(args)
- if argc > 1:
- name = args[1]
- if argc > 2:
- n = int(args[2])
- r_list = []
- for i in range(20):
- r = g(name, n)
- r_list.append(r)
- rgc.collect()
- rgc.collect(); rgc.collect()
- freed = 0
- for r in r_list:
- if r() is None:
- freed += 1
- print freed
- return 0
-
- return entrypoint
-
-
-def get_functions_to_patch():
- from rpython.jit.backend.llsupport import gc
- #
- can_use_nursery_malloc1 = gc.GcLLDescr_framework.can_use_nursery_malloc
- def can_use_nursery_malloc2(*args):
- try:
- if os.environ['PYPY_NO_INLINE_MALLOC']:
- return False
- except KeyError:
- pass
- return can_use_nursery_malloc1(*args)
- #
- return {(gc.GcLLDescr_framework, 'can_use_nursery_malloc'):
- can_use_nursery_malloc2}
-
-def compile(f, gc, enable_opts='', **kwds):
- from rpython.annotator.listdef import s_list_of_strings
- from rpython.translator.translator import TranslationContext
- from rpython.jit.metainterp.warmspot import apply_jit
- from rpython.translator.c import genc
- #
- t = TranslationContext()
- t.config.translation.gc = gc
- if gc != 'boehm':
- t.config.translation.gcremovetypeptr = True
- for name, value in kwds.items():
- setattr(t.config.translation, name, value)
- ann = t.buildannotator()
- ann.build_types(f, [s_list_of_strings], main_entry_point=True)
- t.buildrtyper().specialize()
-
- if kwds['jit']:
- patch = get_functions_to_patch()
- old_value = {}
- try:
- for (obj, attr), value in patch.items():
- old_value[obj, attr] = getattr(obj, attr)
- setattr(obj, attr, value)
- #
- apply_jit(t, enable_opts=enable_opts)
- #
- finally:
- for (obj, attr), oldvalue in old_value.items():
- setattr(obj, attr, oldvalue)
-
- cbuilder = genc.CStandaloneBuilder(t, f, t.config)
- cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
- cbuilder.compile()
- return cbuilder
-
-def run(cbuilder, args=''):
- #
- pypylog = udir.join('test_zrpy_gc.log')
- data = cbuilder.cmdexec(args, env={'PYPYLOG': ':%s' % pypylog})
- return data.strip()
-
-def compile_and_run(f, gc, **kwds):
- cbuilder = compile(f, gc, **kwds)
- return run(cbuilder)
-
-
-
-def test_compile_boehm():
- myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
- @dont_look_inside
- def see(lst, n):
- assert len(lst) == 3
- assert lst[0] == n+10
- assert lst[1] == n+20
- assert lst[2] == n+30
- def main(n, x):
- while n > 0:
- myjitdriver.can_enter_jit(n=n, x=x)
- myjitdriver.jit_merge_point(n=n, x=x)
- y = X()
- y.foo = x.foo
- n -= y.foo
- see([n+10, n+20, n+30], n)
- res = compile_and_run(get_entry(get_g(main)), "boehm", jit=True)
- assert int(res) >= 16
-
-# ______________________________________________________________________
-
-
-class BaseFrameworkTests(object):
- compile_kwds = {}
-
- def setup_class(cls):
- funcs = []
- name_to_func = {}
- for fullname in dir(cls):
- if not fullname.startswith('define'):
- continue
- definefunc = getattr(cls, fullname)
- _, name = fullname.split('_', 1)
- beforefunc, loopfunc, afterfunc = definefunc.im_func(cls)
- if beforefunc is None:
- def beforefunc(n, x):
- return n, x, None, None, None, None, None, None, None, None, None, ''
- if afterfunc is None:
- def afterfunc(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- pass
- beforefunc.func_name = 'before_'+name
- loopfunc.func_name = 'loop_'+name
- afterfunc.func_name = 'after_'+name
- funcs.append((beforefunc, loopfunc, afterfunc))
- assert name not in name_to_func
- name_to_func[name] = len(name_to_func)
- print name_to_func
- def allfuncs(name, n):
- x = X()
- x.foo = 2
- main_allfuncs(name, n, x)
- x.foo = 5
- return weakref.ref(x)
- def main_allfuncs(name, n, x):
- num = name_to_func[name]
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s = funcs[num][0](n, x)
- while n > 0:
- myjitdriver.can_enter_jit(num=num, n=n, x=x, x0=x0, x1=x1,
- x2=x2, x3=x3, x4=x4, x5=x5, x6=x6, x7=x7, l=l, s=s)
- myjitdriver.jit_merge_point(num=num, n=n, x=x, x0=x0, x1=x1,
- x2=x2, x3=x3, x4=x4, x5=x5, x6=x6, x7=x7, l=l, s=s)
-
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s = funcs[num][1](
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s)
- funcs[num][2](n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s)
- myjitdriver = JitDriver(greens = ['num'],
- reds = ['n', 'x', 'x0', 'x1', 'x2', 'x3', 'x4',
- 'x5', 'x6', 'x7', 'l', 's'])
- cls.main_allfuncs = staticmethod(main_allfuncs)
- cls.name_to_func = name_to_func
- OLD_DEBUG = GcLLDescr_framework.DEBUG
- try:
- GcLLDescr_framework.DEBUG = True
- cls.cbuilder = compile(get_entry(allfuncs), DEFL_GC,
- gcrootfinder=cls.gcrootfinder, jit=True,
- **cls.compile_kwds)
- finally:
- GcLLDescr_framework.DEBUG = OLD_DEBUG
-
- def _run(self, name, n, env):
- res = self.cbuilder.cmdexec("%s %d" %(name, n), env=env)
- assert int(res) == 20
-
- def run(self, name, n=2000):
- pypylog = udir.join('TestCompileFramework.log')
- env = {'PYPYLOG': ':%s' % pypylog,
- 'PYPY_NO_INLINE_MALLOC': '1'}
- self._run(name, n, env)
- env['PYPY_NO_INLINE_MALLOC'] = ''
- self._run(name, n, env)
-
- def run_orig(self, name, n, x):
- self.main_allfuncs(name, n, x)
-
-
-class CompileFrameworkTests(BaseFrameworkTests):
- # Test suite using (so far) the minimark GC.
-
-## def define_libffi_workaround(cls):
-## # XXX: this is a workaround for a bug in database.py. It seems that
-## # the problem is triggered by optimizeopt/fficall.py, and in
-## # particular by the ``cast_base_ptr_to_instance(Func, llfunc)``: in
-## # these tests, that line is the only place where libffi.Func is
-## # referenced.
-## #
-## # The problem occurs because the gctransformer tries to annotate a
-## # low-level helper to call the __del__ of libffi.Func when it's too
-## # late.
-## #
-## # This workaround works by forcing the annotator (and all the rest of
-## # the toolchain) to see libffi.Func in a "proper" context, not just as
-## # the target of cast_base_ptr_to_instance. Note that the function
-## # below is *never* called by any actual test, it's just annotated.
-## #
-## from rpython.rlib.libffi import get_libc_name, CDLL, types, ArgChain
-## libc_name = get_libc_name()
-## def f(n, x, *args):
-## libc = CDLL(libc_name)
-## ptr = libc.getpointer('labs', [types.slong], types.slong)
-## chain = ArgChain()
-## chain.arg(n)
-## n = ptr.call(chain, lltype.Signed)
-## return (n, x) + args
-## return None, f, None
-
- def define_compile_framework_1(cls):
- # a moving GC. Supports malloc_varsize_nonmovable. Simple test, works
- # without write_barriers and root stack enumeration.
- def f(n, x, *args):
- y = X()
- y.foo = x.foo
- n -= y.foo
- return (n, x) + args
- return None, f, None
-
- def test_compile_framework_1(self):
- self.run('compile_framework_1')
-
- def define_compile_framework_2(cls):
- # More complex test, requires root stack enumeration but
- # not write_barriers.
- def f(n, x, *args):
- prev = x
- for j in range(101): # f() runs 20'000 times, thus allocates
- y = X() # a total of 2'020'000 objects
- y.foo = prev.foo
- prev = y
- n -= prev.foo
- return (n, x) + args
- return None, f, None
-
- def test_compile_framework_2(self):
- self.run('compile_framework_2')
-
- def define_compile_framework_3(cls):
- # Third version of the test. Really requires write_barriers.
- def f(n, x, *args):
- x.next = None
- for j in range(101): # f() runs 20'000 times, thus allocates
- y = X() # a total of 2'020'000 objects
- y.foo = j+1
- y.next = x.next
- x.next = y
- check(x.next.foo == 101)
- total = 0
- y = x
- for j in range(101):
- y = y.next
- total += y.foo
- check(not y.next)
- check(total == 101*102/2)
- n -= x.foo
- return (n, x) + args
- return None, f, None
-
-
-
- def test_compile_framework_3(self):
- x_test = X()
- x_test.foo = 5
- self.run_orig('compile_framework_3', 6, x_test) # check that it does not raise CheckError
- self.run('compile_framework_3')
-
- def define_compile_framework_3_extra(cls):
- # Extra version of the test, with tons of live vars around the residual
- # call that all contain a GC pointer.
- @dont_look_inside
- def residual(n=26):
- x = X()
- x.next = X()
- x.next.foo = n
- return x
- #
- def before(n, x):
- residual(5)
- x0 = residual()
- x1 = residual()
- x2 = residual()
- x3 = residual()
- x4 = residual()
- x5 = residual()
- x6 = residual()
- x7 = residual()
- n *= 19
- return n, None, x0, x1, x2, x3, x4, x5, x6, x7, None, None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- x8 = residual()
- x9 = residual()
- check(x0.next.foo == 26)
- check(x1.next.foo == 26)
- check(x2.next.foo == 26)
- check(x3.next.foo == 26)
- check(x4.next.foo == 26)
- check(x5.next.foo == 26)
- check(x6.next.foo == 26)
- check(x7.next.foo == 26)
- check(x8.next.foo == 26)
- check(x9.next.foo == 26)
- x0, x1, x2, x3, x4, x5, x6, x7 = x7, x4, x6, x5, x3, x2, x9, x8
- n -= 1
- return n, None, x0, x1, x2, x3, x4, x5, x6, x7, None, None
- return before, f, None
-
- def test_compile_framework_3_extra(self):
- self.run_orig('compile_framework_3_extra', 6, None) # check that it does not raise CheckError
- self.run('compile_framework_3_extra')
-
- def define_compile_framework_4(cls):
- # Fourth version of the test, with __del__.
- from rpython.rlib.debug import debug_print
- class Counter:
- cnt = 0
- counter = Counter()
- class Z:
- def __del__(self):
- counter.cnt -= 1
- def before(n, x):
- debug_print('counter.cnt =', counter.cnt)
- check(counter.cnt < 5)
- counter.cnt = n // x.foo
- return n, x, None, None, None, None, None, None, None, None, None, None
- def f(n, x, *args):
- Z()
- n -= x.foo
- return (n, x) + args
- return before, f, None
-
- def test_compile_framework_4(self):
- self.run('compile_framework_4')
-
- def define_compile_framework_5(cls):
- # Test string manipulation.
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- n -= x.foo
- s += str(n)
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(s) == 1*5 + 2*45 + 3*450 + 4*500)
- return None, f, after
-
- def test_compile_framework_5(self):
- self.run('compile_framework_5')
-
- def define_compile_framework_7(cls):
- # Array of pointers (test the write barrier for setarrayitem_gc)
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- if n < 1900:
- check(l[0].x == 123)
- l = [None] * 16
- l[0] = X(123)
- l[1] = X(n)
- l[2] = X(n+10)
- l[3] = X(n+20)
- l[4] = X(n+30)
- l[5] = X(n+40)
- l[6] = X(n+50)
- l[7] = X(n+60)
- l[8] = X(n+70)
- l[9] = X(n+80)
- l[10] = X(n+90)
- l[11] = X(n+100)
- l[12] = X(n+110)
- l[13] = X(n+120)
- l[14] = X(n+130)
- l[15] = X(n+140)
- if n < 1800:
- check(len(l) == 16)
- check(l[0].x == 123)
- check(l[1].x == n)
- check(l[2].x == n+10)
- check(l[3].x == n+20)
- check(l[4].x == n+30)
- check(l[5].x == n+40)
- check(l[6].x == n+50)
- check(l[7].x == n+60)
- check(l[8].x == n+70)
- check(l[9].x == n+80)
- check(l[10].x == n+90)
- check(l[11].x == n+100)
- check(l[12].x == n+110)
- check(l[13].x == n+120)
- check(l[14].x == n+130)
- check(l[15].x == n+140)
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(l) == 16)
- check(l[0].x == 123)
- check(l[1].x == 2)
- check(l[2].x == 12)
- check(l[3].x == 22)
- check(l[4].x == 32)
- check(l[5].x == 42)
- check(l[6].x == 52)
- check(l[7].x == 62)
- check(l[8].x == 72)
- check(l[9].x == 82)
- check(l[10].x == 92)
- check(l[11].x == 102)
- check(l[12].x == 112)
- check(l[13].x == 122)
- check(l[14].x == 132)
- check(l[15].x == 142)
- return before, f, after
-
- def test_compile_framework_7(self):
- self.run('compile_framework_7')
-
- def define_compile_framework_7_interior(cls):
- # Array of structs containing pointers (test the write barrier
- # for setinteriorfield_gc)
- S = lltype.GcStruct('S', ('i', lltype.Signed))
- A = lltype.GcArray(lltype.Struct('entry', ('x', lltype.Ptr(S)),
- ('y', lltype.Ptr(S)),
- ('z', lltype.Ptr(S))))
- class Glob:
- a = lltype.nullptr(A)
- glob = Glob()
- #
- def make_s(i):
- s = lltype.malloc(S)
- s.i = i
- return s
- #
- @unroll_safe
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- a = glob.a
- if not a:
- a = glob.a = lltype.malloc(A, 10)
- i = 0
- while i < 10:
- a[i].x = make_s(n + i * 100 + 1)
- a[i].y = make_s(n + i * 100 + 2)
- a[i].z = make_s(n + i * 100 + 3)
- i += 1
- i = 0
- while i < 10:
- check(a[i].x.i == n + i * 100 + 1)
- check(a[i].y.i == n + i * 100 + 2)
- check(a[i].z.i == n + i * 100 + 3)
- i += 1
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- return None, f, None
-
- def test_compile_framework_7_interior(self):
- self.run('compile_framework_7_interior')
-
- def define_compile_framework_8(cls):
- # Array of pointers, of unknown length (test write_barrier_from_array)
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- if n < 1900:
- check(l[0].x == 123)
- l = [None] * (16 + (n & 7))
- l[0] = X(123)
- l[1] = X(n)
- l[2] = X(n+10)
- l[3] = X(n+20)
- l[4] = X(n+30)
- l[5] = X(n+40)
- l[6] = X(n+50)
- l[7] = X(n+60)
- l[8] = X(n+70)
- l[9] = X(n+80)
- l[10] = X(n+90)
- l[11] = X(n+100)
- l[12] = X(n+110)
- l[13] = X(n+120)
- l[14] = X(n+130)
- l[15] = X(n+140)
- if n < 1800:
- check(len(l) == 16 + (n & 7))
- check(l[0].x == 123)
- check(l[1].x == n)
- check(l[2].x == n+10)
- check(l[3].x == n+20)
- check(l[4].x == n+30)
- check(l[5].x == n+40)
- check(l[6].x == n+50)
- check(l[7].x == n+60)
- check(l[8].x == n+70)
- check(l[9].x == n+80)
- check(l[10].x == n+90)
- check(l[11].x == n+100)
- check(l[12].x == n+110)
- check(l[13].x == n+120)
- check(l[14].x == n+130)
- check(l[15].x == n+140)
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(l) >= 16)
- check(l[0].x == 123)
- check(l[1].x == 2)
- check(l[2].x == 12)
- check(l[3].x == 22)
- check(l[4].x == 32)
- check(l[5].x == 42)
- check(l[6].x == 52)
- check(l[7].x == 62)
- check(l[8].x == 72)
- check(l[9].x == 82)
- check(l[10].x == 92)
- check(l[11].x == 102)
- check(l[12].x == 112)
- check(l[13].x == 122)
- check(l[14].x == 132)
- check(l[15].x == 142)
- return before, f, after
-
- def test_compile_framework_8(self):
- self.run('compile_framework_8')
-
- def define_compile_framework_9(cls):
- # Like compile_framework_8, but with variable indexes and large
- # arrays, testing the card_marking case
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- if n < 1900:
- check(l[0].x == 123)
- num = 512 + (n & 7)
- l = [None] * num
- l[0] = X(123)
- l[1] = X(n)
- l[2] = X(n+10)
- l[3] = X(n+20)
- l[4] = X(n+30)
- l[5] = X(n+40)
- l[6] = X(n+50)
- l[7] = X(n+60)
- l[num-8] = X(n+70)
- l[num-9] = X(n+80)
- l[num-10] = X(n+90)
- l[num-11] = X(n+100)
- l[-12] = X(n+110)
- l[-13] = X(n+120)
- l[-14] = X(n+130)
- l[-15] = X(n+140)
- if n < 1800:
- num = 512 + (n & 7)
- check(len(l) == num)
- check(l[0].x == 123)
- check(l[1].x == n)
- check(l[2].x == n+10)
- check(l[3].x == n+20)
- check(l[4].x == n+30)
- check(l[5].x == n+40)
- check(l[6].x == n+50)
- check(l[7].x == n+60)
- check(l[num-8].x == n+70)
- check(l[num-9].x == n+80)
- check(l[num-10].x == n+90)
- check(l[num-11].x == n+100)
- check(l[-12].x == n+110)
- check(l[-13].x == n+120)
- check(l[-14].x == n+130)
- check(l[-15].x == n+140)
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(l) >= 512)
- check(l[0].x == 123)
- check(l[1].x == 2)
- check(l[2].x == 12)
- check(l[3].x == 22)
- check(l[4].x == 32)
- check(l[5].x == 42)
- check(l[6].x == 52)
- check(l[7].x == 62)
- check(l[-8].x == 72)
- check(l[-9].x == 82)
- check(l[-10].x == 92)
- check(l[-11].x == 102)
- check(l[-12].x == 112)
- check(l[-13].x == 122)
- check(l[-14].x == 132)
- check(l[-15].x == 142)
- return before, f, after
-
- def test_compile_framework_9(self):
- self.run('compile_framework_9')
-
- def define_compile_framework_external_exception_handling(cls):
- def before(n, x):
- x = X(0)
- return n, x, None, None, None, None, None, None, None, None, None, None
-
- @dont_look_inside
- def g(x):
- if x > 200:
- return 2
- raise ValueError
- @dont_look_inside
- def h(x):
- if x > 150:
- raise ValueError
- return 2
-
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- try:
- x.x += g(n)
- except ValueError:
- x.x += 1
- try:
- x.x += h(n)
- except ValueError:
- x.x -= 1
- n -= 1
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(x.x == 1800 * 2 + 1850 * 2 + 200 - 150)
-
- return before, f, None
-
- def test_compile_framework_external_exception_handling(self):
- self.run('compile_framework_external_exception_handling')
-
- def define_compile_framework_bug1(self):
- @elidable
- def nonmoving():
- x = X(1)
- for i in range(7):
- rgc.collect()
- return x
-
- @dont_look_inside
- def do_more_stuff():
- x = X(5)
- for i in range(7):
- rgc.collect()
- return x
-
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- x0 = do_more_stuff()
- check(nonmoving().x == 1)
- n -= 1
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-
- return None, f, None
-
- def test_compile_framework_bug1(self):
- self.run('compile_framework_bug1', 200)
-
- def define_compile_framework_vref(self):
- from rpython.rlib.jit import virtual_ref, virtual_ref_finish
- class A:
- pass
- glob = A()
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- a = A()
- glob.v = vref = virtual_ref(a)
- virtual_ref_finish(vref, a)
- n -= 1
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- return None, f, None
-
- def test_compile_framework_vref(self):
- self.run('compile_framework_vref', 200)
-
- def define_compile_framework_float(self):
- # test for a bug: the fastpath_malloc does not save and restore
- # xmm registers around the actual call to the slow path
- class A:
- x0 = x1 = x2 = x3 = x4 = x5 = x6 = x7 = 0
- @dont_look_inside
- def escape1(a):
- a.x0 += 0
- a.x1 += 6
- a.x2 += 12
- a.x3 += 18
- a.x4 += 24
- a.x5 += 30
- a.x6 += 36
- a.x7 += 42
- @dont_look_inside
- def escape2(n, f0, f1, f2, f3, f4, f5, f6, f7):
- check(f0 == n + 0.0)
- check(f1 == n + 0.125)
- check(f2 == n + 0.25)
- check(f3 == n + 0.375)
- check(f4 == n + 0.5)
- check(f5 == n + 0.625)
- check(f6 == n + 0.75)
- check(f7 == n + 0.875)
- @unroll_safe
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- i = 0
- while i < 42:
- m = n + i
- f0 = m + 0.0
- f1 = m + 0.125
- f2 = m + 0.25
- f3 = m + 0.375
- f4 = m + 0.5
- f5 = m + 0.625
- f6 = m + 0.75
- f7 = m + 0.875
- a1 = A()
- # at this point, all or most f's are still in xmm registers
- escape1(a1)
- escape2(m, f0, f1, f2, f3, f4, f5, f6, f7)
- i += 1
- n -= 1
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- return None, f, None
-
- def test_compile_framework_float(self):
- self.run('compile_framework_float')
-
- def define_compile_framework_minimal_size_in_nursery(self):
- S = lltype.GcStruct('S') # no fields!
- T = lltype.GcStruct('T', ('i', lltype.Signed))
- @unroll_safe
- def f42(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- lst1 = []
- lst2 = []
- i = 0
- while i < 42:
- s1 = lltype.malloc(S)
- t1 = lltype.malloc(T)
- t1.i = 10000 + i + n
- lst1.append(s1)
- lst2.append(t1)
- i += 1
- i = 0
- while i < 42:
- check(lst2[i].i == 10000 + i + n)
- i += 1
- n -= 1
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- return None, f42, None
-
- def test_compile_framework_minimal_size_in_nursery(self):
- self.run('compile_framework_minimal_size_in_nursery')
-
-
-class TestShadowStack(CompileFrameworkTests):
- gcrootfinder = "shadowstack"
-
+from rpython.jit.backend.llsupport.test.zrpy_gc_test import TestShadowStack
diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py b/rpython/jit/backend/arm/test/test_zrpy_gc_boehm.py
copy from rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
copy to rpython/jit/backend/arm/test/test_zrpy_gc_boehm.py
--- a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
+++ b/rpython/jit/backend/arm/test/test_zrpy_gc_boehm.py
@@ -1,53 +1,3 @@
-
-import weakref
-from rpython.rlib.jit import JitDriver, dont_look_inside
-from rpython.jit.backend.x86.test.test_zrpy_gc import run, get_entry, compile
-from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer
-
-class X(object):
- def __init__(self, x=0):
- self.x = x
-
- next = None
-
-class CheckError(Exception):
- pass
-
-def check(flag):
- if not flag:
- raise CheckError
-
-def compile_and_run(f, gc, **kwds):
- cbuilder = compile(f, gc, **kwds)
- return run(cbuilder)
-
-def get_g(main):
- main._dont_inline_ = True
- def g(name, n):
- x = X()
- x.foo = 2
- main(n, x)
- x.foo = 5
- return weakref.ref(x)
- g._dont_inline_ = True
- return g
-
-def test_compile_boehm(monkeypatch):
- fix_annotator_for_vrawbuffer(monkeypatch)
- myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
- @dont_look_inside
- def see(lst, n):
- assert len(lst) == 3
- assert lst[0] == n+10
- assert lst[1] == n+20
- assert lst[2] == n+30
- def main(n, x):
- while n > 0:
- myjitdriver.can_enter_jit(n=n, x=x)
- myjitdriver.jit_merge_point(n=n, x=x)
- y = X()
- y.foo = x.foo
- n -= y.foo
- see([n+10, n+20, n+30], n)
- res = compile_and_run(get_entry(get_g(main)), "boehm", jit=True)
- assert int(res) >= 16
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
+from rpython.jit.backend.llsupport.test.zrpy_gc_boehm_test import test_compile_boehm
diff --git a/rpython/jit/backend/x86/test/test_zrpy_releasegil.py b/rpython/jit/backend/arm/test/test_zrpy_releasegil.py
copy from rpython/jit/backend/x86/test/test_zrpy_releasegil.py
copy to rpython/jit/backend/arm/test/test_zrpy_releasegil.py
--- a/rpython/jit/backend/x86/test/test_zrpy_releasegil.py
+++ b/rpython/jit/backend/arm/test/test_zrpy_releasegil.py
@@ -1,104 +1,4 @@
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib.jit import dont_look_inside
-from rpython.rlib.objectmodel import invoke_around_extcall
-from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
-from rpython.rtyper.annlowlevel import llhelper
-
-from rpython.jit.backend.x86.test.test_zrpy_gc import BaseFrameworkTests
-from rpython.jit.backend.x86.test.test_zrpy_gc import check
-from rpython.tool.udir import udir
-
-
-class ReleaseGILTests(BaseFrameworkTests):
- compile_kwds = dict(enable_opts=ALL_OPTS_NAMES, thread=True)
-
- def define_simple(self):
- class Glob:
- def __init__(self):
- self.event = 0
- glob = Glob()
- #
-
- c_strchr = rffi.llexternal('strchr', [rffi.CCHARP, lltype.Signed],
- rffi.CCHARP)
-
- def func():
- glob.event += 1
-
- def before(n, x):
- invoke_around_extcall(func, func)
- return (n, None, None, None, None, None,
- None, None, None, None, None, None)
- #
- def f(n, x, *args):
- a = rffi.str2charp(str(n))
- c_strchr(a, ord('0'))
- lltype.free(a, flavor='raw')
- n -= 1
- return (n, x) + args
- return before, f, None
-
- def test_simple(self):
- self.run('simple')
- assert 'call_release_gil' in udir.join('TestCompileFramework.log').read()
-
- def define_close_stack(self):
- #
- class Glob(object):
- pass
- glob = Glob()
- class X(object):
- pass
- #
- def callback(p1, p2):
- for i in range(100):
- glob.lst.append(X())
- return rffi.cast(rffi.INT, 1)
- CALLBACK = lltype.Ptr(lltype.FuncType([lltype.Signed,
- lltype.Signed], rffi.INT))
- #
- @dont_look_inside
- def alloc1():
- return llmemory.raw_malloc(16)
- @dont_look_inside
- def free1(p):
- llmemory.raw_free(p)
-
- c_qsort = rffi.llexternal('qsort', [rffi.VOIDP, rffi.SIZE_T,
- rffi.SIZE_T, CALLBACK], lltype.Void)
- #
- def f42(n):
- length = len(glob.lst)
- raw = alloc1()
- fn = llhelper(CALLBACK, rffi._make_wrapper_for(CALLBACK, callback))
- if n & 1: # to create a loop and a bridge, and also
- pass # to run the qsort() call in the blackhole interp
- c_qsort(rffi.cast(rffi.VOIDP, raw), rffi.cast(rffi.SIZE_T, 2),
- rffi.cast(rffi.SIZE_T, 8), fn)
- free1(raw)
- check(len(glob.lst) > length)
- del glob.lst[:]
- #
- def before(n, x):
- glob.lst = []
-
- return (n, None, None, None, None, None,
- None, None, None, None, None, None)
- #
- def f(n, x, *args):
- f42(n)
- n -= 1
- return (n, x) + args
- return before, f, None
-
- def test_close_stack(self):
- self.run('close_stack')
- assert 'call_release_gil' in udir.join('TestCompileFramework.log').read()
-
-
-class TestShadowStack(ReleaseGILTests):
- gcrootfinder = "shadowstack"
-
-class TestAsmGcc(ReleaseGILTests):
- gcrootfinder = "asmgcc"
+from rpython.jit.backend.llsupport.test.zrpy_releasegil_test import TestShadowStack, TestAsmGcc
diff --git a/rpython/jit/backend/arm/test/test_ztranslation.py b/rpython/jit/backend/arm/test/test_ztranslation.py
deleted file mode 100644
--- a/rpython/jit/backend/arm/test/test_ztranslation.py
+++ /dev/null
@@ -1,279 +0,0 @@
-import py, os, sys
-from rpython.tool.udir import udir
-from rpython.rlib.jit import JitDriver, unroll_parameters, set_param
-from rpython.rlib.jit import PARAMETERS, dont_look_inside
-from rpython.rlib.jit import promote
-from rpython.rlib import jit_hooks
-from rpython.jit.metainterp.jitprof import Profiler
-from rpython.jit.backend.detect_cpu import getcpuclass
-from rpython.jit.backend.test.support import CCompiledMixin
-from rpython.jit.codewriter.policy import StopAtXPolicy
-from rpython.translator.translator import TranslationContext
-from rpython.config.translationoption import DEFL_GC
-from rpython.rlib import rgc
-from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
-skip_unless_run_slow_tests()
-
-class TestTranslationARM(CCompiledMixin):
- CPUClass = getcpuclass()
-
- def _get_TranslationContext(self):
- t = TranslationContext()
- t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark'
- t.config.translation.gcrootfinder = 'shadowstack'
- return t
-
- def _check_cbuilder(self, cbuilder):
- pass
-
- def test_stuff_translates(self):
- # this is a basic test that tries to hit a number of features and their
- # translation:
- # - jitting of loops and bridges
- # - virtualizables
- # - set_param interface
- # - profiler
- # - full optimizer
- # - floats neg and abs
-
- class Frame(object):
- _virtualizable2_ = ['i']
-
- def __init__(self, i):
- self.i = i
-
- @dont_look_inside
- def myabs(x):
- return abs(x)
-
- jitdriver = JitDriver(greens = [],
- reds = ['total', 'frame', 'j'],
- virtualizables = ['frame'])
- def f(i, j):
- for param, _ in unroll_parameters:
- defl = PARAMETERS[param]
- set_param(jitdriver, param, defl)
- set_param(jitdriver, "threshold", 3)
- set_param(jitdriver, "trace_eagerness", 2)
- total = 0
- frame = Frame(i)
- j = float(j)
- while frame.i > 3:
- jitdriver.can_enter_jit(frame=frame, total=total, j=j)
- jitdriver.jit_merge_point(frame=frame, total=total, j=j)
- total += frame.i
- if frame.i >= 20:
- frame.i -= 2
- frame.i -= 1
- j *= -0.712
- if j + (-j): raise ValueError
- k = myabs(j)
- if k - abs(j): raise ValueError
- if k - abs(-j): raise ValueError
- return chr(total % 253)
- #
- from rpython.rtyper.lltypesystem import lltype, rffi
- from rpython.rlib.libffi import types, CDLL, ArgChain
- from rpython.rlib.test.test_clibffi import get_libm_name
- libm_name = get_libm_name(sys.platform)
- jitdriver2 = JitDriver(greens=[], reds = ['i', 'func', 'res', 'x'])
- def libffi_stuff(i, j):
- lib = CDLL(libm_name)
- func = lib.getpointer('fabs', [types.double], types.double)
- res = 0.0
- x = float(j)
- while i > 0:
- jitdriver2.jit_merge_point(i=i, res=res, func=func, x=x)
- promote(func)
- argchain = ArgChain()
- argchain.arg(x)
- res = func.call(argchain, rffi.DOUBLE)
- i -= 1
- return res
- #
- def main(i, j):
- a_char = f(i, j)
- a_float = libffi_stuff(i, j)
- return ord(a_char) * 10 + int(a_float)
- expected = main(40, -49)
- res = self.meta_interp(main, [40, -49])
- assert res == expected
-
- def test_direct_assembler_call_translates(self):
- """Test CALL_ASSEMBLER and the recursion limit"""
- from rpython.rlib.rstackovf import StackOverflow
-
- class Thing(object):
- def __init__(self, val):
- self.val = val
-
- class Frame(object):
- _virtualizable2_ = ['thing']
-
- driver = JitDriver(greens = ['codeno'], reds = ['i', 'frame'],
- virtualizables = ['frame'],
- get_printable_location = lambda codeno: str(codeno))
- class SomewhereElse(object):
- pass
-
- somewhere_else = SomewhereElse()
-
- def change(newthing):
- somewhere_else.frame.thing = newthing
-
- def main(codeno):
- frame = Frame()
- somewhere_else.frame = frame
- frame.thing = Thing(0)
- portal(codeno, frame)
- return frame.thing.val
-
- def portal(codeno, frame):
- i = 0
- while i < 10:
- driver.can_enter_jit(frame=frame, codeno=codeno, i=i)
- driver.jit_merge_point(frame=frame, codeno=codeno, i=i)
- nextval = frame.thing.val
- if codeno == 0:
- subframe = Frame()
- subframe.thing = Thing(nextval)
- nextval = portal(1, subframe)
- elif frame.thing.val > 40:
- change(Thing(13))
- nextval = 13
- frame.thing = Thing(nextval + 1)
- i += 1
- return frame.thing.val
-
- driver2 = JitDriver(greens = [], reds = ['n'])
-
- def main2(bound):
- try:
- while portal2(bound) == -bound+1:
- bound *= 2
- except StackOverflow:
- pass
- return bound
-
- def portal2(n):
- while True:
- driver2.jit_merge_point(n=n)
- n -= 1
- if n <= 0:
- return n
- n = portal2(n)
- assert portal2(10) == -9
-
- def mainall(codeno, bound):
- return main(codeno) + main2(bound)
-
- res = self.meta_interp(mainall, [0, 1], inline=True,
- policy=StopAtXPolicy(change))
- print hex(res)
- assert res & 255 == main(0)
- bound = res & ~255
- assert 1024 <= bound <= 131072
- assert bound & (bound-1) == 0 # a power of two
-
- def test_jit_get_stats(self):
- driver = JitDriver(greens = [], reds = ['i'])
-
- def f():
- i = 0
- while i < 100000:
- driver.jit_merge_point(i=i)
- i += 1
-
- def main():
- jit_hooks.stats_set_debug(None, True)
- f()
- ll_times = jit_hooks.stats_get_loop_run_times(None)
- return len(ll_times)
-
- res = self.meta_interp(main, [])
- assert res == 3
- # one for loop, one for entry point and one for the prologue
-
-class TestTranslationRemoveTypePtrARM(CCompiledMixin):
- CPUClass = getcpuclass()
-
- def _get_TranslationContext(self):
- t = TranslationContext()
- t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark'
- t.config.translation.gcrootfinder = 'shadowstack'
- t.config.translation.list_comprehension_operations = True
- t.config.translation.gcremovetypeptr = True
- return t
-
- def test_external_exception_handling_translates(self):
- jitdriver = JitDriver(greens = [], reds = ['n', 'total'])
-
- class ImDone(Exception):
- def __init__(self, resvalue):
- self.resvalue = resvalue
-
- @dont_look_inside
- def f(x, total):
- if x <= 30:
- raise ImDone(total * 10)
- if x > 200:
- return 2
- raise ValueError
- @dont_look_inside
- def g(x):
- if x > 150:
- raise ValueError
- return 2
- class Base:
- def meth(self):
- return 2
- class Sub(Base):
- def meth(self):
- return 1
- @dont_look_inside
- def h(x):
- if x < 20000:
- return Sub()
- else:
- return Base()
- def myportal(i):
- set_param(jitdriver, "threshold", 3)
- set_param(jitdriver, "trace_eagerness", 2)
- total = 0
- n = i
- while True:
- jitdriver.can_enter_jit(n=n, total=total)
- jitdriver.jit_merge_point(n=n, total=total)
- try:
- total += f(n, total)
- except ValueError:
- total += 1
- try:
- total += g(n)
- except ValueError:
- total -= 1
- n -= h(n).meth() # this is to force a GUARD_CLASS
- def main(i):
- try:
- myportal(i)
- except ImDone, e:
- return e.resvalue
-
- # XXX custom fishing, depends on the exact env var and format
- logfile = udir.join('test_ztranslation.log')
- os.environ['PYPYLOG'] = 'jit-log-opt:%s' % (logfile,)
- try:
- res = self.meta_interp(main, [400])
- assert res == main(400)
- finally:
- del os.environ['PYPYLOG']
-
- guard_class = 0
- for line in open(str(logfile)):
- if 'guard_class' in line:
- guard_class += 1
- # if we get many more guard_classes, it means that we generate
- # guards that always fail (the following assert's original purpose
- # is to catch the following case: each GUARD_CLASS is misgenerated
- # and always fails with "gcremovetypeptr")
- assert 0 < guard_class < 10
diff --git a/rpython/jit/backend/arm/test/test_ztranslation_basic.py b/rpython/jit/backend/arm/test/test_ztranslation_basic.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/arm/test/test_ztranslation_basic.py
@@ -0,0 +1,13 @@
+from rpython.jit.backend.llsupport.test.ztranslation_test import TranslationTest
+from rpython.translator.translator import TranslationContext
+from rpython.config.translationoption import DEFL_GC
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
+
+
+class TestTranslationX86(TranslationTest):
+ def _check_cbuilder(self, cbuilder):
+ # We assume here that we have sse2. If not, the CPUClass
+ # needs to be changed to CPU386_NO_SSE2, but well.
+ assert '-msse2' in cbuilder.eci.compile_extra
+ assert '-mfpmath=sse' in cbuilder.eci.compile_extra
diff --git a/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py b/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/arm/test/test_ztranslation_call_assembler.py
@@ -0,0 +1,13 @@
+from rpython.jit.backend.llsupport.test.ztranslation_test import TranslationTestCallAssembler
+from rpython.translator.translator import TranslationContext
+from rpython.config.translationoption import DEFL_GC
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
+
+
+class TestTranslationCallAssemblerX86(TranslationTestCallAssembler):
+ def _check_cbuilder(self, cbuilder):
+ # We assume here that we have sse2. If not, the CPUClass
+ # needs to be changed to CPU386_NO_SSE2, but well.
+ assert '-msse2' in cbuilder.eci.compile_extra
+ assert '-mfpmath=sse' in cbuilder.eci.compile_extra
\ No newline at end of file
diff --git a/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py b/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/arm/test/test_ztranslation_external_exception.py
@@ -0,0 +1,15 @@
+from rpython.jit.backend.llsupport.test.ztranslation_test import TranslationRemoveTypePtrTest
+from rpython.translator.translator import TranslationContext
+from rpython.config.translationoption import DEFL_GC
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
+
+
+class TestTranslationRemoveTypePtrX86(TranslationRemoveTypePtrTest):
+ def _get_TranslationContext(self):
+ t = TranslationContext()
+ t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark'
+ t.config.translation.gcrootfinder = 'asmgcc'
+ t.config.translation.list_comprehension_operations = True
+ t.config.translation.gcremovetypeptr = True
+ return t
diff --git a/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py b/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/arm/test/test_ztranslation_jit_stats.py
@@ -0,0 +1,13 @@
+from rpython.jit.backend.llsupport.test.ztranslation_test import TranslationTestJITStats
+from rpython.translator.translator import TranslationContext
+from rpython.config.translationoption import DEFL_GC
+from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests
+skip_unless_run_slow_tests()
+
+
+class TestTranslationJITStatsX86(TranslationTestJITStats):
+ def _check_cbuilder(self, cbuilder):
+ # We assume here that we have sse2. If not, the CPUClass
+ # needs to be changed to CPU386_NO_SSE2, but well.
+ assert '-msse2' in cbuilder.eci.compile_extra
+ assert '-mfpmath=sse' in cbuilder.eci.compile_extra
\ No newline at end of file
diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py b/rpython/jit/backend/llsupport/test/zrpy_gc_boehm_test.py
copy from rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
copy to rpython/jit/backend/llsupport/test/zrpy_gc_boehm_test.py
--- a/rpython/jit/backend/x86/test/test_zrpy_gc_boehm.py
+++ b/rpython/jit/backend/llsupport/test/zrpy_gc_boehm_test.py
@@ -1,8 +1,8 @@
import weakref
from rpython.rlib.jit import JitDriver, dont_look_inside
-from rpython.jit.backend.x86.test.test_zrpy_gc import run, get_entry, compile
-from rpython.jit.backend.x86.test.test_ztranslation import fix_annotator_for_vrawbuffer
+from rpython.jit.backend.llsupport.test.zrpy_gc_test import run, get_entry, compile
+from rpython.jit.backend.llsupport.test.ztranslation_test import fix_annotator_for_vrawbuffer
class X(object):
def __init__(self, x=0):
diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc.py b/rpython/jit/backend/llsupport/test/zrpy_gc_test.py
copy from rpython/jit/backend/x86/test/test_zrpy_gc.py
copy to rpython/jit/backend/llsupport/test/zrpy_gc_test.py
diff --git a/rpython/jit/backend/x86/test/test_zrpy_releasegil.py b/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
copy from rpython/jit/backend/x86/test/test_zrpy_releasegil.py
copy to rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
--- a/rpython/jit/backend/x86/test/test_zrpy_releasegil.py
+++ b/rpython/jit/backend/llsupport/test/zrpy_releasegil_test.py
@@ -5,8 +5,8 @@
from rpython.rtyper.annlowlevel import llhelper
-from rpython.jit.backend.x86.test.test_zrpy_gc import BaseFrameworkTests
-from rpython.jit.backend.x86.test.test_zrpy_gc import check
+from rpython.jit.backend.llsupport.test.zrpy_gc_test import BaseFrameworkTests
+from rpython.jit.backend.llsupport.test.zrpy_gc_test import check
from rpython.tool.udir import udir
diff --git a/rpython/jit/backend/x86/test/test_ztranslation.py b/rpython/jit/backend/llsupport/test/ztranslation_test.py
rename from rpython/jit/backend/x86/test/test_ztranslation.py
rename to rpython/jit/backend/llsupport/test/ztranslation_test.py
--- a/rpython/jit/backend/x86/test/test_ztranslation.py
+++ b/rpython/jit/backend/llsupport/test/ztranslation_test.py
@@ -1,17 +1,13 @@
-import py, os, sys
+import os, sys
from rpython.tool.udir import udir
from rpython.rlib.jit import JitDriver, unroll_parameters, set_param
from rpython.rlib.jit import PARAMETERS, dont_look_inside
from rpython.rlib.jit import promote
from rpython.rlib import jit_hooks
-from rpython.jit.metainterp.jitprof import Profiler
from rpython.jit.backend.detect_cpu import getcpuclass
from rpython.jit.backend.test.support import CCompiledMixin
from rpython.jit.codewriter.policy import StopAtXPolicy
-from rpython.translator.translator import TranslationContext
-from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64
-from rpython.config.translationoption import DEFL_GC
-from rpython.rlib import rgc
+
def fix_annotator_for_vrawbuffer(monkeypatch):
from rpython.rlib.nonconst import NonConstant
@@ -25,15 +21,9 @@
monkeypatch.setattr(warmspot, 'hook_for_tests', my_hook_for_tests)
-class TestTranslationX86(CCompiledMixin):
+class TranslationTest(CCompiledMixin):
CPUClass = getcpuclass()
- def _check_cbuilder(self, cbuilder):
- # We assume here that we have sse2. If not, the CPUClass
- # needs to be changed to CPU386_NO_SSE2, but well.
- assert '-msse2' in cbuilder.eci.compile_extra
- assert '-mfpmath=sse' in cbuilder.eci.compile_extra
-
def test_stuff_translates(self, monkeypatch):
fix_annotator_for_vrawbuffer(monkeypatch)
# this is a basic test that tries to hit a number of features and their
@@ -108,6 +98,10 @@
res = self.meta_interp(main, [40, -49])
assert res == expected
+
+class TranslationTestCallAssembler(CCompiledMixin):
+ CPUClass = getcpuclass()
+
def test_direct_assembler_call_translates(self, monkeypatch):
"""Test CALL_ASSEMBLER and the recursion limit"""
from rpython.rlib.rstackovf import StackOverflow
@@ -185,10 +179,14 @@
assert 1024 <= bound <= 131072
assert bound & (bound-1) == 0 # a power of two
+
+class TranslationTestJITStats(CCompiledMixin):
+ CPUClass = getcpuclass()
+
def test_jit_get_stats(self, monkeypatch):
fix_annotator_for_vrawbuffer(monkeypatch)
driver = JitDriver(greens = [], reds = ['i'])
-
+
def f():
i = 0
while i < 100000:
@@ -205,17 +203,10 @@
assert res == 3
# one for loop, one for entry point and one for the prologue
-class TestTranslationRemoveTypePtrX86(CCompiledMixin):
+
+class TranslationRemoveTypePtrTest(CCompiledMixin):
CPUClass = getcpuclass()
- def _get_TranslationContext(self):
- t = TranslationContext()
- t.config.translation.gc = DEFL_GC # 'hybrid' or 'minimark'
- t.config.translation.gcrootfinder = 'asmgcc'
- t.config.translation.list_comprehension_operations = True
- t.config.translation.gcremovetypeptr = True
- return t
-
def test_external_exception_handling_translates(self, monkeypatch):
fix_annotator_for_vrawbuffer(monkeypatch)
jitdriver = JitDriver(greens = [], reds = ['n', 'total'])
diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc.py b/rpython/jit/backend/x86/test/test_zrpy_gc.py
--- a/rpython/jit/backend/x86/test/test_zrpy_gc.py
+++ b/rpython/jit/backend/x86/test/test_zrpy_gc.py
@@ -1,775 +1,1 @@
-"""
-This is a test that translates a complete JIT together with a GC and runs it.
-It is testing that the GC-dependent aspects basically work, mostly the mallocs
-and the various cases of write barrier.
-"""
-
-import weakref
-import os
-from rpython.rlib import rgc
-from rpython.rtyper.lltypesystem import lltype
-from rpython.rlib.jit import JitDriver, dont_look_inside
-from rpython.rlib.jit import elidable, unroll_safe
-from rpython.jit.backend.llsupport.gc import GcLLDescr_framework
-from rpython.tool.udir import udir
-from rpython.config.translationoption import DEFL_GC
-
-
-class X(object):
- def __init__(self, x=0):
- self.x = x
-
- next = None
-
-class CheckError(Exception):
- pass
-
-def check(flag):
- if not flag:
- raise CheckError
-
-def get_entry(g):
-
- def entrypoint(args):
- name = ''
- n = 2000
- argc = len(args)
- if argc > 1:
- name = args[1]
- if argc > 2:
- n = int(args[2])
- r_list = []
- for i in range(20):
- r = g(name, n)
- r_list.append(r)
- rgc.collect()
- rgc.collect(); rgc.collect()
- freed = 0
- for r in r_list:
- if r() is None:
- freed += 1
- print freed
- return 0
-
- return entrypoint
-
-def get_functions_to_patch():
- from rpython.jit.backend.llsupport import gc
- #
- can_use_nursery_malloc1 = gc.GcLLDescr_framework.can_use_nursery_malloc
- def can_use_nursery_malloc2(*args):
- try:
- if os.environ['PYPY_NO_INLINE_MALLOC']:
- return False
- except KeyError:
- pass
- return can_use_nursery_malloc1(*args)
- #
- return {(gc.GcLLDescr_framework, 'can_use_nursery_malloc'):
- can_use_nursery_malloc2}
-
-def compile(f, gc, **kwds):
- from rpython.annotator.listdef import s_list_of_strings
- from rpython.translator.translator import TranslationContext
- from rpython.jit.metainterp.warmspot import apply_jit
- from rpython.translator.c import genc
- #
- t = TranslationContext()
- t.config.translation.gc = gc
- if gc != 'boehm':
- t.config.translation.gcremovetypeptr = True
- for name, value in kwds.items():
- setattr(t.config.translation, name, value)
- ann = t.buildannotator()
- ann.build_types(f, [s_list_of_strings], main_entry_point=True)
- t.buildrtyper().specialize()
-
- if kwds['jit']:
- patch = get_functions_to_patch()
- old_value = {}
- try:
- for (obj, attr), value in patch.items():
- old_value[obj, attr] = getattr(obj, attr)
- setattr(obj, attr, value)
- #
- apply_jit(t)
- #
- finally:
- for (obj, attr), oldvalue in old_value.items():
- setattr(obj, attr, oldvalue)
-
- cbuilder = genc.CStandaloneBuilder(t, f, t.config)
- cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
- cbuilder.compile()
- return cbuilder
-
-def run(cbuilder, args=''):
- #
- pypylog = udir.join('test_zrpy_gc.log')
- data = cbuilder.cmdexec(args, env={'PYPYLOG': ':%s' % pypylog})
- return data.strip()
-
-# ______________________________________________________________________
-
-
-class BaseFrameworkTests(object):
-
- def setup_class(cls):
- funcs = []
- name_to_func = {}
- for fullname in dir(cls):
- if not fullname.startswith('define'):
- continue
- definefunc = getattr(cls, fullname)
- _, name = fullname.split('_', 1)
- beforefunc, loopfunc, afterfunc = definefunc.im_func(cls)
- if beforefunc is None:
- def beforefunc(n, x):
- return n, x, None, None, None, None, None, None, None, None, None, ''
- if afterfunc is None:
- def afterfunc(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- pass
- beforefunc.func_name = 'before_'+name
- loopfunc.func_name = 'loop_'+name
- afterfunc.func_name = 'after_'+name
- funcs.append((beforefunc, loopfunc, afterfunc))
- assert name not in name_to_func
- name_to_func[name] = len(name_to_func)
- print name_to_func
- def allfuncs(name, n):
- x = X()
- x.foo = 2
- main_allfuncs(name, n, x)
- x.foo = 5
- return weakref.ref(x)
- def main_allfuncs(name, n, x):
- num = name_to_func[name]
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s = funcs[num][0](n, x)
- while n > 0:
- myjitdriver.can_enter_jit(num=num, n=n, x=x, x0=x0, x1=x1,
- x2=x2, x3=x3, x4=x4, x5=x5, x6=x6, x7=x7, l=l, s=s)
- myjitdriver.jit_merge_point(num=num, n=n, x=x, x0=x0, x1=x1,
- x2=x2, x3=x3, x4=x4, x5=x5, x6=x6, x7=x7, l=l, s=s)
-
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s = funcs[num][1](
- n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s)
- funcs[num][2](n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s)
- myjitdriver = JitDriver(greens = ['num'],
- reds = ['n', 'x', 'x0', 'x1', 'x2', 'x3', 'x4',
- 'x5', 'x6', 'x7', 'l', 's'])
- cls.main_allfuncs = staticmethod(main_allfuncs)
- cls.name_to_func = name_to_func
- OLD_DEBUG = GcLLDescr_framework.DEBUG
- try:
- GcLLDescr_framework.DEBUG = True
- cls.cbuilder = compile(get_entry(allfuncs), DEFL_GC,
- gcrootfinder=cls.gcrootfinder, jit=True,
- thread=True)
- finally:
- GcLLDescr_framework.DEBUG = OLD_DEBUG
-
- def _run(self, name, n, env):
- res = self.cbuilder.cmdexec("%s %d" %(name, n), env=env)
- assert int(res) == 20
-
- def run(self, name, n=2000):
- pypylog = udir.join('TestCompileFramework.log')
- env = {'PYPYLOG': ':%s' % pypylog,
- 'PYPY_NO_INLINE_MALLOC': '1'}
- self._run(name, n, env)
- env['PYPY_NO_INLINE_MALLOC'] = ''
- self._run(name, n, env)
-
- def run_orig(self, name, n, x):
- self.main_allfuncs(name, n, x)
-
-
-class CompileFrameworkTests(BaseFrameworkTests):
- # Test suite using (so far) the minimark GC.
-
-## def define_libffi_workaround(cls):
-## # XXX: this is a workaround for a bug in database.py. It seems that
-## # the problem is triggered by optimizeopt/fficall.py, and in
-## # particular by the ``cast_base_ptr_to_instance(Func, llfunc)``: in
-## # these tests, that line is the only place where libffi.Func is
-## # referenced.
-## #
-## # The problem occurs because the gctransformer tries to annotate a
-## # low-level helper to call the __del__ of libffi.Func when it's too
-## # late.
-## #
-## # This workaround works by forcing the annotator (and all the rest of
-## # the toolchain) to see libffi.Func in a "proper" context, not just as
-## # the target of cast_base_ptr_to_instance. Note that the function
-## # below is *never* called by any actual test, it's just annotated.
-## #
-## from rpython.rlib.libffi import get_libc_name, CDLL, types, ArgChain
-## libc_name = get_libc_name()
-## def f(n, x, *args):
-## libc = CDLL(libc_name)
-## ptr = libc.getpointer('labs', [types.slong], types.slong)
-## chain = ArgChain()
-## chain.arg(n)
-## n = ptr.call(chain, lltype.Signed)
-## return (n, x) + args
-## return None, f, None
-
- def define_compile_framework_1(cls):
- # a moving GC. Supports malloc_varsize_nonmovable. Simple test, works
- # without write_barriers and root stack enumeration.
- def f(n, x, *args):
- y = X()
- y.foo = x.foo
- n -= y.foo
- return (n, x) + args
- return None, f, None
-
- def test_compile_framework_1(self):
- self.run('compile_framework_1')
-
- def define_compile_framework_2(cls):
- # More complex test, requires root stack enumeration but
- # not write_barriers.
- def f(n, x, *args):
- prev = x
- for j in range(101): # f() runs 20'000 times, thus allocates
- y = X() # a total of 2'020'000 objects
- y.foo = prev.foo
- prev = y
- n -= prev.foo
- return (n, x) + args
- return None, f, None
-
- def test_compile_framework_2(self):
- self.run('compile_framework_2')
-
- def define_compile_framework_3(cls):
- # Third version of the test. Really requires write_barriers.
- def f(n, x, *args):
- x.next = None
- for j in range(101): # f() runs 20'000 times, thus allocates
- y = X() # a total of 2'020'000 objects
- y.foo = j+1
- y.next = x.next
- x.next = y
- check(x.next.foo == 101)
- total = 0
- y = x
- for j in range(101):
- y = y.next
- total += y.foo
- check(not y.next)
- check(total == 101*102/2)
- n -= x.foo
- return (n, x) + args
- return None, f, None
-
-
-
- def test_compile_framework_3(self):
- x_test = X()
- x_test.foo = 5
- self.run_orig('compile_framework_3', 6, x_test) # check that it does not raise CheckError
- self.run('compile_framework_3')
-
- def define_compile_framework_3_extra(cls):
- # Extra version of the test, with tons of live vars around the residual
- # call that all contain a GC pointer.
- @dont_look_inside
- def residual(n=26):
- x = X()
- x.next = X()
- x.next.foo = n
- return x
- #
- def before(n, x):
- residual(5)
- x0 = residual()
- x1 = residual()
- x2 = residual()
- x3 = residual()
- x4 = residual()
- x5 = residual()
- x6 = residual()
- x7 = residual()
- n *= 19
- return n, None, x0, x1, x2, x3, x4, x5, x6, x7, None, None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- x8 = residual()
- x9 = residual()
- check(x0.next.foo == 26)
- check(x1.next.foo == 26)
- check(x2.next.foo == 26)
- check(x3.next.foo == 26)
- check(x4.next.foo == 26)
- check(x5.next.foo == 26)
- check(x6.next.foo == 26)
- check(x7.next.foo == 26)
- check(x8.next.foo == 26)
- check(x9.next.foo == 26)
- x0, x1, x2, x3, x4, x5, x6, x7 = x7, x4, x6, x5, x3, x2, x9, x8
- n -= 1
- return n, None, x0, x1, x2, x3, x4, x5, x6, x7, None, None
- return before, f, None
-
- def test_compile_framework_3_extra(self):
- self.run_orig('compile_framework_3_extra', 6, None) # check that it does not raise CheckError
- self.run('compile_framework_3_extra')
-
- def define_compile_framework_4(cls):
- # Fourth version of the test, with __del__.
- from rpython.rlib.debug import debug_print
- class Counter:
- cnt = 0
- counter = Counter()
- class Z:
- def __del__(self):
- counter.cnt -= 1
- def before(n, x):
- debug_print('counter.cnt =', counter.cnt)
- check(counter.cnt < 5)
- counter.cnt = n // x.foo
- return n, x, None, None, None, None, None, None, None, None, None, None
- def f(n, x, *args):
- Z()
- n -= x.foo
- return (n, x) + args
- return before, f, None
-
- def test_compile_framework_4(self):
- self.run('compile_framework_4')
-
- def define_compile_framework_5(cls):
- # Test string manipulation.
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- n -= x.foo
- s += str(n)
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(s) == 1*5 + 2*45 + 3*450 + 4*500)
- return None, f, after
-
- def test_compile_framework_5(self):
- self.run('compile_framework_5')
-
- def define_compile_framework_7(cls):
- # Array of pointers (test the write barrier for setarrayitem_gc)
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- if n < 1900:
- check(l[0].x == 123)
- l = [None] * 16
- l[0] = X(123)
- l[1] = X(n)
- l[2] = X(n+10)
- l[3] = X(n+20)
- l[4] = X(n+30)
- l[5] = X(n+40)
- l[6] = X(n+50)
- l[7] = X(n+60)
- l[8] = X(n+70)
- l[9] = X(n+80)
- l[10] = X(n+90)
- l[11] = X(n+100)
- l[12] = X(n+110)
- l[13] = X(n+120)
- l[14] = X(n+130)
- l[15] = X(n+140)
- if n < 1800:
- check(len(l) == 16)
- check(l[0].x == 123)
- check(l[1].x == n)
- check(l[2].x == n+10)
- check(l[3].x == n+20)
- check(l[4].x == n+30)
- check(l[5].x == n+40)
- check(l[6].x == n+50)
- check(l[7].x == n+60)
- check(l[8].x == n+70)
- check(l[9].x == n+80)
- check(l[10].x == n+90)
- check(l[11].x == n+100)
- check(l[12].x == n+110)
- check(l[13].x == n+120)
- check(l[14].x == n+130)
- check(l[15].x == n+140)
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(l) == 16)
- check(l[0].x == 123)
- check(l[1].x == 2)
- check(l[2].x == 12)
- check(l[3].x == 22)
- check(l[4].x == 32)
- check(l[5].x == 42)
- check(l[6].x == 52)
- check(l[7].x == 62)
- check(l[8].x == 72)
- check(l[9].x == 82)
- check(l[10].x == 92)
- check(l[11].x == 102)
- check(l[12].x == 112)
- check(l[13].x == 122)
- check(l[14].x == 132)
- check(l[15].x == 142)
- return before, f, after
-
- def test_compile_framework_7(self):
- self.run('compile_framework_7')
-
- def define_compile_framework_7_interior(cls):
- # Array of structs containing pointers (test the write barrier
- # for setinteriorfield_gc)
- S = lltype.GcStruct('S', ('i', lltype.Signed))
- A = lltype.GcArray(lltype.Struct('entry', ('x', lltype.Ptr(S)),
- ('y', lltype.Ptr(S)),
- ('z', lltype.Ptr(S))))
- class Glob:
- a = lltype.nullptr(A)
- glob = Glob()
- #
- def make_s(i):
- s = lltype.malloc(S)
- s.i = i
- return s
- #
- @unroll_safe
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- a = glob.a
- if not a:
- a = glob.a = lltype.malloc(A, 10)
- i = 0
- while i < 10:
- a[i].x = make_s(n + i * 100 + 1)
- a[i].y = make_s(n + i * 100 + 2)
- a[i].z = make_s(n + i * 100 + 3)
- i += 1
- i = 0
- while i < 10:
- check(a[i].x.i == n + i * 100 + 1)
- check(a[i].y.i == n + i * 100 + 2)
- check(a[i].z.i == n + i * 100 + 3)
- i += 1
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- return None, f, None
-
- def test_compile_framework_7_interior(self):
- self.run('compile_framework_7_interior')
-
- def define_compile_framework_8(cls):
- # Array of pointers, of unknown length (test write_barrier_from_array)
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- if n < 1900:
- check(l[0].x == 123)
- l = [None] * (16 + (n & 7))
- l[0] = X(123)
- l[1] = X(n)
- l[2] = X(n+10)
- l[3] = X(n+20)
- l[4] = X(n+30)
- l[5] = X(n+40)
- l[6] = X(n+50)
- l[7] = X(n+60)
- l[8] = X(n+70)
- l[9] = X(n+80)
- l[10] = X(n+90)
- l[11] = X(n+100)
- l[12] = X(n+110)
- l[13] = X(n+120)
- l[14] = X(n+130)
- l[15] = X(n+140)
- if n < 1800:
- check(len(l) == 16 + (n & 7))
- check(l[0].x == 123)
- check(l[1].x == n)
- check(l[2].x == n+10)
- check(l[3].x == n+20)
- check(l[4].x == n+30)
- check(l[5].x == n+40)
- check(l[6].x == n+50)
- check(l[7].x == n+60)
- check(l[8].x == n+70)
- check(l[9].x == n+80)
- check(l[10].x == n+90)
- check(l[11].x == n+100)
- check(l[12].x == n+110)
- check(l[13].x == n+120)
- check(l[14].x == n+130)
- check(l[15].x == n+140)
- n -= x.foo
- return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
- def after(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
- check(len(l) >= 16)
- check(l[0].x == 123)
- check(l[1].x == 2)
- check(l[2].x == 12)
- check(l[3].x == 22)
- check(l[4].x == 32)
- check(l[5].x == 42)
- check(l[6].x == 52)
- check(l[7].x == 62)
- check(l[8].x == 72)
- check(l[9].x == 82)
- check(l[10].x == 92)
- check(l[11].x == 102)
- check(l[12].x == 112)
- check(l[13].x == 122)
- check(l[14].x == 132)
- check(l[15].x == 142)
- return before, f, after
-
- def test_compile_framework_8(self):
- self.run('compile_framework_8')
-
- def define_compile_framework_9(cls):
- # Like compile_framework_8, but with variable indexes and large
- # arrays, testing the card_marking case
- def before(n, x):
- return n, x, None, None, None, None, None, None, None, None, [X(123)], None
- def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
More information about the pypy-commit
mailing list