Skip to content

Commit

Permalink
twister: allow loading external configuration
Browse files Browse the repository at this point in the history
Add a new option to Twister that allows to load alternative
configuration files, `--alt-config-root`. This new option takes an
arbitrary number of root folders where alternative configuration files
can be stored. Twister will check if a test configuration file exists in
any of the alternative test configuration folders. For example, given
`$test_root/tests/foo/testcase.yaml`, Twister will use
`$alt_config_root/tests/foo/testcase.yaml` if it exists.

This feature can be useful if an out-of-tree project needs to run
upstream tests in different configurations, potentially not available
upstream (e.g. an out-of-tree board, or Kconfig setting).

Note that overlaying has been discarded because we can't easily delete
fields from the original configuration file, something that in certain
cases could be required. Current approach may lead to some dupplication,
but guarantees full control of the test configuration.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
  • Loading branch information
gmarull authored and nashif committed May 16, 2023
1 parent 2c12960 commit 21b9a1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ def add_parse_arguments(parser = None):
parser.add_argument("extra_test_args", nargs=argparse.REMAINDER,
help="Additional args following a '--' are passed to the test binary")

parser.add_argument("--alt-config-root", action="append", default=[],
help="Alternative test configuration root/s. When a test is found, "
"Twister will check if a test configuration file exist in any of "
"the alternative test configuration root folders. For example, "
"given $test_root/tests/foo/testcase.yaml, Twister will use "
"$alt_config_root/tests/foo/testcase.yaml if it exists")

return parser


Expand Down Expand Up @@ -795,6 +802,8 @@ def __init__(self, options=None) -> None:

self.test_config = options.test_config

self.alt_config_root = options.alt_config_root

def discover(self):
self.check_zephyr_version()
self.get_toolchain()
Expand Down
10 changes: 10 additions & 0 deletions scripts/pylib/twister/twisterlib/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ def add_testsuites(self, testsuite_filter=[]):
suite_yaml_path = os.path.join(dirpath, filename)
suite_path = os.path.dirname(suite_yaml_path)

for alt_config_root in self.env.alt_config_root:
alt_config = os.path.join(os.path.abspath(alt_config_root),
os.path.relpath(suite_path, root),
filename)
if os.path.exists(alt_config):
logger.info("Using alternative configuration from %s" %
os.path.normpath(alt_config))
suite_yaml_path = alt_config
break

try:
parsed_data = TwisterConfigParser(suite_yaml_path, self.suite_schema)
parsed_data.load()
Expand Down

0 comments on commit 21b9a1c

Please sign in to comment.