Dan Albert | 98e2c64 | 2014-09-19 14:40:57 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (C) 2014 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | # |
| 17 | # acov is a tool for gathering coverage information from a device and generating |
| 18 | # a report from that information. To use: |
| 19 | # |
| 20 | # 1. sudo apt-get install lcov |
| 21 | # 2. Build application/library with coverage information. |
| 22 | # 3. Push the new binaries to the device. |
| 23 | # 4. Run tests with the additional environment variables: |
| 24 | # * GCOV_PREFIX=/data/local/tmp/gcov |
| 25 | # * GCOV_PREFIX_STRIP=`echo $(ANDROID_BUILD_TOP) | grep -o / | wc -l` |
| 26 | # 5. Run `acov`. |
| 27 | # |
| 28 | # acov will pull all coverage information from the device, push it to the right |
| 29 | # directories, run lcov, and display the coverage report (currently by opening |
| 30 | # it in your browser). |
| 31 | # |
| 32 | |
Dan Albert | cf347cc | 2015-01-24 13:40:42 -0800 | [diff] [blame] | 33 | if [ "$1" = "--clean" ]; then |
| 34 | find $ANDROID_HOST_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete |
| 35 | find $ANDROID_PRODUCT_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete |
| 36 | exit 0 |
| 37 | fi |
| 38 | |
| 39 | if [ "$1" = "--prep" ]; then |
Dan Albert | f1d27e2 | 2015-04-14 13:46:57 -0700 | [diff] [blame] | 40 | if [ -d "$ANDROID_HOST_OUT" ]; then |
| 41 | find $ANDROID_HOST_OUT -name '*.gcda' -delete |
| 42 | fi |
| 43 | |
| 44 | if [ -d "$ANDROID_PRODUCT_OUT" ]; then |
| 45 | find $ANDROID_PRODUCT_OUT -name '*.gcda' -delete |
| 46 | fi |
| 47 | |
Dan Albert | cf347cc | 2015-01-24 13:40:42 -0800 | [diff] [blame] | 48 | exit 0 |
| 49 | fi |
| 50 | |
Dan Albert | 7d133d2 | 2014-09-25 11:23:30 -0700 | [diff] [blame] | 51 | which lcov >/dev/null 2>/dev/null |
Dan Albert | 98e2c64 | 2014-09-19 14:40:57 -0700 | [diff] [blame] | 52 | if [ $? -ne 0 ]; then |
| 53 | echo 'lcov not found: running `sudo apt-get install lcov`' |
| 54 | sudo apt-get install lcov |
| 55 | fi |
| 56 | |
Dan Albert | 72324d8 | 2015-01-24 13:47:03 -0800 | [diff] [blame] | 57 | HOST=false |
| 58 | ANDROID_OUT=$ANDROID_PRODUCT_OUT |
Dan Albert | f12f658 | 2015-01-29 16:51:39 -0800 | [diff] [blame] | 59 | EXTRA_ARGS="$@" |
Dan Albert | 72324d8 | 2015-01-24 13:47:03 -0800 | [diff] [blame] | 60 | if [ "$1" = "--host" ]; then |
| 61 | HOST=true |
| 62 | ANDROID_OUT=$ANDROID_HOST_OUT |
Dan Albert | f12f658 | 2015-01-29 16:51:39 -0800 | [diff] [blame] | 63 | EXTRA_ARGS="--gcov-tool=/usr/bin/gcov-4.6 ${@:2}" |
Dan Albert | 72324d8 | 2015-01-24 13:47:03 -0800 | [diff] [blame] | 64 | fi |
| 65 | |
Dan Albert | 98e2c64 | 2014-09-19 14:40:57 -0700 | [diff] [blame] | 66 | cd $ANDROID_BUILD_TOP |
| 67 | FILE=cov.info |
| 68 | DIR=$(mktemp -d covreport-XXXXXX) |
Dan Albert | 72324d8 | 2015-01-24 13:47:03 -0800 | [diff] [blame] | 69 | |
| 70 | if [ "$HOST" = "false" ]; then |
| 71 | adb pull /data/local/tmp/gcov |
| 72 | fi |
| 73 | |
Dan Albert | f12f658 | 2015-01-29 16:51:39 -0800 | [diff] [blame] | 74 | lcov -c -d $ANDROID_OUT -o $DIR/$FILE $EXTRA_ARGS |
Dan Albert | 98e2c64 | 2014-09-19 14:40:57 -0700 | [diff] [blame] | 75 | echo "Generating coverage report at $DIR" |
| 76 | genhtml -q -o $DIR $DIR/$FILE |
| 77 | xdg-open $DIR/index.html >/dev/null |