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