[U-Boot] [PATCH 29/37] binman: Allow verbosity control when running tests

Simon Glass sjg at chromium.org
Fri Jun 28 14:09:11 UTC 2019


At present the -v flag is ignored with tests, so that (for example) -v2
does not have any effect. Update binman to pass this flag through to tests
so that they work just like running binman normally, except in a few
special cases where we are actually testing behaviour with different
levels of verbosity.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/binman.py |  8 ++++++--
 tools/binman/ftest.py  | 17 ++++++++++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index bab98826dc6..7c1dcfb65fc 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -46,11 +46,12 @@ except:
 import control
 import test_util
 
-def RunTests(debug, processes, args):
+def RunTests(debug, verbosity, processes, args):
     """Run the functional tests and any embedded doctests
 
     Args:
         debug: True to enable debugging, which shows a full stack trace on error
+        verbosity: Verbosity level to use
         args: List of positional args provided to binman. This can hold a test
             name to execute (as in 'binman -t testSections', for example)
         processes: Number of processes to use to run tests (None=same as #CPUs)
@@ -71,6 +72,8 @@ def RunTests(debug, processes, args):
     sys.argv = [sys.argv[0]]
     if debug:
         sys.argv.append('-D')
+    if verbosity:
+        sys.argv.append('-v%d' % verbosity)
 
     # Run the entry tests first ,since these need to be the first to import the
     # 'entry' module.
@@ -153,7 +156,8 @@ def RunBinman(options, args):
         sys.tracebacklimit = 0
 
     if options.test:
-        ret_code = RunTests(options.debug, options.processes, args[1:])
+        ret_code = RunTests(options.debug, options.verbosity, options.processes,
+                            args[1:])
 
     elif options.test_coverage:
         RunTestCoverage()
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index b1780854cfe..f5e0b9b9742 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -153,6 +153,19 @@ class TestFunctional(unittest.TestCase):
         TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA)
         TestFunctional._MakeInputFile('tpl/u-boot-tpl.dtb', U_BOOT_TPL_DTB_DATA)
 
+    def _GetVerbosity(self):
+        """Check if verbosity should be enabled
+
+        Returns:
+            list containing either:
+                - Verbosity flag (e.g. '-v2') if it is present on the cmd line
+                - nothing if the flag is not present
+        """
+        for arg in sys.argv[1:]:
+            if arg.startswith('-v'):
+                return [arg]
+        return []
+
     def _RunBinman(self, *args, **kwargs):
         """Run binman using the command line
 
@@ -213,6 +226,8 @@ class TestFunctional(unittest.TestCase):
             args.append('--fake-dtb')
         if verbosity is not None:
             args.append('-v%d' % verbosity)
+        else:
+            args += self._GetVerbosity()
         if entry_args:
             for arg, value in entry_args.items():
                 args.append('-a%s=%s' % (arg, value))
@@ -1471,7 +1486,7 @@ class TestFunctional(unittest.TestCase):
         expected = 'Skipping images: image1'
 
         # We should only get the expected message in verbose mode
-        for verbosity in (None, 2):
+        for verbosity in (0, 2):
             with test_util.capture_sys_output() as (stdout, stderr):
                 retcode = self._DoTestFile('006_dual_image.dts',
                                            verbosity=verbosity,
-- 
2.22.0.410.gd8fdbe21b5-goog



More information about the U-Boot mailing list