edtlib: tests: refine coverage of Binding objects initialization

Add a series of unit tests which try to cover somewhat systematically
the possible inputs and what we finally get at the exit
of the Binding constructor.

Running the assumption that any (valid) YAML binding file is
something we can make a Binding instance with:
- check which properties are defined at which level (binding,
  child-binding, grandchild-binding, etc) and their specifications
  once the binding is initialized
- check how including bindings are permitted to specialize
  the specifications of inherited properties
- check the rules applied when overwriting a binding's description
  or compatible string (at the binding, child-binding, etc, levels)

Some tests covering known issues are disabled by default:
- this permits to document these issues
- while not causing CI errors (when running the python-devicetree
  unit tests)
- enabling these tests without causing errors should allow us
  to consider the related issues are fixed

Signed-off-by: Christophe Dufaza <chris@openmarl.org>
This commit is contained in:
Christophe Dufaza 2024-10-16 04:51:20 +02:00 committed by Benjamin Cabé
parent 4ad83e72e6
commit ee5c520326
33 changed files with 1992 additions and 0 deletions

View file

@ -0,0 +1,104 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Base include file for testing bindings initialization.
#
# Involves base property definitions ("type:", "description:", "const:",
# "required:", "enum:" and "default:") up to the grandchild-binding level.
#
# Binding:
# + prop-1
# + prop-2
# + prop-enum
# + prop-req
# + prop-const
# + prop-default
#
# Child-binding:
# + child-prop-1
# + child-prop-2
# + child-prop-enum
# + child-prop-req
# + child-prop-const
# + child-prop-default
#
# Grandchild-binding:
# + grandchild-prop-1
# + grandchild-prop-2
# + grandchild-prop-enum
# + grandchild-prop-req
# + grandchild-prop-const
# + grandchild-prop-default
description: Base property specifications.
properties:
prop-1:
description: Base property 1.
type: int
prop-2:
type: string
prop-enum:
type: string
required: false
enum:
- FOO
- BAR
prop-const:
type: int
const: 8
prop-req:
type: int
required: true
prop-default:
type: int
default: 1
child-binding:
description: Base child-binding description.
properties:
child-prop-1:
description: Base child-prop 1.
type: int
child-prop-2:
type: string
child-prop-enum:
type: string
required: false
enum:
- CHILD_FOO
- CHILD_BAR
child-prop-const:
type: int
const: 16
child-prop-req:
type: int
required: true
child-prop-default:
type: int
default: 2
child-binding:
description: Base grandchild-binding description.
properties:
grandchild-prop-1:
description: Base grandchild-prop 1.
type: int
grandchild-prop-2:
type: string
grandchild-prop-enum:
type: string
required: false
enum:
- GRANDCHILD_FOO
- GRANDCHILD_BAR
grandchild-prop-const:
type: int
const: 32
grandchild-prop-req:
type: int
required: true
grandchild-prop-default:
type: int
default: 3

View file

@ -0,0 +1,96 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Amends base properties specifications:
# - extends property specifications by adding definitions,
# e.g. setting a "default:" value
# - overwrites existing definitions of a property,
# e.g. change its "description:"
# - specify new properties
#
# The same kind of amendments are applied to the same properties
# at each level (binding, child-binding, grandchild-binding).
#
# | Definition | Extended for | Overwritten for |
# |----------------|--------------|-----------------|
# | description: | prop-2 | prop-1 |
# | required: | | prop-enum |
# | enum: | prop-2 | |
# | const: | prop-1 | |
# | default: | prop-2 | |
#
# Non authorized amendments, e.g. changing a "const:" value
# or downgrading a "required: true" definition are tested separately.
description: Amended description.
include: base.yaml
properties:
prop-1:
# The including binding is permitted to overwrite a property description.
description: Overwritten description.
# The including binding is permitted to set a "const:" value.
const: 0xf0
prop-2:
# The including binding is permitted to add a property description.
description: New description.
# The including binding is permitted to limit property values
# to an enumeration.
enum:
- EXT_FOO
- EXT_BAR
# The including binding is permitted to set a default value.
default: EXT_FOO
# The including binding is permitted to promote a property
# to requirement.
prop-enum:
required: true
# The including binding is permitted to define a new property.
prop-new:
type: int
# Same amendments at the child-binding level.
child-binding:
properties:
child-prop-1:
description: Overwritten description (child).
const: 0xf1
child-prop-2:
description: New description (child).
enum:
- CHILD_EXT_FOO
- CHILD_EXT_BAR
default: CHILD_EXT_FOO
child-prop-enum:
required: true
child-prop-new:
type: int
# Same amendments at the grandchild-binding level.
child-binding:
# Plus amended grandchild-binding description.
description: Amended grandchild-binding description.
properties:
grandchild-prop-1:
description: Overwritten description (grandchild).
const: 0xf2
grandchild-prop-2:
description: New description (grandchild).
enum:
- GRANDCHILD_EXT_FOO
- GRANDCHILD_EXT_BAR
default: GRANDCHILD_EXT_FOO
grandchild-prop-enum:
required: true
grandchild-prop-new:
type: int

View file

@ -0,0 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Inherit base specifications without modification.
include: base.yaml

View file

@ -0,0 +1,103 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Includes base bindings at multiple levels (binding,
# child-binding, grandchild-binding):
#
# include: base.yaml
# child-binding:
# include: base.yaml
# child-binding:
# include: base.yaml
#
# Which properties are specified at which levels is summarized bellow
# for convenience.
#
# Child-binding level:
# From top-level "include:" element.
# - child-prop-1 (amended)
# - child-prop-2
# - child-prop-enum
# From "child-binding: include:" element.
# - prop-1 (amended)
# - prop-2 (amended)
# - prop-enum (amended)
#
# Grandchild-binding level:
# From top-level "include:" element.
# - grandchild-prop-1 (amended)
# - grandchild-prop-2
# - grandchild-prop-enum
# From "child-binding: include:" element.
# - child-prop-1 (amended)
# - child-prop-2
# - child-prop-enum
# From "child-binding: child-binding: include:" element.
# - prop-1 (amended)
# - prop-2 (amended)
# - prop-enum (amended)
#
# Grand-grandchild-binding level:
# From "child-binding: include:" element.
# - child-prop-1
# - child-prop-2
# - child-prop-enum
# From "child-binding: child-binding: include:" element.
# - grandchild-prop-1
# - grandchild-prop-2
# - grandchild-prop-enum
description: Description of 'base_multi.yaml'.
include:
- name: base.yaml
child-binding:
property-allowlist: [child-prop-1, child-prop-2, child-prop-enum]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-2, grandchild-prop-enum]
child-binding:
include:
- name: base.yaml
property-allowlist: [prop-1, prop-2, prop-enum]
child-binding:
property-allowlist: [child-prop-1, child-prop-2, child-prop-enum]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-2, grandchild-prop-enum]
properties:
# Amend top-level "include:" element.
child-prop-1:
const: 0xf1
# Amend this "child-binding: include:" element.
prop-1:
const: 0xf1
prop-2:
description: New description (child).
prop-enum:
required: true
default: FOO
child-binding:
include:
- name: base.yaml
property-allowlist: [prop-1, prop-2, prop-enum]
child-binding:
property-allowlist: [child-prop-1, child-prop-2, child-prop-enum]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-2, grandchild-prop-enum]
properties:
# Amend above top-level "include:" element.
grandchild-prop-1:
const: 0xf2
# Amend above "child-binding: include:" element.
child-prop-1:
const: 0xf2
# Amend this "child-binding: child-binding: include:" element.
prop-1:
const: 0xf2
prop-2:
description: New description (grandchild).
prop-enum:
required: true
default: FOO

View file

@ -0,0 +1,18 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Test inheritance rules applied to compatible strings
# and bindings descriptions.
description: Binding description.
compatible: vnd,compat-desc
include: compat_desc_base.yaml
child-binding:
description: Child-binding description.
compatible: vnd,child-compat-desc
child-binding:
description: Grandchild-binding description.
compatible: vnd,grandchild-compat-desc

View file

@ -0,0 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Base file for testing inheritance rules applied to
# compatible strings and bindings descriptions.
description: Binding description (base).
compatible: vnd,compat-desc-base
child-binding:
description: Child-binding description (base).
compatible: vnd,child-compat-desc-base
child-binding:
description: Grandchild-binding description (base).
compatible: vnd,grandchild-compat-desc-base

View file

@ -0,0 +1,14 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Test consequences of inclusion order on inherited
# compatible strings and descriptions.
description: Binding description (multi).
compatible: vnd,compat-desc-multi
# Descriptions at the child-binding level and bellow
# will depend on inclusion order: the first wins.
include:
- compat_desc_base.yaml
- compat_desc.yaml

View file

@ -0,0 +1,93 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Binding file for testing diamond inheritance (top-bottom).
#
# diamond.yaml
# / \
# / \
# base_amend.yaml thing.yaml
# \ /
# \ /
# base.yaml
#
# Which properties are specified at which levels is summarized bellow
# for convenience.
#
# * Binding level.
# Diamond's left:
# - prop-1 (amended in base_amend.yaml)
# - prop-enum (amended in base_amend.yaml)
# - prop-default (inherited from base.yaml)
# Diamond's right:
# - prop-1 (last amended in thing.yaml)
# - prop-enum (amended in thing.yaml)
# - prop-thing (inherited from thing.yaml)
# Diamond's top:
# - prop-enum (last amended here)
# - prop-diamond
#
# * Child-binding level:
# Diamond's left:
# - child-prop-1 (amended in base_amend.yaml)
# - child-prop-enum (amended in base_amend.yaml)
# - child-prop-default (inherited from base.yaml)
# Diamond's right:
# - child-prop-1 (last amended in thing.yaml)
# - child-prop-enum (amended in thing.yaml)
# - child-prop-thing (inherited from thing.yaml)
# Diamond's top:
# - child-prop-enum (last amended here)
# - child-prop-diamond
#
# * Grandchild-binding level:
# Diamond's left:
# - grandchild-prop-1 (amended in base_amend.yaml)
# - grandchild-prop-enum (amended in base_amend.yaml)
# - grandchild-prop-default (inherited from base.yaml)
# Diamond's right:
# - grandchild-prop-1 (last amended in thing.yaml)
# - grandchild-prop-enum (amended in thing.yaml)
# - grandchild-prop-thing (inherited from thing.yaml)
# Diamond's top:
# - grandchild-prop-enum (last amended here)
# - grandchild-prop-diamond
description: Diamond's top.
compatible: diamond
include:
# Diamond's left.
- name: base_amend.yaml
property-allowlist: [prop-1, prop-enum, prop-default]
child-binding:
property-allowlist: [child-prop-1, child-prop-enum, child-prop-default]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-enum, grandchild-prop-default]
# Diamond's right.
- name: thing.yaml
properties:
prop-diamond:
type: int
prop-enum:
description: Overwritten in diamond.yaml.
default: FOO
child-binding:
description: Diamond's child-binding.
properties:
child-prop-diamond:
type: int
child-prop-enum:
description: Overwritten in diamond.yaml (child).
default: CHILD_FOO
child-binding:
properties:
grandchild-prop-diamond:
type: int
grandchild-prop-enum:
description: Overwritten in diamond.yaml (grandchild).
default: GRANDCHILD_FOO

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding file allows a property which is not blocked
# in simple_blocklist.yaml: we should end up with this property.
include:
- name: simple_blocklist.yaml
property-allowlist: [prop-2]
child-binding:
property-allowlist: [child-prop-2]
child-binding:
property-allowlist: [grandchild-prop-2]

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding file allows only properties that are not allowed
# in simple_allowlist.yaml: we should end up with no property at all.
include:
- name: simple_allowlist.yaml
property-allowlist: [prop-3]
child-binding:
property-allowlist: [child-prop-3]
child-binding:
property-allowlist: [grandchild-prop-3]

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding file blocks all properties not blocked
# in simple_filter.yaml: we should end up with no property at all.
include:
- name: simple_blocklist.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]

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "const:" value
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
properties:
child-prop-const:
const: 999

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "default:" value
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
properties:
child-prop-default:
default: 999

View file

@ -0,0 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to change the "enum:" values
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
properties:
child-prop-enum:
enum:
- OTHER_FOO
- OTHER_BAR

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override "required: true"
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
properties:
child-prop-req:
required: false

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "type:"
# of an inherited property.
include: base.yaml
child-binding:
properties:
child-prop-1:
type: string

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "const:" value
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
child-binding:
properties:
grandchild-prop-const:
const: 999

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "default:" value
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
child-binding:
properties:
grandchild-prop-default:
default: 999

View file

@ -0,0 +1,14 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to change the "enum:" values
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
child-binding:
properties:
grandchild-prop-enum:
enum:
- OTHER_FOO
- OTHER_BAR

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override "required: true"
# in a property specification inherited from an included file.
include: base.yaml
child-binding:
child-binding:
properties:
grandchild-prop-req:
required: false

View file

@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "type:"
# of an inherited property.
include: base.yaml
child-binding:
child-binding:
properties:
grandchild-prop-1:
type: string

View file

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "const:" value
# in a property specification inherited from an included file.
#
# Bindings, child-bindings and grandchild-bindings have
# to be tested separately, see also:
# - invalid_child_propconst.yaml
# - invalid_grandchild_propconst.yaml
include: base.yaml
properties:
prop-const:
const: 999

View file

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "default:" value
# in a property specification inherited from an included file.
#
# Bindings, child-bindings and grandchild-bindings have
# to be tested separately, see also:
# - invalid_child_propdefault.yaml
# - invalid_grandchild_propdefault.yaml
include: base.yaml
properties:
prop-default:
default: 999

View file

@ -0,0 +1,17 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to change the "enum:" values
# in a property specification inherited from an included file.
#
# Bindings, child-bindings and grandchild-bindings have
# to be tested separately, see also:
# - invalid_child_propenum.yaml
# - invalid_grandchild_propenum.yaml
include: base.yaml
properties:
prop-enum:
enum:
- OTHER_FOO
- OTHER_BAR

View file

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override "required: true"
# in a property specification inherited from an included file.
#
# Bindings, child-bindings and grandchild-bindings have
# to be tested separately, see also:
# - invalid_child_propreq.yaml
# - invalid_grandchild_propreq.yaml
include: base.yaml
properties:
prop-req:
required: false

View file

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# This binding should not try to override the "type:"
# of an inherited property.
#
# Bindings, child-bindings and grandchild-bindings have
# to be tested separately, see also:
# - invalid_child_protype.yaml
# - invalid_grandchild_proptype.yaml
include: base.yaml
properties:
prop-1:
type: string

View file

@ -0,0 +1,30 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Base properties for testing property filters propagation
# 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

View file

@ -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, prop-2]
child-binding:
property-allowlist: [child-prop-1, child-prop-2]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-2]

View file

@ -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-1]
child-binding:
property-blocklist: [child-prop-1]
child-binding:
property-blocklist: [grandchild-prop-1]

View file

@ -0,0 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Inherits property specifications without modification.
include: simple.yaml

View file

@ -0,0 +1,72 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Right (included last) YAML file for testing diamond inheritance.
#
# Amends base.yaml.
#
# Binding level:
# - prop-1 (amended)
# - prop-enum (amended)
# - prop-thing (new property)
#
# Child-binding level:
# - child-prop-1 (amended)
# - child-prop-enum (amended)
# - child-prop-thing (new property)
#
# Grandchild-binding level:
# - grandchild-prop-1 (amended)
# - grandchild-prop-enum (amended)
# - grandchild-prop-thing (new property)
description: Description of 'thing.yaml'.
include:
- name: base.yaml
property-allowlist: [prop-1, prop-enum]
child-binding:
property-allowlist: [child-prop-1, child-prop-enum]
child-binding:
property-allowlist: [grandchild-prop-1, grandchild-prop-enum]
properties:
prop-1:
default: 1
# Diamond inheritance in diamond.yaml: should overwrite
# the amended description from base_amend.yaml.
description: Overwritten in thing.yaml.
prop-enum:
# This is the definition inherited from base.yaml.
#
# Diamond inheritance in diamond.yaml: should be ORed
# with the definition inherited via base_amend.yaml.
required: false
prop-thing:
description: Thing property.
type: int
child-binding:
description: Child-binding description (thing).
properties:
child-prop-1:
description: Overwritten in thing.yaml (child).
default: 2
child-prop-enum:
required: false
child-prop-thing:
description: Thing child-binding property.
type: int
child-binding:
description: Grandchild-binding description (thing).
properties:
grandchild-prop-1:
description: Overwritten in thing.yaml (grandchild).
default: 3
grandchild-prop-enum:
required: false
grandchild-prop-thing:
description: Thing grandchild-binding property.
type: int

View file

@ -0,0 +1,20 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Top level binding file (device binding) for testing
# descriptions and compatible strings.
description: The Thing device.
compatible: "vnd,thing"
include:
- name: base_amend.yaml
- name: thing.yaml
child-binding:
compatible: "vnd,thing-child"
description: The Thing's child-binding.
child-binding:
compatible: "vnd,thing-grandchild"
description: The Thing's grandchild-binding.

File diff suppressed because it is too large Load diff