Commit c58d6761 authored by Christophe Dufaza's avatar Christophe Dufaza Committed by Mahesh Mahadevan
Browse files

edtlib: tests: cover basics of filtering inherited properties



Use-case "B includes I includes X":
- X is a base binding file, specifying common properties
- I is an intermediary binding file, which includes X
  without modification nor filter
- B includes I, filtering the properties it chooses
  to inherit with an allowlist or a blocklist

Check that the properties inherited from X via I
are actually filtered as B intends to,
up to the grandchild-binding level.

Signed-off-by: default avatarChristophe Dufaza <chris@openmarl.org>
parent 0b946dfc
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
#
# Base properties for testing property filters up to
# the grandchild-binding level.

properties:
  prop-1:
    type: int
  prop-2:
    type: int
  prop-3:
    type: int

child-binding:
  properties:
    child-prop-1:
      type: int
    child-prop-2:
      type: int
    child-prop-3:
      type: int

  child-binding:
    properties:
      grandchild-prop-1:
        type: int
      grandchild-prop-2:
        type: int
      grandchild-prop-3:
        type: int
+12 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
#
# Filter inherited property specifications
# up to the grandchild-binding level.

include:
  - name: simple_inherit.yaml
    property-allowlist: [prop-1]
    child-binding:
      property-allowlist: [child-prop-1]
      child-binding:
        property-allowlist: [grandchild-prop-1]
+12 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
#
# Filter inherited property specifications
# up to the grandchild-binding level.

include:
  - name: simple_inherit.yaml
    property-blocklist: [prop-2, prop-3]
    child-binding:
      property-blocklist: [child-prop-2, child-prop-3]
      child-binding:
        property-blocklist: [grandchild-prop-2, grandchild-prop-3]
+5 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
#
# Inherits property specifications without modification.

include: simple.yaml
+112 −0
Original line number Diff line number Diff line
@@ -365,6 +365,118 @@ def test_include_filters():
        assert set(child.prop2specs.keys()) == {'child-prop-1', 'child-prop-2',
                                                'x', 'z'}  # root level 'y' is blocked

def test_include_filters_inherited_bindings() -> None:
    '''Test the basics of filtering properties inherited via an intermediary binding file.

    Use-case "B includes I includes X":
    - X is a base binding file, specifying common properties
    - I is an intermediary binding file, which includes X without modification
      nor filter
    - B includes I, filtering the properties it chooses to inherit
      with an allowlist or a blocklist

    Checks that the properties inherited from X via I are actually filtered
    as B intends to.
    '''
    fname2path = {
        # Base binding file, specifies a few properties up to the grandchild-binding level.
        "simple.yaml": "test-bindings-include/simple.yaml",
        # 'include:'s the base file above, without modification nor filter
        "simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
    }
    with from_here():
        binding = edtlib.Binding(
            # Filters inherited specifications with an allowlist.
            "test-bindings-include/simple_filter_allowlist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    # Only property allowed.
    assert {"prop-1"} == set(binding.prop2specs.keys())

    with from_here():
        binding = edtlib.Binding(
            # Filters inherited specifications with a blocklist.
            "test-bindings-include/simple_filter_blocklist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    # Only non blocked property.
    assert {"prop-1"} == set(binding.prop2specs.keys())

def test_include_filters_inherited_child_bindings() -> None:
    '''Test the basics of filtering properties inherited via an intermediary binding file
    (child-binding level).

    See also: test_include_filters_inherited_bindings()
    '''
    fname2path = {
        "simple.yaml": "test-bindings-include/simple.yaml",
        "simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
    }
    with from_here():
        binding = edtlib.Binding(
            "test-bindings-include/simple_filter_allowlist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    assert binding.child_binding
    child_binding = binding.child_binding
    # Only property allowed.
    assert {"child-prop-1"} == set(child_binding.prop2specs.keys())

    with from_here():
        binding = edtlib.Binding(
            "test-bindings-include/simple_filter_blocklist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    # Only non blocked property.
    assert binding.child_binding
    child_binding = binding.child_binding
    assert {"child-prop-1"} == set(child_binding.prop2specs.keys())

def test_include_filters_inherited_grandchild_bindings() -> None:
    '''Test the basics of filtering properties inherited via an intermediary binding file
    (grandchild-binding level).

    See also: test_include_filters_inherited_bindings()
    '''
    fname2path = {
        "simple.yaml": "test-bindings-include/simple.yaml",
        "simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
    }
    with from_here():
        binding = edtlib.Binding(
            "test-bindings-include/simple_filter_allowlist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    assert binding.child_binding
    child_binding = binding.child_binding
    assert child_binding.child_binding
    grandchild_binding = child_binding.child_binding
    # Only property allowed.
    assert {"grandchild-prop-1"} == set(grandchild_binding.prop2specs.keys())

    with from_here():
        binding = edtlib.Binding(
            "test-bindings-include/simple_filter_blocklist.yaml",
            fname2path,
            require_compatible=False,
            require_description=False,
        )
    assert binding.child_binding
    child_binding = binding.child_binding
    assert child_binding.child_binding
    grandchild_binding = child_binding.child_binding
    # Only non blocked property.
    assert {"grandchild-prop-1"} == set(grandchild_binding.prop2specs.keys())

def test_bus():
    '''Test 'bus:' and 'on-bus:' in bindings'''