Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trunner.tools: fix error message in wait_for_vid_pid() #365

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, device="smt2", timeout=5)

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, device: str, timeout: int = 0):
"""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, device="plo", timeout=10)
except (TimeoutError, Exception) as exc:
raise PhoenixdError(str(exc)) from exc

Expand Down
Loading