Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: tools/llvm_coverage_run.py

Issue 1258083006: Cherry-pick m45 fixes onto m44 (Closed) Base URL: https://skia.googlesource.com/skia.git@m44
Patch Set: All the fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/llvm_coverage_build ('k') | tools/parse_llvm_coverage.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/llvm_coverage_run.py
diff --git a/tools/llvm_coverage_run.py b/tools/llvm_coverage_run.py
new file mode 100755
index 0000000000000000000000000000000000000000..8b497506e64d3dfb59911f98d28a66bb3c2fe84c
--- /dev/null
+++ b/tools/llvm_coverage_run.py
@@ -0,0 +1,63 @@
+#!/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'
+SKIA_OUT = 'SKIA_OUT'
+
+
+def _get_out_dir():
+ """Determine the location for compiled binaries."""
+ return os.path.join(os.environ.get(SKIA_OUT, os.path.realpath('out')),
+ BUILDTYPE)
+
+
+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.
+ """
+ binary_path = os.path.join(_get_out_dir(), cmd[0])
+ 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:
+ return subprocess.check_output(['llvm-cov', 'show', '-no-colors',
+ '-instr-profile', PROFILE_DATA_MERGED,
+ binary_path])
+ finally:
+ os.remove(PROFILE_DATA_MERGED)
+
+
+def main():
+ """Run coverage and generate a report."""
+ # Parse args.
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--outResultsFile')
+ args, cmd = parser.parse_known_args()
+
+ # Run coverage.
+ report = run_coverage(cmd)
+ with open(args.outResultsFile, 'w') as f:
+ f.write(report)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « tools/llvm_coverage_build ('k') | tools/parse_llvm_coverage.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698