Skip to content

Commit

Permalink
edtlib: tests: cover last modified of PropertySpec.path
Browse files Browse the repository at this point in the history
These tests show a known issue and will fail with
the version of edtlib at the time of writing.

See also: #78095

Signed-off-by: Christophe Dufaza <[email protected]>
  • Loading branch information
dottspina committed Oct 10, 2024
1 parent efdbace commit 4208824
Showing 1 changed file with 130 additions and 2 deletions.
132 changes: 130 additions & 2 deletions scripts/dts/python-devicetree/tests/test_edtlib_binding_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2024 Christophe Dufaza
# Copyright (c) 2024, Christophe Dufaza

"""Unit tests dedicated to edtlib.Binding objects initialization.
Expand Down Expand Up @@ -1007,6 +1006,135 @@ def test_bindings_propspecs_consistency() -> None:
binding = load_binding("test-bindings-init/diamond.yaml")
verify_binding_propspecs_consistency(binding)

def test_binding_propspecs_last_modified() -> None:
"""Verify the Last Modified Here semantic of PropertySpec.path.
This test verifies the binding level.
"""
binding = load_binding("test-bindings-init/base_inherit.yaml")
# All properties are inherited without modifications.
assert all(
"base.yaml" == _basename(propspec.path)
for propspec in binding.prop2specs.values()
)

binding = load_binding("test-bindings-init/base_amend.yaml")
assert all(
"base.yaml" == _basename(binding.prop2specs[prop].path)
for prop in (
"prop-default",
"prop-const",
"prop-req",
)
)
assert all(
"base_amend.yaml" == _basename(binding.prop2specs[prop].path)
for prop in (
# Amended.
"prop-1",
"prop-2",
"prop-enum",
# New.
"prop-new",
)
)

binding = load_binding("test-bindings-init/diamond.yaml")
assert "base.yaml" == _basename(binding.prop2specs["prop-default"].path)
assert all(
"thing.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("prop-1", "prop-thing")
)
assert all(
"diamond.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("prop-enum", "prop-diamond")
)

def test_child_binding_propspecs_last_modified() -> None:
"""Verify the Last Modified Here semantic of PropertySpec.path.
This test verifies the child-binding level.
"""
binding = child_binding_of("test-bindings-init/base_inherit.yaml")
# All properties are inherited without modifications.
assert all(
_basename(propspec.path) == "base.yaml"
for propspec in binding.prop2specs.values()
)

binding = child_binding_of("test-bindings-init/base_amend.yaml")
assert all(
_basename(binding.prop2specs[prop].path) == "base.yaml"
for prop in (
"child-prop-default",
"child-prop-const",
"child-prop-req",
)
)
assert all(
_basename(binding.prop2specs[prop].path) == "base_amend.yaml"
for prop in (
"child-prop-1",
"child-prop-2",
"child-prop-enum",
"child-prop-new",
)
)

binding = child_binding_of("test-bindings-init/diamond.yaml")
assert "base.yaml" == _basename(
binding.prop2specs["child-prop-default"].path
)
assert all(
"thing.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("child-prop-1", "child-prop-thing")
)
assert all(
"diamond.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("child-prop-enum", "child-prop-diamond")
)

def test_grandchild_binding_propspecs_last_modified() -> None:
"""Verify the Last Modified Here semantic of PropertySpec.path.
This test verifies the grandchild-binding level.
"""
binding = grandchild_binding_of("test-bindings-init/base_inherit.yaml")
# All properties are inherited without modifications.
assert all(
_basename(propspec.path) == "base.yaml"
for propspec in binding.prop2specs.values()
)

binding = grandchild_binding_of("test-bindings-init/base_amend.yaml")
assert all(
_basename(binding.prop2specs[prop].path) == "base.yaml"
for prop in (
"grandchild-prop-default",
"grandchild-prop-const",
"grandchild-prop-req",
)
)
assert all(
_basename(binding.prop2specs[prop].path) == "base_amend.yaml"
for prop in (
"grandchild-prop-1",
"grandchild-prop-2",
"grandchild-prop-enum",
"grandchild-prop-new",
)
)

binding = grandchild_binding_of("test-bindings-init/diamond.yaml")
assert "base.yaml" == _basename(
binding.prop2specs["grandchild-prop-default"].path
)
assert all(
"thing.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("grandchild-prop-1", "grandchild-prop-thing")
)
assert all(
"diamond.yaml" == _basename(binding.prop2specs[prop].path)
for prop in ("grandchild-prop-enum", "grandchild-prop-diamond")
)


# Borrowed from test_edtlib.py.
@contextlib.contextmanager
Expand Down

0 comments on commit 4208824

Please sign in to comment.