
From: Simon Glass <sjg@chromium.org> As a first step towards moving the expect() handler to console_base, move the exceptions there. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/conftest.py | 2 +- test/py/console_base.py | 55 ++++++++++++++++++++++++++++++++++++++++- test/py/spawn.py | 50 ------------------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 8b198c93ccc..f0101ed6b3d 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -25,7 +25,7 @@ import re from _pytest.runner import runtestprotocol import subprocess import sys -from spawn import BootFail, Timeout, Unexpected, handle_exception +from console_base import BootFail, Timeout, Unexpected, handle_exception import time # Globals: The HTML log file, and the top-level fixture diff --git a/test/py/console_base.py b/test/py/console_base.py index 194db5fedf2..25adcda215b 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -13,9 +13,9 @@ serial console of real hardware. from collections import namedtuple import re import sys +import pytest import spawn -from spawn import BootFail, Timeout, Unexpected, handle_exception # Regexes for text we expect U-Boot to send to the console. pattern_u_boot_spl_signon = re.compile('(U-Boot Concept SPL \\d{4}\\.\\d{2}[^\r\n]*\\))') @@ -55,6 +55,59 @@ PATTERNS = ( ) +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.""" + + +def handle_exception(ubconfig, console, log, err, name, fatal, output=''): + """Handle an exception from the console + + Exceptions can occur when there is unexpected output or due to the board + crashing or hanging. Some exceptions are likely fatal, where retrying will + just chew up time to no available. In those cases it is best to cause + further tests be skipped. + + Args: + ubconfig (ArbitraryAttributeContainer): ubconfig object + log (Logfile): Place to log errors + console (ConsoleBase): Console to clean up, if fatal + err (Exception): Exception which was thrown + name (str): Name of problem, to log + fatal (bool): True to abort all tests + output (str): Extra output to report on boot failure. This can show the + target's console output as it tried to boot + """ + msg = f'{name}: ' + if fatal: + msg += 'Marking connection bad - no other tests will run' + else: + msg += 'Assuming that lab is healthy' + print(msg) + log.error(msg) + log.error(f'Error: {err}') + + if output: + msg += f'; output {output}' + + if fatal: + ubconfig.connection_ok = False + console.cleanup_spawn() + pytest.exit(msg) + + class ConsoleDisableCheck(): """Context manager (for Python's with statement) that temporarily disables the specified console output error check. This is useful when deliberately diff --git a/test/py/spawn.py b/test/py/spawn.py index 49b9f2729ac..65555e0d901 100644 --- a/test/py/spawn.py +++ b/test/py/spawn.py @@ -37,56 +37,6 @@ import pytest # Character to send (twice) to exit the terminal EXIT_CHAR = 0x1d # FS (Ctrl + ]) -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.""" - - -def handle_exception(ubconfig, console, log, err, name, fatal, output=''): - """Handle an exception from the console - - Exceptions can occur when there is unexpected output or due to the board - crashing or hanging. Some exceptions are likely fatal, where retrying will - just chew up time to no available. In those cases it is best to cause - further tests be skipped. - - Args: - ubconfig (ArbitraryAttributeContainer): ubconfig object - log (Logfile): Place to log errors - console (ConsoleBase): Console to clean up, if fatal - err (Exception): Exception which was thrown - name (str): Name of problem, to log - fatal (bool): True to abort all tests - output (str): Extra output to report on boot failure. This can show the - target's console output as it tried to boot - """ - msg = f'{name}: ' - if fatal: - msg += 'Marking connection bad - no other tests will run' - else: - msg += 'Assuming that lab is healthy' - print(msg) - log.error(msg) - log.error(f'Error: {err}') - - if output: - msg += f'; output {output}' - - if fatal: - ubconfig.connection_ok = False - console.cleanup_spawn() - pytest.exit(msg) - class Spawn: """Represents the stdio of a freshly created sub-process. Commands may be -- 2.43.0