Exemple #1
0
def test_bitfield_enums_invalid_name():
    """Test bitfield enums with invalid enum name."""
    parent_reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield = RegsBitField(
        parent_reg,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    parent_reg.add_bitfield(bitfield)
    bitfield.add_enum(
        RegsEnum(f"{TEST_ENUM_NAME}", 0, f"{TEST_ENUM_DESCR}",
                 TEST_BITFIELD_WIDTH))
    with pytest.raises(SPSDKError):
        bitfield.set_enum_value(f"Invalid Enum name")
def test_register():
    parent_reg = RegsRegister(TEST_REG_NAME, TEST_REG_OFFSET, TEST_REG_WIDTH,
                              TEST_REG_DESCR, TEST_REG_REV, TEST_REG_ACCESS)

    bitfield = RegsBitField(parent_reg, TEST_BITFIELD_NAME,
                            TEST_BITFILED_OFFSET, TEST_BITFILED_WIDTH,
                            TEST_BITFIELD_DESCR, TEST_BITFIELD_RESET_VAL,
                            TEST_BITFIELD_ACCESS)

    enum = RegsEnum(TEST_ENUM_NAME, 0, TEST_ENUM_DESCR)
    bitfield.add_enum(enum)

    parent_reg.add_bitfield(bitfield)

    printed_str = str(parent_reg)

    assert "Name:" in printed_str
    assert TEST_REG_NAME in printed_str
    assert TEST_REG_DESCR in printed_str
    assert "Width:" in printed_str
    assert "Access:" in printed_str
    assert "Bitfield" in printed_str
    assert TEST_BITFIELD_NAME in printed_str
    assert TEST_BITFIELD_DESCR in printed_str
    assert TEST_ENUM_NAME in printed_str
    assert TEST_ENUM_DESCR in printed_str
Exemple #3
0
def test_bitfield_has_enums():
    """Test bitfield has enums function."""
    parent_reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield = RegsBitField(
        parent_reg,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    parent_reg.add_bitfield(bitfield)

    assert bitfield.has_enums() is False
    enum = RegsEnum(TEST_ENUM_NAME, 0, TEST_ENUM_DESCR)
    bitfield.add_enum(enum)

    assert bitfield.has_enums() is True

    assert enum in bitfield.get_enums()
Exemple #4
0
def test_bitfield_find():
    """Test bitfield find function."""
    parent_reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield = RegsBitField(
        parent_reg,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    enum = RegsEnum(TEST_ENUM_NAME, 0, TEST_ENUM_DESCR)
    bitfield.add_enum(enum)

    parent_reg.add_bitfield(bitfield)

    assert bitfield == parent_reg.find_bitfield(TEST_BITFIELD_NAME)

    with pytest.raises(SPSDKRegsErrorBitfieldNotFound):
        parent_reg.find_bitfield("Invalid Name")
Exemple #5
0
def test_bitfield():
    """Basic bitfield test."""
    parent_reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield = RegsBitField(
        parent_reg,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    enum = RegsEnum(TEST_ENUM_NAME, 0, TEST_ENUM_DESCR)
    bitfield.add_enum(enum)

    parent_reg.add_bitfield(bitfield)

    printed_str = str(bitfield)

    assert "Name:" in printed_str
    assert "Offset:" in printed_str
    assert "Width:" in printed_str
    assert "Access:" in printed_str
    assert "Reset val:" in printed_str
    assert "Description:" in printed_str
    assert "Enum" in printed_str
Exemple #6
0
def test_bitfield_enums():
    """Test bitfield enums."""
    parent_reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield = RegsBitField(
        parent_reg,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    parent_reg.add_bitfield(bitfield)

    enums = []
    for index in range((1 << TEST_BITFIELD_WIDTH) - 1):
        enum = RegsEnum(f"{TEST_ENUM_NAME}{index}", index,
                        f"{TEST_ENUM_DESCR}{index}", TEST_BITFIELD_WIDTH)
        enums.append(enum)
        bitfield.add_enum(enum)

    enum_names = bitfield.get_enum_names()

    for index in range((1 << TEST_BITFIELD_WIDTH) - 1):
        assert index == bitfield.get_enum_constant(f"{TEST_ENUM_NAME}{index}")
        assert enums[index].name in enum_names

    for index in range((1 << TEST_BITFIELD_WIDTH)):
        bitfield.set_value(index)
        if index < (1 << TEST_BITFIELD_WIDTH) - 1:
            assert f"{TEST_ENUM_NAME}{index}" == bitfield.get_enum_value()
        else:
            assert index == bitfield.get_enum_value()

    for index in range((1 << TEST_BITFIELD_WIDTH) - 1):
        bitfield.set_enum_value(f"{TEST_ENUM_NAME}{index}")
        assert index == bitfield.get_value()

    for index in range((1 << TEST_BITFIELD_WIDTH) - 1):
        bitfield.set_enum_value(f"{index}")
        assert index == bitfield.get_value()

    with pytest.raises(SPSDKRegsErrorEnumNotFound):
        bitfield.get_enum_constant("Invalid name")
Exemple #7
0
def create_simple_regs():
    """Create siple reg structure with basic cases."""
    regs = Registers(TEST_DEVICE_NAME)

    reg1 = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    reg2 = RegsRegister(
        TEST_REG_NAME + "_2",
        TEST_REG_OFFSET + 4,
        TEST_REG_WIDTH,
        TEST_REG_DESCR + "_2",
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    bitfield1 = RegsBitField(
        reg2,
        TEST_BITFIELD_NAME,
        TEST_BITFIELD_OFFSET,
        TEST_BITFIELD_WIDTH,
        TEST_BITFIELD_DESCR,
        TEST_BITFIELD_RESET_VAL,
        TEST_BITFIELD_ACCESS,
    )

    bitfield2 = RegsBitField(
        reg2,
        TEST_BITFIELD_NAME + "_2",
        TEST_BITFIELD_OFFSET + TEST_BITFIELD_WIDTH,
        1,
        ".",
        0,
        TEST_BITFIELD_ACCESS,
    )
    enum1 = RegsEnum(TEST_ENUM_NAME, 0, TEST_ENUM_DESCR, 1)
    enum2 = RegsEnum(TEST_ENUM_NAME + "_2", 0, TEST_ENUM_DESCR + "_2", 1)
    bitfield2.add_enum(enum1)
    bitfield2.add_enum(enum2)
    reg2.add_bitfield(bitfield1)
    reg2.add_bitfield(bitfield2)
    regs.add_register(reg1)
    regs.add_register(reg2)

    return regs
def test_bitfield_enums():
    parent_reg = RegsRegister(TEST_REG_NAME, TEST_REG_OFFSET, TEST_REG_WIDTH,
                              TEST_REG_DESCR, TEST_REG_REV, TEST_REG_ACCESS)

    bitfield = RegsBitField(parent_reg, TEST_BITFIELD_NAME,
                            TEST_BITFILED_OFFSET, TEST_BITFILED_WIDTH,
                            TEST_BITFIELD_DESCR, TEST_BITFIELD_RESET_VAL,
                            TEST_BITFIELD_ACCESS)

    parent_reg.add_bitfield(bitfield)

    enums = []
    for n in range((1 << TEST_BITFILED_WIDTH) - 1):
        enum = RegsEnum(f"{TEST_ENUM_NAME}{n}", n, f"{TEST_ENUM_DESCR}{n}",
                        TEST_BITFILED_WIDTH)
        enums.append(enum)
        bitfield.add_enum(enum)

    enum_names = bitfield.get_enum_names()

    for n in range((1 << TEST_BITFILED_WIDTH) - 1):
        assert n == bitfield.get_enum_constant(f"{TEST_ENUM_NAME}{n}")
        assert enums[n].name in enum_names

    for n in range((1 << TEST_BITFILED_WIDTH)):
        bitfield.set_value(n)
        if n < (1 << TEST_BITFILED_WIDTH) - 1:
            assert f"{TEST_ENUM_NAME}{n}" == bitfield.get_enum_value()
        else:
            assert n == bitfield.get_enum_value()

    for n in range((1 << TEST_BITFILED_WIDTH) - 1):
        bitfield.set_enum_value(f"{TEST_ENUM_NAME}{n}")
        assert n == bitfield.get_value()

    with pytest.raises(EnumNotFound):
        bitfield.get_enum_constant("Invalid name")

    regs = Registers(TEST_DEVICE_NAME)

    regs.add_register(parent_reg)