Commit bf2378e3 authored by Grzegorz Chwierut's avatar Grzegorz Chwierut Committed by Henrik Brix Andersen
Browse files

twister: scripts: sharing of built applications

This feature enables sharing of built applications between test
scenarios, allowing tests to access build artifacts from other
applications.

Signed-off-by: default avatarGrzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
parent 6cb06cdd
Loading
Loading
Loading
Loading
+37 −0
Changes for doc/develop/test/twister.rst: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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
+18 −0
Changes for samples/subsys/testsuite/pytest/shell/pytest_shared_app/test_shared_app.py: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
# 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 −0
Changes for samples/subsys/testsuite/pytest/shell/testcase.yaml: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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"
+5 −0
Changes for scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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."""
+5 −0
Changes for scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -126,6 +126,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.'
Loading