def test_prof_inline(self): py.test.skip("broken by 5b0e029514d4, but we don't use it any more") if sys.platform == 'win32': py.test.skip("instrumentation support is unix only for now") def add(a,b): return a + b - b + b - b + b - b + b - b + b - b + b - b + b def entry_point(argv): tot = 0 x = int(argv[1]) while x > 0: tot = add(tot, x) x -= 1 os.write(1, str(tot)) return 0 from rpython.translator.interactive import Translation t = Translation(entry_point, backend='c') # no counters t.backendopt(inline_threshold=100, profile_based_inline="500") exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500*501/2 t = Translation(entry_point, backend='c') # counters t.backendopt(inline_threshold=all.INLINE_THRESHOLD_FOR_TEST*0.5, profile_based_inline="500") exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500*501/2
def test_profopt(self): if sys.platform == 'win32': py.test.skip("no profopt on win32") def add(a,b): return a + b - b + b - b + b - b + b - b + b - b + b - b + b def entry_point(argv): tot = 0 x = int(argv[1]) while x > 0: tot = add(tot, x) x -= 1 os.write(1, str(tot)) return 0 from rpython.translator.interactive import Translation # XXX this is mostly a "does not crash option" t = Translation(entry_point, backend='c', profopt="100") # no counters t.backendopt() exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500*501/2 t = Translation(entry_point, backend='c', profopt="100", noprofopt=True) # no counters t.backendopt() exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500*501/2
def test_profopt(self): if sys.platform == 'win32': py.test.skip("no profopt on win32") def add(a, b): return a + b - b + b - b + b - b + b - b + b - b + b - b + b def entry_point(argv): tot = 0 x = int(argv[1]) while x > 0: tot = add(tot, x) x -= 1 os.write(1, str(tot)) return 0 from rpython.translator.interactive import Translation # XXX this is mostly a "does not crash option" t = Translation(entry_point, backend='c', profopt="100") # no counters t.backendopt() exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500 * 501 / 2 t = Translation(entry_point, backend='c', profopt="100", noprofopt=True) # no counters t.backendopt() exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500 * 501 / 2
def test_prof_inline(self): py.test.skip("broken by 5b0e029514d4, but we don't use it any more") if sys.platform == 'win32': py.test.skip("instrumentation support is unix only for now") def add(a, b): return a + b - b + b - b + b - b + b - b + b - b + b - b + b def entry_point(argv): tot = 0 x = int(argv[1]) while x > 0: tot = add(tot, x) x -= 1 os.write(1, str(tot)) return 0 from rpython.translator.interactive import Translation t = Translation(entry_point, backend='c') # no counters t.backendopt(inline_threshold=100, profile_based_inline="500") exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500 * 501 / 2 t = Translation(entry_point, backend='c') # counters t.backendopt(inline_threshold=all.INLINE_THRESHOLD_FOR_TEST * 0.5, profile_based_inline="500") exe = t.compile() out = py.process.cmdexec("%s 500" % exe) assert int(out) == 500 * 501 / 2
def test_simple_compile_c(): import ctypes def f(x,y): return x+y t = Translation(f, [int, int]) t.source(backend='c') t.compile() dll = ctypes.CDLL(str(t.driver.c_entryp)) f = dll.pypy_g_f assert f(2, 3) == 5
def compile(f, gc='ref'): t = Translation(f, backend='c', sandbox=True, gc=gc, check_str_without_nul=True) return str(t.compile())
def _makefunc_str_int(cls, f): def main(argv): arg0 = argv[1] arg1 = int(argv[2]) try: res = f(arg0, arg1) except MemoryError: print "MEMORY-ERROR" else: print res return 0 t = Translation(main, gc=cls.gcpolicy, taggedpointers=cls.taggedpointers, gcremovetypeptr=cls.removetypeptr) t.disable(['backendopt']) t.set_backend_extra_options(c_debug_defines=True) t.rtype() if option.view: t.viewcg() exename = t.compile() def run(s, i): data = py.process.cmdexec("%s %s %d" % (exename, s, i)) data = data.strip() if data == 'MEMORY-ERROR': raise MemoryError return data return run
def test_nonmoving_raw_ptr_for_resizable_list(): def f(n): lst = ['a', 'b', 'c'] lst = rgc.resizable_list_supporting_raw_ptr(lst) lst.append(chr(n)) assert lst[3] == chr(n) assert lst[-1] == chr(n) # ptr = rgc.nonmoving_raw_ptr_for_resizable_list(lst) assert lst[:] == ['a', 'b', 'c', chr(n)] assert lltype.typeOf(ptr) == rffi.CCHARP assert [ptr[i] for i in range(4)] == ['a', 'b', 'c', chr(n)] # lst[-3] = 'X' assert ptr[1] == 'X' ptr[2] = 'Y' assert lst[-2] == 'Y' # addr = rffi.cast(lltype.Signed, ptr) ptr = rffi.cast(rffi.CCHARP, addr) rgc.collect() # should not move lst.items lst[-4] = 'g' assert ptr[0] == 'g' ptr[3] = 'H' assert lst[-1] == 'H' return lst # # direct untranslated run lst = f(35) assert isinstance(lst, rgc._ResizableListSupportingRawPtr) # # llinterp run interpret(f, [35]) # # compilation with the GC transformer import subprocess from rpython.translator.interactive import Translation # def main(argv): f(len(argv)) print "OK!" return 0 # t = Translation(main, gc="incminimark") t.disable(['backendopt']) t.set_backend_extra_options(c_debug_defines=True) exename = t.compile() data = subprocess.check_output([str(exename), '.', '.', '.']) assert data.strip().endswith('OK!')
def test_profopt_mac_osx_bug(self): if sys.platform == 'win32': py.test.skip("no profopt on win32") def entry_point(argv): import os pid = os.fork() if pid: os.waitpid(pid, 0) else: os._exit(0) return 0 from rpython.translator.interactive import Translation # XXX this is mostly a "does not crash option" t = Translation(entry_point, backend='c', profopt="") # no counters t.backendopt() exe = t.compile() #py.process.cmdexec(exe) t = Translation(entry_point, backend='c', profopt="", noprofopt=True) # no counters t.backendopt() exe = t.compile()
def test_ll_for_resizable_list(): def f(n): lst = ['a', 'b', 'c'] lst = rgc.resizable_list_supporting_raw_ptr(lst) lst.append(chr(n)) assert lst[3] == chr(n) assert lst[-1] == chr(n) # ll_list = rgc.ll_for_resizable_list(lst) assert lst[:] == ['a', 'b', 'c', chr(n)] assert ll_list.length == 4 assert [ll_list.items[i] for i in range(4)] == ['a', 'b', 'c', chr(n)] # lst[-3] = 'X' assert ll_list.items[1] == 'X' ll_list.items[2] = 'Y' assert lst[-2] == 'Y' # return lst # # direct untranslated run lst = f(35) assert isinstance(lst, rgc._ResizableListSupportingRawPtr) # # llinterp run interpret(f, [35]) # # compilation with the GC transformer import subprocess from rpython.translator.interactive import Translation # def main(argv): f(len(argv)) print "OK!" return 0 # t = Translation(main, gc="incminimark") t.disable(['backendopt']) t.set_backend_extra_options(c_debug_defines=True) exename = t.compile() data = subprocess.check_output([str(exename), '.', '.', '.']) assert data.strip().endswith('OK!')
def setup_module(mod): t = Translation(mini_pypy_like_entry_point, backend='c', sandbox=True) mod.executable = str(t.compile())
def _test_translated(self, use_gc, llcase): import subprocess from rpython.rlib import objectmodel from rpython.translator.interactive import Translation # class Seen: count = 0 class MySimpleFQ(rgc.FinalizerQueue): if not llcase: Class = T_Root else: Class = None def finalizer_trigger(self): seen.count += 1 seen = Seen() fq = MySimpleFQ() if not llcase: EMPTY = None llbuilder = T_Int else: from rpython.rtyper.annlowlevel import llstr EMPTY = lltype.nullptr(llmemory.GCREF.TO) def llbuilder(n): return lltype.cast_opaque_ptr(llmemory.GCREF, llstr(str(n))) def subfunc(): w0 = llbuilder(40) fq.register_finalizer(w0) w1 = llbuilder(41) fq.register_finalizer(w1) w2 = llbuilder(42) fq.register_finalizer(w2) w3 = llbuilder(43) fq.register_finalizer(w3) w4 = llbuilder(44) fq.register_finalizer(w4) w5 = llbuilder(45) fq.register_finalizer(w5) w6 = llbuilder(46) fq.register_finalizer(w6) w7 = llbuilder(47) fq.register_finalizer(w7) w8 = llbuilder(48) fq.register_finalizer(w8) w9 = llbuilder(49) fq.register_finalizer(w9) gc.collect() assert seen.count == 0 assert fq.next_dead() is EMPTY objectmodel.keepalive_until_here(w0) objectmodel.keepalive_until_here(w1) objectmodel.keepalive_until_here(w2) objectmodel.keepalive_until_here(w3) objectmodel.keepalive_until_here(w4) objectmodel.keepalive_until_here(w5) objectmodel.keepalive_until_here(w6) objectmodel.keepalive_until_here(w7) objectmodel.keepalive_until_here(w8) objectmodel.keepalive_until_here(w9) def main(argv): assert fq.next_dead() is EMPTY subfunc() gc.collect() gc.collect() gc.collect() assert seen.count > 0 n = fq.next_dead() while True: if not llcase: assert type(n) is T_Int and 40 <= n.x <= 49 else: from rpython.rtyper.lltypesystem.rstr import STR assert lltype.typeOf(n) is llmemory.GCREF p = lltype.cast_opaque_ptr(lltype.Ptr(STR), n) assert len(p.chars) == 2 assert p.chars[0] == "4" assert "0" <= p.chars[1] <= "9" n = fq.next_dead() if n is EMPTY: break print "OK!" return 0 # t = Translation(main, gc=use_gc) t.disable(['backendopt']) t.set_backend_extra_options(c_debug_defines=True) exename = t.compile() data = subprocess.check_output([str(exename), '.', '.', '.']) assert data.strip().endswith('OK!')
def setup_module(mod): t = Translation(mini_pypy_like_entry_point, backend='c', sandbox=True, lldebug=True) mod.executable = str(t.compile())