Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Jeff Gaston | dbfa9db | 2017-04-18 18:12:45 -0700 | [diff] [blame] | 3 | if [[ ! ($# == 1) ]]; then |
| 4 | echo "$0: usage: coverage.sh OUTPUT_DIR" |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | if [ -z $ANDROID_BUILD_TOP ]; then |
| 9 | echo "You need to source and lunch before you can use this script" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
Jeff Gaston | dbfa9db | 2017-04-18 18:12:45 -0700 | [diff] [blame] | 13 | cd "$(dirname $0)" #cd to directory containing this script |
| 14 | |
| 15 | |
| 16 | REPORTER_JAR=$ANDROID_HOST_OUT/framework/jacoco-cli.jar |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 17 | |
| 18 | OUTPUT_DIR=$1 |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 19 | |
| 20 | echo "Running tests and generating coverage report" |
| 21 | echo "Output dir: $OUTPUT_DIR" |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 22 | |
| 23 | REMOTE_COVERAGE_OUTPUT_FILE=/data/data/com.android.server.wifi.test/files/coverage.ec |
| 24 | COVERAGE_OUTPUT_FILE=$OUTPUT_DIR/wifi_coverage.ec |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 25 | |
| 26 | set -e # fail early |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 27 | set -x # print commands |
| 28 | |
Jeff Gaston | dbfa9db | 2017-04-18 18:12:45 -0700 | [diff] [blame] | 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 |
| 32 | make \ |
| 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 Plass | 581381e | 2017-12-22 13:55:31 -0800 | [diff] [blame] | 43 | MODULES-IN-external-jacoco \ |
Jeff Gaston | dbfa9db | 2017-04-18 18:12:45 -0700 | [diff] [blame] | 44 | FrameworksWifiTests |
| 45 | |
Mitchell Wills | 0855f2c | 2016-03-07 10:53:27 -0800 | [diff] [blame] | 46 | adb root |
| 47 | adb wait-for-device |
| 48 | |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 49 | adb shell rm -f $REMOTE_COVERAGE_OUTPUT_FILE |
| 50 | |
| 51 | adb install -r -g "$OUT/data/app/FrameworksWifiTests/FrameworksWifiTests.apk" |
| 52 | |
Michael Plass | 93d722b | 2017-06-20 08:33:28 -0700 | [diff] [blame] | 53 | adb shell am instrument -e coverage true -w 'com.android.server.wifi.test/com.android.server.wifi.CustomTestRunner' |
Mitchell Wills | a54db13 | 2016-02-02 10:53:39 -0800 | [diff] [blame] | 54 | |
| 55 | mkdir -p $OUTPUT_DIR |
| 56 | |
| 57 | adb pull $REMOTE_COVERAGE_OUTPUT_FILE $COVERAGE_OUTPUT_FILE |
| 58 | |
| 59 | java -jar $REPORTER_JAR \ |
Jeff Gaston | dbfa9db | 2017-04-18 18:12:45 -0700 | [diff] [blame] | 60 | report \ |
| 61 | -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 -sourcefiles $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java \ |
| 64 | -name wifi-coverage \ |
| 65 | $COVERAGE_OUTPUT_FILE |
| 66 | |
| 67 | echo Created report at $OUTPUT_DIR/index.html |
| 68 | |