Skip to content
Merged
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
37 changes: 37 additions & 0 deletions doc/develop/test/twister.rst
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,43 @@ required_snippets: <list of needed snippets>
- cdc-acm-console
- user-snippet-example

required_applications: <list of required applications> (default empty)
Specify a list of test applications that must be built before current test can run.
It enables sharing of built applications between test scenarios, allowing tests
to access build artifacts from other applications.

Each required application entry supports:
- ``name``: Test scenario identifier (required)
- ``platform``: Target platform (optional, defaults to current test's platform)

Required applications must be available in the source tree (specified with ``-T``
and/or ``-s`` options). When reusing build directories (e.g., with ``--no-clean``),
Twister can find required applications in the current build directory.

How it works:

- Twister builds the required applications first
- The main test application waits for required applications to complete
- Build directories of required applications are made available to the test harness
- For pytest harness, build directories are passed via ``--required-build`` arguments
and accessible through the ``required_build_dirs`` fixture

Example configuration:

.. code-block:: yaml

tests:
sample.required_app_demo:
harness: pytest
required_applications:
- name: sample.shared_app
- name: sample.basic.helloworld
platform: native_sim
sample.shared_app:
build_only: true

Limitations: Not supported with ``--subset`` or ``--runtime-artifact-cleanup`` options.

expect_reboot: <True|False> (default False)
Notify twister that the test scenario is expected to reboot while executing.
When enabled, twister will suppress warnings about unexpected multiple runs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import logging
from pathlib import Path

from twister_harness import DeviceAdapter

logger = logging.getLogger(__name__)


def test_required_build_dirs_found(dut: DeviceAdapter, required_build_dirs):
logger.info(f"Required build directories: {required_build_dirs}")
assert len(required_build_dirs) == 2, "Expected two required build directories"
assert Path(required_build_dirs[0]).is_dir()
assert Path(Path(required_build_dirs[0]) / 'build.log').exists()
8 changes: 8 additions & 0 deletions samples/subsys/testsuite/pytest/shell/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ tests:
- CONFIG_SHELL_VT100_COLORS=n
harness_config:
shell_commands: *kernel_commands
sample.pytest.required_app_demo:
required_applications:
- name: sample.pytest.shell
- name: sample.harness.shell
harness: pytest
harness_config:
pytest_root:
- "pytest_shared_app/test_shared_app.py"
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def shell(dut: DeviceAdapter) -> Shell:
return shell


@pytest.fixture(scope='session')
def required_build_dirs(request: pytest.FixtureRequest) -> list[str]:
return request.config.getoption('--required-build')


@pytest.fixture()
def mcumgr(device_object: DeviceAdapter) -> Generator[MCUmgr, None, None]:
"""Fixture to create an MCUmgr instance for serial connection."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def pytest_addoption(parser: pytest.Parser):
choices=('function', 'class', 'module', 'package', 'session'),
help='The scope for which `dut` and `shell` fixtures are shared.'
)
twister_harness_group.addoption(
'--required-build', action='append', default=[], metavar='PATH',
help='Required build directory / shared applications for the test. '
'May be given multiple times.'
)
twister_harness_group.addoption(
'--twister-fixture', action='append', dest='fixtures', metavar='FIXTURE', default=[],
help='Twister fixture supported by this platform. May be given multiple times.'
Expand Down
1 change: 1 addition & 0 deletions scripts/pylib/twister/twisterlib/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TwisterConfigParser:
"extra_conf_files": {"type": "list", "default": []},
"extra_overlay_confs": {"type": "list", "default": []},
"extra_dtc_overlay_files": {"type": "list", "default": []},
"required_applications": {"type": "list"},
"required_snippets": {"type": "list"},
"build_only": {"type": "bool", "default": False},
"build_on_all": {"type": "bool", "default": False},
Expand Down
3 changes: 3 additions & 0 deletions scripts/pylib/twister/twisterlib/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ def generate_command(self):
f'Support for handler {handler.type_str} not implemented yet'
)

for req_build in self.instance.required_build_dirs:
command.append(f'--required-build={req_build}')

if handler.type_str != 'device':
for fixture in handler.options.fixture:
command.append(f'--twister-fixture={fixture}')
Expand Down
Loading
Loading