Skip to content

Commit 358c7f4

Browse files
committed
scripts: ci: test_plan: verify test paths
Make sure that found testsuite path is within provided testsuite roots. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent f22578f commit 358c7f4

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

scripts/ci/test_plan.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ def find_boards(self):
280280
logging.info(f'Potential board filters...')
281281
self.get_plan(_options)
282282

283+
def is_in_testsuite_root(self, new_testsuite_root):
284+
# verify if proposed testsuite matches the one already provided
285+
# to prevent executing tests which were not in the scope
286+
result = False
287+
if not self.testsuite_root:
288+
result = True
289+
else:
290+
for root in self.testsuite_root:
291+
if root in new_testsuite_root:
292+
result = True
293+
break
294+
return result
295+
283296
def find_tests(self):
284297
tests = set()
285298
for f in self.modified_files:
@@ -291,16 +304,19 @@ def find_tests(self):
291304
head, tail = os.path.split(d)
292305
if os.path.exists(os.path.join(d, "testcase.yaml")) or \
293306
os.path.exists(os.path.join(d, "sample.yaml")):
294-
tests.add(d)
295-
# Modified file is treated as resolved, since a matching scope was found
296-
self.resolved_files.append(f)
297-
scope_found = True
307+
if self.is_in_testsuite_root(d):
308+
tests.add(d)
309+
# Modified file is treated as resolved, since a matching scope was found
310+
self.resolved_files.append(f)
311+
scope_found = True
312+
else:
313+
d = os.path.dirname(d)
298314
elif tail == "common":
299315
# Look for yamls in directories collocated with common
300316

301317
yamls_found = [yaml for yaml in glob.iglob(head + '/**/testcase.yaml', recursive=True)]
302318
yamls_found.extend([yaml for yaml in glob.iglob(head + '/**/sample.yaml', recursive=True)])
303-
if yamls_found:
319+
if yamls_found and self.is_in_testsuite_root(head):
304320
for yaml in yamls_found:
305321
tests.add(os.path.dirname(yaml))
306322
self.resolved_files.append(f)

0 commit comments

Comments
 (0)