halcanary | 3948a1b | 2016-09-26 10:30:39 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2016 Google Inc. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | if [ -z "$1" ]; then |
| 8 | cat <<-EOM |
| 9 | Usage: |
| 10 | $0 SKIA_EXECUTABLE [ARGUMENTS_FOR_EXECUTABLE...] |
| 11 | |
| 12 | Run something like this: |
| 13 | $0 dm --src tests |
| 14 | or |
| 15 | $0 dm --src gm skp |
| 16 | |
| 17 | EOM |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | set -x |
| 22 | set -e |
| 23 | |
| 24 | cd "$(dirname "$0")/.." |
| 25 | |
| 26 | EXECUTABLE="$1" |
| 27 | shift |
| 28 | |
| 29 | DIR="$(mktemp -d "${TMPDIR:-/tmp}/skia_coverage_XXXXXXXXXX")" |
| 30 | BUILD=out/coverage |
| 31 | |
| 32 | # Build $EXECUTABLE |
| 33 | bin/sync |
| 34 | bin/fetch-gn |
| 35 | |
| 36 | #TODO: make this work with Clang. |
Kevin Lubick | 0168e04 | 2017-02-14 13:12:37 -0500 | [diff] [blame] | 37 | ARGS='cc="gcc" cxx="g++" extra_cflags=["--coverage"] extra_ldflags=["--coverage"]' |
halcanary | 3948a1b | 2016-09-26 10:30:39 -0700 | [diff] [blame] | 38 | gn gen --args="$ARGS" "$BUILD" |
| 39 | |
| 40 | ninja -C "$BUILD" "$EXECUTABLE" |
| 41 | |
| 42 | GCOV="$(realpath tools/gcov_shim)" |
| 43 | |
| 44 | # Generate a zero-baseline so files not covered by $EXECUTABLE $@ will |
| 45 | # still show up in the report. This reads the .gcno files that are |
| 46 | # created at compile time. |
| 47 | lcov -q --gcov-tool="$GCOV" -c -b "$BUILD" -d "$BUILD" -o "$DIR"/baseline -i |
| 48 | |
| 49 | # Running the binary generates the real coverage information, the .gcda files. |
| 50 | "$BUILD"/"$EXECUTABLE" "$@" |
| 51 | |
| 52 | lcov -q --gcov-tool="$GCOV" -c -b "$BUILD" -d "$BUILD" -o "$DIR"/coverage |
| 53 | |
| 54 | lcov -q -a "$DIR"/baseline -a "$DIR"/coverage -o "$DIR"/merged |
| 55 | |
| 56 | genhtml -q "$DIR"/merged --legend -o "$DIR"/coverage_report --ignore-errors source |
| 57 | |
| 58 | xdg-open "$DIR"/coverage_report/index.html |