Exemple #1
0
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')
Exemple #2
0
 def test_insert_gcroot_marker(self):
     puts = []
     class FakeGcRootMap:
         def register_asm_addr(self, retaddr, mark):
             puts.append((retaddr, mark))
     #
     mc = BlockBuilderMixin()
     mc.writechar('X')
     mc.writechar('x')
     mc.insert_gcroot_marker(['a', 'b', 'c', 'd'])
     mc.writechar('Y')
     mc.writechar('y')
     mc.insert_gcroot_marker(['e', 'f', 'g'])
     mc.writechar('Z')
     mc.writechar('z')
     #
     gcrootmap = FakeGcRootMap()
     allblocks = []
     rawstart = mc.materialize(self.memmgr, allblocks, gcrootmap)
     p = rffi.cast(rffi.CArrayPtr(lltype.Char), rawstart)
     assert p[0] == 'X'
     assert p[1] == 'x'
     assert p[2] == 'Y'
     assert p[3] == 'y'
     assert p[4] == 'Z'
     assert p[5] == 'z'
     # 'allblocks' should be one block of length 6 + 15
     # (15 = alignment - 1) containing the range(rawstart, rawstart + 6)
     [(blockstart, blockend)] = allblocks
     assert blockend == blockstart + 6 + (mc.ALIGN_MATERIALIZE - 1)
     assert blockstart <= rawstart < rawstart + 6 <= blockend
     assert puts == [(rawstart + 2, ['a', 'b', 'c', 'd']),
                     (rawstart + 4, ['e', 'f', 'g'])]
Exemple #3
0
 def test_insert_gcroot_marker(self):
     puts = []
     class FakeGcRootMap:
         def register_asm_addr(self, retaddr, mark):
             puts.append((retaddr, mark))
     #
     mc = BlockBuilderMixin()
     mc.writechar('X')
     mc.writechar('x')
     mc.insert_gcroot_marker(['a', 'b', 'c', 'd'])
     mc.writechar('Y')
     mc.writechar('y')
     mc.insert_gcroot_marker(['e', 'f', 'g'])
     mc.writechar('Z')
     mc.writechar('z')
     #
     gcrootmap = FakeGcRootMap()
     allblocks = []
     rawstart = mc.materialize(self.memmgr, allblocks, gcrootmap)
     p = rffi.cast(rffi.CArrayPtr(lltype.Char), rawstart)
     assert p[0] == 'X'
     assert p[1] == 'x'
     assert p[2] == 'Y'
     assert p[3] == 'y'
     assert p[4] == 'Z'
     assert p[5] == 'z'
     assert allblocks == [(rawstart, rawstart + 6)]
     assert puts == [(rawstart + 2, ['a', 'b', 'c', 'd']),
                     (rawstart + 4, ['e', 'f', 'g'])]