forked from ALIGN-analoglayout/ALIGN-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runcoverage.py
executable file
·133 lines (114 loc) · 4.5 KB
/
runcoverage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
import os
import sys
import pathlib
import subprocess
import shutil
import itertools
def main():
exit_status = 0
assert pathlib.Path.cwd().resolve() == pathlib.Path(__file__).parent.resolve(), \
f"Please run {__file__} from ALIGN_HOME."
argv = sys.argv[1:]
output_dir = pathlib.Path('coverage-reports').resolve()
c_coverage_file = pathlib.Path('coverage.info').resolve()
try:
from tests._cmake import CMAKE_BINARY_DIR, CMAKE_SOURCE_DIR
except:
CMAKE_BINARY_DIR = None
CMAKE_SOURCE_DIR = None
# Detect whether to run LCOV
GCOV_ENABLED = False
if shutil.which('lcov') is None:
print("WARNING: `lcov` not found. Generating coverage for python components only.")
elif not CMAKE_BINARY_DIR or not CMAKE_SOURCE_DIR:
print("WARNING: CPP Source / Binary information not found. Generating coverage for python components only.")
print(" Run `pip install -e .[test] --no-build-isolation --install-option='-DCODE_COVERAGE=ON' --install-option='-DBUILD_TESTING=ON'` to instrument cpp code.")
elif next(pathlib.Path(CMAKE_BINARY_DIR).glob('**/*.gcno'), None) is None:
print("WARNING: Could not find any .gcno files. Generating coverage for python components only.")
print(" Run `pip install -e .[test] --no-build-isolation --install-option='-DCODE_COVERAGE=ON' --install-option='-DBUILD_TESTING=ON'` to instrument cpp code.")
else:
print("INFO: Code coverage for cpp extension has been enabled. Please see coverage-reports/cpp.")
GCOV_ENABLED = True
# Clean existing report (if any)
if output_dir.is_dir():
shutil.rmtree(str(output_dir))
# Number of parallel jobs
if 'MAX_JOBS' in os.environ:
MAX_JOBS = os.environ['MAX_JOBS']
else:
MAX_JOBS = 'auto'
# LCOV init
if GCOV_ENABLED:
ret = subprocess.run(' '.join([
'lcov', '--directory', CMAKE_BINARY_DIR, '--zerocounters']),
shell=True)
if not exit_status:
exit_status = ret.returncode
# Actual command is run here
ret = subprocess.run(' '.join([
'pytest', '-vv', # Call pytest in verbose mode
'-n', MAX_JOBS, # pytest-xdist options
'--cov-report', f'html:{output_dir}/python', '--cov=align', # pytest-cov options
*argv
]),
shell=True)
if not exit_status:
exit_status = ret.returncode
# Standard checkin integration tests
os.environ['CI_LEVEL'] = 'checkin'
ret = subprocess.run(' '.join([
'pytest', '-vv', # Call pytest in verbose mode
'--runnightly',
'--maxerrors=0',
'-n', MAX_JOBS, # pytest-xdist options
'--cov-report', f'html:{output_dir}/python', '--cov=align', # pytest-cov options
'--cov-append', # append to existing run
'--',
'tests/integration/'
]),
shell=True)
del os.environ['CI_LEVEL']
# One integration test (to get guard_ring_coverage)
ret = subprocess.run(' '.join([
'pytest', '-vv', # Call pytest in verbose mode
'--runnightly',
'-k', 'telescopic_ota_guard_ring or switched_capacitor_filter',
'-n', MAX_JOBS, # pytest-xdist options
'--cov-report', f'html:{output_dir}/python', '--cov=align', # pytest-cov options
'--cov-append' # append to existing run
]),
shell=True)
if not exit_status:
pass
# Currently failing
#exit_status = ret.returncode
if GCOV_ENABLED:
# Finish capture
ret = subprocess.run(' '.join([
'lcov', '--capture', '--no-external',
'--directory', '.',
'--output-file', f'{c_coverage_file}']),
shell=True)
if not exit_status:
exit_status = ret.returncode
# Remove coverage we aren't interested in
ret = subprocess.run(' '.join([
'lcov', '--remove',
f'{c_coverage_file}',
'--output-file', f'{c_coverage_file}',
'*/_deps/*']),
shell=True)
if not exit_status:
exit_status = ret.returncode
# Generate report
ret = subprocess.run(' '.join([
'genhtml', f'{c_coverage_file}',
'--output-directory', f'{output_dir}/cpp',
'--no-branch-coverage',
'--title', '"CPP lcov report"']), shell=True)
if not exit_status:
exit_status = ret.returncode
return exit_status
if __name__ == '__main__':
sys.exit(main())