Author: Armin Rigo <ar...@tunes.org> Branch: jitypes2 Changeset: r44611:1f7c40ec3850 Date: 2011-05-31 15:05 +0200 http://bitbucket.org/pypy/pypy/changeset/1f7c40ec3850/
Log: Add a simpler test. diff --git a/pypy/jit/backend/x86/test/test_zrpy_gc.py b/pypy/jit/backend/x86/test/test_zrpy_gc.py --- a/pypy/jit/backend/x86/test/test_zrpy_gc.py +++ b/pypy/jit/backend/x86/test/test_zrpy_gc.py @@ -149,8 +149,10 @@ # ______________________________________________________________________ -class CompileFrameworkTests(object): - # Test suite using (so far) the minimark GC. + +class BaseFrameworkTests(object): + compile_kwds = {} + def setup_class(cls): funcs = [] name_to_func = {} @@ -200,7 +202,8 @@ try: GcLLDescr_framework.DEBUG = True cls.cbuilder = compile(get_entry(allfuncs), DEFL_GC, - gcrootfinder=cls.gcrootfinder, jit=True) + gcrootfinder=cls.gcrootfinder, jit=True, + **cls.compile_kwds) finally: GcLLDescr_framework.DEBUG = OLD_DEBUG @@ -219,32 +222,36 @@ def run_orig(self, name, n, x): self.main_allfuncs(name, n, x) - 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 pypy.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 + +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 pypy.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 diff --git a/pypy/jit/backend/x86/test/test_zrpy_releasegil.py b/pypy/jit/backend/x86/test/test_zrpy_releasegil.py --- a/pypy/jit/backend/x86/test/test_zrpy_releasegil.py +++ b/pypy/jit/backend/x86/test/test_zrpy_releasegil.py @@ -1,18 +1,51 @@ from pypy.rpython.lltypesystem import lltype, llmemory, rffi -from pypy.rlib.jit import JitDriver, dont_look_inside -from pypy.config.translationoption import DEFL_GC +from pypy.rlib.jit import dont_look_inside +from pypy.jit.metainterp.optimizeopt import ALL_OPTS_NAMES -from pypy.jit.backend.x86.test.test_zrpy_gc import get_entry, get_g -from pypy.jit.backend.x86.test.test_zrpy_gc import compile_and_run +from pypy.rlib.libffi import CDLL, types, ArgChain, clibffi +from pypy.rpython.lltypesystem.ll2ctypes import libc_name +from pypy.rpython.annlowlevel import llhelper + +from pypy.jit.backend.x86.test.test_zrpy_gc import BaseFrameworkTests from pypy.jit.backend.x86.test.test_zrpy_gc import check -class ReleaseGILTests(object): - def test_close_stack(self): - from pypy.rlib.libffi import CDLL, types, ArgChain, clibffi - from pypy.rpython.lltypesystem.ll2ctypes import libc_name - from pypy.rpython.annlowlevel import llhelper - from pypy.jit.metainterp.optimizeopt import ALL_OPTS_NAMES +class ReleaseGILTests(BaseFrameworkTests): + compile_kwds = dict(enable_opts=ALL_OPTS_NAMES, thread=True) + + def define_simple(self): + class Glob: + pass + glob = Glob() + # + def f42(n): + c_strchr = glob.c_strchr + raw = rffi.str2charp("foobar" + chr((n & 63) + 32)) + argchain = ArgChain() + argchain = argchain.arg(rffi.cast(lltype.Signed, raw)) + argchain = argchain.arg(rffi.cast(rffi.INT, ord('b'))) + res = c_strchr.call(argchain, rffi.CCHARP) + check(rffi.charp2str(res) == "bar" + chr((n & 63) + 32)) + rffi.free_charp(raw) + # + def before(n, x): + libc = CDLL(libc_name) + c_strchr = libc.getpointer('strchr', [types.pointer, types.sint], + types.pointer) + glob.c_strchr = c_strchr + 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_simple(self): + self.run('simple') + + def define_close_stack(self): # class Glob(object): pass @@ -49,7 +82,7 @@ check(len(glob.lst) > length) del glob.lst[:] # - def before(): + def before(n, x): libc = CDLL(libc_name) types_size_t = clibffi.cast_type_to_ffitype(rffi.SIZE_T) c_qsort = libc.getpointer('qsort', [types.pointer, types_size_t, @@ -57,23 +90,21 @@ types.void) glob.c_qsort = c_qsort glob.lst = [] + return (n, None, None, None, None, None, + None, None, None, None, None, None) # - myjitdriver = JitDriver(greens=[], reds=['n']) - def main(n, x): - before() - while n > 0: - myjitdriver.jit_merge_point(n=n) - f42() - n -= 1 - # - res = compile_and_run(get_entry(get_g(main)), DEFL_GC, - gcrootfinder=self.gcrootfinder, jit=True, - enable_opts=ALL_OPTS_NAMES, - thread=True) - assert int(res) == 20 + def f(n, x, *args): + f42() + n -= 1 + return (n, x) + args + return before, f, None -class TestGILShadowStack(ReleaseGILTests): + def test_close_stack(self): + self.run('close_stack') + + +class TestShadowStack(ReleaseGILTests): gcrootfinder = "shadowstack" -class TestGILAsmGcc(ReleaseGILTests): +class TestAsmGcc(ReleaseGILTests): gcrootfinder = "asmgcc" _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit