106 parser = argparse.ArgumentParser()
107
108 parser.add_argument(
109 '-t',
110 '--tests',
111 nargs='+',
112 dest='tests',
113 required=True,
114 help='The unit tests to run and gather coverage data on.'
115 )
116 parser.add_argument(
117 '-o',
118 '--output',
119 dest='output',
120 required=True,
121 help='The output directory for coverage results.'
122 )
123 parser.add_argument(
124 '-f',
125 '--format',
126 type=str,
127 choices=['all', 'html', 'summary', 'lcov'],
128 required=True,
129 help='The type of coverage information to be displayed.'
130 )
131 parser.add_argument(
132 '-a',
133 '--args',
134 nargs='+',
135 dest='test_args',
136 required=False,
137 help='The arguments to pass to the unit test executable being run.'
138 )
139
140 args = parser.parse_args()
141
142 output = os.path.abspath(args.output)
143
145
146 generate_all_reports = args.format == 'all'
147
149
150 if len(raw_profiles) == 0:
151 print(
'No raw profiles could be generated.')
152 return -1
153
154 binaries_flag = []
155 for binary in binaries:
156 binaries_flag.append('-object')
157 binaries_flag.append(binary)
158
160
161 merged_profile_path =
merge_profiles(llvm_bin_dir, raw_profiles, output)
162
163 if not os.path.exists(merged_profile_path):
164 print(
'Could not generate or find merged profile %s.' % merged_profile_path)
165 return -1
166
167 llvm_cov_binary = os.path.join(llvm_bin_dir, 'llvm-cov')
168 instr_profile_flag = '-instr-profile=%s' % merged_profile_path
169 ignore_flags = '-ignore-filename-regex=third_party|unittest|fixture'
170
171
172 if generate_all_reports or args.format == 'html':
173 print(
'Generating HTML report.')
174 subprocess.check_call([llvm_cov_binary, 'show'] + binaries_flag + [
175 instr_profile_flag,
176 '-format=html',
177 '-output-dir=%s' % output,
178 '-tab-size=2',
179 ignore_flags,
180 ])
182
183
184 if generate_all_reports or args.format == 'summary':
185 print(
'Generating a summary report.')
186 subprocess.check_call([llvm_cov_binary, 'report'] + binaries_flag + [
187 instr_profile_flag,
188 ignore_flags,
189 ])
191
192
193 if generate_all_reports or args.format == 'lcov':
194 print(
'Generating LCOV report.')
195 lcov_file = os.path.join(output, 'coverage.lcov')
197 with open(lcov_file, 'w') as lcov_redirect:
198 subprocess.check_call([llvm_cov_binary, 'export'] + binaries_flag + [
199 instr_profile_flag,
200 ignore_flags,
201 '-format=lcov',
202 ],
203 stdout=lcov_redirect)
205
206 return 0
207
208
def merge_profiles(llvm_bin_dir, raw_profiles, output)