[PATCH v5 17/20] test: Try to shut down the lab console gracefully

neil.armstrong at linaro.org neil.armstrong at linaro.org
Thu Aug 29 16:26:01 CEST 2024


On 29/08/2024 00:08, Simon Glass wrote:
> Send the Labgrid quit characters to ask it to exit gracefully. This
> typically allows it to power off the board being used.

Sending those characters every time could collide with other CI systems,
I don't think it's a good idea.

> 
> If that doesn't work, try the less graceful approach.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
> (no changes since v1)
> 
>   test/py/u_boot_spawn.py | 17 +++++++++++++++--
>   1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py
> index c0ff0813554..ec1fa465047 100644
> --- a/test/py/u_boot_spawn.py
> +++ b/test/py/u_boot_spawn.py
> @@ -16,6 +16,9 @@ import termios
>   import time
>   import traceback
>   
> +# 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."""
>   
> @@ -304,15 +307,25 @@ class Spawn:
>               None.
>   
>           Returns:
> -            Nothing.
> +            str: Type of closure completed
>           """
> +        self.send(chr(EXIT_CHAR) * 2)
>   
> +        # Wait about 10 seconds for Labgrid to close and power off the board
> +        for _ in range(100):
> +            if not self.isalive():
> +                return 'normal'
> +            time.sleep(0.1)
> +
> +        # That didn't work, so try closing the PTY
>           os.close(self.fd)
>           for _ in range(100):
>               if not self.isalive():
> -                break
> +                return 'break'
>               time.sleep(0.1)
>   
> +        return 'timeout'
> +
>       def get_expect_output(self):
>           """Return the output read by expect()
>   



More information about the U-Boot mailing list