Skip to content

Commit ea2cdd2

Browse files
committed
scripts: Make workflow of test_plan.py script more robust
The script was not resolving all detected changes uniformly: find_excludes() could skip or not certain patterns based on required testing scope. The idea was to not include files that were already handled by find_test() and find_boards() workflows. However, only boards and tests folders could be removed but not samples. This also led to blind spots: changes in some files were not triggering any tests. E.g. change in a test/common, where no corresponding yaml can be found by find_tests() which is also ignored by find_excludes(). In the new workflow a list of resolved files (for which find_arch(), find_tests() or find_boards() found scope) is created. Instead of using skip in find_excludes, files are excluded only if they were resolved. Signed-off-by: Maciej Perkowski <[email protected]>
1 parent aff7a7b commit ea2cdd2

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

scripts/ci/test_plan.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ def __repr__(self):
8888
class Filters:
8989
def __init__(self, modified_files, pull_request=False, platforms=[], no_path_name = False, ignore_path=None, alt_tags=None, testsuite_root=None):
9090
self.modified_files = modified_files
91+
self.resolved_files = []
9192
self.testsuite_root = testsuite_root
9293
self.twister_options = []
9394
self.full_twister = False
9495
self.all_tests = []
9596
self.tag_options = []
9697
self.pull_request = pull_request
9798
self.platforms = platforms
98-
self.default_run = False
9999
self.no_path_name = no_path_name
100100
self.tag_cfg_file = os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml')
101101
if alt_tags:
@@ -111,11 +111,7 @@ def process(self):
111111
if not self.platforms:
112112
self.find_archs()
113113
self.find_boards()
114-
115-
if self.default_run:
116-
self.find_excludes(skip=["tests/*", "boards/*/*/*"])
117-
else:
118-
self.find_excludes()
114+
self.find_excludes()
119115

120116
def get_plan(self, options, integration=False, use_testsuite_root=True):
121117
fname = "_test_plan_partial.json"
@@ -192,6 +188,8 @@ def find_archs(self):
192188
archs.add('riscv64')
193189
else:
194190
archs.add(p.group(1))
191+
# Modified file is treated as resolved, since a matching scope was found
192+
self.resolved_files.append(f)
195193

196194
_options = []
197195
for arch in archs:
@@ -210,13 +208,15 @@ def find_archs(self):
210208
def find_boards(self):
211209
boards = set()
212210
all_boards = set()
211+
resolved = []
213212

214213
for f in self.modified_files:
215214
if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"):
216215
continue
217216
p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f)
218217
if p and p.groups():
219218
boards.add(p.group(1))
219+
resolved.append(f)
220220

221221
roots = [zephyr_base]
222222
if repository_path != zephyr_base:
@@ -231,10 +231,16 @@ def find_boards(self):
231231
if name_re.search(kb.name):
232232
all_boards.add(kb.name)
233233

234+
# If modified file is catched by "find_boards" workflow (change in "boards" dir AND board recognized)
235+
# it means a proper testing scope for this file was found and this file can be removed
236+
# from further consideration
237+
for board in all_boards:
238+
self.resolved_files.extend(list(filter(lambda f: board in f, resolved)))
239+
234240
_options = []
235241
if len(all_boards) > 20:
236242
logging.warning(f"{len(boards)} boards changed, this looks like a global change, skipping test handling, revert to default.")
237-
self.default_run = True
243+
self.full_twister = True
238244
return
239245

240246
for board in all_boards:
@@ -254,6 +260,8 @@ def find_tests(self):
254260
if os.path.exists(os.path.join(d, "testcase.yaml")) or \
255261
os.path.exists(os.path.join(d, "sample.yaml")):
256262
tests.add(d)
263+
# Modified file is treated as resolved, since a matching scope was found
264+
self.resolved_files.append(f)
257265
break
258266
else:
259267
d = os.path.dirname(d)
@@ -264,7 +272,7 @@ def find_tests(self):
264272

265273
if len(tests) > 20:
266274
logging.warning(f"{len(tests)} tests changed, this looks like a global change, skipping test handling, revert to default")
267-
self.default_run = True
275+
self.full_twister = True
268276
return
269277

270278
if _options:
@@ -320,21 +328,22 @@ def find_excludes(self, skip=[]):
320328
ignores = filter(lambda x: not x.startswith("#"), ignores)
321329

322330
found = set()
323-
files = list(filter(lambda x: x, self.modified_files))
331+
files_not_resolved = list(filter(lambda x: x not in self.resolved_files, self.modified_files))
324332

325333
for pattern in ignores:
326-
if pattern in skip:
327-
continue
328334
if pattern:
329-
found.update(fnmatch.filter(files, pattern))
335+
found.update(fnmatch.filter(files_not_resolved, pattern))
330336

331337
logging.debug(found)
332-
logging.debug(files)
338+
logging.debug(files_not_resolved)
333339

334-
if sorted(files) != sorted(found):
340+
# Full twister run can be ordered by detecting great number of tests/boards changed
341+
# or if not all modified files were resolved (corresponding scope found)
342+
self.full_twister = self.full_twister or sorted(files_not_resolved) != sorted(found)
343+
344+
if self.full_twister:
335345
_options = []
336346
logging.info(f'Need to run full or partial twister...')
337-
self.full_twister = True
338347
if self.platforms:
339348
for platform in self.platforms:
340349
_options.extend(["-p", platform])

scripts/ci/twister_ignore.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,6 @@ CODEOWNERS
1717
MAINTAINERS.yml
1818
LICENSE
1919
Makefile
20-
tests/*
21-
samples/*
22-
boards/*/*/*
23-
arch/xtensa/*
24-
arch/x86/*
25-
arch/posix/*
26-
arch/arc/*
27-
arch/sparc/*
28-
arch/arm/*
29-
arch/nios2/*
30-
arch/riscv/*
31-
include/arch/xtensa/*
32-
include/arch/x86/*
33-
include/arch/posix/*
34-
include/arch/arc/*
35-
include/arch/sparc/*
36-
include/arch/arm/*
37-
include/arch/nios2/*
38-
include/arch/riscv/*
3920
doc/*
4021
# GH action have no impact on code
4122
.github/*

0 commit comments

Comments
 (0)