Home | History | Annotate | Download | only in wifitests
      1 #!/usr/bin/env bash
      2 
      3 if [[ ! ($# == 1) ]]; then
      4   echo "$0: usage: coverage.sh OUTPUT_DIR"
      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 
     13 cd "$(dirname $0)" #cd to directory containing this script
     14 
     15 
     16 REPORTER_JAR=$ANDROID_HOST_OUT/framework/jacoco-cli.jar
     17 
     18 OUTPUT_DIR=$1
     19 
     20 echo "Running tests and generating coverage report"
     21 echo "Output dir: $OUTPUT_DIR"
     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
     25 
     26 set -e # fail early
     27 set -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-cli.jar so we can generate the report
     32 $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode \
     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   MODULES-IN-frameworks-opt-net-wifi-tests \
     39   MODULES-IN-system-core \
     40   MODULES-IN-external-jacoco \
     41   FrameworksWifiTests
     42 
     43 APK_NAME="$(ls -t $(find $OUT -name FrameworksWifiTests.apk) | head -n 1)"
     44 
     45 adb root
     46 adb wait-for-device
     47 
     48 adb shell rm -f $REMOTE_COVERAGE_OUTPUT_FILE
     49 
     50 adb install -r -g "$APK_NAME"
     51 
     52 adb shell am instrument -e coverage true --no-hidden-api-checks -w 'com.android.server.wifi.test/com.android.server.wifi.CustomTestRunner'
     53 
     54 mkdir -p $OUTPUT_DIR
     55 
     56 adb pull $REMOTE_COVERAGE_OUTPUT_FILE $COVERAGE_OUTPUT_FILE
     57 
     58 java -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 \
     63   --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 
     69