twister: Fix serial open for UART devices that do not immediately appear

Testing on linux, --flash-before argument did not work to wait for jlink
upload to complete. Instead Serial port opening throws file not found. The
fix ensures that the code waits for the serial port to appear before
attempting to connect. Tested on a proprietary platform with virtual UART
through usb.

Signed-off-by: Eemil Visakorpi <eemil@doublepoint.com>
This commit is contained in:
Eemil Visakorpi
2025-11-05 18:41:50 +02:00
committed by Benjamin Cabé
parent 0b173063fe
commit 1d70b705b0

View File

@@ -27,6 +27,7 @@ from pathlib import Path
from queue import Empty, Queue
import psutil
from serial.tools import list_ports
from twisterlib.environment import ZEPHYR_BASE, strip_ansi_sequences
from twisterlib.error import TwisterException
from twisterlib.hardwaremap import DUT
@@ -867,6 +868,10 @@ class DeviceHandler(Handler):
# Return to normal boot
ser.rts = False
else:
while ser.port not in (p.name for p in list_ports.comports()):
time.sleep(0.1)
if time.time() - start_time > flash_timeout:
break
ser.open()
except serial.SerialException as e: