Home | History | Annotate | Download | only in wifitests
      1 #!/usr/bin/env bash
      2 
      3 if [[ ! ( ($# == 1) || ($# == 2 && ($2 == "HTML" || $2 == "XML" || $2 == "CSV"))) ]]; then
      4   echo "$0: usage: coverage.sh OUTPUT_DIR [REPORT_TYPE]"
      5   echo "REPORT_TYPE [HTML | XML | CSV] : the type of the report (default is HTML)"
      6   exit 1
      7 fi
      8 
      9 if [ -z $ANDROID_BUILD_TOP ]; then
     10   echo "You need to source and lunch before you can use this script"
     11   exit 1
     12 fi
     13 
     14 REPORTER_JAR=$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jack-jacoco-reporter.jar
     15 
     16 OUTPUT_DIR=$1
     17 if [[ $# == 2 ]]; then
     18   REPORT_TYPE=$2
     19 else
     20   REPORT_TYPE="HTML"
     21 fi
     22 
     23 echo "Running tests and generating coverage report"
     24 echo "Output dir: $OUTPUT_DIR"
     25 echo "Report type: $REPORT_TYPE"
     26 
     27 REMOTE_COVERAGE_OUTPUT_FILE=/data/data/com.android.server.wifi.test/files/coverage.ec
     28 COVERAGE_OUTPUT_FILE=$OUTPUT_DIR/wifi_coverage.ec
     29 COVERAGE_METADATA_FILE=$ANDROID_BUILD_TOP/out/target/common/obj/APPS/FrameworksWifiTests_intermediates/coverage.em
     30 
     31 set -e # fail early
     32 
     33 echo "+ EMMA_INSTRUMENT_STATIC=true mmma -j32 $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests"
     34 # NOTE Don't actually run the command above since this shell doesn't inherit functions from the
     35 #      caller.
     36 EMMA_INSTRUMENT_STATIC=true make -j32 -C $ANDROID_BUILD_TOP -f build/core/main.mk MODULES-IN-frameworks-opt-net-wifi-tests
     37 
     38 set -x # print commands
     39 
     40 adb root
     41 adb wait-for-device
     42 
     43 adb shell rm -f $REMOTE_COVERAGE_OUTPUT_FILE
     44 
     45 adb install -r -g "$OUT/data/app/FrameworksWifiTests/FrameworksWifiTests.apk"
     46 
     47 adb shell am instrument -e coverage true -w 'com.android.server.wifi.test/android.support.test.runner.AndroidJUnitRunner'
     48 
     49 mkdir -p $OUTPUT_DIR
     50 
     51 adb pull $REMOTE_COVERAGE_OUTPUT_FILE $COVERAGE_OUTPUT_FILE
     52 
     53 java -jar $REPORTER_JAR \
     54   --report-dir $OUTPUT_DIR \
     55   --metadata-file $COVERAGE_METADATA_FILE \
     56   --coverage-file $COVERAGE_OUTPUT_FILE \
     57   --report-type $REPORT_TYPE \
     58   --source-dir $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests/wifitests/src \
     59   --source-dir $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java \
     60   --source-dir $ANDROID_BUILD_TOP/frameworks/base/wifi/java
     61