From 7bad218659e27c155b7ac60b654fe8c9ebd32cae Mon Sep 17 00:00:00 2001 From: Grygorii Strashko Date: Thu, 16 May 2024 14:53:29 +0300 Subject: [PATCH] pytest: add "--skip-flash" option The pytest is always trying to flash when running on real HW (--device-type=hardware). On ARM64 Cortex-A platform like RPI5 there no way to implement flashing through pytest framework now: the Zephyr binary has to be stored on SD-card and loaded by bootloader. Add "--skip-flash" option which still will allow to run pytest with shell interface manually after platform is booted and shell is ready. Signed-off-by: Grygorii Strashko Acked-by: Dmytro Firsov --- .../src/twister_harness/device/device_adapter.py | 2 +- .../pytest-twister-harness/src/twister_harness/plugin.py | 6 ++++++ .../src/twister_harness/twister_harness_config.py | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py index b5560650c1b6cf..6d641732635314 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py @@ -74,7 +74,7 @@ def launch(self) -> None: self._start_reader_thread() self.connect() - if self.device_config.type == 'hardware': + if not self.device_config.skip_flash and self.device_config.type == 'hardware': # On hardware, flash after connecting to COM port, otherwise some messages # from target can be lost. self._flash_and_run() 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 dbd3465aba19e9..f47e7daf7b661a 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -105,6 +105,12 @@ 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( + '--skip-flash', + default=False, + help='Skip flashing.', + action='store_true', + ) def pytest_configure(config: pytest.Config): 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 bcb88715d59492..2043bcd0665c19 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 @@ -30,6 +30,7 @@ class DeviceConfig: pre_script: Path | None = None post_script: Path | None = None post_flash_script: Path | None = None + skip_flash: bool = False @dataclass @@ -61,6 +62,7 @@ def create(cls, config: pytest.Config) -> TwisterHarnessConfig: pre_script=_cast_to_path(config.option.pre_script), post_script=_cast_to_path(config.option.post_script), post_flash_script=_cast_to_path(config.option.post_flash_script), + skip_flash=config.option.skip_flash, ) devices.append(device_from_cli)