[PATCH 3/5] patman: test_util: Use unittest text runner to print test results

2022-04-02 Thread Alper Nebi Yasak
The python tools' test utilities handle printing test results, but the
output is quite bare compared to an ordinary unittest run. Delegate
printing the results to a unittest text runner, which gives us niceties
like clear separation between each test's result and how long it took to
run the test suite.

Unfortunately it does not print info for skipped tests by default, but
this can be handled later by a custom test result subclass. It also does
not print the tool name; manually print a heading that includes the
toolname so that the outputs of each tool's tests are distinguishable in
the CI output.

Signed-off-by: Alper Nebi Yasak 
---

 tools/binman/main.py  |  8 ++
 tools/buildman/main.py|  8 ++
 tools/dtoc/main.py|  9 +++---
 tools/dtoc/test_fdt.py|  8 +++---
 tools/patman/main.py  |  8 ++
 tools/patman/test_util.py | 58 ++-
 6 files changed, 38 insertions(+), 61 deletions(-)

diff --git a/tools/binman/main.py b/tools/binman/main.py
index 9392b59adb15..d2eea1c4bb76 100755
--- a/tools/binman/main.py
+++ b/tools/binman/main.py
@@ -14,7 +14,6 @@
 import site
 import sys
 import traceback
-import unittest
 
 # Get the absolute path to this file at run-time
 our_path = os.path.dirname(os.path.realpath(__file__))
@@ -80,19 +79,18 @@ def RunTests(debug, verbosity, processes, 
test_preserve_dirs, args, toolpath):
 from binman import image_test
 import doctest
 
-result = unittest.TestResult()
 test_name = args and args[0] or None
 
 # Run the entry tests first ,since these need to be the first to import the
 # 'entry' module.
-test_util.run_test_suites(
-result, debug, verbosity, test_preserve_dirs, processes, test_name,
+result = test_util.run_test_suites(
+'binman', debug, verbosity, test_preserve_dirs, processes, test_name,
 toolpath,
 [bintool_test.TestBintool, entry_test.TestEntry, ftest.TestFunctional,
  fdt_test.TestFdt, elf_test.TestElf, image_test.TestImage,
  cbfs_util_test.TestCbfs, fip_util_test.TestFip])
 
-return test_util.report_result('binman', test_name, result)
+return (0 if result.wasSuccessful() else 1)
 
 def RunTestCoverage(toolpath):
 """Run the tests and check that we get 100% coverage"""
diff --git a/tools/buildman/main.py b/tools/buildman/main.py
index 3b6af240802d..67c560c48d37 100755
--- a/tools/buildman/main.py
+++ b/tools/buildman/main.py
@@ -11,7 +11,6 @@
 import os
 import re
 import sys
-import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
@@ -34,19 +33,18 @@ def RunTests(skip_net_tests, verboose, args):
 from buildman import test
 import doctest
 
-result = unittest.TestResult()
 test_name = args and args[0] or None
 if skip_net_tests:
 test.use_network = False
 
 # Run the entry tests first ,since these need to be the first to import the
 # 'entry' module.
-test_util.run_test_suites(
-result, False, verboose, False, None, test_name, [],
+result = test_util.run_test_suites(
+'buildman', False, verboose, False, None, test_name, [],
 [test.TestBuild, func_test.TestFunctional,
  'buildman.toolchain', 'patman.gitutil'])
 
-return test_util.report_result('buildman', test_name, result)
+return (0 if result.wasSuccessful() else 1)
 
 options, args = cmdline.ParseArgs()
 
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index fac9db9c786f..5508759d4d56 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -24,7 +24,6 @@
 from argparse import ArgumentParser
 import os
 import sys
-import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
@@ -49,18 +48,18 @@ def run_tests(processes, args):
 from dtoc import test_src_scan
 from dtoc import test_dtoc
 
-result = unittest.TestResult()
 sys.argv = [sys.argv[0]]
 test_name = args.files and args.files[0] or None
 
 test_dtoc.setup()
 
-test_util.run_test_suites(
-result, debug=True, verbosity=1, test_preserve_dirs=False,
+result = test_util.run_test_suites(
+toolname='dtoc', debug=True, verbosity=1, test_preserve_dirs=False,
 processes=processes, test_name=test_name, toolpath=[],
 class_and_module_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
 
-return test_util.report_result('binman', test_name, result)
+return (0 if result.wasSuccessful() else 1)
+
 
 def RunTestCoverage():
 """Run the tests and check that we get 100% coverage"""
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 3859af8d032b..3baf4437cdd3 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -784,13 +784,13 @@ def RunTests(args):
 Returns:
 Return code, 0 on success
 """
-result = unittest.TestResult()
 test_name = args and args[0] or None
-test_util.run_test_suites(
-result

Re: [PATCH 3/5] patman: test_util: Use unittest text runner to print test results

2022-06-28 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> The python tools' test utilities handle printing test results, but the
> output is quite bare compared to an ordinary unittest run. Delegate
> printing the results to a unittest text runner, which gives us niceties
> like clear separation between each test's result and how long it took to
> run the test suite.
>
> Unfortunately it does not print info for skipped tests by default, but
> this can be handled later by a custom test result subclass. It also does
> not print the tool name; manually print a heading that includes the
> toolname so that the outputs of each tool's tests are distinguishable in
> the CI output.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/binman/main.py  |  8 ++
>  tools/buildman/main.py|  8 ++
>  tools/dtoc/main.py|  9 +++---
>  tools/dtoc/test_fdt.py|  8 +++---
>  tools/patman/main.py  |  8 ++
>  tools/patman/test_util.py | 58 ++-
>  6 files changed, 38 insertions(+), 61 deletions(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 3/5] patman: test_util: Use unittest text runner to print test results

2022-04-19 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> The python tools' test utilities handle printing test results, but the
> output is quite bare compared to an ordinary unittest run. Delegate
> printing the results to a unittest text runner, which gives us niceties
> like clear separation between each test's result and how long it took to
> run the test suite.
>
> Unfortunately it does not print info for skipped tests by default, but
> this can be handled later by a custom test result subclass. It also does
> not print the tool name; manually print a heading that includes the
> toolname so that the outputs of each tool's tests are distinguishable in
> the CI output.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/binman/main.py  |  8 ++
>  tools/buildman/main.py|  8 ++
>  tools/dtoc/main.py|  9 +++---
>  tools/dtoc/test_fdt.py|  8 +++---
>  tools/patman/main.py  |  8 ++
>  tools/patman/test_util.py | 58 ++-
>  6 files changed, 38 insertions(+), 61 deletions(-)
>

Reviewed-by: Simon Glass