test/py: Move the timeout to console_base

This timeout relates to the expect() function so move it into the same
file and class.

Reset the timeout when a new spawn is created, to mimic the existing
behabiour. Update a few tests which access the timeout directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-07-23 17:42:03 -06:00
parent c5cad939ad
commit 31c6d1d063
4 changed files with 23 additions and 20 deletions

View File

@@ -164,15 +164,15 @@ class ConsoleSetupTimeout():
then default 30s."""
def __init__(self, console, timeout):
self.p = console.p
self.orig_timeout = self.p.timeout
self.p.timeout = timeout
self.console = console
self.orig_timeout = self.console.timeout
self.console.timeout = timeout
def __enter__(self):
return self
def __exit__(self, extype, value, traceback):
self.p.timeout = self.orig_timeout
self.console.timeout = self.orig_timeout
class ConsoleBase():
@@ -218,6 +218,8 @@ class ConsoleBase():
u_boot_version_string (str): Version string obtained from U-Boot as
it booted. In lab mode this is provided by
pattern_ready_prompt
timeout (str): Timeout in seconds before giving up and aborting the
test
"""
self.log = log
self.config = config
@@ -235,6 +237,7 @@ class ConsoleBase():
self.at_prompt_logevt = None
self.lab_mode = False
self.u_boot_version_string = None
self.timeout = None
self.eval_patterns()
@@ -278,7 +281,7 @@ class ConsoleBase():
ready for use. We don't need to look for signon messages.
"""
self.log.info('test.py: Lab mode is active')
self.p.timeout = TIMEOUT_PREPARE_MS
self.timeout = TIMEOUT_PREPARE_MS
self.lab_mode = True
def _wait_for_boot_prompt(self, loop_num=1):
@@ -326,7 +329,7 @@ class ConsoleBase():
m = pattern_ready_prompt.search(self.p.after)
self.u_boot_version_string = m.group(2)
self.log.info('Lab: Board is ready')
self.p.timeout = TIMEOUT_MS
self.timeout = TIMEOUT_MS
break
if m == 2:
self.log.info(f'Found autoboot prompt {m}')
@@ -516,10 +519,10 @@ class ConsoleBase():
if not self.p:
return
orig_timeout = self.p.timeout
orig_timeout = self.timeout
try:
# Drain the log for a relatively short time.
self.p.timeout = 1000
self.timeout = 1000
# Wait for something U-Boot will likely never send. This will
# cause the console output to be read and logged.
self.expect(['This should never match U-Boot output'])
@@ -536,7 +539,7 @@ class ConsoleBase():
# correctly terminate any log sections, etc.
pass
finally:
self.p.timeout = orig_timeout
self.timeout = orig_timeout
def ensure_spawned(self, expect_reset=False):
"""Ensure a connection to a correctly running U-Boot instance.
@@ -555,18 +558,19 @@ class ConsoleBase():
# Reset the console timeout value as some tests may change
# its default value during the execution
if not self.config.gdbserver:
self.p.timeout = TIMEOUT_MS
self.timeout = TIMEOUT_MS
return
try:
self.log.start_section('Starting U-Boot')
self.at_prompt = False
self.timeout = None
self.p = self.get_spawn()
# Real targets can take a long time to scroll large amounts of
# text if LCD is enabled. This value may need tweaking in the
# future, possibly per-test to be optimal. This works for 'help'
# on board 'seaboard'.
if not self.config.gdbserver:
self.p.timeout = TIMEOUT_MS
self.timeout = TIMEOUT_MS
self.p.logfile_read = self.logstream
if self.config.use_running_system:
# Send an empty command to set up the 'expect' logic. This has
@@ -724,10 +728,10 @@ class ConsoleBase():
self.p.buf = self.p.buf[posafter:]
return earliest_pi
tnow_s = time.time()
if self.p.timeout:
if self.timeout:
tdelta_ms = (tnow_s - tstart_s) * 1000
poll_maxwait = self.p.timeout - tdelta_ms
if tdelta_ms > self.p.timeout:
poll_maxwait = self.timeout - tdelta_ms
if tdelta_ms > self.timeout:
raise Timeout()
else:
poll_maxwait = None

View File

@@ -68,7 +68,6 @@ class Spawn:
self.logfile_read = None
self.before = ''
self.after = ''
self.timeout = None
# http://stackoverflow.com/questions/7857352/python-regex-to-match-vt100-escape-sequences
self.re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_]*[@-_]|\x1b[@-_]', re.I)

View File

@@ -358,7 +358,7 @@ def test_net_pxe_get(ubman):
pytest.skip("No PXE readable file to read")
addr = f.get("addr", None)
timeout = f.get("timeout", ubman.p.timeout)
timeout = f.get("timeout", ubman.timeout)
pxeuuid = uuid.uuid1()
ubman.run_command(f"setenv pxeuuid {pxeuuid}")
@@ -416,7 +416,7 @@ def test_net_tftpput(ubman):
addr = utils.find_ram_base(ubman)
sz = f.get("size", None)
timeout = f.get("timeout", ubman.p.timeout)
timeout = f.get("timeout", ubman.timeout)
fn = f["fn"]
fnu = f.get("fnu", "_".join([datetime.datetime.now().strftime("%y%m%d%H%M%S"), fn]))
expected_text = "Bytes transferred = "

View File

@@ -224,7 +224,7 @@ def test_net_pxe_boot(ubman):
f, bootfile = setup_pxe_boot(ubman)
addr = f.get('addr', None)
timeout = f.get('timeout', ubman.p.timeout)
timeout = f.get('timeout', ubman.timeout)
fn = f['fn']
if addr:
@@ -275,7 +275,7 @@ def test_net_pxe_boot_config(ubman):
f, bootfile = setup_pxe_boot(ubman)
addr = f.get('addr', None)
timeout = f.get('timeout', ubman.p.timeout)
timeout = f.get('timeout', ubman.timeout)
fn = f['fn']
local_label = f['local_label']
empty_label = f['empty_label']
@@ -354,7 +354,7 @@ def test_net_pxe_boot_config_invalid(ubman):
f, bootfile = setup_pxe_boot(ubman)
addr = f.get('addr', None)
timeout = f.get('timeout', ubman.p.timeout)
timeout = f.get('timeout', ubman.timeout)
fn = f['fn']
invalid_label = f['invalid_label']
exp_str_invalid = f['exp_str_invalid']