Skip to content

twister: support filtering tests using regex #93054

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
6 changes: 6 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
timeout would be multiplication of test timeout value, board-level timeout multiplier
and global timeout multiplier (this parameter)""")

test_xor_subtest.add_argument(
"--test-pattern", action="append",
help="""Run only the tests matching the specified pattern. The pattern
can include regular expressions.
""")

test_xor_subtest.add_argument(
"-s", "--test", "--scenario", action="append", type = norm_path,
help="""Run only the specified test suite scenario. These are named by
Expand Down
15 changes: 15 additions & 0 deletions scripts/pylib/twister/twisterlib/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def discover(self):

self.add_configurations()
num = self.add_testsuites(testsuite_filter=self.run_individual_testsuite)

if num == 0:
raise TwisterRuntimeError("No testsuites found at the specified location...")
if self.load_errors:
Expand All @@ -202,6 +203,20 @@ def discover(self):
for _, ts in self.testsuites.items():
self.scenarios.append(ts.id)

if self.options.test_pattern:
logger.info(
"Running tests matching the specified patterns: %s",
', '.join(self.options.test_pattern)
)
# If test_pattern is used, we run all tests that match the pattern.
# The pattern can be a regular expression.
self.run_individual_testsuite = []
for pattern in self.options.test_pattern:
r = re.compile(pattern)
for ts in self.testsuites.values():
if r.search(ts.id):
self.run_individual_testsuite.append(ts.id)

self.report_duplicates()
self.parse_configuration(config_file=self.env.test_config)

Expand Down
1 change: 1 addition & 0 deletions scripts/tests/twister/test_testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def test_testplan_discover(

testplan = TestPlan(env=mock.Mock())
testplan.options = mock.Mock(
test_pattern=[],
test='ts1',
quarantine_list=[tmp_path / qf for qf in ql],
quarantine_verify=qv,
Expand Down
Loading