Skip to content

Commit c58d676

Browse files
dottspinammahadevan108
authored andcommitted
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: Christophe Dufaza <[email protected]>
1 parent 0b946df commit c58d676

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
#
3+
# Base properties for testing property filters up to
4+
# the grandchild-binding level.
5+
6+
properties:
7+
prop-1:
8+
type: int
9+
prop-2:
10+
type: int
11+
prop-3:
12+
type: int
13+
14+
child-binding:
15+
properties:
16+
child-prop-1:
17+
type: int
18+
child-prop-2:
19+
type: int
20+
child-prop-3:
21+
type: int
22+
23+
child-binding:
24+
properties:
25+
grandchild-prop-1:
26+
type: int
27+
grandchild-prop-2:
28+
type: int
29+
grandchild-prop-3:
30+
type: int
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
#
3+
# Filter inherited property specifications
4+
# up to the grandchild-binding level.
5+
6+
include:
7+
- name: simple_inherit.yaml
8+
property-allowlist: [prop-1]
9+
child-binding:
10+
property-allowlist: [child-prop-1]
11+
child-binding:
12+
property-allowlist: [grandchild-prop-1]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
#
3+
# Filter inherited property specifications
4+
# up to the grandchild-binding level.
5+
6+
include:
7+
- name: simple_inherit.yaml
8+
property-blocklist: [prop-2, prop-3]
9+
child-binding:
10+
property-blocklist: [child-prop-2, child-prop-3]
11+
child-binding:
12+
property-blocklist: [grandchild-prop-2, grandchild-prop-3]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
#
3+
# Inherits property specifications without modification.
4+
5+
include: simple.yaml

scripts/dts/python-devicetree/tests/test_edtlib.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,118 @@ def test_include_filters():
365365
assert set(child.prop2specs.keys()) == {'child-prop-1', 'child-prop-2',
366366
'x', 'z'} # root level 'y' is blocked
367367

368+
def test_include_filters_inherited_bindings() -> None:
369+
'''Test the basics of filtering properties inherited via an intermediary binding file.
370+
371+
Use-case "B includes I includes X":
372+
- X is a base binding file, specifying common properties
373+
- I is an intermediary binding file, which includes X without modification
374+
nor filter
375+
- B includes I, filtering the properties it chooses to inherit
376+
with an allowlist or a blocklist
377+
378+
Checks that the properties inherited from X via I are actually filtered
379+
as B intends to.
380+
'''
381+
fname2path = {
382+
# Base binding file, specifies a few properties up to the grandchild-binding level.
383+
"simple.yaml": "test-bindings-include/simple.yaml",
384+
# 'include:'s the base file above, without modification nor filter
385+
"simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
386+
}
387+
with from_here():
388+
binding = edtlib.Binding(
389+
# Filters inherited specifications with an allowlist.
390+
"test-bindings-include/simple_filter_allowlist.yaml",
391+
fname2path,
392+
require_compatible=False,
393+
require_description=False,
394+
)
395+
# Only property allowed.
396+
assert {"prop-1"} == set(binding.prop2specs.keys())
397+
398+
with from_here():
399+
binding = edtlib.Binding(
400+
# Filters inherited specifications with a blocklist.
401+
"test-bindings-include/simple_filter_blocklist.yaml",
402+
fname2path,
403+
require_compatible=False,
404+
require_description=False,
405+
)
406+
# Only non blocked property.
407+
assert {"prop-1"} == set(binding.prop2specs.keys())
408+
409+
def test_include_filters_inherited_child_bindings() -> None:
410+
'''Test the basics of filtering properties inherited via an intermediary binding file
411+
(child-binding level).
412+
413+
See also: test_include_filters_inherited_bindings()
414+
'''
415+
fname2path = {
416+
"simple.yaml": "test-bindings-include/simple.yaml",
417+
"simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
418+
}
419+
with from_here():
420+
binding = edtlib.Binding(
421+
"test-bindings-include/simple_filter_allowlist.yaml",
422+
fname2path,
423+
require_compatible=False,
424+
require_description=False,
425+
)
426+
assert binding.child_binding
427+
child_binding = binding.child_binding
428+
# Only property allowed.
429+
assert {"child-prop-1"} == set(child_binding.prop2specs.keys())
430+
431+
with from_here():
432+
binding = edtlib.Binding(
433+
"test-bindings-include/simple_filter_blocklist.yaml",
434+
fname2path,
435+
require_compatible=False,
436+
require_description=False,
437+
)
438+
# Only non blocked property.
439+
assert binding.child_binding
440+
child_binding = binding.child_binding
441+
assert {"child-prop-1"} == set(child_binding.prop2specs.keys())
442+
443+
def test_include_filters_inherited_grandchild_bindings() -> None:
444+
'''Test the basics of filtering properties inherited via an intermediary binding file
445+
(grandchild-binding level).
446+
447+
See also: test_include_filters_inherited_bindings()
448+
'''
449+
fname2path = {
450+
"simple.yaml": "test-bindings-include/simple.yaml",
451+
"simple_inherit.yaml": "test-bindings-include/simple_inherit.yaml",
452+
}
453+
with from_here():
454+
binding = edtlib.Binding(
455+
"test-bindings-include/simple_filter_allowlist.yaml",
456+
fname2path,
457+
require_compatible=False,
458+
require_description=False,
459+
)
460+
assert binding.child_binding
461+
child_binding = binding.child_binding
462+
assert child_binding.child_binding
463+
grandchild_binding = child_binding.child_binding
464+
# Only property allowed.
465+
assert {"grandchild-prop-1"} == set(grandchild_binding.prop2specs.keys())
466+
467+
with from_here():
468+
binding = edtlib.Binding(
469+
"test-bindings-include/simple_filter_blocklist.yaml",
470+
fname2path,
471+
require_compatible=False,
472+
require_description=False,
473+
)
474+
assert binding.child_binding
475+
child_binding = binding.child_binding
476+
assert child_binding.child_binding
477+
grandchild_binding = child_binding.child_binding
478+
# Only non blocked property.
479+
assert {"grandchild-prop-1"} == set(grandchild_binding.prop2specs.keys())
368480

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

0 commit comments

Comments
 (0)