Skip to content

Commit

Permalink
scripts: ci: test_plan: add option for testsuite excludes
Browse files Browse the repository at this point in the history
Allow to filter out testsuites base on changed files.
This is allow for similar way of excluding tests as for tags,
however now there will be possible to specify paths
for testsuites that should be excluded if certain files were not changed.

Signed-off-by: Piotr Kosycarz <[email protected]>
  • Loading branch information
nordic-piks committed Jan 20, 2025
1 parent 46b2e49 commit 6700fd7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
34 changes: 29 additions & 5 deletions scripts/ci/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,28 @@ def __repr__(self):

class Filters:
def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root,
pull_request=False, platforms=[], detailed_test_id=True, quarantine_list=None, tc_roots_th=20):
pull_request=False, platforms=[], detailed_test_id=True, quarantine_list=None, tc_roots_th=20, testsuite_excludes_def=None):
self.modified_files = modified_files
self.testsuite_root = testsuite_root
self.resolved_files = []
self.twister_options = []
self.full_twister = False
self.all_tests = []
self.tag_options = []
self.testsuite_excludes_options = []
self.pull_request = pull_request
self.platforms = platforms
self.detailed_test_id = detailed_test_id
self.ignore_path = ignore_path
self.tag_cfg_file = alt_tags
self.quarantine_list = quarantine_list
self.tc_roots_th = tc_roots_th
self.testsuite_excludes_def = testsuite_excludes_def

def process(self):
self.find_modules()
self.find_tags()
self.find_testsuite_excludes()
self.find_tests()
if not self.platforms:
# disable for now, this is generating lots of churn when changing
Expand Down Expand Up @@ -326,9 +329,8 @@ def find_tests(self):
_options.extend(["-p", platform])
self.get_plan(_options, use_testsuite_root=False)

def find_tags(self):

with open(self.tag_cfg_file, 'r') as ymlfile:
def _get_tags(self, yml_path):
with open(yml_path, 'r') as ymlfile:
tags_config = yaml.safe_load(ymlfile)

tags = {}
Expand Down Expand Up @@ -358,12 +360,29 @@ def find_tags(self):
if t.exclude:
exclude_tags.add(t.name)

return exclude_tags

def find_tags(self):
exclude_tags = self._get_tags(self.tag_cfg_file)

for tag in exclude_tags:
self.tag_options.extend(["-e", tag ])

if exclude_tags:
logging.info(f'Potential tag based filters: {exclude_tags}')

def find_testsuite_excludes(self):
if self.testsuite_excludes_def is None:
return

exclude_testsuites = self._get_tags(self.testsuite_excludes_def)

for tag in exclude_testsuites:
self.testsuite_excludes_options.extend(["--testsuite-exclude-path", tag ])

if exclude_testsuites:
logging.info(f'Testsuite exclude filters: {exclude_testsuites}')

def find_excludes(self, skip=[]):
with open(self.ignore_path, "r") as twister_ignore:
ignores = twister_ignore.read().splitlines()
Expand Down Expand Up @@ -391,9 +410,11 @@ def find_excludes(self, skip=[]):
_options.extend(["-p", platform])

_options.extend(self.tag_options)
_options.extend(self.testsuite_excludes_options)
self.get_plan(_options)
else:
_options.extend(self.tag_options)
_options.extend(self.testsuite_excludes_options)
self.get_plan(_options, True)
else:
logging.info(f'No twister needed or partial twister run only...')
Expand Down Expand Up @@ -443,6 +464,9 @@ def parse_args():
"the file need to correspond to the test scenarios names as in "
"corresponding tests .yaml files. These scenarios "
"will be skipped with quarantine as the reason.")
parser.add_argument('--testsuite-excludes-def',
default=None,
help="Path to a file describing relations between directories/paths (modified files) and testsuites filters.")

# Include paths in names by default.
parser.set_defaults(detailed_test_id=True)
Expand Down Expand Up @@ -472,7 +496,7 @@ def parse_args():

f = Filters(files, args.ignore_path, args.alt_tags, args.testsuite_root,
args.pull_request, args.platform, args.detailed_test_id, args.quarantine_list,
args.testcase_roots_threshold)
args.testcase_roots_threshold, args.testsuite_excludes_def)
f.process()

# remove dupes and filtered cases
Expand Down
17 changes: 17 additions & 0 deletions scripts/ci/testsuite_excludes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file contains information on what files are associated with which
# twister testsuite excludes patterns.
#
# File format is the same as for tags.yaml - please refer to its description.

# zephyr-keep-sorted-start
"*tests/kernel*":
files:
- kernel/
- arch/
- tests/kernel/

"*tests/posix*":
files:
- lib/posix/
- tests/posix/
# zephyr-keep-sorted-stop

0 comments on commit 6700fd7

Please sign in to comment.