Skip to content

Commit

Permalink
ci: test_plan: fix handling of v2 boards
Browse files Browse the repository at this point in the history
Handling of board changes was broken and did not support v2 boards, fix
this to optimize CI execution on localized changes of board files.

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Jun 5, 2024
1 parent ec9f71e commit 532c57d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
56 changes: 31 additions & 25 deletions scripts/ci/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
repository_path = zephyr_base
repo_to_scan = Repo(zephyr_base)
args = None


logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
logging.getLogger("pykwalify.core").setLevel(50)

sys.path.append(os.path.join(zephyr_base, 'scripts'))
import list_boards


def _get_match_fn(globs, regexes):
# Constructs a single regex that tests for matches against the globs in
# 'globs' and the regexes in 'regexes'. Parts are joined with '|' (OR).
Expand Down Expand Up @@ -214,45 +214,51 @@ def find_archs(self):
self.get_plan(_options, True)

def find_boards(self):
boards = set()
all_boards = set()
resolved = []
changed_boards = set()
matched_boards = {}
resolved_files = []

for f in self.modified_files:
if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"):
for file in self.modified_files:
if file.endswith(".rst") or file.endswith(".png") or file.endswith(".jpg"):
continue
p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f)
if p and p.groups():
boards.add(p.group(1))
resolved.append(f)
if file.startswith("boards/"):
changed_boards.add(file)
resolved_files.append(file)

roots = [zephyr_base]
if repository_path != zephyr_base:
roots.append(repository_path)

# Look for boards in monitored repositories
lb_args = argparse.Namespace(**{'arch_roots': roots, 'board_roots': roots, 'board': None,
lb_args = argparse.Namespace(**{'arch_roots': roots, 'board_roots': roots, 'board': None, 'soc_roots':roots,
'board_dir': None})
known_boards = list_boards.find_boards(lb_args)
for b in boards:
name_re = re.compile(b)
for kb in known_boards:
if name_re.search(kb.name):
all_boards.add(kb.name)

# If modified file is catched by "find_boards" workflow (change in "boards" dir AND board recognized)
known_boards = list_boards.find_v2_boards(lb_args)

for changed in changed_boards:
for board in known_boards:
c = (zephyr_base / changed).resolve()
if c.is_relative_to(board.dir.resolve()):
for qual in list_boards.board_v2_qualifiers(board):
bname = f"{board.name}/{qual}"
normalized = bname.replace("/", "_")
if os.path.exists(os.path.join(board.dir, f"{normalized}.yaml")):
matched_boards[bname] = board


logging.info(f"found boards: {','.join(matched_boards.keys())}")
# If modified file is caught by "find_boards" workflow (change in "boards" dir AND board recognized)
# it means a proper testing scope for this file was found and this file can be removed
# from further consideration
for board in all_boards:
self.resolved_files.extend(list(filter(lambda f: board in f, resolved)))
for _, board in matched_boards.items():
self.resolved_files.extend(list(filter(lambda f: str(board.dir.relative_to(zephyr_base)) in f, resolved_files)))

_options = []
if len(all_boards) > 20:
logging.warning(f"{len(boards)} boards changed, this looks like a global change, skipping test handling, revert to default.")
if len(matched_boards) > 20:
logging.warning(f"{len(matched_boards)} boards changed, this looks like a global change, skipping test handling, revert to default.")
self.full_twister = True
return

for board in all_boards:
for board in matched_boards.keys():

Check warning on line 261 in scripts/ci/test_plan.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C0201

scripts/ci/test_plan.py:261 Consider iterating the dictionary directly instead of calling .keys() (consider-iterating-dictionary)
_options.extend(["-p", board ])

if _options:
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/twister_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ doc/*
# GH action have no impact on code
.github/*
*.rst
*.jpg
*.png
*.md
# if we change this file or associated script, it should not trigger a full
# twister.
Expand Down

0 comments on commit 532c57d

Please sign in to comment.