Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport v3.7-branch] twister: setup soc/arch roots based on module settings #77822

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,22 @@ def __init__(self, options=None, default_options=None) -> None:
if snippet_root:
self.snippet_roots.append(Path(module.project) / snippet_root)


self.soc_roots = [Path(ZEPHYR_BASE), Path(ZEPHYR_BASE) / 'subsys' / 'testsuite']
self.dts_roots = [Path(ZEPHYR_BASE)]
self.arch_roots = [Path(ZEPHYR_BASE)]

for module in modules:
soc_root = module.meta.get("build", {}).get("settings", {}).get("soc_root")
if soc_root:
self.soc_roots.append(os.path.join(module.project, soc_root))
Copy link
Contributor

@rexut rexut Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: see arch_roots below

Suggested change
self.soc_roots.append(os.path.join(module.project, soc_root))
self.soc_roots.append(Path(os.path.join(module.project, soc_root)))

OR:

Suggested change
self.soc_roots.append(os.path.join(module.project, soc_root))
self.soc_roots.append(Path(module.project) / soc_root)

dts_root = module.meta.get("build", {}).get("settings", {}).get("dts_root")
if soc_root:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if soc_root:
if dts_root:

self.dts_roots.append(os.path.join(module.project, dts_root))
Copy link
Contributor

@rexut rexut Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: see arch_roots below

Suggested change
self.dts_roots.append(os.path.join(module.project, dts_root))
self.dts_roots.append(Path(os.path.join(module.project, dts_root)))

OR:

Suggested change
self.dts_roots.append(os.path.join(module.project, dts_root))
self.dts_roots.append(Path(module.project) / dts_root)

arch_root = module.meta.get("build", {}).get("settings", {}).get("arch_root")
if arch_root:
self.arch_roots.append(os.path.join(module.project, arch_root))
Copy link
Contributor

@rexut rexut Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: append with path-like object (PEP 519):

Suggested change
self.arch_roots.append(os.path.join(module.project, arch_root))
self.arch_roots.append(Path(os.path.join(module.project, arch_root)))

OR:

Suggested change
self.arch_roots.append(os.path.join(module.project, arch_root))
self.arch_roots.append(Path(module.project) / arch_root)

otherwise following line will cause AttributeError: 'str' object has no attribute '_closed':

v1_boards = list_boards.find_boards(lb_args)

full traceback:

Traceback (most recent call last):
  File "./zephyr/scripts/twister", line 215, in <module>
    ret = main(options, default_options)
  File "/.../workspace/zephyr/scripts/pylib/twister/twisterlib/twister_main.py", line 124, in main
    tplan.discover()
  File "/.../workspace/zephyr/scripts/pylib/twister/twisterlib/testplan.py", line 197, in discover
    self.add_configurations()
  File "/.../workspace/zephyr/scripts/pylib/twister/twisterlib/testplan.py", line 410, in add_configurations
    v1_boards = list_boards.find_boards(lb_args)
  File "/.../workspace/zephyr/scripts/list_boards.py", line 117, in find_boards
    return sorted(itertools.chain(*find_arch2board_set(args).values()),
  File "/.../workspace/zephyr/scripts/list_boards.py", line 122, in find_arch2board_set
    arches = sorted(find_arches(args))
  File "/.../workspace/zephyr/scripts/list_boards.py", line 138, in find_arches
    for root in unique_paths(args.arch_roots):
  File "/.../workspace/zephyr/scripts/list_hardware.py", line 182, in unique_paths
    yield from dict.fromkeys(map(Path.resolve, paths)).keys()
  File "/usr/lib/python3.8/pathlib.py", line 1179, in resolve
    if self._closed:


self.hwm = None

self.test_config = options.test_config if options else None
Expand Down
4 changes: 2 additions & 2 deletions scripts/pylib/twister/twisterlib/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ def add_configurations(self):
# Note, internally in twister a board root includes the `boards` folder
# but in Zephyr build system, the board root is without the `boards` in folder path.
board_roots = [Path(os.path.dirname(root)) for root in self.env.board_roots]
lb_args = Namespace(arch_roots=[Path(ZEPHYR_BASE)], soc_roots=[Path(ZEPHYR_BASE),
Path(ZEPHYR_BASE) / 'subsys' / 'testsuite'],
lb_args = Namespace(arch_roots=self.env.arch_roots, soc_roots=self.env.soc_roots,
board_roots=board_roots, board=None, board_dir=None)

v1_boards = list_boards.find_boards(lb_args)
v2_dirs = list_boards.find_v2_board_dirs(lb_args)
for b in v1_boards:
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/twister/test_testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ def test_testplan_add_configurations(
p3_yamlfile = tmp_p3_dir / 'p3_B.conf'
p3_yamlfile.write_text('')

env = mock.Mock(board_roots=[tmp_board_root_dir])
env = mock.Mock(board_roots=[tmp_board_root_dir],soc_roots=[tmp_path], arch_roots=[tmp_path])

testplan = TestPlan(env=env)

Expand Down
Loading