
From: Simon Glass <sjg@chromium.org> Board reset in pytests is pretty ad-hoc at present. The normal approach is to cause a reset to happen, or come to a point in a test where a reset is expected. Then the test looks for the U-Boot banner, indicating that the board has rebooted. This has a few problems: - Some lab boards use USB to send U-Boot to the board. Resetting may result in a hang, since U-Boot is not present after a reset - Resetting generally does a software reset, which is different to a hardware reset. For example the TPM is not reset on a software reset so the previous TPM state is still present. This means that tests which want to check early TPM-setup cannot work - To do a hardware reset, the current integration simply throws away the ConsoleExecAttach() object and created a new one. This unnecessary with the sjg Labgrid integration and it is quite inefficient, since U-Boot is built again, written to the board again, etc. - Some boards may need a signal to be provided to indicate whence the firmware should be read. If this signal happens to not be present, the wrong firmware will be started There are various other corner cases as well. To resolve this, provide a restart_board() implementation in ConsoleExecAttach which can reliably restart a board. There is one parameter, which tells it whether the reset has already been triggered. If not, it triggers one. Implement this in the sjg Labgrid integration (i.e. 'lab mode', via a new `u-boot-test-restart` hook. Enable it for ellesmere (sjg lab). This allows send-only boards like pcduino3 to handle the EFI watchdog test, for example. There is quite a bit of cleanup which could be pursured following this change, mostly calling the new function instead ubman.run_command() and improving how sandbox restarts. This can be dealt with later. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/hooks/bin/ellesmere/common-labgrid-sjg | 1 + test/hooks/bin/restart.labgrid-sjg | 43 +++++++++++++++++++++ test/hooks/bin/u-boot-test-restart | 38 ++++++++++++++++++ test/py/console_board.py | 14 +++++++ 4 files changed, 96 insertions(+) create mode 100755 test/hooks/bin/restart.labgrid-sjg create mode 100755 test/hooks/bin/u-boot-test-restart diff --git a/test/hooks/bin/ellesmere/common-labgrid-sjg b/test/hooks/bin/ellesmere/common-labgrid-sjg index 6b3eff5f277..d62f5fadf92 100755 --- a/test/hooks/bin/ellesmere/common-labgrid-sjg +++ b/test/hooks/bin/ellesmere/common-labgrid-sjg @@ -44,3 +44,4 @@ console_impl=labgrid-sjg release_impl=labgrid-sjg getrole_impl=labgrid-sjg power_impl=none +restart_impl=labgrid-sjg diff --git a/test/hooks/bin/restart.labgrid-sjg b/test/hooks/bin/restart.labgrid-sjg new file mode 100755 index 00000000000..7c533753fe3 --- /dev/null +++ b/test/hooks/bin/restart.labgrid-sjg @@ -0,0 +1,43 @@ +# Copyright 2024 Google LLC +# Written by Simon Glass +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# The variables here can come from one of two places: +# +# 1. When using the ub-xxx scripts (e.g. ub-int) they come from those scripts, +# set by the get_args.sh script +# +# 2. When running from gitlab, the variables are all empty and so take the +# default values below, except for ${strategy} which is set in the gitlab +# script + +# On input: +# strategy: Strategy arguments to use, e.g. "-s start". Normally this is +# "-s uboot -e off" but it can be "-s start -e off" or even empty +# verbose: Verbose argument to use, e.g. "-v" +# +# The 'vars' variable is set by .gitlab-ci.yml or by get_args.sh in the Labgrid +# integration + +reset="$3" +exec labgrid-client -V do-bootstrap ${bootstrap:-1} \ + -V do-send ${send:-0} -V do-reset ${reset:-0} ${vars} \ + -r "${U_BOOT_BOARD_IDENTITY}" -i uboot -s restart ${verbose} \ + --assume-ready query diff --git a/test/hooks/bin/u-boot-test-restart b/test/hooks/bin/u-boot-test-restart new file mode 100755 index 00000000000..2f60bddab2b --- /dev/null +++ b/test/hooks/bin/u-boot-test-restart @@ -0,0 +1,38 @@ +#!/bin/bash + +# Copyright 2025 Simon Glass <sjg@chromium.org> +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Restarts the board, bringing it back to the U-Boot prompt ready for running +# tests + +# This is called from restart_board() in test/py + +# Arguments: +# - board 'type' (U-Boot board name) +# - board identity (Labgrid role) +# - <reset_flag> +# +# <reset_flag> is 1 if this script should reset the board, 0 (or empty) if it +# has already been done + +. "$(dirname $0)/u-boot-test-common" + +. "${bin_dir}/restart.${restart_impl}" diff --git a/test/py/console_board.py b/test/py/console_board.py index bacb1e2526c..1c7ee8be7d9 100644 --- a/test/py/console_board.py +++ b/test/py/console_board.py @@ -74,6 +74,20 @@ class ConsoleExecAttach(ConsoleBase): return s + def restart_board(self, need_reset=True): + if not self.lab_mode: + super().restart_board(need_reset) + return + + self.log.action(f'Restarting board (need_reset {need_reset})') + args = [self.config.board_type, self.config.board_identity] + if need_reset: + args.append('1') + cmd = ['u-boot-test-restart'] + args + runner = self.log.get_runner(cmd[0], sys.stdout) + runner.run(cmd) + runner.close() + def close(self): super().close() -- 2.43.0