Skip to content

Commit

Permalink
scripts: check_init_priorities: ignore zephyr,cdc-acm-uart
Browse files Browse the repository at this point in the history
The new stack zephyr,cdc-acm-uart driver has two separate init path, one
of which kicks in before the USB stack to start buffering log messages.

This generates a false positive in the build time priority checking,
adding a check to ignore that compatible entirely.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Jul 21, 2023
1 parent b829dbc commit a7cdd3d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/build/check_init_priorities.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
# opposite of the device tree inferred dependency.
_INVERTED_PRIORITY_COMPATIBLES = frozenset()

# List of compatibles for nodes where we don't check the priority.
_IGNORE_COMPATIBLES = frozenset([
# This is pre-initialized early to start processing data as soon as
# possible, there's a separate SYS_INIT entry running later in the boot
# sequence.
"zephyr,cdc-acm-uart",
])

class Priority:
"""Parses and holds a device initialization priority.
Expand Down Expand Up @@ -230,6 +238,10 @@ def _check_dep(self, dev_ord, dep_ord):
dev_node = self._ord2node[dev_ord]
dep_node = self._ord2node[dep_ord]

if dev_node._binding and dev_node._binding.compatible in _IGNORE_COMPATIBLES:
self.log.info(f"Ignoring priority: {dev_node._binding.compatible}")
return

if dev_node._binding and dep_node._binding:
dev_compat = dev_node._binding.compatible
dep_compat = dep_node._binding.compatible
Expand Down
35 changes: 35 additions & 0 deletions scripts/build/check_init_priorities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def test_check_swapped(self, mock_vinit):
validator.warnings = 0
validator.errors = 0

save_inverted_priorities = check_init_priorities._INVERTED_PRIORITY_COMPATIBLES

check_init_priorities._INVERTED_PRIORITY_COMPATIBLES = set([("compat-3", "compat-1")])

validator._ord2node = {1: mock.Mock(), 3: mock.Mock()}
Expand All @@ -282,6 +284,39 @@ def test_check_swapped(self, mock_vinit):
mock.call("Swapped priority: compat-3, compat-1"),
mock.call("/3 20 > /1 10"),
])
self.assertEqual(validator.warnings, 0)
self.assertEqual(validator.errors, 0)

check_init_priorities._INVERTED_PRIORITY_COMPATIBLES = save_inverted_priorities

@mock.patch("check_init_priorities.Validator.__init__", return_value=None)
def test_check_ignored(self, mock_vinit):
validator = check_init_priorities.Validator("", "", None)
validator.log = mock.Mock()
validator.warnings = 0
validator.errors = 0

save_ignore_compatibles = check_init_priorities._IGNORE_COMPATIBLES

check_init_priorities._IGNORE_COMPATIBLES = set(["compat-3"])

validator._ord2node = {1: mock.Mock(), 3: mock.Mock()}
validator._ord2node[1]._binding.compatible = "compat-1"
validator._ord2node[1].path = "/1"
validator._ord2node[3]._binding.compatible = "compat-3"
validator._ord2node[3].path = "/3"

validator._dev_priorities = {1: 20, 3: 10}

validator._check_dep(3, 1)

self.assertListEqual(validator.log.info.call_args_list, [
mock.call("Ignoring priority: compat-3"),
])
self.assertEqual(validator.warnings, 0)
self.assertEqual(validator.errors, 0)

check_init_priorities._IGNORE_COMPATIBLES = save_ignore_compatibles

@mock.patch("check_init_priorities.Validator._check_dep")
@mock.patch("check_init_priorities.Validator.__init__", return_value=None)
Expand Down

0 comments on commit a7cdd3d

Please sign in to comment.