blob: e6423a3e7309c4b15e55912af3963f2400d357fe [file] [log] [blame]
Hall Liu2ccf2042015-12-14 16:18:10 -08001lite_test_telecom() {
2 usage="
Brad Ebinger1c59a3b2015-12-15 14:28:01 -08003 Usage: lite_test_telecom [-c CLASSNAME] [-d] [-a | -i] [-e], where
Hall Liu2ccf2042015-12-14 16:18:10 -08004
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.
Brad Ebinger1c59a3b2015-12-15 14:28:01 -08008 -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).
Hall Liu2ccf2042015-12-14 16:18:10 -080011 -e Run code coverage. Coverage will be output into the coverage/
12 directory in the repo root.
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080013 -h This help message.
Hall Liu2ccf2042015-12-14 16:18:10 -080014 "
15
Hall Liu0c4f4352016-10-13 18:33:49 -070016 local OPTIND=1
17 local class=
18 local install=false
19 local installwdep=false
20 local debug=false
21 local coverage=false
Hall Liu2ccf2042015-12-14 16:18:10 -080022
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080023 while getopts "c:hadie" opt; do
Hall Liu2ccf2042015-12-14 16:18:10 -080024 case "$opt" in
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080025 h)
26 echo "$usage"
27 return 0;;
Brad Ebinger98a44dc2015-12-15 10:57:45 -080028 \?)
Hall Liu2ccf2042015-12-14 16:18:10 -080029 echo "$usage"
30 return 0;;
31 c)
32 class=$OPTARG;;
33 d)
34 debug=true;;
35 i)
36 install=true;;
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080037 a)
38 install=true
39 installwdep=true;;
Hall Liu2ccf2042015-12-14 16:18:10 -080040 e)
41 coverage=true;;
42 esac
43 done
44
Hall Liu0c4f4352016-10-13 18:33:49 -070045 local T=$(gettop)
Hall Liu2ccf2042015-12-14 16:18:10 -080046
47 if [ $install = true ] ; then
Hall Liu0c4f4352016-10-13 18:33:49 -070048 local olddir=$(pwd)
49 local emma_opt=
Hall Liu2ccf2042015-12-14 16:18:10 -080050 cd $T
Hall Liu0c4f4352016-10-13 18:33:49 -070051 # Build and exit script early if build fails
52
Hall Liu2ccf2042015-12-14 16:18:10 -080053 if [ $coverage = true ] ; then
Hall Liu5b8551e2017-03-10 17:05:23 -080054 emma_opt="EMMA_INSTRUMENT=true LOCAL_EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true"
Hall Liu2ccf2042015-12-14 16:18:10 -080055 else
Hall Liu5b8551e2017-03-10 17:05:23 -080056 emma_opt="EMMA_INSTRUMENT=false"
Hall Liu2ccf2042015-12-14 16:18:10 -080057 fi
Hall Liu0c4f4352016-10-13 18:33:49 -070058
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080059 if [ $installwdep = true ] ; then
Hall Liu5b8551e2017-03-10 17:05:23 -080060 (export ${emma_opt}; mmma -j40 "packages/services/Telecomm/tests")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080061 else
Hall Liu5b8551e2017-03-10 17:05:23 -080062 (export ${emma_opt}; mmm "packages/services/Telecomm/tests")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080063 fi
64 if [ $? -ne 0 ] ; then
65 echo "Make failed! try using -a instead of -i if building with coverage"
66 return
67 fi
68
Hall Liu0c4f4352016-10-13 18:33:49 -070069 # Strip off any possible aosp_ prefix from the target product
70 local canonical_product=$(sed 's/^aosp_//' <<< "$TARGET_PRODUCT")
71
72 adb install -r -t "out/target/product/$canonical_product/data/app/TelecomUnitTests/TelecomUnitTests.apk"
Hall Liu2ccf2042015-12-14 16:18:10 -080073 if [ $? -ne 0 ] ; then
74 cd "$olddir"
75 return $?
76 fi
77 cd "$olddir"
78 fi
79
Hall Liu0c4f4352016-10-13 18:33:49 -070080 local e_options=""
Hall Liu2ccf2042015-12-14 16:18:10 -080081 if [ -n "$class" ] ; then
82 e_options="${e_options} -e class com.android.server.telecom.tests.${class}"
83 fi
84 if [ $debug = true ] ; then
85 e_options="${e_options} -e debug 'true'"
86 fi
87 if [ $coverage = true ] ; then
88 e_options="${e_options} -e coverage 'true'"
89 fi
90 adb shell am instrument ${e_options} -w com.android.server.telecom.tests/android.test.InstrumentationTestRunner
91
92 if [ $coverage = true ] ; then
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080093 adb root
94 adb wait-for-device
Hall Liu2ccf2042015-12-14 16:18:10 -080095 adb pull /data/user/0/com.android.server.telecom.tests/files/coverage.ec /tmp/
Hall Liuccd78412016-02-17 18:07:21 -080096 if [ ! -d "$T/coverage" ] ; then
97 mkdir -p "$T/coverage"
98 fi
99 java -jar "$T/prebuilts/sdk/tools/jack-jacoco-reporter.jar" \
100 --report-dir "$T/coverage/" \
101 --metadata-file "$T/out/target/common/obj/APPS/TelecomUnitTests_intermediates/coverage.em" \
102 --coverage-file "/tmp/coverage.ec" \
103 --source-dir "$T/packages/services/Telecomm/src/"
Hall Liu2ccf2042015-12-14 16:18:10 -0800104 fi
105}