Пример #1
0
def test_shadowreg_yml_invalid_computed(tmpdir, data_dir):
    """Test Shadow Registers - INVALID computed configuration."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir,
                                     TEST_DATABASE_BAD_COMPUTED_FUNC))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    test_val = bytearray(32)
    for i in range(32):
        test_val[i] = i

    shadowregs.set_register("REG1", 0x12345678)
    shadowregs.set_register("REG2", 0x4321)
    shadowregs.set_register("REG_INVERTED_AP", 0xA5A5A5A5)
    shadowregs.set_register("REG_BIG", test_val)
    shadowregs.set_register("REG_BIG_REV", test_val)

    assert shadowregs.get_register("REG1") == 0x12345678.to_bytes(4, "big")
    assert shadowregs.get_register("REG2") == 0x00004321.to_bytes(4, "big")
    assert shadowregs.get_register("REG_INVERTED_AP") == 0xA5A5A5A5.to_bytes(
        4, "big")
    assert shadowregs.get_register("REG_BIG") == test_val
    assert shadowregs.get_register("REG_BIG_REV") == test_val

    shadowregs.create_yml_config(os.path.join(tmpdir, "sh_regs.yml"),
                                 raw=False)

    shadowregs1 = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    with pytest.raises(SPSDKError):
        shadowregs1.load_yml_config(os.path.join(tmpdir, "sh_regs.yml"))
Пример #2
0
def test_shadowreg_basic(data_dir):
    """Test Shadow Registers - Basic test."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    assert shadowregs.device == TEST_DEV_NAME
Пример #3
0
def test_shadowreg_get_reg_invalid(data_dir):
    """Test Shadow Registers - another INVALID cases of get registers."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    with pytest.raises(SPSDKError):
        shadowregs.get_register("REG1_Invalid")
Пример #4
0
def test_shadowreg_set_reg_invalid(data_dir):
    """Test Shadow Registers - INVALID cases of set and get registers."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    with pytest.raises(SPSDKError):
        shadowregs.set_register("REG1", 0x1234567800004321)

    with pytest.raises(SPSDKError):
        shadowregs.set_register("REG1_Invalid", 0x12345678)
Пример #5
0
def test_shadowreg_invalid_probe(data_dir):
    """Test Shadow Registers - INVALID probe used for constructor."""
    probe = None
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    with pytest.raises(DP.SPSDKDebugProbeError):
        shadowregs.set_register("REG1", 0x12345678)

    with pytest.raises(DP.SPSDKDebugProbeError):
        shadowregs.get_register("REG1")
Пример #6
0
def test_shadowreg_yml_none_existing(data_dir):
    """Test Shadow Registers - None existing YML configuration."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    test_val = bytearray(32)
    for i in range(32):
        test_val[i] = i

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    with pytest.raises(SPSDKError):
        shadowregs.load_yml_config(os.path.join(data_dir, "sh_regs_none.yml"),
                                   raw=True)
Пример #7
0
def test_shadowreg_yml_corrupted(data_dir):
    """Test Shadow Registers - Corrupted YML configuration."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    test_val = bytearray(32)
    for i in range(32):
        test_val[i] = i

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    with pytest.raises(
        (SPSDKRegsErrorBitfieldNotFound, SPSDKRegsErrorRegisterNotFound)):
        shadowregs.load_yml_config(os.path.join(data_dir,
                                                "sh_regs_corrupted.yml"),
                                   raw=True)
Пример #8
0
def test_shadowreg_verify_write(data_dir):
    """Test Shadow Registers - Verify write to register test."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    shadowregs._write_shadow_reg(1, 0x12345678, verify=True)
    shadowregs._write_shadow_reg(1, 0x87654321, verify=False)

    assert probe.mem_reg_read(1) == 0x87654321

    probe.set_virtual_memory_substitute_data({1: [0x12345678, 0x5555AAAA]})
    with pytest.raises(SR.IoVerificationError):
        shadowregs._write_shadow_reg(1, 0x87654321, verify=True)

    assert probe.mem_reg_read(1) == 0x5555AAAA
Пример #9
0
def test_shadowreg_set_get_reg(data_dir):
    """Test Shadow Registers - Setting and getting register."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    test_val = bytearray(32)
    for i in range(32):
        test_val[i] = i

    shadowregs.set_register("REG1", 0x12345678)
    shadowregs.set_register("REG2", 0x4321)
    shadowregs.set_register("REG_INVERTED_AP", 0xA5A5A5A5)
    shadowregs.set_register("REG_BIG", test_val)
    shadowregs.set_register("REG_BIG_REV", test_val)

    assert shadowregs.get_register("REG1") == 0x12345678.to_bytes(4, "big")
    assert shadowregs.get_register("REG2") == 0x00004321.to_bytes(4, "big")
    assert shadowregs.get_register("REG_INVERTED_AP") == 0xA5A5A5A5.to_bytes(
        4, "big")
    assert shadowregs.get_register("REG_BIG") == test_val
    assert shadowregs.get_register("REG_BIG_REV") == test_val
Пример #10
0
def test_shadowreg_yml(data_dir, tmpdir):
    """Test Shadow Registers - Load YML configuration test."""
    probe = get_probe()
    config = get_config(os.path.join(data_dir, TEST_DATABASE))

    shadowregs = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)

    test_val = bytearray(32)
    for i in range(32):
        test_val[i] = i

    shadowregs.set_register("REG1", 0x12345678)
    shadowregs.set_register("REG2", 0x4321)
    shadowregs.set_register("REG_INVERTED_AP", 0xA5A5A5A5)
    shadowregs.set_register("REG_BIG", test_val)
    shadowregs.set_register("REG_BIG_REV", test_val)

    assert shadowregs.get_register("REG1") == 0x12345678.to_bytes(4, "big")
    assert shadowregs.get_register("REG2") == 0x00004321.to_bytes(4, "big")
    assert shadowregs.get_register("REG_INVERTED_AP") == 0xA5A5A5A5.to_bytes(
        4, "big")
    assert shadowregs.get_register("REG_BIG") == test_val
    assert shadowregs.get_register("REG_BIG_REV") == test_val

    shadowregs.create_yml_config(os.path.join(tmpdir, "sh_regs.yml"),
                                 raw=False)
    shadowregs.create_yml_config(os.path.join(tmpdir, "sh_regs_raw.yml"),
                                 raw=True)

    probe.clear()

    shadowregs_load_raw = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    shadowregs_load_raw.load_yml_config(os.path.join(tmpdir,
                                                     "sh_regs_raw.yml"),
                                        raw=True)
    shadowregs_load_raw.sets_all_registers()

    assert shadowregs_load_raw.get_register("REG1") == 0x12345678.to_bytes(
        4, "big")
    assert shadowregs_load_raw.get_register("REG2") == 0x00004321.to_bytes(
        4, "big")
    assert shadowregs_load_raw.get_register(
        "REG_INVERTED_AP") == 0xA5A5A5A5.to_bytes(4, "big")
    assert shadowregs_load_raw.get_register("REG_BIG") == test_val
    assert shadowregs_load_raw.get_register("REG_BIG_REV") == test_val

    probe.clear()

    shadowregs_load = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    shadowregs_load.load_yml_config(os.path.join(tmpdir, "sh_regs.yml"),
                                    raw=False)
    shadowregs_load.sets_all_registers()

    assert shadowregs_load.get_register("REG1") == b"\x80\x34\x56\x28"
    assert shadowregs_load.get_register("REG2") == b"\x00\x00\x03!"
    assert shadowregs_load.get_register(
        "REG_INVERTED_AP") == b"\x7f\xcb\xa9\xd7"
    assert shadowregs_load.get_register("REG_BIG") == test_val
    assert shadowregs_load.get_register("REG_BIG_REV") == test_val

    probe.clear()

    shadowregs_load2 = SR.ShadowRegisters(probe, config, TEST_DEV_NAME)
    shadowregs_load2.load_yml_config(os.path.join(tmpdir, "sh_regs_raw.yml"),
                                     raw=False)
    shadowregs_load2.sets_all_registers()

    assert shadowregs_load2.get_register("REG1") == b"\x80\x34\x56\x28"
    assert shadowregs_load2.get_register("REG2") == b"\x00\x00\x03!"
    assert shadowregs_load2.get_register(
        "REG_INVERTED_AP") == b"\x7f\xcb\xa9\xd7"
    assert shadowregs_load2.get_register("REG_BIG") == test_val
    assert shadowregs_load2.get_register("REG_BIG_REV") == test_val