Skip to content

Commit

Permalink
scripts: check_init_priorities: drop recursive child parsing
Browse files Browse the repository at this point in the history
Now that child nodes are handled by edtlib there's no need to parse
child nodes in check_init_priorities anymore.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Sep 14, 2023
1 parent c5d86f8 commit 58c015a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
15 changes: 2 additions & 13 deletions scripts/build/check_init_priorities.py
Expand Up @@ -272,23 +272,12 @@ def _check_dep(self, dev_ord, dep_ord):
self.log.info(
f"{dev_node.path} {dev_prio} > {dep_node.path} {dep_prio}")

def _check_edt_r(self, dev_ord, dev):
"""Recursively check for dependencies of a device."""
for dep in dev.depends_on:
self._check_dep(dev_ord, dep.dep_ordinal)
if dev._binding and dev._binding.child_binding:
for child in dev.children.values():
if "compatible" in child.props:
continue
if dev._binding.path != child._binding.path:
continue
self._check_edt_r(dev_ord, child)

def check_edt(self):
"""Scan through all known devices and validate the init priorities."""
for dev_ord in self._dev_priorities:
dev = self._ord2node[dev_ord]
self._check_edt_r(dev_ord, dev)
for dep in dev.depends_on:
self._check_dep(dev_ord, dep.dep_ordinal)

def _parse_args(argv):
"""Parse the command line arguments."""
Expand Down
48 changes: 14 additions & 34 deletions scripts/build/check_init_priorities_test.py
Expand Up @@ -323,51 +323,31 @@ def test_check_ignored(self, mock_vinit):

@mock.patch("check_init_priorities.Validator._check_dep")
@mock.patch("check_init_priorities.Validator.__init__", return_value=None)
def test_check_edt_r(self, mock_vinit, mock_cd):
validator = check_init_priorities.Validator("", "", None)

def test_check_edt(self, mock_vinit, mock_cd):
d0 = mock.Mock()
d0.dep_ordinal = 1
d1 = mock.Mock()
d1.dep_ordinal = 2
d2 = mock.Mock()
d2.dep_ordinal = 3

c0 = mock.Mock()
c0.props = {"compatible": "c"}
c1 = mock.Mock()
c1.props = {}
c1._binding.path = "another-binding-path.yaml"
c2 = mock.Mock()
c2.props = {}
c2._binding.path = "binding-path.yaml"
c2._binding.child_binding = None
c2.depends_on = [d1]

dev = mock.Mock()
dev.depends_on = [d0]
dev._binding.child_binding = "child-binding"
dev._binding.path = "binding-path.yaml"
dev.children.values.return_value = [c0, c1, c2]

validator._check_edt_r(0, dev)

self.assertListEqual(mock_cd.call_args_list, [
mock.call(0, 1),
mock.call(0, 2),
])
dev0 = mock.Mock()
dev0.depends_on = [d0]
dev1 = mock.Mock()
dev1.depends_on = [d1]
dev2 = mock.Mock()
dev2.depends_on = [d2]

@mock.patch("check_init_priorities.Validator._check_edt_r")
@mock.patch("check_init_priorities.Validator.__init__", return_value=None)
def test_check_edt(self, mock_vinit, mock_cer):
validator = check_init_priorities.Validator("", "", None)
validator._ord2node = {1: mock.Mock(), 2: mock.Mock(), 3: mock.Mock()}
validator._ord2node = {1: dev0, 2: dev1, 3: dev2}
validator._dev_priorities = {1: 10, 2: 10, 3: 20}

validator.check_edt()

self.assertListEqual(mock_cer.call_args_list, [
mock.call(1, validator._ord2node[1]),
mock.call(2, validator._ord2node[2]),
mock.call(3, validator._ord2node[3]),
self.assertListEqual(mock_cd.call_args_list, [
mock.call(1, 1),
mock.call(2, 2),
mock.call(3, 3),
])

if __name__ == "__main__":
Expand Down

0 comments on commit 58c015a

Please sign in to comment.