Esempio n. 1
0
def test_image_with_startup():
    archive = symbol.Archive()
    archive.symbols["$test.main"] = symbol.Symbol("text", b"",
                                                  types.FunctionType(None))
    _, bs = link(image.make_startup_for("$test.main", 0x0001), archive)
    assert bs == bytes([
        0x01,
        0x08,  # .prg header
        0x0B,
        0x08,  # addr of next BASIC line
        0x01,
        0x00,  # number of BASIC line
        0x9E,
        0x32,
        0x30,
        0x36,
        0x31,
        0x00,  # SYS2061
        0x00,
        0x00,  # BASIC end-of-program
        0x20,
        0x11,
        0x08,  # jsr $0811
        0x60,  # rts
    ])
Esempio n. 2
0
def test_roundtrip_archive(a):
    with io.BytesIO() as f:
        a.dump(f)
        packed = f.getvalue()

    with io.BytesIO(packed) as f:
        unpacked = symbol.Archive(f)

    assert unpacked.symbols == a.symbols
Esempio n. 3
0
def test_pack_archive():
    archive = symbol.Archive()
    archive.symbols["eggs"] = symbol.Symbol(
        section="text",
        data=b"spam",
        type_info=types.u32,
        relocations={0xCAFE: symbol.Relocation("beans", 7)},
    )
    with io.BytesIO() as f:
        archive.dump(f)
        assert f.getvalue() == simple_archive
Esempio n. 4
0
def test_unpack_archive():
    with io.BytesIO(simple_archive) as f:
        archive = symbol.Archive(f)
    assert list(archive.symbols) == ["eggs"]
    sym = archive.symbols["eggs"]
    assert sym.section == "text"
    assert sym.data == b"spam"
    assert sym.type_info == types.u32
    assert list(sym.relocations) == [0xCAFE]
    reloc = sym.relocations[0xCAFE]
    assert reloc.symbol == "beans"
    assert reloc.increment == 7
    assert reloc.byte == symbol.Relocation.full
Esempio n. 5
0
def archives(draw):
    @hs.composite
    def symbols(draw):
        return symbol.Symbol(
            section=draw(hs.text()),
            data=draw(hs.binary()),
            type_info=draw(type_infos()),
            relocations=draw(
                hs.dictionaries(
                    hs.integers(min_value=0, max_value=0xFFFF), relocations()
                )
            ),
        )

    archive = symbol.Archive()
    archive.symbols = draw(hs.dictionaries(hs.text(), symbols()))
    return archive
Esempio n. 6
0
def test_empty_image():
    archive = symbol.Archive()
    archive.symbols["$startup.__start"] = symbol.Symbol(
        "startup", b"", types.phantom)
    _, bs = link(archive)
    assert bs == bytes([0x01, 0x08])