diff mbox series

[U-Boot,20/26] binman: Check for files missing from test coverage

Message ID 20171113045231.15911-21-sjg@chromium.org
State Accepted
Commit a25ebed36fcf95d09629e8d2e95fdf4907798fb5
Delegated to: Simon Glass
Headers show
Series test: Include Python tools in test coverage | expand

Commit Message

Simon Glass Nov. 13, 2017, 4:52 a.m. UTC
Files that are never imported are not shown in the test-coverage report.
Detect these and show an error.

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

 tools/binman/binman.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Simon Glass Nov. 24, 2017, 1:46 a.m. UTC | #1
Files that are never imported are not shown in the test-coverage report.
Detect these and show an error.

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

 tools/binman/binman.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Applied to u-boot-dm thanks!
diff mbox series

Patch

diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index cf83edfd044..7ad4d3030b9 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -10,6 +10,7 @@ 
 
 """See README for more information"""
 
+import glob
 import os
 import sys
 import traceback
@@ -67,12 +68,27 @@  def RunTestCoverage():
             'tools/binman/binman.py -t' % options.build_dir)
     os.system(cmd)
     stdout = command.Output('coverage', 'report')
-    coverage = stdout.splitlines()[-1].split(' ')[-1]
+    lines = stdout.splitlines()
+
+    test_set= set([os.path.basename(line.split()[0])
+                     for line in lines if '/etype/' in line])
+    glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
+    all_set = set([os.path.basename(item) for item in glob_list])
+    missing_list = all_set
+    missing_list.difference_update(test_set)
+    missing_list.remove('_testing.py')
+    coverage = lines[-1].split(' ')[-1]
+    ok = True
+    if missing_list:
+        print 'Missing tests for %s' % (', '.join(missing_list))
+        ok = False
     if coverage != '100%':
         print stdout
         print "Type 'coverage html' to get a report in htmlcov/index.html"
-        raise ValueError('Coverage error: %s, but should be 100%%' % coverage)
-
+        print 'Coverage error: %s, but should be 100%%' % coverage
+        ok = False
+    if not ok:
+      raise ValueError('Test coverage failure')
 
 def RunBinman(options, args):
     """Main entry point to binman once arguments are parsed