Home | History | Annotate | Download | only in scripts
      1 lite_test_telecom() {
      2   usage="
      3   Usage: lite_test_telecom [-c CLASSNAME] [-d] [-a | -i] [-e], where
      4 
      5   -c CLASSNAME          Run tests only for the specified class/method. CLASSNAME
      6                           should be of the form SomeClassTest or SomeClassTest#testMethod.
      7   -d                    Waits for a debugger to attach before starting to run tests.
      8   -i                    Rebuild and reinstall the test apk before running tests (mmm).
      9   -a                    Rebuild all dependencies and reinstall the test apk before/
     10                           running tests (mmma).
     11   -e                    Run code coverage. Coverage will be output into the coverage/
     12                           directory in the repo root.
     13   -h                    This help message.
     14   "
     15 
     16   OPTIND=1
     17   class=
     18   install=false
     19   installwdep=false
     20   debug=false
     21   coverage=false
     22 
     23   while getopts "c:hadie" opt; do
     24     case "$opt" in
     25       h)
     26         echo "$usage"
     27         return 0;;
     28       \?)
     29         echo "$usage"
     30         return 0;;
     31       c)
     32         class=$OPTARG;;
     33       d)
     34         debug=true;;
     35       i)
     36         install=true;;
     37       a)
     38         install=true
     39         installwdep=true;;
     40       e)
     41         coverage=true;;
     42     esac
     43   done
     44 
     45   T=$(gettop)
     46 
     47   if [ $install = true ] ; then
     48     olddir=$(pwd)
     49     cd $T
     50     if [ $coverage = true ] ; then
     51       emma_opt="EMMA_INSTRUMENT_STATIC=true"
     52     else
     53       emma_opt="EMMA_INSTRUMENT_STATIC=false"
     54     fi
     55     # Build and exit script early if build fails
     56     if [ $installwdep = true ] ; then
     57       mmma -j40 "packages/services/Telecomm/tests" ${emma_opt}
     58     else
     59       mmm "packages/services/Telecomm/tests" ${emma_opt}
     60     fi
     61     if [ $? -ne 0 ] ; then
     62       echo "Make failed! try using -a instead of -i if building with coverage"
     63       return
     64     fi
     65 
     66     adb install -r -t "out/target/product/$TARGET_PRODUCT/data/app/TelecomUnitTests/TelecomUnitTests.apk"
     67     if [ $? -ne 0 ] ; then
     68       cd "$olddir"
     69       return $?
     70     fi
     71     cd "$olddir"
     72   fi
     73 
     74   e_options=""
     75   if [ -n "$class" ] ; then
     76     e_options="${e_options} -e class com.android.server.telecom.tests.${class}"
     77   fi
     78   if [ $debug = true ] ; then
     79     e_options="${e_options} -e debug 'true'"
     80   fi
     81   if [ $coverage = true ] ; then
     82     e_options="${e_options} -e coverage 'true'"
     83   fi
     84   adb shell am instrument ${e_options} -w com.android.server.telecom.tests/android.test.InstrumentationTestRunner
     85 
     86   if [ $coverage = true ] ; then
     87     adb root
     88     adb wait-for-device
     89     adb pull /data/user/0/com.android.server.telecom.tests/files/coverage.ec /tmp/
     90     if [ ! -d "$T/coverage" ] ; then
     91       mkdir -p "$T/coverage"
     92     fi
     93     java -jar "$T/prebuilts/sdk/tools/jack-jacoco-reporter.jar" \
     94       --report-dir "$T/coverage/" \
     95       --metadata-file "$T/out/target/common/obj/APPS/TelecomUnitTests_intermediates/coverage.em" \
     96       --coverage-file "/tmp/coverage.ec" \
     97       --source-dir "$T/packages/services/Telecomm/src/"
     98   fi
     99 }
    100