def test_debug_print_start_stop(self): def f(x): debug_start("mycat") debug_print("foo", 2, "bar", x) debug_stop("mycat") debug_flush() # does nothing debug_offset() # should not explode at least return have_debug_prints() try: debug._log = dlog = debug.DebugLog() res = f(3) assert res == True finally: debug._log = None assert dlog == [ ("mycat", [ ('debug_print', 'foo', 2, 'bar', 3), ]), ] try: debug._log = dlog = debug.DebugLog() res = self.interpret(f, [3]) assert res == True finally: debug._log = None assert dlog == [ ("mycat", [ ('debug_print', 'foo', 2, 'bar', 3), ]), ]
def test_debug_print_start_stop(self): def f(x): debug_start("mycat") debug_print("foo", 2, "bar", x) debug_stop("mycat") return have_debug_prints() try: debug._log = dlog = debug.DebugLog() res = f(3) assert res == True finally: debug._log = None assert dlog == [ ("mycat", [ ('debug_print', 'foo', 2, 'bar', 3), ]), ] try: debug._log = dlog = debug.DebugLog() res = self.interpret(f, [3]) assert res == True finally: debug._log = None assert dlog == [ ("mycat", [ ('debug_print', 'foo', 2, 'bar', 3), ]), ]
def test_ops_offset(self): from pypy.rlib import debug i0 = BoxInt() i1 = BoxInt() i2 = BoxInt() looptoken = JitCellToken() targettoken = TargetToken() operations = [ ResOperation(rop.LABEL, [i0], None, descr=targettoken), ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1), ResOperation(rop.INT_LE, [i1, ConstInt(9)], i2), ResOperation(rop.JUMP, [i1], None, descr=targettoken), ] inputargs = [i0] debug._log = dlog = debug.DebugLog() info = self.cpu.compile_loop(inputargs, operations, looptoken) ops_offset = info.ops_offset debug._log = None # assert ops_offset is looptoken._x86_ops_offset # 2*(getfield_raw/int_add/setfield_raw) + ops + None assert len(ops_offset) == 2*3 + len(operations) + 1 assert (ops_offset[operations[0]] <= ops_offset[operations[1]] <= ops_offset[operations[2]] <= ops_offset[None])
def test_debugger_on(self): from pypy.tool.logparser import parse_log_file, extract_category from pypy.rlib import debug targettoken, preambletoken = TargetToken(), TargetToken() loop = """ [i0] label(i0, descr=preambletoken) debug_merge_point('xyz', 0, 0) i1 = int_add(i0, 1) i2 = int_ge(i1, 10) guard_false(i2) [] label(i1, descr=targettoken) debug_merge_point('xyz', 0, 0) i11 = int_add(i1, 1) i12 = int_ge(i11, 10) guard_false(i12) [] jump(i11, descr=targettoken) """ ops = parse(loop, namespace={ 'targettoken': targettoken, 'preambletoken': preambletoken }) debug._log = dlog = debug.DebugLog() try: self.cpu.assembler.set_debug(True) looptoken = JitCellToken() self.cpu.compile_loop(ops.inputargs, ops.operations, looptoken) self.cpu.execute_token(looptoken, 0) # check debugging info struct = self.cpu.assembler.loop_run_counters[0] assert struct.i == 1 struct = self.cpu.assembler.loop_run_counters[1] assert struct.i == 1 struct = self.cpu.assembler.loop_run_counters[2] assert struct.i == 9 self.cpu.finish_once() finally: debug._log = None l0 = ('debug_print', 'entry -1:1') l1 = ('debug_print', preambletoken.repr_of_descr() + ':1') l2 = ('debug_print', targettoken.repr_of_descr() + ':9') assert ('jit-backend-counts', [l0, l1, l2]) in dlog
def test_blockbuildermixin(translated=True): mc = BlockBuilderMixin(translated) writtencode = [] for i in range(mc.SUBBLOCK_SIZE * 2 + 3): assert mc.get_relative_pos() == i mc.writechar(chr(i % 255)) writtencode.append(chr(i % 255)) if translated: assert mc._cursubindex == 3 assert mc._cursubblock assert mc._cursubblock.prev assert mc._cursubblock.prev.prev assert not mc._cursubblock.prev.prev.prev # for i in range(0, mc.SUBBLOCK_SIZE * 2 + 3, 2): mc.overwrite(i, chr((i + 63) % 255)) writtencode[i] = chr((i + 63) % 255) # p = lltype.malloc(rffi.CCHARP.TO, mc.SUBBLOCK_SIZE * 2 + 3, flavor='raw') addr = rffi.cast(lltype.Signed, p) mc.copy_to_raw_memory(addr) # for i in range(mc.SUBBLOCK_SIZE * 2 + 3): assert p[i] == writtencode[i] # debug._log = debug.DebugLog() try: mc._dump(addr, 'test-logname-section') log = list(debug._log) finally: debug._log = None encoded = ''.join(writtencode).encode('hex').upper() ataddr = '@%x' % addr assert log == [('test-logname-section', [('debug_print', 'SYS_EXECUTABLE', '??'), ('debug_print', 'CODE_DUMP', ataddr, '+0 ', encoded)])] lltype.free(p, flavor='raw')
def setup_method(self, meth): debug._log = debug.DebugLog()