51 for test
in args.tests:
52 absolute_test_path = os.path.abspath(test)
53 absolute_test_dir = os.path.dirname(absolute_test_path)
54 test_name = os.path.basename(absolute_test_path)
56 if not os.path.exists(absolute_test_path):
57 print(
'Path %s does not exist.' % absolute_test_path)
60 unstripped_test_path = os.path.join(absolute_test_dir,
'exe.unstripped', test_name)
62 if os.path.exists(unstripped_test_path):
63 binaries.append(unstripped_test_path)
65 binaries.append(absolute_test_path)
67 raw_profile = absolute_test_path +
'.rawprofile'
71 print(
'Running test %s to gather profile.' % os.path.basename(absolute_test_path))
73 test_command = [absolute_test_path]
75 test_args =
' '.join(args.test_args).split()
77 if test_args
is not None:
78 test_command += test_args
80 subprocess.check_call(test_command, env={
'LLVM_PROFILE_FILE': raw_profile})
82 if not os.path.exists(raw_profile):
83 print(
'Could not find raw profile data for unit test run %s.' % test)
84 print(
'Did you build with the --coverage flag?')
87 raw_profiles.append(raw_profile)
89 return (binaries, raw_profiles)
94 profdata_binary = os.path.join(llvm_bin_dir,
'llvm-profdata')
96 print(
'Merging %d raw profile(s) into single profile.' % len(raw_profiles))
97 merged_profile_path = os.path.join(output,
'all.profile')
99 merge_command = [profdata_binary,
'merge',
'-sparse'] + raw_profiles + [
'-o', merged_profile_path]
100 subprocess.check_call(merge_command)
102 return merged_profile_path
106 parser = argparse.ArgumentParser()
114 help=
'The unit tests to run and gather coverage data on.'
121 help=
'The output directory for coverage results.'
127 choices=[
'all',
'html',
'summary',
'lcov'],
129 help=
'The type of coverage information to be displayed.'
137 help=
'The arguments to pass to the unit test executable being run.'
140 args = parser.parse_args()
142 output = os.path.abspath(args.output)
146 generate_all_reports = args.format ==
'all'
150 if len(raw_profiles) == 0:
151 print(
'No raw profiles could be generated.')
155 for binary
in binaries:
156 binaries_flag.append(
'-object')
157 binaries_flag.append(binary)
161 merged_profile_path =
merge_profiles(llvm_bin_dir, raw_profiles, output)
163 if not os.path.exists(merged_profile_path):
164 print(
'Could not generate or find merged profile %s.' % merged_profile_path)
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'
172 if generate_all_reports
or args.format ==
'html':
173 print(
'Generating HTML report.')
174 subprocess.check_call([llvm_cov_binary,
'show'] + binaries_flag + [
177 '-output-dir=%s' % output,
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 + [
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 + [
203 stdout=lcov_redirect)