mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 16:01:27 +00:00
test: Move the receive code into a function
There is quite a bit of code to deal with receiving data from the target so move it into its own receive() function. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
40a1ed1e76
commit
e4ad90149c
1 changed files with 27 additions and 12 deletions
|
@ -137,6 +137,32 @@ class Spawn:
|
||||||
|
|
||||||
os.write(self.fd, data.encode(errors='replace'))
|
os.write(self.fd, data.encode(errors='replace'))
|
||||||
|
|
||||||
|
def receive(self, num_bytes):
|
||||||
|
"""Receive data from the sub-process's stdin.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
num_bytes (int): Maximum number of bytes to read
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The data received
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError if U-Boot died
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
c = os.read(self.fd, num_bytes).decode(errors='replace')
|
||||||
|
except OSError as err:
|
||||||
|
# With sandbox, try to detect when U-Boot exits when it
|
||||||
|
# shouldn't and explain why. This is much more friendly than
|
||||||
|
# just dying with an I/O error
|
||||||
|
if self.decode_signal and err.errno == 5: # I/O error
|
||||||
|
alive, _, info = self.checkalive()
|
||||||
|
if alive:
|
||||||
|
raise err
|
||||||
|
raise ValueError('U-Boot exited with %s' % info)
|
||||||
|
raise
|
||||||
|
return c
|
||||||
|
|
||||||
def expect(self, patterns):
|
def expect(self, patterns):
|
||||||
"""Wait for the sub-process to emit specific data.
|
"""Wait for the sub-process to emit specific data.
|
||||||
|
|
||||||
|
@ -193,18 +219,7 @@ class Spawn:
|
||||||
events = self.poll.poll(poll_maxwait)
|
events = self.poll.poll(poll_maxwait)
|
||||||
if not events:
|
if not events:
|
||||||
raise Timeout()
|
raise Timeout()
|
||||||
try:
|
c = self.receive(1024)
|
||||||
c = os.read(self.fd, 1024).decode(errors='replace')
|
|
||||||
except OSError as err:
|
|
||||||
# With sandbox, try to detect when U-Boot exits when it
|
|
||||||
# shouldn't and explain why. This is much more friendly than
|
|
||||||
# just dying with an I/O error
|
|
||||||
if self.decode_signal and err.errno == 5: # I/O error
|
|
||||||
alive, _, info = self.checkalive()
|
|
||||||
if alive:
|
|
||||||
raise err
|
|
||||||
raise ValueError('U-Boot exited with %s' % info)
|
|
||||||
raise
|
|
||||||
if self.logfile_read:
|
if self.logfile_read:
|
||||||
self.logfile_read.write(c)
|
self.logfile_read.write(c)
|
||||||
self.buf += c
|
self.buf += c
|
||||||
|
|
Loading…
Add table
Reference in a new issue