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 7if [ -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 19fi 20 21set -x 22set -e 23 24cd "$(dirname "$0")/.." 25 26EXECUTABLE="$1" 27shift 28 29DIR="$(mktemp -d "${TMPDIR:-/tmp}/skia_coverage_XXXXXXXXXX")" 30BUILD=out/coverage 31 32# Build $EXECUTABLE 33bin/sync 34bin/fetch-gn 35 36#TODO: make this work with Clang. 37ARGS='cc="gcc" cxx="g++" extra_cflags=["--coverage"] extra_ldflags=["--coverage"]' 38gn gen --args="$ARGS" "$BUILD" 39 40ninja -C "$BUILD" "$EXECUTABLE" 41 42GCOV="$(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. 47lcov -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 52lcov -q --gcov-tool="$GCOV" -c -b "$BUILD" -d "$BUILD" -o "$DIR"/coverage 53 54lcov -q -a "$DIR"/baseline -a "$DIR"/coverage -o "$DIR"/merged 55 56genhtml -q "$DIR"/merged --legend -o "$DIR"/coverage_report --ignore-errors source 57 58xdg-open "$DIR"/coverage_report/index.html 59