aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-13 19:32:43 +0000
committerGravatar mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-13 19:32:43 +0000
commit1fb04e25405d5ec75aea4a099819d6feca348ff6 (patch)
tree7b7b97caa0cfeafbc604ecc712f29ab34f4c5e1a
parentcee9dcb8377e1f85a7a232822a894464ea6ccddc (diff)
add a way to get code coverage
BUG= R=borenet@google.com Review URL: https://codereview.chromium.org/23523055 git-svn-id: http://skia.googlecode.com/svn/trunk@11261 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gyp/common_conditions.gypi4
-rwxr-xr-xtools/coverage.sh31
-rwxr-xr-xtools/gcov_shim15
3 files changed, 50 insertions, 0 deletions
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index d2b2611205..f9feb1c132 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -205,6 +205,10 @@
'SK_BUILD_FOR_UNIX',
],
'configurations': {
+ 'Coverage': {
+ 'cflags': ['-g --coverage'],
+ 'ldflags': ['--coverage'],
+ },
'Debug': {
'cflags': ['-g']
},
diff --git a/tools/coverage.sh b/tools/coverage.sh
new file mode 100755
index 0000000000..3e34806843
--- /dev/null
+++ b/tools/coverage.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Run from Skia trunk something like this:
+# $ tools/coverage.sh tests
+# or
+# $ tools/coverage.sh gm
+
+set -x
+set -e
+
+COMMAND=$@
+GCOV=$(realpath tools/gcov_shim)
+
+QUIET=-q
+
+# Build all of Skia.
+./gyp_skia
+ninja -C out/Coverage
+
+# Generate a zero-baseline so files not covered by $COMMAND will still show up in the report.
+# This reads the .gcno files that are created at compile time.
+lcov $QUIET --gcov-tool=$GCOV -c -b out/Coverage -d out/Coverage -o /tmp/baseline -i
+
+# Running the binary generates the real coverage information, the .gcda files.
+out/Coverage/$COMMAND
+lcov $QUIET --gcov-tool=$GCOV -c -b out/Coverage -d out/Coverage -o /tmp/coverage
+
+lcov $QUIET -a /tmp/baseline -a /tmp/coverage -o /tmp/merged
+
+genhtml $QUIET /tmp/merged -o out/Coverage/report
+xdg-open out/Coverage/report/index.html
diff --git a/tools/gcov_shim b/tools/gcov_shim
new file mode 100755
index 0000000000..1bac3b7f02
--- /dev/null
+++ b/tools/gcov_shim
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Running gcov with -a (--all-blocks) will hang on some files. lcov uses -a.
+# This shim strips out that flag (a minor feature) so we can run gcov.
+
+CMD="gcov"
+
+while (( "$#" )); do
+ if [[ "$1" != "-a" && "$1" != "-all-blocks" && "$1" != "--all-blocks" ]]; then
+ CMD="$CMD $1"
+ fi
+ shift
+done
+
+$CMD