From e16a9fa8b519494c21e8f3f67d33bca13178a2fe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Dec 2025 20:01:13 -0700 Subject: [PATCH] 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 Signed-off-by: Simon Glass --- test/py/conftest.py | 8 +++++++- test/py/multiplexed_log.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index a269c68bf0f..247d4e19094 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -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") diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 63237594bb4..4eb9b0e416f 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -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.