diff mbox

[U-Boot,4/9] test/py: check for bad patterns everywhere we wait

Message ID 1453964274-9129-4-git-send-email-swarren@wwwdotorg.org
State Accepted
Commit 0c6189b5d60a2b0fcec65f3513bad7eee289da3f
Delegated to: Simon Glass
Headers show

Commit Message

Stephen Warren Jan. 28, 2016, 6:57 a.m. UTC
From: Stephen Warren <swarren@nvidia.com>

Currently, bad patterns are only honored when executing a shell command.
Other cases, such as the initial boot-up of U-Boot or when interacting
with command output rather than gathering all output prior to the shell
prompt, do not currently look for bad patterns in console output. This
patch makes sure that bad patterns are honored everywhere.

One benefit of this change is that if U-Boot sandbox fails to start up,
the error message it emits can be caught immediately, rather than relying
on a (long) timeout when waiting for the expected signon message and/or
command prompt.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 test/py/u_boot_console_base.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

Comments

Simon Glass Jan. 29, 2016, 3:47 a.m. UTC | #1
On 27 January 2016 at 23:57, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Currently, bad patterns are only honored when executing a shell command.
> Other cases, such as the initial boot-up of U-Boot or when interacting
> with command output rather than gathering all output prior to the shell
> prompt, do not currently look for bad patterns in console output. This
> patch makes sure that bad patterns are honored everywhere.
>
> One benefit of this change is that if U-Boot sandbox fails to start up,
> the error message it emits can be caught immediately, rather than relying
> on a (long) timeout when waiting for the expected signon message and/or
> command prompt.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  test/py/u_boot_console_base.py | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass Jan. 29, 2016, 4:02 a.m. UTC | #2
On 28 January 2016 at 20:47, Simon Glass <sjg@chromium.org> wrote:
> On 27 January 2016 at 23:57, Stephen Warren <swarren@wwwdotorg.org> wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> Currently, bad patterns are only honored when executing a shell command.
>> Other cases, such as the initial boot-up of U-Boot or when interacting
>> with command output rather than gathering all output prior to the shell
>> prompt, do not currently look for bad patterns in console output. This
>> patch makes sure that bad patterns are honored everywhere.
>>
>> One benefit of this change is that if U-Boot sandbox fails to start up,
>> the error message it emits can be caught immediately, rather than relying
>> on a (long) timeout when waiting for the expected signon message and/or
>> command prompt.
>>
>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>> ---
>>  test/py/u_boot_console_base.py | 26 +++++++++++++++++++-------
>>  1 file changed, 19 insertions(+), 7 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

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

Patch

diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py
index efb06cad0af0..71a00e863385 100644
--- a/test/py/u_boot_console_base.py
+++ b/test/py/u_boot_console_base.py
@@ -231,7 +231,10 @@  class ConsoleBase(object):
 
         if type(text) == type(''):
             text = re.escape(text)
-        self.p.expect([text])
+        m = self.p.expect([text] + self.bad_patterns)
+        if m != 0:
+            raise Exception('Bad pattern found on console: ' +
+                            self.bad_pattern_ids[m - 1])
 
     def drain_console(self):
         """Read from and log the U-Boot console for a short time.
@@ -298,8 +301,14 @@  class ConsoleBase(object):
             self.p.timeout = 30000
             self.p.logfile_read = self.logstream
             if self.config.buildconfig.get('CONFIG_SPL', False) == 'y':
-                self.p.expect([pattern_u_boot_spl_signon])
-            self.p.expect([pattern_u_boot_main_signon])
+                m = self.p.expect([pattern_u_boot_spl_signon] + self.bad_patterns)
+                if m != 0:
+                    raise Exception('Bad pattern found on console: ' +
+                                    self.bad_pattern_ids[m - 1])
+            m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns)
+            if m != 0:
+                raise Exception('Bad pattern found on console: ' +
+                                self.bad_pattern_ids[m - 1])
             signon = self.p.after
             build_idx = signon.find(', Build:')
             if build_idx == -1:
@@ -307,12 +316,15 @@  class ConsoleBase(object):
             else:
                 self.u_boot_version_string = signon[:build_idx]
             while True:
-                match = self.p.expect([self.prompt_escaped,
-                                       pattern_stop_autoboot_prompt])
-                if match == 1:
+                m = self.p.expect([self.prompt_escaped,
+                    pattern_stop_autoboot_prompt] + self.bad_patterns)
+                if m == 0:
+                    break
+                if m == 1:
                     self.p.send(chr(3)) # CTRL-C
                     continue
-                break
+                raise Exception('Bad pattern found on console: ' +
+                                self.bad_pattern_ids[m - 2])
             self.at_prompt = True
             self.at_prompt_logevt = self.logstream.logfile.cur_evt
         except Exception as ex: