diff mbox

[U-Boot,V2,5/8] test/py: optionally ignore errors from shell commands

Message ID 1453491014-1122-5-git-send-email-swarren@wwwdotorg.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Stephen Warren Jan. 22, 2016, 7:30 p.m. UTC
From: Stephen Warren <swarren@nvidia.com>

Sometimes it's useful to run shell commands and ignore any errors. One
example might be cleanup logic; if a test-case experiences an error, the
cleanup logic might experience an error too, and we don't want that error
to mask the original error, so we want to ignore the subsequent error.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
---
 test/py/multiplexed_log.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Simon Glass Jan. 22, 2016, 8:14 p.m. UTC | #1
On 22 January 2016 at 12:30, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Sometimes it's useful to run shell commands and ignore any errors. One
> example might be cleanup logic; if a test-case experiences an error, the
> cleanup logic might experience an error too, and we don't want that error
> to mask the original error, so we want to ignore the subsequent error.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
>  test/py/multiplexed_log.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox

Patch

diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 48f2b51de15f..5059bbfb99c3 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -106,13 +106,17 @@  class RunAndLog(object):
         '''Clean up any resources managed by this object.'''
         pass
 
-    def run(self, cmd, cwd=None):
+    def run(self, cmd, cwd=None, ignore_errors=False):
         '''Run a command as a sub-process, and log the results.
 
         Args:
             cmd: The command to execute.
             cwd: The directory to run the command in. Can be None to use the
                 current directory.
+            ignore_errors: Indicate whether to ignore errors. If True, the
+                function will simply return if the command cannot be executed
+                or exits with an error code, otherwise an exception will be
+                raised if such problems occur.
 
         Returns:
             Nothing.
@@ -148,7 +152,7 @@  class RunAndLog(object):
             exception = e
         if output and not output.endswith('\n'):
             output += '\n'
-        if exit_status and not exception:
+        if exit_status and not exception and not ignore_errors:
             exception = Exception('Exit code: ' + str(exit_status))
         if exception:
             output += str(exception) + '\n'