Skip to content

twister: match platform regex pattern #93051

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
"specified. If this option is not used, then platforms marked "
"as default in the platform metadata file will be chosen "
"to build and test. ")
parser.add_argument(
"--platform-pattern", action="append", default=[],
help="""Platform regular expression filter for testing. This option may be used multiple
times. Test suites will only be built/run on the platforms
matching the specified patterns. If this option is not used, then platforms marked
as default in the platform metadata file will be chosen
to build and test.
""")

parser.add_argument(
"--platform-reports", action="store_true",
Expand Down
24 changes: 15 additions & 9 deletions scripts/pylib/twister/twisterlib/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
from devicetree import edtlib # pylint: disable=unused-import

sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/"))

class Filters:
# platform keys
PLATFORM_KEY = 'platform key filter'
Expand Down Expand Up @@ -702,6 +701,7 @@ def check_platform(self, platform, platform_list):
def apply_filters(self, **kwargs):

platform_filter = self.options.platform
platform_pattern = self.options.platform_pattern
vendor_filter = self.options.vendor
exclude_platform = self.options.exclude_platform
testsuite_filter = self.run_individual_testsuite
Expand All @@ -716,11 +716,12 @@ def apply_filters(self, **kwargs):
ignore_platform_key = self.options.ignore_platform_key
emu_filter = self.options.emulation_only

logger.debug("platform filter: " + str(platform_filter))
logger.debug(" vendor filter: " + str(vendor_filter))
logger.debug(" arch_filter: " + str(arch_filter))
logger.debug(" tag_filter: " + str(tag_filter))
logger.debug(" exclude_tag: " + str(exclude_tag))
logger.debug(" platform filter: " + str(platform_filter))
logger.debug("platform_pattern: " + str(platform_pattern))
logger.debug(" vendor filter: " + str(vendor_filter))
logger.debug(" arch_filter: " + str(arch_filter))
logger.debug(" tag_filter: " + str(tag_filter))
logger.debug(" exclude_tag: " + str(exclude_tag))

default_platforms = False
vendor_platforms = False
Expand All @@ -730,7 +731,7 @@ def apply_filters(self, **kwargs):
logger.info("Selecting all possible platforms per testsuite scenario")
# When --all used, any --platform arguments ignored
platform_filter = []
elif not platform_filter and not emu_filter and not vendor_filter:
elif not platform_filter and not emu_filter and not vendor_filter and not platform_pattern:
logger.info("Selecting default platforms per testsuite scenario")
default_platforms = True
elif emu_filter:
Expand All @@ -745,6 +746,11 @@ def apply_filters(self, **kwargs):
# find in aliases and rename
platform_filter = self.verify_platforms_existence(platform_filter, "platform_filter")
platforms = list(filter(lambda p: p.name in platform_filter, self.platforms))
elif platform_pattern:
platforms = list(
filter(lambda p: any(re.match(pat, alias) for pat in platform_pattern \
for alias in p.aliases), self.platforms)
)
elif emu_filter:
platforms = list(
filter(lambda p: bool(p.simulator_by_name(self.options.sim_name)), self.platforms)
Expand Down Expand Up @@ -783,14 +789,14 @@ def apply_filters(self, **kwargs):
else:
_integration_platforms = []

if (ts.build_on_all and not platform_filter and
if (ts.build_on_all and not platform_filter and not platform_pattern and
platform_config.get('increased_platform_scope', True)):
# if build_on_all is set, we build on all platforms
platform_scope = self.platforms
elif ts.integration_platforms and self.options.integration:
# if integration is set, we build on integration platforms
platform_scope = _integration_platforms
elif ts.integration_platforms and not platform_filter:
elif ts.integration_platforms and not platform_filter and not platform_pattern:
# if integration platforms are set, we build on those and integration mode is set
# for this test suite, we build on integration platforms
if any(ts.id.startswith(i) for i in integration_mode_list):
Expand Down
Loading