1#!/usr/bin/env bash 2 3if [[ ! ($# == 1) ]]; then 4 echo "$0: usage: coverage.sh OUTPUT_DIR" 5 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 13cd "$(dirname $0)" #cd to directory containing this script 14 15 16REPORTER_JAR=$ANDROID_HOST_OUT/framework/jacoco-cli.jar 17 18OUTPUT_DIR=$1 19 20echo "Running tests and generating coverage report" 21echo "Output dir: $OUTPUT_DIR" 22 23REMOTE_COVERAGE_OUTPUT_FILE=/data/data/com.android.server.wifi.test/files/coverage.ec 24COVERAGE_OUTPUT_FILE=$OUTPUT_DIR/wifi_coverage.ec 25 26set -e # fail early 27set -x # print commands 28 29# 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 \ 43 FrameworksWifiTests 44 45adb root 46adb wait-for-device 47 48adb shell rm -f $REMOTE_COVERAGE_OUTPUT_FILE 49 50adb install -r -g "$OUT/data/app/FrameworksWifiTests/FrameworksWifiTests.apk" 51 52adb shell am instrument -e coverage true -w 'com.android.server.wifi.test/com.android.server.wifi.CustomTestRunner' 53 54mkdir -p $OUTPUT_DIR 55 56adb pull $REMOTE_COVERAGE_OUTPUT_FILE $COVERAGE_OUTPUT_FILE 57 58java -jar $REPORTER_JAR \ 59 report \ 60 -classfiles $ANDROID_PRODUCT_OUT/../../common/obj/APPS/FrameworksWifiTests_intermediates/jacoco/report-resources/jacoco-report-classes.jar \ 61 -html $OUTPUT_DIR \ 62 -sourcefiles $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests/wifitests/src -sourcefiles $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java \ 63 -name wifi-coverage \ 64 $COVERAGE_OUTPUT_FILE 65 66echo Created report at $OUTPUT_DIR/index.html 67 68