diff mbox series

[U-Boot,1/1] test/py: catch errors occurring when reading the console

Message ID 20180920181932.12788-1-xypron.glpk@gmx.de
State Changes Requested
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/1] test/py: catch errors occurring when reading the console | expand

Commit Message

Heinrich Schuchardt Sept. 20, 2018, 6:19 p.m. UTC
Spawn.exept has a try block without 'except'.

When the py test is running it is connected via pipes to the U-Boot
process. If the U-Boot process ends prematurely, e.g. due to a
segmentation fault, the pipes are broken. Trying to read from a broken
pipe results in an OSError. Catch the exception and treat the broken pipe
like any other end of output. By returning None expect() indicates that
the output does not match.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
I suggest that Alex takes the patch because we need it when working on
the efi-next branch.

v3
	add more comments
v2
	replace TAB by spaces
	fix type in subject
---
 test/py/u_boot_spawn.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Stephen Warren Sept. 20, 2018, 7:07 p.m. UTC | #1
On 09/20/2018 12:19 PM, Heinrich Schuchardt wrote:
> Spawn.exept has a try block without 'except'.
> 
> When the py test is running it is connected via pipes to the U-Boot
> process. If the U-Boot process ends prematurely, e.g. due to a
> segmentation fault, the pipes are broken. Trying to read from a broken
> pipe results in an OSError. Catch the exception and treat the broken pipe
> like any other end of output. By returning None expect() indicates that
> the output does not match.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
> I suggest that Alex takes the patch because we need it when working on
> the efi-next branch.
> 
> v3
> 	add more comments

Adding comments doesn't solve the fundamental problem with this patch. 
I'll send an alternative patch in a minute. That patch will hide 
exceptions only during a very specific portion of time, rather than just 
ignoring all of them.
diff mbox series

Patch

diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
index b011a3e3da..adc1d00287 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/u_boot_spawn.py
@@ -181,6 +181,14 @@  class Spawn(object):
                 # unlimited substitutions, but in practice the version of
                 # Python in Ubuntu 14.04 appears to default to count=2!
                 self.buf = self.re_vt100.sub('', self.buf, count=1000000)
+        except OSError, EOFError:
+            # When the py test is running it is connected via pipes to the
+            # U-Boot process. If the U-Boot process ends prematurely, e.g. due
+            # to a segmentation fault, the pipes are broken. Trying to read
+            # from a broken pipe results in an OSError. Treat the broken pipe
+            # like any other end of output. By returning None expect()
+            # indicates that the output does not match.
+            pass
         finally:
             if self.logfile_read:
                 self.logfile_read.flush()