summaryrefslogtreecommitdiff
path: root/tools/u_boot_pylib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/u_boot_pylib')
-rw-r--r--tools/u_boot_pylib/gitutil.py27
-rw-r--r--tools/u_boot_pylib/test_util.py20
2 files changed, 43 insertions, 4 deletions
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index 5e3e98ac9a6..0376bece3e6 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -701,13 +701,38 @@ def setup():
.return_code == 0)
+def get_hash(spec):
+ """Get the hash of a commit
+
+ Args:
+ spec (str): Git commit to show, e.g. 'my-branch~12'
+
+ Returns:
+ str: Hash of commit
+ """
+ return command.output_one_line('git', 'show', '-s', '--pretty=format:%H',
+ spec)
+
+
def get_head():
"""Get the hash of the current HEAD
Returns:
Hash of HEAD
"""
- return command.output_one_line('git', 'show', '-s', '--pretty=format:%H')
+ return get_hash('HEAD')
+
+
+def get_branch():
+ """Get the branch we are currently on
+
+ Return:
+ str: branch name, or None if none
+ """
+ out = command.output_one_line('git', 'rev-parse', '--abbrev-ref', 'HEAD')
+ if out == 'HEAD':
+ return None
+ return out
if __name__ == "__main__":
diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py
index dd671965263..637403f8715 100644
--- a/tools/u_boot_pylib/test_util.py
+++ b/tools/u_boot_pylib/test_util.py
@@ -8,6 +8,7 @@ import doctest
import glob
import multiprocessing
import os
+import re
import sys
import unittest
@@ -25,7 +26,7 @@ except:
def run_test_coverage(prog, filter_fname, exclude_list, build_dir,
required=None, extra_args=None, single_thread='-P1',
- args=None):
+ args=None, allow_failures=None):
"""Run tests and check that we get 100% coverage
Args:
@@ -56,14 +57,14 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir,
else:
glob_list = []
glob_list += exclude_list
- glob_list += ['*libfdt.py', '*site-packages*', '*dist-packages*']
+ glob_list += ['*libfdt.py', '*/site-packages/*', '*/dist-packages/*']
glob_list += ['*concurrencytest*']
test_cmd = 'test' if 'binman' in prog or 'patman' in prog else '-t'
prefix = ''
if build_dir:
prefix = 'PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools ' % build_dir
- # Detect a Python virtualenv and use 'coverage' instead
+ # Detect a Python sandbox and use 'coverage' instead
covtool = ('python3-coverage' if sys.prefix == sys.base_prefix else
'coverage')
@@ -96,6 +97,19 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir,
print('Coverage error: %s, but should be 100%%' % coverage)
ok = False
if not ok:
+ if allow_failures:
+ # for line in lines:
+ # print('.', line, re.match(r'^(tools/.*py) *\d+ *(\d+) *(\d+)%$', line))
+ lines = [re.match(r'^(tools/.*py) *\d+ *(\d+) *\d+%$', line)
+ for line in stdout.splitlines()]
+ bad = []
+ for mat in lines:
+ if mat and mat.group(2) != '0':
+ fname = mat.group(1)
+ if fname not in allow_failures:
+ bad.append(fname)
+ if not bad:
+ return
raise ValueError('Test coverage failure')