Skip to content

Commit

Permalink
trunner.tools: fix error message in wait_for_vid_pid()
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-bloch committed Aug 12, 2024
1 parent 21d61a7 commit 2233646
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion trunner/target/armv7a9.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __call__(self):
"""Loads plo image to RAM using gdb."""

# after reboot we need to wait for smt2 device
wait_for_vid_pid(vid=0x0403, pid=0x6014, timeout=5)
wait_for_vid_pid(vid=0x0403, pid=0x6014, timeout=5, device="smt2")

with self.gdbserver.run():
try:
Expand Down
20 changes: 10 additions & 10 deletions trunner/tools/phoenix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
import pexpect

from trunner.harness import ProcessError
from trunner.dut import PortNotFound
from serial.tools import list_ports
from contextlib import contextmanager
from .common import add_output_to_exception


def wait_for_vid_pid(vid: int, pid: int, timeout=0):
def wait_for_vid_pid(vid: int, pid: int, timeout: int = 0, device: str = ""):
"""wait for connected usb serial device with required vendor & product id"""

asleep = 0
found_ports = []

while not found_ports:
time.sleep(0.01)
asleep += 0.01

found_ports = [port for port in list_ports.comports() if port.pid == pid and port.vid == vid]

if len(found_ports) > 1:
raise Exception(
"More than one plo port was found! Maybe more than one device is connected? Hint used to find port:"
f"{vid:04x}:{pid:04x}"
raise PortNotFound(
f"More than one {device} port was found! Maybe more than one device is connected?"
f"Hint used to find port: {vid:04x}:{pid:04x}"
)

if timeout and asleep >= timeout:
raise TimeoutError(f"Couldn't find plo USB device with vid/pid: '{vid:04x}:{pid:04x}'")
raise PortNotFound(f"Couldn't find {device} device! Hint used to find port:" f"{vid:04x}:{pid:04x}")

time.sleep(0.01)
asleep += 0.01

return found_ports[0].device

Expand Down Expand Up @@ -115,7 +115,7 @@ def _reader(self):

def _run(self):
try:
self.port = wait_for_vid_pid(self.vid, self.pid, timeout=10)
self.port = wait_for_vid_pid(self.vid, self.pid, timeout=10, device="PLO")
except (TimeoutError, Exception) as exc:
raise PhoenixdError(str(exc)) from exc

Expand Down

0 comments on commit 2233646

Please sign in to comment.