blob: 305371fd7d05b0941cc36833f55fe4975edff3c8 [file] [log] [blame]
#!/usr/bin/env python3
import argparse
import subprocess
from typing import Iterable, List, Tuple
_TEAM_AUTHORS = frozenset([
'Brendan Higgins', 'David Gow', 'Heidi Fahim', 'Felix Guo',
'Avinash Kondareddy', 'Daniel Latypov', 'Patricia Alfonso',
'Rae Moar',
])
# Manual list of files to exclude in `_test_names`.
_NOT_TESTS=frozenset(['lib/kunit/test.c'])
def _outside_contributors_and_patches() -> Tuple[int, int]:
cmd = ['git', 'log', '--format=%an', '--', 'include/kunit', 'lib/kunit', 'tools/testing/kunit']
contributors = set()
patches = 0
with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as p:
for author in p.stdout:
if author.strip() not in _TEAM_AUTHORS:
contributors.add(author)
patches += 1
return len(contributors), patches
def _is_test_file(filename: str) -> bool:
if filename.startswith('Documentation/') or filename in _NOT_TESTS:
return False
return 'test' in filename or filename.endswith('_kunit.c')
def _test_names() -> List[str]:
cmd = ['git', 'grep', '-l', '-e', '#include <kunit/test.h']
with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as p:
return list(filter(_is_test_file, (line.strip() for line in p.stdout)))
def _test_authors(test_names: List[str]) -> List[str]:
cmd = ['git', '--no-pager', 'shortlog', '--no-merges', '-n', '-s', '--'] + test_names
return subprocess.check_output(cmd, text=True).strip().split('\n')
def _num_test_cases() -> int:
cmd = ['git', 'grep', 'KUNIT_CASE']
count = 0
with subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True) as p:
for line in p.stdout:
line = line.strip()
if line.startswith('Documentation/') or line.startswith('include/kunit/test.h'):
continue
count += 1
return count
parser = argparse.ArgumentParser(description='Optional app description')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
num_test_cases = _num_test_cases()
test_names = _test_names()
contributors, patches = _outside_contributors_and_patches()
print(f'Number of test cases: {num_test_cases}')
print(f'Number of patches: {patches}')
print(f'Unique contributors: {contributors}')
print(f'Number of total tests: {len(test_names)}')
test_authors = _test_authors(test_names) # this step takes ~15s as of Aug 2022
print(f'Number of test authors: {len(test_authors)}')
if args.verbose:
print(f'All tests: ' + '\n'.join(test_names))
print(f'Test authors: ' + '\n'.join(test_authors))