Ejemplo n.º 1
0
def test_coredump_writer(gdb_base_fixture, snapshot):
    from memfault_gdb import ArmCortexMCoredumpArch, MemfaultCoredumpWriter, Section

    arch = ArmCortexMCoredumpArch()
    cd_writer = MemfaultCoredumpWriter(arch)
    cd_writer.device_serial = "device_serial"
    cd_writer.firmware_version = "1.2.3"
    cd_writer.hardware_revision = "gdb-proto"
    cd_writer.trace_reason = 5
    cd_writer.regs = [
        {
            "r0": 4 * b"\x00",
            "r1": 4 * b"\x01",
            "r2": 4 * b"\x02",
            "r3": 4 * b"\x03",
            "r4": 4 * b"\x04",
            "r5": 4 * b"\x05",
            "r6": 4 * b"\x06",
            "r7": 4 * b"\x07",
            "r8": 4 * b"\x08",
            "r9": 4 * b"\x09",
            "r10": 4 * b"\x0A",
            "r11": 4 * b"\x0B",
            "r12": 4 * b"\x0C",
            "sp": 4 * b"\x0D",
            "lr": 4 * b"\x0E",
            "pc": 4 * b"\x0F",
            "xpsr": 4 * b"\x10",
            "msp": 4 * b"\x11",
            "psp": 4 * b"\x12",
            "primask": 4 * b"\x13",
            "control": 4 * b"\x14",
        },
    ]
    section = Section(4, 32, ".test", "")
    section.data = b"hello world"
    cd_writer.add_section(section)

    f_out = BytesIO()
    cd_writer.write(f_out)
    f_out.seek(0)
    snapshot.assert_match(f_out.read().hex())
Ejemplo n.º 2
0
def test_coredump_writer():
    with mock.patch.dict("sys.modules", gdb=MagicMock()):
        from memfault_gdb import Section, MemfaultCoredumpWriter

    cd_writer = MemfaultCoredumpWriter()
    cd_writer.device_serial = "device_serial"
    cd_writer.firmware_version = "1.2.3"
    cd_writer.hardware_revision = "gdb-proto"
    cd_writer.trace_reason = 5
    cd_writer.regs = {
        "r0": 4 * b"\x00",
        "r1": 4 * b"\x01",
        "r2": 4 * b"\x02",
        "r3": 4 * b"\x03",
        "r4": 4 * b"\x04",
        "r5": 4 * b"\x05",
        "r6": 4 * b"\x06",
        "r7": 4 * b"\x07",
        "r8": 4 * b"\x08",
        "r9": 4 * b"\x09",
        "r10": 4 * b"\x0A",
        "r11": 4 * b"\x0B",
        "r12": 4 * b"\x0C",
        "sp": 4 * b"\x0D",
        "lr": 4 * b"\x0E",
        "pc": 4 * b"\x0F",
        "xpsr": 4 * b"\x10",
    }
    section = Section(4, 32, ".test", "")
    section.data = b"hello world"
    cd_writer.add_section(section)

    f_out = BytesIO()
    cd_writer.write(f_out)
    f_out.seek(0)
    fixture_bin = open(os.path.join(script_dir, "fixture.bin"), "rb").read()
    assert f_out.read() == fixture_bin