blob: fd705561639709f1639f32b7c0dc2b7b21d580cd [file] [log] [blame]
Mitchell Willsa54db132016-02-02 10:53:39 -08001#!/usr/bin/env bash
2
Jeff Gastondbfa9db2017-04-18 18:12:45 -07003if [[ ! ($# == 1) ]]; then
4 echo "$0: usage: coverage.sh OUTPUT_DIR"
Mitchell Willsa54db132016-02-02 10:53:39 -08005 exit 1
6fi
7
8if [ -z $ANDROID_BUILD_TOP ]; then
9 echo "You need to source and lunch before you can use this script"
10 exit 1
11fi
12
Jeff Gastondbfa9db2017-04-18 18:12:45 -070013cd "$(dirname $0)" #cd to directory containing this script
14
15
16REPORTER_JAR=$ANDROID_HOST_OUT/framework/jacoco-cli.jar
Mitchell Willsa54db132016-02-02 10:53:39 -080017
18OUTPUT_DIR=$1
Mitchell Willsa54db132016-02-02 10:53:39 -080019
20echo "Running tests and generating coverage report"
21echo "Output dir: $OUTPUT_DIR"
Mitchell Willsa54db132016-02-02 10:53:39 -080022
23REMOTE_COVERAGE_OUTPUT_FILE=/data/data/com.android.server.wifi.test/files/coverage.ec
24COVERAGE_OUTPUT_FILE=$OUTPUT_DIR/wifi_coverage.ec
Mitchell Willsa54db132016-02-02 10:53:39 -080025
26set -e # fail early
Mitchell Willsa54db132016-02-02 10:53:39 -080027set -x # print commands
28
Jeff Gastondbfa9db2017-04-18 18:12:45 -070029# build this module so we can run its tests, and
30# build system/core so we can invoke `adb`, and
31# build jacoco-report-classes.jar so we can generate the report
32make \
33 EMMA_INSTRUMENT=true \
34 EMMA_INSTRUMENT_FRAMEWORK=false \
35 EMMA_INSTRUMENT_STATIC=true \
36 ANDROID_COMPILE_WITH_JACK=false \
37 SKIP_BOOT_JARS_CHECK=true \
38 -j32 \
39 -C $ANDROID_BUILD_TOP \
40 -f build/core/main.mk \
41 MODULES-IN-frameworks-opt-net-wifi-tests \
42 MODULES-IN-system-core \
Michael Plass581381e2017-12-22 13:55:31 -080043 MODULES-IN-external-jacoco \
Jeff Gastondbfa9db2017-04-18 18:12:45 -070044 FrameworksWifiTests
45
Mitchell Wills0855f2c2016-03-07 10:53:27 -080046adb root
47adb wait-for-device
48
Mitchell Willsa54db132016-02-02 10:53:39 -080049adb shell rm -f $REMOTE_COVERAGE_OUTPUT_FILE
50
51adb install -r -g "$OUT/data/app/FrameworksWifiTests/FrameworksWifiTests.apk"
52
Michael Plass93d722b2017-06-20 08:33:28 -070053adb shell am instrument -e coverage true -w 'com.android.server.wifi.test/com.android.server.wifi.CustomTestRunner'
Mitchell Willsa54db132016-02-02 10:53:39 -080054
55mkdir -p $OUTPUT_DIR
56
57adb pull $REMOTE_COVERAGE_OUTPUT_FILE $COVERAGE_OUTPUT_FILE
58
59java -jar $REPORTER_JAR \
Jeff Gastondbfa9db2017-04-18 18:12:45 -070060 report \
Michael Plassaaa452e2018-01-11 14:21:42 -080061 --classfiles $ANDROID_PRODUCT_OUT/../../common/obj/APPS/FrameworksWifiTests_intermediates/jacoco/report-resources/jacoco-report-classes.jar \
62 --html $OUTPUT_DIR \
63 --sourcefiles $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests/wifitests/src \
64 --sourcefiles $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java \
65 --name wifi-coverage \
Jeff Gastondbfa9db2017-04-18 18:12:45 -070066 $COVERAGE_OUTPUT_FILE
67
68echo Created report at $OUTPUT_DIR/index.html
69