Skip to content

Commit

Permalink
edtlib: tests: cover basics of filtering inherited properties
Browse files Browse the repository at this point in the history
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: Christophe Dufaza <[email protected]>
  • Loading branch information
dottspina authored and mark-inderhees committed Nov 7, 2024
1 parent 2d17437 commit 0a8ba9e
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Inherits property specifications without modification.

include: simple.yaml
112 changes: 112 additions & 0 deletions scripts/dts/python-devicetree/tests/test_edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down

0 comments on commit 0a8ba9e

Please sign in to comment.