def setup_class(cls): from test_basic import compile, run class EC(object): def __init__(self, value): self.value = value raw_thread_local = rthread.ThreadLocalReference(EC) def bootstrap(): rthread.gc_thread_start() _sleep(1) ec = EC(4567) raw_thread_local.set(ec) revdb.stop_point() print raw_thread_local.get().value assert raw_thread_local.get() is ec rthread.gc_thread_die() def main(argv): revdb.stop_point() ec = EC(12) raw_thread_local.set(ec) rthread.start_new_thread(bootstrap, ()) _sleep(2) print raw_thread_local.get().value assert raw_thread_local.get() is ec return 9 compile(cls, main, backendopt=False, thread=True) assert run(cls, '') == '4567\n12\n'
def setup_class(cls): from test_basic import compile, run class X: def __init__(self, s): self.s = s prebuilt = X('prebuilt') def make(s): lst = [prebuilt] + [X(c) for c in s] keepalive = lst[-1] return [weakref.ref(x) for x in lst], keepalive def main(argv): lst, keepalive = make(argv[0]) expected = ['prebuilt'] + [c for c in argv[0]] dead = [False] * len(lst) for j in range(17000): outp = [] for i in range(len(lst)): v = lst[i]() debug_print(v) if dead[i]: assert v is None elif v is None: outp.append('<DEAD>') dead[i] = True else: outp.append(v.s) assert v.s == expected[i] print ''.join(outp) if (j % 1000) == 999: debug_print('============= COLLECT ===========') rgc.collect() debug_print('------ done', j, '.') assert not dead[0] assert not dead[-1] keepalive_until_here(keepalive) revdb.stop_point() return 9 compile(cls, main, backendopt=False) output = run(cls, '') lines = output.splitlines() assert lines[-1].startswith('prebuilt') and lines[-1].endswith( str(cls.exename)[-1]) assert (len(lines[-1]) + output.count('<DEAD>') == len('prebuilt') + len(str(cls.exename)))
def setup_class(cls): class W_Root(object): def __init__(self, n): self.n = n PyObjectS = lltype.Struct('PyObjectS', ('c_ob_refcnt', lltype.Signed), ('c_ob_pypy_link', lltype.Signed)) PyObject = lltype.Ptr(PyObjectS) w1 = W_Root(-42) ob1 = lltype.malloc(PyObjectS, flavor='raw', zero=True, immortal=True) ob1.c_ob_refcnt = rawrefcount.REFCNT_FROM_PYPY def main(argv): rawrefcount.create_link_pypy(w1, ob1) w = None ob = lltype.nullptr(PyObjectS) oblist = [] for op in argv[1:]: revdb.stop_point() w = W_Root(42) ob = lltype.malloc(PyObjectS, flavor='raw', zero=True) ob.c_ob_refcnt = rawrefcount.REFCNT_FROM_PYPY rawrefcount.create_link_pypy(w, ob) oblist.append(ob) del oblist[-1] # rgc.collect() assert rawrefcount.from_obj(PyObject, w) == ob assert rawrefcount.to_obj(W_Root, ob) == w while True: ob = rawrefcount.next_dead(PyObject) if not ob: break assert ob in oblist oblist.remove(ob) objectmodel.keepalive_until_here(w) revdb.stop_point() return 9 compile(cls, main, backendopt=False) ARGS26 = 'a b c d e f g h i j k l m n o p q r s t u v w x y z' run(cls, ARGS26) rdb = fetch_rdb(cls, [cls.exename] + ARGS26.split()) assert rdb.number_of_stop_points() == cls.expected_stop_points
def setup_class(cls): from test_basic import compile, run def bootstrap(): rthread.gc_thread_start() _sleep(1) revdb.stop_point() _sleep(2) revdb.stop_point() rthread.gc_thread_die() def main(argv): revdb.stop_point() rthread.start_new_thread(bootstrap, ()) for i in range(2): _sleep(2) revdb.stop_point() print "ok" return 9 compile(cls, main, backendopt=False, thread=True) assert run(cls, '') == 'ok\n'
def setup_class(cls): from test_basic import compile, run main = get_old_style_finalizer_main() compile(cls, main, backendopt=False) run(cls, '')
def setup_class(cls): from test_basic import compile, run class Stuff: pass class DBState: break_loop = -2 stuff = None metavar = None printed_stuff = None watch_future = -1 dbstate = DBState() def blip(cmd, extra): debug_print('<<<', cmd.c_cmd, cmd.c_arg1, cmd.c_arg2, cmd.c_arg3, extra, '>>>') if extra == 'set-breakpoint': dbstate.break_loop = cmd.c_arg1 revdb.send_answer(42, cmd.c_cmd, -43, -44, extra) lambda_blip = lambda: blip def command_print(cmd, extra): if extra == 'print-me': stuff = dbstate.stuff elif extra == '$0': stuff = dbstate.metavar elif extra == '2.35': val = rdtoa.strtod('2.35') valx, valy = math.modf(val) revdb.send_output(rdtoa.dtoa(valx) + '\n') revdb.send_output(rdtoa.dtoa(valy) + '\n') xx, yy = math.frexp(val) revdb.send_output(rdtoa.dtoa(xx) + '\n') revdb.send_output('%d\n' % yy) return elif extra == 'very-long-loop': i = 0 total = 0 while i < 2000000000: total += revdb.flag_io_disabled() i += 1 revdb.send_output(str(total)) return else: assert False uid = revdb.get_unique_id(stuff) ll_assert(uid > 0, "uid == 0") revdb.send_nextnid(uid) # outputs '$NUM = ' revdb.send_output('stuff\n') dbstate.printed_stuff = stuff lambda_print = lambda: command_print def command_attachid(cmd, extra): index_metavar = cmd.c_arg1 uid = cmd.c_arg2 ll_assert(index_metavar == 0, "index_metavar != 0") # in this test dbstate.metavar = dbstate.printed_stuff if dbstate.metavar is None: # uid not found, probably a future object dbstate.watch_future = uid lambda_attachid = lambda: command_attachid def command_allocating(uid, gcref): stuff = cast_gcref_to_instance(Stuff, gcref) # 'stuff' is just allocated; 'stuff.x' is not yet initialized dbstate.printed_stuff = stuff if dbstate.watch_future != -1: ll_assert(dbstate.watch_future == uid, "watch_future out of sync") dbstate.watch_future = -1 dbstate.metavar = stuff lambda_allocating = lambda: command_allocating def command_compilewatch(cmd, expression): revdb.send_watch("marshalled_code", ok_flag=1) lambda_compilewatch = lambda: command_compilewatch def command_checkwatch(cmd, marshalled_code): assert marshalled_code == "marshalled_code" # check that $0 exists if dbstate.metavar is not None: revdb.send_watch("ok, stuff exists\n", ok_flag=1) else: revdb.send_watch("stuff does not exist!\n", ok_flag=0) lambda_checkwatch = lambda: command_checkwatch def main(argv): revdb.register_debug_command(100, lambda_blip) revdb.register_debug_command(CMD_PRINT, lambda_print) revdb.register_debug_command(CMD_ATTACHID, lambda_attachid) revdb.register_debug_command("ALLOCATING", lambda_allocating) revdb.register_debug_command(revdb.CMD_COMPILEWATCH, lambda_compilewatch) revdb.register_debug_command(revdb.CMD_CHECKWATCH, lambda_checkwatch) for i, op in enumerate(argv[1:]): dbstate.stuff = Stuff() dbstate.stuff.x = i + 1000 if i == dbstate.break_loop or i == dbstate.break_loop + 1: revdb.breakpoint(99) revdb.stop_point() print op return 9 compile(cls, main, backendopt=False) assert run( cls, 'abc d ef g h i j k l m') == ('abc\nd\nef\ng\nh\ni\nj\nk\nl\nm\n')
def setup_class(cls): from test_basic import compile, run main = get_callback_demo() compile(cls, main, backendopt=False) run(cls, '')