Beispiel #1
0
def test_reg_config_get_devices(data_dir):
    """Test Register Config - get_devices function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))
    devices = reg_config.get_devices()

    assert "test_device1" in devices
    assert "test_device2" in devices
Beispiel #2
0
def test_reg_config_get_grouped_registers(data_dir):
    """Test Register Config - get_grouped_registers function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    grouped_registers = reg_config.get_grouped_registers("test_device1")
    assert grouped_registers[0]["name"] == "DeviceTest"
    grouped_registers = reg_config.get_grouped_registers("test_device2")
    assert grouped_registers[0]["name"] == "Test"
Beispiel #3
0
def test_reg_config_get_address(data_dir):
    """Test Register Config - get_address function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    addr = reg_config.get_address("test_device1")
    assert addr == "0xA5A5_1234"

    addr = reg_config.get_address("test_device2", remove_underscore=True)
    assert addr == "0x40000000"
Beispiel #4
0
def test_reg_config_get_latest_revision(data_dir):
    """Test Register Config - get_latest_revision function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    rev = reg_config.get_latest_revision("test_device1")
    assert rev == "x1"

    rev = reg_config.get_latest_revision("test_device2")
    assert rev == "b0"
Beispiel #5
0
def test_reg_config_get_revisions(data_dir):
    """Test Register Config - get_revisions function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    revs = reg_config.get_revisions("test_device1")
    assert "x0" in revs
    assert "x1" in revs

    revs = reg_config.get_revisions("test_device2")
    assert "b0" in revs
Beispiel #6
0
def test_reg_config_get_antipole_regs(data_dir):
    """Test Register Config - get_antipole_regs function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    antipole = reg_config.get_antipole_regs("test_device1")
    assert antipole["INVERTED_REG"] == "INVERTED_REG_AP"

    antipole = reg_config.get_antipole_regs("test_device2")
    assert antipole["INVERTED_REG"] == "INVERTED_REG_AP"

    antipole = reg_config.get_antipole_regs()
    assert antipole["INVERTED_REG"] == "INVERTED_REG_AP"
Beispiel #7
0
def test_reg_config_get_data_file(data_dir):
    """Test Register Config - get_data_file function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    data_file = reg_config.get_data_file("test_device1", "x0")
    assert os.path.join(data_dir, "test_device1_x0.xml") == data_file

    data_file = reg_config.get_data_file("test_device1", "x1")
    assert os.path.join(data_dir, "test_device1_x1.xml") == data_file

    data_file = reg_config.get_data_file("test_device2", "b0")
    assert os.path.join(data_dir, "test_device2_b0.xml") == data_file
Beispiel #8
0
def test_reg_config_get_computed_fields(data_dir):
    """Test Register Config - get_computed_fields function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    computed_fields = reg_config.get_computed_fields("test_device1")
    assert computed_fields["COMPUTED_REG"][
        "TEST_FIELD1"] == "computed_reg_test_field1"
    assert computed_fields["COMPUTED_REG"][
        "TEST_FIELD2"] == "computed_reg_test_field2"
    assert computed_fields["COMPUTED_REG2"][
        "TEST_FIELD1"] == "computed_reg2_test_field1"
    assert computed_fields["COMPUTED_REG2"][
        "TEST_FIELD2"] == "computed_reg2_test_field2"
Beispiel #9
0
def info(pass_obj: dict, output: str, open_result: bool) -> None:
    """The command generate HTML of Shadow registers."""
    config = RegConfig(pass_obj["config_file"])
    device = pass_obj["device"]
    revision = pass_obj["revision"]
    registers = Registers(device)
    rev = revision if revision != "latest" else config.get_latest_revision(
        device)
    registers.load_registers_from_xml(config.get_data_file(device, rev))
    html_output = registers.generate_html(
        f"{device} - Shadow Registers",
        f"The table with Shadow registers description for {device}",
    )
    with open(output, "w", encoding="utf-8") as f:
        f.write(html_output)

    if open_result:  # pragma: no cover # can't test opening the html document
        click.launch(f"{output}")
Beispiel #10
0
def _open_shadow_registers(pass_obj: Dict) -> ShadowRegisters:
    """Method opens ShadowRegisters object based on input arguments.

    :param pass_obj: Input dictionary with arguments.
    :return: Active ShadowRegisters object.
    :raises SPSDKError: Raised with any kind of problems with debug probe.
    """
    config_file = pass_obj["config_file"]
    interface = pass_obj["interface"]
    serial_no = pass_obj["serial_no"]
    debug_probe_params = pass_obj["debug_probe_params"]
    device = pass_obj["device"]
    revision = pass_obj["revision"]

    if device not in RegConfig.devices(config_file):
        raise SPSDKError(
            "Invalid or none device parameter(-dev). Use 'listdevs' command to get supported devices."
        )

    regs_cfg = RegConfig(config_file)

    try:
        debug_probes = DebugProbeUtils.get_connected_probes(
            interface=interface,
            hardware_id=serial_no,
            user_params=debug_probe_params)
        selected_probe = debug_probes.select_probe()
        debug_probe = selected_probe.get_probe(debug_probe_params)
        debug_probe.open()
        if not enable_debug(debug_probe):
            raise SPSDKError("Cannot enable debug interface")

        debug_probe.enable_memory_interface()
    except SPSDKError as exc:
        raise SPSDKError(
            f"Error with opening debug probe: ({str(exc)})") from exc

    return ShadowRegisters(debug_probe=debug_probe,
                           config=regs_cfg,
                           device=device,
                           revision=revision)
Beispiel #11
0
    def __init__(
        self,
        debug_probe: DebugProbe,
        config: RegConfig,
        device: str,
        revision: str = "latest",
    ) -> None:
        """Initialization of Shadow register class."""
        self.probe = debug_probe
        self.config = config
        self.device = device
        self.offset = int(
            self.config.get_address(self.device, remove_underscore=True), 16)

        self.regs = Registers(self.device)
        rev = revision or "latest"
        rev = rev if rev != "latest" else config.get_latest_revision(
            self.device)
        self.regs.load_registers_from_xml(
            config.get_data_file(self.device, rev),
            grouped_regs=config.get_grouped_registers(self.device),
        )

        # Set the computed field handler
        for reg, fields in self.config.get_computed_fields(
                self.device).items():
            reg_obj = self.regs.find_reg(reg)
            reg_obj.add_setvalue_hook(self.reg_computed_fields_handler, fields)

        # Set the antipolize handler
        for reg, antipole_reg in self.config.get_antipole_regs(
                self.device).items():
            src = self.regs.find_reg(reg)
            dst = self.regs.find_reg(antipole_reg)
            src.add_setvalue_hook(self.reg_antipolize_src_handler, dst)
            dst.add_setvalue_hook(self.reg_antipolize_dst_handler, src)
Beispiel #12
0
def test_reg_config_get_value(data_dir):
    """Test Register Config - get_value function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    ignored_fields = reg_config.get_value("ignored_fields", "test_device1")
    assert "FIELD" in ignored_fields

    ignored_fields = reg_config.get_value("ignored_fields", "test_device2")
    assert "FIELD_GENERAL" in ignored_fields

    ignored_fields = reg_config.get_value("ignored_fields", "invalid_device")
    assert "FIELD_GENERAL" in ignored_fields

    ignored_fields = reg_config.get_value("ignored_fields")
    assert "FIELD_GENERAL" in ignored_fields

    none_exist = reg_config.get_value("none_exist_key", default="Yuppie")
    assert "Yuppie" is none_exist

    none_exist = reg_config.get_value("none_exist_key")
    assert None is none_exist
Beispiel #13
0
def test_reg_config_get_computed_regs(data_dir):
    """Test Register Config - get_computed_registers function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    computed_regs = reg_config.get_computed_registers("test_device1")
    assert "COMPUTED_REG" in computed_regs

    computed_regs = reg_config.get_computed_registers("test_device2")
    assert "COMPUTED_REG_GENERAL" in computed_regs

    computed_regs = reg_config.get_computed_registers("invalid_device")
    assert "COMPUTED_REG_GENERAL" in computed_regs

    computed_regs = reg_config.get_computed_registers()
    assert "COMPUTED_REG_GENERAL" in computed_regs
Beispiel #14
0
def test_reg_config_get_seal_count(data_dir):
    """Test Register Config - get_seal_count function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    seal_count = reg_config.get_seal_count("test_device1")
    assert seal_count == 4

    seal_count = reg_config.get_seal_count("test_device2")
    assert seal_count == 8

    seal_count = reg_config.get_seal_count("invalid_device")
    assert seal_count == 8

    seal_count = reg_config.get_seal_count()
    assert seal_count == 8
Beispiel #15
0
def test_reg_config_get_ignored_fields(data_dir):
    """Test Register Config - get_ignored_fields function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    ignored_fields = reg_config.get_ignored_fields("test_device1")
    assert "FIELD" in ignored_fields

    ignored_fields = reg_config.get_ignored_fields("test_device2")
    assert "FIELD_GENERAL" in ignored_fields

    ignored_fields = reg_config.get_ignored_fields("invalid_device")
    assert "FIELD_GENERAL" in ignored_fields

    ignored_fields = reg_config.get_ignored_fields()
    assert "FIELD_GENERAL" in ignored_fields
Beispiel #16
0
def test_reg_config_get_ignored_registers(data_dir):
    """Test Register Config - get_ignored_registers function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    ignored_registers = reg_config.get_ignored_registers("test_device1")
    assert "IGNORED_REG" in ignored_registers

    ignored_registers = reg_config.get_ignored_registers("test_device2")
    assert "IGNORED_REG_GENERAL" in ignored_registers

    ignored_registers = reg_config.get_ignored_registers("invalid_device")
    assert "IGNORED_REG_GENERAL" in ignored_registers

    ignored_registers = reg_config.get_ignored_registers()
    assert "IGNORED_REG_GENERAL" in ignored_registers
Beispiel #17
0
def test_reg_config_get_seal_start_address(data_dir):
    """Test Register Config - get_seal_start_address function."""
    reg_config = RegConfig(os.path.join(data_dir, "reg_config.json"))

    seal_address = reg_config.get_seal_start_address("test_device1")
    assert seal_address == "COMPUTED_REG"

    seal_address = reg_config.get_seal_start_address("test_device2")
    assert seal_address == "COMPUTED_REG2"

    seal_address = reg_config.get_seal_start_address("invalid_device")
    assert seal_address == "COMPUTED_REG2"

    seal_address = reg_config.get_seal_start_address()
    assert seal_address == "COMPUTED_REG2"
Beispiel #18
0
    def _load_config(cls) -> RegConfig:
        """Loads the PFR block configuration file.

        :return: PFR block configuration database.
        """
        return RegConfig(os.path.join(cls.CONFIG_DIR, cls.CONFIG_FILE))
Beispiel #19
0
def get_config(database_filename):
    """Help function to get RegConfig - used in tests."""
    config = RegConfig(database_filename)
    return config
Beispiel #20
0
def test_reg_config_get_devices_class(data_dir):
    """Test Register Config - get_devices class function."""
    devices = RegConfig.devices(os.path.join(data_dir, "reg_config.json"))

    assert "test_device1" in devices
    assert "test_device2" in devices
Beispiel #21
0
def test_reg_invalid(data_dir):
    reg_config = RegConfig(os.path.join(data_dir, "reg_config_invalid.json"))
    with pytest.raises(SPSDKError, match="Invalid seal start address name"):
        reg_config.get_seal_start_address("test_device1")
    with pytest.raises(SPSDKError, match="Invalid seal count"):
        reg_config.get_seal_count("test_device1")
Beispiel #22
0
def listdevs(pass_obj: dict) -> None:
    """The command prints a list of supported devices."""
    config_filename = pass_obj["config_file"]
    for index, device in enumerate(RegConfig.devices(config_filename)):
        click.echo(f"{index:03}: {device}")