From dc168866731bedc2d3d4fc2c640503a57004bcc4 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Fri, 30 Aug 2024 10:07:22 +0200 Subject: [PATCH] [nrf fromtree] twister: Pass device flash timeout to pytest-harness. Pass flashing timeout to pytest-harness and use them Signed-off-by: Grzegorz Chwierut (cherry picked from commit 392304706b625338cfc66667fd5bb5a0744309d6) --- .../src/twister_harness/device/hardware_adapter.py | 2 +- .../pytest-twister-harness/src/twister_harness/plugin.py | 9 +++++++-- .../src/twister_harness/twister_harness_config.py | 2 ++ scripts/pylib/twister/twisterlib/harness.py | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py index 98375873eb9..32fe611d747 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py @@ -30,7 +30,7 @@ class HardwareAdapter(DeviceAdapter): def __init__(self, device_config: DeviceConfig) -> None: super().__init__(device_config) - self._flashing_timeout: float = self.base_timeout + self._flashing_timeout: float = device_config.flash_timeout self._serial_connection: serial.Serial | None = None self._serial_pty_proc: subprocess.Popen | None = None self._serial_buffer: bytearray = bytearray() diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py index e484cb8bb43..ef8a1fb6dc1 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -36,8 +36,13 @@ def pytest_addoption(parser: pytest.Parser): type=float, default=60.0, help='Set base timeout (in seconds) used during monitoring if some ' - 'operations are finished in a finite amount of time (e.g. waiting ' - 'for flashing).' + 'operations are finished in a finite amount of time.' + ) + twister_harness_group.addoption( + '--flash-timeout', + type=float, + default=60.0, + help='Set timeout for device flashing (in seconds).' ) twister_harness_group.addoption( '--build-dir', diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/twister_harness_config.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/twister_harness_config.py index a4b0b749777..c635f62973a 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/twister_harness_config.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/twister_harness_config.py @@ -19,6 +19,7 @@ class DeviceConfig: type: str build_dir: Path base_timeout: float = 60.0 # [s] + flash_timeout: float = 60.0 # [s] platform: str = '' serial: str = '' baud: int = 115200 @@ -65,6 +66,7 @@ def create(cls, config: pytest.Config) -> TwisterHarnessConfig: type=config.option.device_type, build_dir=_cast_to_path(config.option.build_dir), base_timeout=config.option.base_timeout, + flash_timeout=config.option.flash_timeout, platform=config.option.platform, serial=config.option.device_serial, baud=config.option.device_serial_baud, diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index d11d174a1bb..6cc46b98c3b 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -386,6 +386,9 @@ def _generate_parameters_for_hardware(self, handler: Handler): f'--device-serial-baud={hardware.baud}' ]) + if hardware.flash_timeout: + command.append(f'--flash-timeout={hardware.flash_timeout}') + options = handler.options if runner := hardware.runner or options.west_runner: command.append(f'--runner={runner}')