2015-07-06 14:43:58 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
|
"""Run the given command through LLVM's coverage tools."""
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
BUILDTYPE = 'Coverage'
|
|
|
|
PROFILE_DATA = 'default.profraw'
|
|
|
|
PROFILE_DATA_MERGED = 'prof_merged'
|
2015-07-15 14:43:06 +00:00
|
|
|
SKIA_OUT = 'SKIA_OUT'
|
2015-07-06 14:43:58 +00:00
|
|
|
|
|
|
|
|
2015-07-15 14:43:06 +00:00
|
|
|
def _get_out_dir():
|
|
|
|
"""Determine the location for compiled binaries."""
|
|
|
|
return os.path.join(os.environ.get(SKIA_OUT, os.path.realpath('out')),
|
|
|
|
BUILDTYPE)
|
|
|
|
|
|
|
|
|
2015-07-06 14:43:58 +00:00
|
|
|
def run_coverage(cmd):
|
|
|
|
"""Run the given command and return per-file coverage data.
|
|
|
|
|
|
|
|
Assumes that the binary has been built using llvm_coverage_build and that
|
|
|
|
LLVM 3.6 or newer is installed.
|
|
|
|
"""
|
2015-07-15 14:43:06 +00:00
|
|
|
binary_path = os.path.join(_get_out_dir(), cmd[0])
|
2015-07-06 14:43:58 +00:00
|
|
|
subprocess.call([binary_path] + cmd[1:])
|
|
|
|
try:
|
|
|
|
subprocess.check_call(
|
|
|
|
['llvm-profdata', 'merge', PROFILE_DATA,
|
|
|
|
'-output=%s' % PROFILE_DATA_MERGED])
|
|
|
|
finally:
|
|
|
|
os.remove(PROFILE_DATA)
|
|
|
|
try:
|
2015-07-20 16:43:36 +00:00
|
|
|
return subprocess.check_output(['llvm-cov', 'show', '-no-colors',
|
|
|
|
'-instr-profile', PROFILE_DATA_MERGED,
|
|
|
|
binary_path])
|
2015-07-06 14:43:58 +00:00
|
|
|
finally:
|
|
|
|
os.remove(PROFILE_DATA_MERGED)
|
2015-07-06 18:18:45 +00:00
|
|
|
|
|
|
|
|
2015-07-06 14:43:58 +00:00
|
|
|
def main():
|
2015-07-06 18:18:45 +00:00
|
|
|
"""Run coverage and generate a report."""
|
|
|
|
# Parse args.
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--outResultsFile')
|
|
|
|
args, cmd = parser.parse_known_args()
|
2015-07-16 14:01:44 +00:00
|
|
|
|
2015-07-06 18:18:45 +00:00
|
|
|
# Run coverage.
|
2015-07-20 16:43:36 +00:00
|
|
|
report = run_coverage(cmd)
|
|
|
|
with open(args.outResultsFile, 'w') as f:
|
|
|
|
f.write(report)
|
2015-07-06 14:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|