From 1f25531d7ce04af2b27d321c582a41255b7c5e80 Mon Sep 17 00:00:00 2001 From: Michal Smola Date: Fri, 26 Jan 2024 14:40:08 +0100 Subject: [PATCH] twister: pytest: fix missing messages from hardware target When pytest harness test is run on harware, messages sent from target right after application start-up are lost, because connection to COM port is not established yet. It can cause unexpected behavior of a test. Fix it by flashing and running application after connecting to COM port when testing on hardware. Signed-off-by: Michal Smola --- .../src/twister_harness/device/device_adapter.py | 10 +++++++++- 1 file 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 ce8492c78b7..b5560650c1b 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 @@ -66,11 +66,19 @@ class DeviceAdapter(abc.ABC): if not self.command: self.generate_command() - self._flash_and_run() + + if self.device_config.type != 'hardware': + self._flash_and_run() + self._device_run.set() self._start_reader_thread() self.connect() + if 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() + def close(self) -> None: """Disconnect, close device and close reader thread.""" if not self._device_run.is_set():