Exemplo n.º 1
0
def test_writedata_cmd_equality():
    cmd = CmdWriteData(data=[(0, 1)])
    cmd_other = CmdWriteData()
    nop = CmdNop()
    assert cmd != nop
    assert cmd == cmd
    assert cmd != cmd_other
Exemplo n.º 2
0
def dcd_in_python() -> SegDCD:
    """Create DCD in python code."""
    dcd = SegDCD(enabled=True)
    dcd.append(
        CmdWriteData(
            ops=EnumWriteOps.WRITE_VALUE,
            data=(
                (0x30340004, 0x4F400005),
                (0x30340004, 0x4F400005),
                (0x30340004, 0x4F400005),
                (0x30340004, 0x4F400005),
            ),
        ))
    dcd.append(
        CmdWriteData(ops=EnumWriteOps.CLEAR_BITMASK,
                     data=((0x307900C4, 0x00000001), )))
    dcd.append(
        CmdWriteData(ops=EnumWriteOps.SET_BITMASK,
                     data=((0x307900C4, 0x00000001), )))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ALL_CLEAR,
                     address=0x307900C4,
                     mask=0x00000001))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ALL_CLEAR,
                     address=0x307900C4,
                     mask=0x00000001,
                     count=5))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ANY_CLEAR,
                     address=0x307900C4,
                     mask=0x00000001))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ANY_CLEAR,
                     address=0x307900C4,
                     mask=0x00000001,
                     count=5))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ALL_SET,
                     address=0x307900C4,
                     mask=0x00000001))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ALL_SET,
                     address=0x307900C4,
                     mask=0x00000001,
                     count=5))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ANY_SET,
                     address=0x307900C4,
                     mask=0x00000001))
    dcd.append(
        CmdCheckData(ops=EnumCheckOps.ANY_SET,
                     address=0x307900C4,
                     mask=0x00000001,
                     count=5))
    dcd.append(CmdNop())
    return dcd
Exemplo n.º 3
0
def test_SegCSF_repr_info():
    csf_seg = SegCSF()
    assert "CSF <Commands:" in repr(csf_seg)
    csf_seg.append_command(
        CmdWriteData(ops=EnumWriteOps.WRITE_VALUE,
                     data=[(0x30340004, 0x4F400005)]))
    assert "Write Data Command" in csf_seg.info()
Exemplo n.º 4
0
def ref_csf_obj():
    # Prepare reference CSF object
    obj = SegCSF(enabled=True)
    obj.append_command(CmdWriteData(ops=EnumWriteOps.WRITE_VALUE, data=((0x30340004, 0x4F400005),)))
    obj.append_command(
        CmdCheckData(ops=EnumCheckOps.ALL_CLEAR, address=0x307900C4, mask=0x00000001, count=10)
    )
    return obj
Exemplo n.º 5
0
def test_SegCSF_export_parse():
    obj = SegCSF(enabled=True)
    obj.append_command(
        CmdWriteData(ops=EnumWriteOps.WRITE_VALUE,
                     data=[(0x30340004, 0x4F400005)]))

    data = obj.export()
    csf_parsed = SegCSF.parse(data)
    assert data == csf_parsed.export()

    # with padding
    obj.padding_len = 0x10
    assert obj.export() == extend_block(data, obj.size + 0x10)
Exemplo n.º 6
0
def test_writedata_cmd_pop_append():
    cmd = CmdWriteData()
    cmd._header.length == 4
    cmd.append(5, 6)
    cmd.append(7, 8)
    cmd._header.length == 12
    cmd.pop(1)
    cmd._header.length == 4
Exemplo n.º 7
0
def test_write_value_cmd_clear():
    cmd = CmdWriteData()
    assert cmd._header.length == 4
    assert cmd._header.size == 4
    cmd.append(0xff, 5)
    assert cmd._header.length == 12
    assert cmd._header.size == 4
    cmd.clear()
    assert cmd._header.length == 4
    assert cmd._header.size == 4
Exemplo n.º 8
0
def test_write_value_cmd_get_set_iter():
    cmd = CmdWriteData()
    cmd.append(9, 9)
    assert len(cmd) == 1
    cmd[0] = [5, 6]
    assert cmd[0] == [5, 6]
    cmd.append(5, 6)
    my_iter = iter(cmd)
    assert next(my_iter) == [5, 6]
    assert next(my_iter) == [5, 6]
Exemplo n.º 9
0
def test_write_value_cmd_basic(input_data):
    """ Basic test with input data in format: list """
    cmd = CmdWriteData(data=input_data)

    cmd.num_bytes = 1
    assert cmd._header.param == 1
    cmd.num_bytes = 2
    assert cmd._header.param == 2
    cmd.num_bytes = 4
    assert cmd._header.param == 4

    cmd.ops = EnumWriteOps.CLEAR_BITMASK
    assert cmd._header.param == 20

    assert "CmdWriteData" in repr(cmd)
Exemplo n.º 10
0
def ref_dcd_obj():
    # Prepare reference DCD object
    obj = SegDCD(enabled=True)
    obj.append(
        CmdWriteData(
            ops=EnumWriteOps.WRITE_VALUE,
            data=[(0x400FC010, 0x4F400005), (0x400FC010, 0x4F463645), (0x400FC010, 0xA54EF14A)],
        )
    )
    obj.append(
        CmdWriteData(
            ops=EnumWriteOps.WRITE_CLEAR_BITS,
            data=[(0x402F0008, 0x00000001), (0x402F0008, 0x00000002), (0x402F0008, 0x00000003)],
        )
    )
    obj.append(
        CmdWriteData(
            ops=EnumWriteOps.SET_BITMASK,
            data=[(0x400D8158, 0x00000009), (0x400D8158, 0x0000000A), (0x400D8158, 0x000000B4)],
        )
    )
    obj.append(
        CmdCheckData(ops=EnumCheckOps.ALL_CLEAR, address=0x401F83F4, mask=0x000000AF, count=5)
    )
    obj.append(CmdCheckData(ops=EnumCheckOps.ALL_CLEAR, address=0x401F83F4, mask=0x000000A1))
    obj.append(
        CmdCheckData(ops=EnumCheckOps.ANY_CLEAR, address=0x400D8150, mask=0x000000FF, count=3)
    )
    obj.append(CmdCheckData(ops=EnumCheckOps.ANY_CLEAR, address=0x400D8150, mask=0x00000004))
    obj.append(CmdCheckData(ops=EnumCheckOps.ALL_SET, address=0x402F0008, mask=0x00000006))
    obj.append(CmdCheckData(ops=EnumCheckOps.ALL_SET, address=0x402F0008, mask=0x00000AF3, count=2))
    obj.append(CmdCheckData(ops=EnumCheckOps.ANY_SET, address=0x400D8158, mask=0x00000009))
    obj.append(CmdCheckData(ops=EnumCheckOps.ANY_SET, address=0x400D8158, mask=0xB00E60E1))
    obj.append(CmdCheckData(ops=EnumCheckOps.ANY_CLEAR, address=0x400D8158, mask=0x000F00A2))
    obj.append(CmdCheckData(ops=EnumCheckOps.ANY_CLEAR, address=0x400D8158, mask=0xA00F60C1))
    obj.append(CmdWriteData(ops=EnumWriteOps.WRITE_CLEAR_BITS, data=[(0x401F8400, 0x00000001)]))
    obj.append(CmdWriteData(ops=EnumWriteOps.SET_BITMASK, data=[(0x401F8400, 0x00000000)]))
    obj.append(CmdWriteData(ops=EnumWriteOps.WRITE_CLEAR_BITS, data=[(0x401F8400, 0x00000000)]))
    obj.append(CmdWriteData(ops=EnumWriteOps.SET_BITMASK, data=[(0x401F8400, 0x00000001)]))
    obj.append(CmdNop())
    return obj
Exemplo n.º 11
0
def test_writedata_cmd_export_parse_with_data():
    cmd = CmdWriteData()
    cmd.append(5, 6)
    data = cmd.export()
    assert cmd == CmdWriteData.parse(data)
Exemplo n.º 12
0
def test_invalid_cmd_write_data():
    cmd = CmdWriteData()
    with pytest.raises(SPSDKError):
        cmd.num_bytes = 16
    with pytest.raises(SPSDKError):
        cmd.ops = 10
    with pytest.raises(SPSDKError):
        cmd = CmdWriteData(numbytes=8)
    with pytest.raises(SPSDKError):
        cmd = CmdWriteData(ops=9)
    cmd = CmdWriteData()
    with pytest.raises(SPSDKError):
        cmd.append(address=0xFFFFFFFFF, value=0)
    with pytest.raises(SPSDKError):
        cmd.append(address=0xFFFFFFFF, value=0xFFFFFFFFF)
    cmd.append(5, 6)
    cmd.append(7, 8)
    with pytest.raises(SPSDKError):
        cmd.pop(3)