[PATCH v2 60/60] buildman: Enable test coverage
Simon Glass
sjg at chromium.org
Wed Jul 5 14:19:28 CEST 2023
Enable measuring test coverage for buildman so we can see the gaps. It is
currently at 68%.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2:
- Drop patch to move -A logic up a little (since it breaks it)
tools/buildman/cmdline.py | 2 ++
tools/buildman/main.py | 15 ++++++++++++++-
tools/u_boot_pylib/test_util.py | 10 +++++++---
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/tools/buildman/cmdline.py b/tools/buildman/cmdline.py
index 41384840427a..983165546ea2 100644
--- a/tools/buildman/cmdline.py
+++ b/tools/buildman/cmdline.py
@@ -136,6 +136,8 @@ def add_after_m(parser):
help='Skip tests which need the network')
parser.add_argument('-t', '--test', action='store_true', dest='test',
default=False, help='run tests')
+ parser.add_argument('--coverage', action='store_true',
+ help='Calculated test coverage')
parser.add_argument('-T', '--threads', type=int,
default=None,
help='Number of builder threads to use (0=single-thread)')
diff --git a/tools/buildman/main.py b/tools/buildman/main.py
index 593911353101..cb3d0b4fc663 100755
--- a/tools/buildman/main.py
+++ b/tools/buildman/main.py
@@ -47,12 +47,22 @@ def run_tests(skip_net_tests, verbose, args):
# Run the entry tests first ,since these need to be the first to import the
# 'entry' module.
result = test_util.run_test_suites(
- 'buildman', False, verbose, False, None, test_name, [],
+ 'buildman', False, verbose, False, args.threads, test_name, [],
[test.TestBuild, func_test.TestFunctional,
'buildman.toolchain', 'patman.gitutil'])
return (0 if result.wasSuccessful() else 1)
+def run_test_coverage():
+ """Run the tests and check that we get 100% coverage"""
+ test_util.run_test_coverage(
+ 'tools/buildman/buildman', None,
+ ['tools/patman/*.py', 'tools/u_boot_pylib/*', '*test_fdt.py',
+ 'tools/buildman/kconfiglib.py', 'tools/buildman/*test*.py',
+ 'tools/buildman/main.py'],
+ '/tmp/b', single_thread='-T1')
+
+
def run_buildman():
"""Run bulidman
@@ -68,6 +78,9 @@ def run_buildman():
if cmdline.HAS_TESTS and args.test:
run_tests(args.skip_net_tests, args.verbose, args)
+ elif cmdline.HAS_TESTS and args.coverage:
+ run_test_coverage()
+
elif args.full_help:
tools.print_full_help(str(files('buildman').joinpath('README.rst')))
diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py
index e7564e10c997..f18d385d9951 100644
--- a/tools/u_boot_pylib/test_util.py
+++ b/tools/u_boot_pylib/test_util.py
@@ -24,7 +24,7 @@ except:
def run_test_coverage(prog, filter_fname, exclude_list, build_dir, required=None,
- extra_args=None):
+ extra_args=None, single_thread='-P1'):
"""Run tests and check that we get 100% coverage
Args:
@@ -39,6 +39,9 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir, required=None
required: List of modules which must be in the coverage report
extra_args (str): Extra arguments to pass to the tool before the -t/test
arg
+ single_thread (str): Argument string to make the tests run
+ single-threaded. This is necessary to get proper coverage results.
+ The default is '-P0'
Raises:
ValueError if the code coverage is not 100%
@@ -58,8 +61,9 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir, required=None
if build_dir:
prefix = 'PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools ' % build_dir
cmd = ('%spython3-coverage run '
- '--omit "%s" %s %s %s -P1' % (prefix, ','.join(glob_list),
- prog, extra_args or '', test_cmd))
+ '--omit "%s" %s %s %s %s' % (prefix, ','.join(glob_list),
+ prog, extra_args or '', test_cmd,
+ single_thread or '-P1'))
os.system(cmd)
stdout = command.output('python3-coverage', 'report')
lines = stdout.splitlines()
--
2.41.0.255.g8b1d071c50-goog
More information about the U-Boot
mailing list