test: Allow connecting to a running board

Sometimes we know that the board is already running the right software,
so provide an option to allow running of tests directly, without first
resetting the board.

This saves time when re-running a test where only the Python code is
changing.

Note that this feature is open to errors, since the user must know that
the board is in a fit state to execute tests. It is useful for repeated
iteration on a particular test, where it can save quite a bit of time.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2024-11-12 07:13:17 -07:00 committed by Tom Rini
parent 530c694c45
commit 6f3583074f
3 changed files with 25 additions and 13 deletions

View file

@ -80,6 +80,8 @@ def pytest_addoption(parser):
parser.addoption('--gdbserver', default=None,
help='Run sandbox under gdbserver. The argument is the channel '+
'over which gdbserver should communicate, e.g. localhost:1234')
parser.addoption('--use-running-system', default=False, action='store_true',
help="Assume that U-Boot is ready and don't wait for a prompt")
def run_build(config, source_dir, build_dir, board_type, log):
"""run_build: Build U-Boot
@ -254,6 +256,7 @@ def pytest_configure(config):
ubconfig.board_type = board_type
ubconfig.board_identity = board_identity
ubconfig.gdbserver = gdbserver
ubconfig.use_running_system = config.getoption('use_running_system')
ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'
ubconfig.connection_ok = True

View file

@ -441,11 +441,17 @@ class ConsoleBase(object):
if not self.config.gdbserver:
self.p.timeout = TIMEOUT_MS
self.p.logfile_read = self.logstream
if expect_reset:
loop_num = 2
if self.config.use_running_system:
# Send an empty command to set up the 'expect' logic. This has
# the side effect of ensuring that there was no partial command
# line entered
self.run_command(' ')
else:
loop_num = 1
self.wait_for_boot_prompt(loop_num = loop_num)
if expect_reset:
loop_num = 2
else:
loop_num = 1
self.wait_for_boot_prompt(loop_num = loop_num)
self.at_prompt = True
self.at_prompt_logevt = self.logstream.logfile.cur_evt
except Exception as ex:

View file

@ -59,15 +59,18 @@ class ConsoleExecAttach(ConsoleBase):
args = [self.config.board_type, self.config.board_identity]
s = Spawn(['u-boot-test-console'] + args)
try:
self.log.action('Resetting board')
cmd = ['u-boot-test-reset'] + args
runner = self.log.get_runner(cmd[0], sys.stdout)
runner.run(cmd)
runner.close()
except:
s.close()
raise
if self.config.use_running_system:
self.log.action('Connecting to board without reset')
else:
try:
self.log.action('Resetting board')
cmd = ['u-boot-test-reset'] + args
runner = self.log.get_runner(cmd[0], sys.stdout)
runner.run(cmd)
runner.close()
except:
s.close()
raise
return s