test: pytest: Add --quiet-hooks option

Add a --quiet-hooks option to suppress display of hook commands to
stdout while still logging them to the HTML log file. This reduces
console noise during test runs.

Cover-letter:
test: pytest and hook improvements
This series includes several improvements to the pytest infrastructure
and test hook configurations:

- Fix the timing check in conftest to properly check if timing is enabled
- Add a --quiet-hooks option to suppress hook command display
- Add and update ellesmere hook config files for various QEMU boards
- Update qemu-riscv64 config for S-mode with OpenSBI
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-26 20:01:13 -07:00
parent b5b75c768e
commit e16a9fa8b5
2 changed files with 15 additions and 5 deletions

View File

@@ -87,6 +87,8 @@ def pytest_addoption(parser):
help='Compile U-Boot before running tests')
parser.addoption('--buildman', default=False, action='store_true',
help='Use buildman to build U-Boot (assuming --build is given)')
parser.addoption('--quiet-hooks', default=False, action='store_true',
help='Suppress display of hook commands (still logged to file)')
parser.addoption(
'-E', '--allow-exceptions', '-E', default=False, action='store_true',
help='Avoid catching exceptions with test failures')
@@ -113,6 +115,8 @@ def run_build(config, source_dir, build_dir, board_type, log):
if config.getoption('buildman'):
if build_dir != source_dir:
dest_args = ['-o', build_dir, '-w']
if config.getoption('quiet_hooks'):
dest_args.append('-I')
else:
dest_args = ['-i']
cmds = (['buildman', '--board', board_type] + dest_args,)
@@ -276,7 +280,9 @@ def pytest_configure(config):
raise Exception('--gdbserver only supported with sandbox targets')
import multiplexed_log
log = multiplexed_log.Logfile(result_dir + '/test-log.html')
quiet_hooks = config.getoption('quiet_hooks')
log = multiplexed_log.Logfile(result_dir + '/test-log.html',
quiet_hooks=quiet_hooks)
if config.getoption('build'):
worker_id = os.environ.get("PYTEST_XDIST_WORKER")

View File

@@ -88,7 +88,7 @@ class RunAndLog(object):
a multiplexed log file. Objects of this type should be created by factory
functions in the Logfile class rather than directly."""
def __init__(self, logfile, name, chained_file):
def __init__(self, logfile, name, chained_file, quiet=False):
"""Initialize a new object.
Args:
@@ -96,6 +96,7 @@ class RunAndLog(object):
name: The name of this log stream or sub-process.
chained_file: The file-like object to which all stream data should
be logged to in addition to logfile. Can be None.
quiet: Suppress display of hook commands to chained_file.
Returns:
Nothing.
@@ -104,6 +105,7 @@ class RunAndLog(object):
self.logfile = logfile
self.name = name
self.chained_file = chained_file
self.quiet = quiet
self.output = None
self.exit_status = None
@@ -133,7 +135,7 @@ class RunAndLog(object):
"""
msg = '+' + ' '.join(cmd) + '\n'
if self.chained_file:
if self.chained_file and not self.quiet:
self.chained_file.write(msg)
self.logfile.write(self, msg)
@@ -215,11 +217,12 @@ class Logfile:
"""Generates an HTML-formatted log file containing multiple streams of
data, each represented in a well-delineated/-structured fashion."""
def __init__(self, fn):
def __init__(self, fn, quiet_hooks=False):
"""Initialize a new object.
Args:
fn: The filename to write to.
quiet_hooks: Suppress display of hook commands to stdout.
Returns:
Nothing.
@@ -234,6 +237,7 @@ class Logfile:
self.timestamp_prev = self.timestamp_start
self.timestamp_blocks = []
self.seen_warning = False
self.quiet_hooks = quiet_hooks
shutil.copy(mod_dir + '/multiplexed_log.css', os.path.dirname(fn))
self.f.write('''\
@@ -666,7 +670,7 @@ $(document).ready(function () {
A RunAndLog object.
"""
return RunAndLog(self, name, chained_file)
return RunAndLog(self, name, chained_file, self.quiet_hooks)
def write(self, stream, data, implicit=False):
"""Write stream data into the log file.