From ae3695f691c6325f1a504ee3df7f22d75c7a0c96 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Apr 2025 07:21:59 -0600 Subject: patman: Move capture_sys_output() into terminal and rename This function is sometimes useful outside tests. Also it can affect how terminal output is done, e.g. whether ANSI characters should be emitted or not. Move it out of the test_util package and into terminal. Signed-off-by: Simon Glass --- tools/u_boot_pylib/test_util.py | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'tools/u_boot_pylib/test_util.py') diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py index 637403f8715..d46c3df5094 100644 --- a/tools/u_boot_pylib/test_util.py +++ b/tools/u_boot_pylib/test_util.py @@ -3,7 +3,6 @@ # Copyright (c) 2016 Google, Inc # -from contextlib import contextmanager import doctest import glob import multiprocessing @@ -14,8 +13,6 @@ import unittest from u_boot_pylib import command -from io import StringIO - use_concurrent = True try: from concurrencytest import ConcurrentTestSuite @@ -113,20 +110,6 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir, raise ValueError('Test coverage failure') -# Use this to suppress stdout/stderr output: -# with capture_sys_output() as (stdout, stderr) -# ...do something... -@contextmanager -def capture_sys_output(): - capture_out, capture_err = StringIO(), StringIO() - old_out, old_err = sys.stdout, sys.stderr - try: - sys.stdout, sys.stderr = capture_out, capture_err - yield capture_out, capture_err - finally: - sys.stdout, sys.stderr = old_out, old_err - - class FullTextTestResult(unittest.TextTestResult): """A test result class that can print extended text results to a stream -- cgit v1.2.3 From 55342144af598453c2de0271b8df50821f39ba13 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Apr 2025 07:22:04 -0600 Subject: u_boot_pylib: Avoid concurrent execution of only one test There is no point in spinning up multiple processes if there is only one test to execute. Add a check for this. Signed-off-by: Simon Glass --- tools/u_boot_pylib/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/u_boot_pylib/test_util.py') diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py index d46c3df5094..fc441a78dc1 100644 --- a/tools/u_boot_pylib/test_util.py +++ b/tools/u_boot_pylib/test_util.py @@ -191,7 +191,7 @@ def run_test_suites(toolname, debug, verbosity, test_preserve_dirs, processes, resultclass=FullTextTestResult, ) - if use_concurrent and processes != 1: + if use_concurrent and processes != 1 and not test_name: suite = ConcurrentTestSuite(suite, fork_for_tests(processes or multiprocessing.cpu_count())) -- cgit v1.2.3 From a61635d2af81d00b02155eb5decc03eb92f94413 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Apr 2025 07:22:06 -0600 Subject: tools: Plumb in capture control Add control of capturing output into u_boot_pylib and the tools which use it. Signed-off-by: Simon Glass --- tools/u_boot_pylib/test_util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tools/u_boot_pylib/test_util.py') diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py index fc441a78dc1..d258a1935c9 100644 --- a/tools/u_boot_pylib/test_util.py +++ b/tools/u_boot_pylib/test_util.py @@ -12,6 +12,7 @@ import sys import unittest from u_boot_pylib import command +from u_boot_pylib import terminal use_concurrent = True try: @@ -155,8 +156,8 @@ class FullTextTestResult(unittest.TextTestResult): super().addSkip(test, reason) -def run_test_suites(toolname, debug, verbosity, test_preserve_dirs, processes, - test_name, toolpath, class_and_module_list): +def run_test_suites(toolname, debug, verbosity, no_capture, test_preserve_dirs, + processes, test_name, toolpath, class_and_module_list): """Run a series of test suites and collect the results Args: @@ -179,6 +180,9 @@ def run_test_suites(toolname, debug, verbosity, test_preserve_dirs, processes, sys.argv.append('-D') if verbosity: sys.argv.append('-v%d' % verbosity) + if no_capture: + sys.argv.append('-N') + terminal.USE_CAPTURE = False if toolpath: for path in toolpath: sys.argv += ['--toolpath', path] @@ -207,7 +211,7 @@ def run_test_suites(toolname, debug, verbosity, test_preserve_dirs, processes, setup_test_args = getattr(module, 'setup_test_args') setup_test_args(preserve_indir=test_preserve_dirs, preserve_outdirs=test_preserve_dirs and test_name is not None, - toolpath=toolpath, verbosity=verbosity) + toolpath=toolpath, verbosity=verbosity, no_capture=no_capture) if test_name: # Since Python v3.5 If an ImportError or AttributeError occurs # while traversing a name then a synthetic test that raises that -- cgit v1.2.3