summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorBrian J. Nemec <bnemec@chromium.org>2020-10-20 09:10:20 -0700
committerCommit Bot <commit-bot@chromium.org>2020-10-21 16:52:53 +0000
commit5047df065dfede71f795c18d9f75cc8ef98d2017 (patch)
treef35e3f71acc663a051a8fdb9df2dca007793e4e2 /extra
parentef23cf615a0dcc853d373c6fc766c60032e9f9b3 (diff)
downloadchrome-ec-5047df065dfede71f795c18d9f75cc8ef98d2017.tar.gz
servo_updater: Add timeout on the pty flush
If the servo is in a loop where it sends output on a continuous basis, the flush operation needs to eventually timeout. If the servo sends commands out faster than the timeout provided to the expects() call, it would never advance. This blocked the servo_updater from advancing. BUG=b:162628581 TEST=Connect Servo_v4p1 to DUT validate servo_updater works TEST=Modify Servo firmware to generate many console messages in a loop. Validate that the flush operation succeeds and servo updater still works. Change-Id: I8c0e65a0733b4d4ee25a9f9c866aa2b863cb0e5a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2487256 Reviewed-by: Matthew Blecker <matthewb@chromium.org> Tested-by: Brian Nemec <bnemec@chromium.org> Commit-Queue: Brian Nemec <bnemec@chromium.org>
Diffstat (limited to 'extra')
-rw-r--r--extra/tigertool/ecusb/pty_driver.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/extra/tigertool/ecusb/pty_driver.py b/extra/tigertool/ecusb/pty_driver.py
index 63df230e7e..e5ff043aad 100644
--- a/extra/tigertool/ecusb/pty_driver.py
+++ b/extra/tigertool/ecusb/pty_driver.py
@@ -14,10 +14,12 @@ import errno
import fcntl
import os
import pexpect
+import time
from pexpect import fdpexpect
# Expecting a result in 3 seconds is plenty even for slow platforms.
DEFAULT_UART_TIMEOUT = 3
+FLUSH_UART_TIMEOUT = 1
class ptyError(Exception):
@@ -76,9 +78,13 @@ class ptyDriver(object):
"""Flush device output to prevent previous messages interfering."""
if self._child.sendline('') != 1:
raise ptyError('Failed to send newline.')
- while True:
+ # Have a maximum timeout for the flush operation. We should have cleared
+ # all data from the buffer, but if data is regularly being generated, we
+ # can't guarantee it will ever stop.
+ flush_end_time = time.time() + FLUSH_UART_TIMEOUT
+ while time.time() <= flush_end_time:
try:
- self._child.expect('.', timeout=0.2)
+ self._child.expect('.', timeout=0.01)
except (pexpect.TIMEOUT, pexpect.EOF):
break
except OSError as e: