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

ci: test_plan: fix handling of v2 boards #73817

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
60 changes: 35 additions & 25 deletions scripts/ci/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
from git import Repo
from west.manifest import Manifest

try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader

if "ZEPHYR_BASE" not in os.environ:
exit("$ZEPHYR_BASE environment variable undefined.")

Expand All @@ -26,13 +31,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 +219,50 @@ 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 file in glob.glob(os.path.join(board.dir, f"{board.name}*.yaml")):
with open(file, 'r') as f:
b = yaml.load(f.read(), Loader=SafeLoader)
matched_boards[b['identifier']] = 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:
_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
Loading