All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH v6 09/19] test: Separate out the exception handling
Date: Fri, 20 Sep 2024 08:01:44 +0200	[thread overview]
Message-ID: <20240920060158.106612-10-sjg@chromium.org> (raw)
In-Reply-To: <20240920060158.106612-1-sjg@chromium.org>

The tests currently catch a very board Exception in each case. This is
thrown even in the event of a coding error.

We want to handle exceptions differently depending on their severity,
so that we can avoid hour-long delays waiting for a board that is
clearly broken.

As a first step, create some new exception types, separating out those
which are simply an unexpected result from executed a command, from
those which indicate some kind of hardware failure.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 test/py/u_boot_console_base.py | 26 ++++++++++++++------------
 test/py/u_boot_spawn.py        | 11 +++++++++++
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py
index 8a9c4a576dc..fa87952694d 100644
--- a/test/py/u_boot_console_base.py
+++ b/test/py/u_boot_console_base.py
@@ -14,6 +14,7 @@ import pytest
 import re
 import sys
 import u_boot_spawn
+from u_boot_spawn import BootFail, Timeout, Unexpected
 
 # Regexes for text we expect U-Boot to send to the console.
 pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
@@ -190,13 +191,13 @@ class ConsoleBase(object):
                     m = self.p.expect([pattern_u_boot_spl_signon] +
                                       self.bad_patterns)
                     if m != 0:
-                        raise Exception('Bad pattern found on SPL console: ' +
+                        raise BootFail('Bad pattern found on SPL console: ' +
                                         self.bad_pattern_ids[m - 1])
                     env_spl_banner_times -= 1
 
                 m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns)
                 if m != 0:
-                    raise Exception('Bad pattern found on console: ' +
+                    raise BootFail('Bad pattern found on console: ' +
                                     self.bad_pattern_ids[m - 1])
             self.u_boot_version_string = self.p.after
             while True:
@@ -207,13 +208,9 @@ class ConsoleBase(object):
                 if m == 2:
                     self.p.send(' ')
                     continue
-                raise Exception('Bad pattern found on console: ' +
+                raise BootFail('Bad pattern found on console: ' +
                                 self.bad_pattern_ids[m - 3])
 
-        except Exception as ex:
-            self.log.error(str(ex))
-            self.cleanup_spawn()
-            raise
         finally:
             self.log.timestamp()
 
@@ -279,7 +276,7 @@ class ConsoleBase(object):
                 m = self.p.expect([chunk] + self.bad_patterns)
                 if m != 0:
                     self.at_prompt = False
-                    raise Exception('Bad pattern found on console: ' +
+                    raise BootFail('Bad pattern found on console: ' +
                                     self.bad_pattern_ids[m - 1])
             if not wait_for_prompt:
                 return
@@ -289,14 +286,18 @@ class ConsoleBase(object):
                 m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
                 if m != 0:
                     self.at_prompt = False
-                    raise Exception('Bad pattern found on console: ' +
+                    raise BootFail('Missing prompt on console: ' +
                                     self.bad_pattern_ids[m - 1])
             self.at_prompt = True
             self.at_prompt_logevt = self.logstream.logfile.cur_evt
             # Only strip \r\n; space/TAB might be significant if testing
             # indentation.
             return self.p.before.strip('\r\n')
-        except Exception as ex:
+        except Timeout as exc:
+            self.log.error(str(exc))
+            self.cleanup_spawn()
+            raise
+        except BootFail as ex:
             self.log.error(str(ex))
             self.cleanup_spawn()
             raise
@@ -355,8 +356,9 @@ class ConsoleBase(object):
             text = re.escape(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])
+            raise Unexpected(
+                "Unexpected pattern found on console (exp '{text}': " +
+                self.bad_pattern_ids[m - 1])
 
     def drain_console(self):
         """Read from and log the U-Boot console for a short time.
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
index 69a2cd55816..bcba7b5cd43 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/u_boot_spawn.py
@@ -16,6 +16,17 @@ import traceback
 class Timeout(Exception):
     """An exception sub-class that indicates that a timeout occurred."""
 
+class BootFail(Exception):
+    """An exception sub-class that indicates that a boot failure occurred.
+
+    This is used when a bad pattern is seen when waiting for the boot prompt.
+    It is regarded as fatal, to avoid trying to boot the again and again to no
+    avail.
+    """
+
+class Unexpected(Exception):
+    """An exception sub-class that indicates that unexpected test was seen."""
+
 class Spawn:
     """Represents the stdio of a freshly created sub-process. Commands may be
     sent to the process, and responses waited for.
-- 
2.43.0


  parent reply	other threads:[~2024-09-20  6:04 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-20  6:01 [PATCH v6 00/19] labgrid: Provide an integration with Labgrid Simon Glass
2024-09-20  6:01 ` [PATCH v6 01/19] test: Allow signaling that U-Boot is ready Simon Glass
2024-09-23 20:35   ` Tom Rini
2024-09-25 12:49     ` Simon Glass
2024-09-25 17:26       ` Tom Rini
2024-09-26 21:36         ` Simon Glass
2024-09-27  2:51           ` Tom Rini
2024-10-31 18:03             ` Simon Glass
2024-10-31 18:28               ` Tom Rini
2024-11-01 15:33                 ` Simon Glass
2024-11-01 19:02                   ` Tom Rini
2024-11-02 16:32                     ` Simon Glass
2024-11-02 21:39                       ` Tom Rini
2024-09-20  6:01 ` [PATCH v6 02/19] test: Use a constant for the test timeout Simon Glass
2024-09-23 20:35   ` Tom Rini
2024-09-20  6:01 ` [PATCH v6 03/19] test: Release board after tests complete Simon Glass
2024-09-20  6:01 ` [PATCH v6 04/19] test: Allow connecting to a running board Simon Glass
2024-09-23 20:35   ` Tom Rini
2024-09-25 12:50     ` Simon Glass
2024-09-20  6:01 ` [PATCH v6 05/19] test: Avoid failing skipped tests Simon Glass
2024-09-20  6:01 ` [PATCH v6 06/19] test: Create a common function to get the config Simon Glass
2024-09-20  6:01 ` [PATCH v6 07/19] test: Introduce the concept of a role Simon Glass
2024-09-20  6:01 ` [PATCH v6 08/19] test: Move the receive code into a function Simon Glass
2024-09-20  6:01 ` Simon Glass [this message]
2024-09-20  6:01 ` [PATCH v6 10/19] test: Detect dead connections Simon Glass
2024-09-20  6:01 ` [PATCH v6 11/19] test: Tidy up remaining exceptions Simon Glass
2024-09-20  6:01 ` [PATCH v6 12/19] test: Introduce lab mode Simon Glass
2024-09-20  6:01 ` [PATCH v6 13/19] test: Improve handling of sending commands Simon Glass
2024-09-20  6:01 ` [PATCH v6 14/19] test: Fix mulptiplex_log typo Simon Glass
2024-09-20  6:01 ` [PATCH v6 15/19] test: Avoid double echo when starting up Simon Glass
2024-09-20  6:01 ` [PATCH v6 16/19] test: Try to shut down the lab console gracefully Simon Glass
2024-09-20  6:01 ` [PATCH v6 17/19] test: Add a section for closing the connection Simon Glass
2024-09-20  6:01 ` [PATCH v6 18/19] test: Support testing with two board-builds Simon Glass
2024-09-20  6:01 ` [PATCH v6 19/19] CI: Allow running tests on sjg lab Simon Glass
2024-09-23 20:36 ` [PATCH v6 00/19] labgrid: Provide an integration with Labgrid Tom Rini
2024-09-25 12:50   ` Simon Glass
2024-09-25 17:26     ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240920060158.106612-10-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.