Exemplo n.º 1
0
def test_config_cmpa_yml(tmpdir):
    """Test PFR tool - Test CMPA configuration from YAML."""
    yaml = YAML()
    yaml.indent(sequence=4, offset=2)
    cmpa = CMPA("lpc55s6x")
    config = cmpa.get_yaml_config(exclude_computed=True)
    with open(tmpdir + "/config.yml", "w") as yml_file:
        yaml.dump(config, yml_file)

    config2 = cmpa.get_yaml_config(exclude_computed=False)
    with open(tmpdir + "/config2.yml", "w") as yml_file:
        yaml.dump(config2, yml_file)

    assert not filecmp.cmp(tmpdir + "/config.yml", tmpdir + "/config2.yml")

    cmpa2 = CMPA("lpc55s6x")
    cmpa2_pfr_cfg = PfrConfiguration(tmpdir + "/config.yml")
    cmpa2.set_config(cmpa2_pfr_cfg)
    out_config = cmpa2.get_yaml_config(exclude_computed=True)
    with open(tmpdir + "/out_config.yml", "w") as yml_file:
        yaml.dump(out_config, yml_file)

    assert filecmp.cmp(tmpdir + "/config.yml", tmpdir + "/out_config.yml")

    cmpa2_pfr_cfg = PfrConfiguration(tmpdir + "/config2.yml")
    cmpa2.set_config(cmpa2_pfr_cfg, raw=True)
    out_config2 = cmpa2.get_yaml_config(exclude_computed=False)
    with open(tmpdir + "/out_config2.yml", "w") as yml_file:
        yaml.dump(out_config2, yml_file)

    assert filecmp.cmp(tmpdir + "/config2.yml", tmpdir + "/out_config2.yml")
Exemplo n.º 2
0
def test_json_yml_configs(data_dir):
    """Test of JSON and YML configuration, it must be equal."""
    cmpa_json = CMPA(
        "lpc55s6x",
        user_config=PfrConfiguration(f"{data_dir}/cmpa_96mhz.json"))
    cmpa_yml = CMPA("lpc55s6x",
                    user_config=PfrConfiguration(f"{data_dir}/cmpa_96mhz.yml"))

    assert cmpa_yml.get_yaml_config(False) == cmpa_json.get_yaml_config(False)
    assert cmpa_yml.get_yaml_config(True) == cmpa_json.get_yaml_config(True)
Exemplo n.º 3
0
def test_config_invalid_yaml_config():
    cfg = PfrConfiguration(device="lpc55s6x")
    cmpa = CMPA("lpc55s6x", user_config=cfg)
    cmpa.parse(bytes(512))
    cmpa.user_config.device = None
    with pytest.raises(SPSDKError, match="Device not found"):
        cmpa.get_yaml_config(exclude_computed=False)
    cfg = PfrConfiguration(device="lpc55s6x")
    cmpa = CMPA("lpc55s6x", user_config=cfg)
    cmpa.parse(bytes(512))
    cmpa.user_config.type = None
    with pytest.raises(SPSDKError, match="Type not found"):
        cmpa.get_yaml_config(exclude_computed=False)
Exemplo n.º 4
0
def test_config_cmpa():
    """Test PFR tool - Test CMPA configuration."""
    cmpa = CMPA("lpc55s6x")
    config = cmpa.generate_config()
    config2 = cmpa.generate_config(exclude_computed=False)

    assert config != config2

    cmpa2 = CMPA("lpc55s6x", user_config=PfrConfiguration(config2))
    cmpa2.parse(bytes(512))
    out = cmpa2.get_yaml_config(exclude_computed=False)

    assert out == config2