summaryrefslogtreecommitdiffstats
path: root/scripts/acov
blob: a884ca238cc7058200514f9cbbbc5b03dcc3c4e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# acov is a tool for gathering coverage information from a device and generating
# a report from that information. To use:
#
# 1. sudo apt-get install lcov
# 2. Build application/library with coverage information.
# 3. Push the new binaries to the device.
# 4. Run tests with the additional environment variables:
#     * GCOV_PREFIX=/data/local/tmp/gcov
#     * GCOV_PREFIX_STRIP=`echo $(ANDROID_BUILD_TOP) | grep -o / | wc -l`
# 5. Run `acov`.
#
# acov will pull all coverage information from the device, push it to the right
# directories, run lcov, and display the coverage report (currently by opening
# it in your browser).
#

if [ "$1" = "--clean" ]; then
  find $ANDROID_HOST_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete
  find $ANDROID_PRODUCT_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete
  exit 0
fi

if [ "$1" = "--prep" ]; then
  if [ -d "$ANDROID_HOST_OUT" ]; then
    find $ANDROID_HOST_OUT -name '*.gcda' -delete
  fi

  if [ -d "$ANDROID_PRODUCT_OUT" ]; then
    find $ANDROID_PRODUCT_OUT -name '*.gcda' -delete
  fi

  exit 0
fi

which lcov >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
  echo 'lcov not found: running `sudo apt-get install lcov`'
  sudo apt-get install lcov
fi

HOST=false
ANDROID_OUT=$ANDROID_PRODUCT_OUT
EXTRA_ARGS="$@"
if [ "$1" = "--host" ]; then
  HOST=true
  ANDROID_OUT=$ANDROID_HOST_OUT
  EXTRA_ARGS="--gcov-tool=/usr/bin/gcov-4.6 ${@:2}"
fi

cd $ANDROID_BUILD_TOP
FILE=cov.info
DIR=$(mktemp -d covreport-XXXXXX)

if [ "$HOST" = "false" ]; then
  adb pull /data/local/tmp/gcov
fi

lcov -c -d $ANDROID_OUT -o $DIR/$FILE $EXTRA_ARGS
echo "Generating coverage report at $DIR"
genhtml -q -o $DIR $DIR/$FILE
xdg-open $DIR/index.html >/dev/null