scripts: check_init_priorities: add extra verbose output

Add support for more verbose output enabling debugging output and add a
first debug print to output the file to device path mapping. Found this
to be extremely useful to find what file is instantiating a specific
device for non obvious cases.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2023-06-01 15:11:19 +00:00 committed by Anas Nashif
commit 44e691e20e
2 changed files with 14 additions and 5 deletions

View file

@ -194,6 +194,9 @@ class Validator():
obj = ZephyrObjectFile(file)
if obj.defined_devices:
self._objs.append(obj)
for dev in obj.defined_devices:
dev_path = self._ord2node[dev].path
self.log.debug(f"{file}: {dev_path}")
self._dev_priorities = {}
for obj in self._objs:
@ -279,8 +282,9 @@ def _parse_args(argv):
parser.add_argument("-d", "--build-dir", default="build",
help="build directory to use")
parser.add_argument("-v", "--verbose", action="store_true",
help="enable verbose Output")
parser.add_argument("-v", "--verbose", action="count",
help=("enable verbose output, can be used multiple times "
"to increase verbosity level"))
parser.add_argument("-w", "--fail-on-warning", action="store_true",
help="fail on both warnings and errors")
parser.add_argument("--always-succeed", action="store_true",
@ -306,7 +310,9 @@ def _init_log(verbose, output):
file.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
log.addHandler(file)
if verbose:
if verbose and verbose > 1:
log.setLevel(logging.DEBUG)
elif verbose and verbose > 0:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.WARNING)

View file

@ -143,13 +143,14 @@ class testValidator(unittest.TestCase):
def test_initialize(self, mock_pl, mock_fbo, mock_zof):
mock_fbo.return_value = ["filepath"]
mock_log = mock.Mock()
mock_prio = mock.Mock()
mock_obj = mock.Mock()
mock_obj.defined_devices = {123: mock_prio}
mock_zof.return_value = mock_obj
with mock.patch("builtins.open", mock.mock_open()) as mock_open:
validator = check_init_priorities.Validator("path", "pickle", None)
validator = check_init_priorities.Validator("path", "pickle", mock_log)
self.assertListEqual(validator._objs, [mock_obj])
self.assertDictEqual(validator._dev_priorities, {123: mock_prio})
@ -160,7 +161,9 @@ class testValidator(unittest.TestCase):
@mock.patch("pathlib.Path")
@mock.patch("check_init_priorities.Validator.__init__", return_value=None)
def test_find_build_objfiles(self, mock_vinit, mock_path):
validator = check_init_priorities.Validator("", "", None)
mock_log = mock.Mock()
validator = check_init_priorities.Validator("", "", mock_log)
mock_file = mock.Mock()
mock_file.is_file.return_value = True