blob: 779f449b24fea41b6bc43ffe37dfceb0fd3ad7a2 [file] [log] [blame]
Hall Liu90fc0b42017-03-30 11:29:44 -07001_lite_test_general() {
Hall Liu2ccf2042015-12-14 16:18:10 -08002 usage="
Hall Liu90fc0b42017-03-30 11:29:44 -07003 Usage: $0 [-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 Ebinger7bba1112017-06-08 13:57:28 -070013 -g Run build commands with USE_GOMA=true
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080014 -h This help message.
Hall Liu2ccf2042015-12-14 16:18:10 -080015 "
16
Hall Liu0c4f4352016-10-13 18:33:49 -070017 local OPTIND=1
18 local class=
Hall Liu90fc0b42017-03-30 11:29:44 -070019 local project=
Hall Liu0c4f4352016-10-13 18:33:49 -070020 local install=false
21 local installwdep=false
22 local debug=false
23 local coverage=false
Brad Ebinger7bba1112017-06-08 13:57:28 -070024 local goma=false
Hall Liu2ccf2042015-12-14 16:18:10 -080025
Brad Ebinger7bba1112017-06-08 13:57:28 -070026 while getopts "c:p:hadieg" opt; do
Hall Liu2ccf2042015-12-14 16:18:10 -080027 case "$opt" in
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080028 h)
29 echo "$usage"
30 return 0;;
Brad Ebinger98a44dc2015-12-15 10:57:45 -080031 \?)
Hall Liu2ccf2042015-12-14 16:18:10 -080032 echo "$usage"
33 return 0;;
34 c)
35 class=$OPTARG;;
36 d)
37 debug=true;;
38 i)
39 install=true;;
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080040 a)
41 install=true
42 installwdep=true;;
Hall Liu2ccf2042015-12-14 16:18:10 -080043 e)
44 coverage=true;;
Brad Ebinger7bba1112017-06-08 13:57:28 -070045 g)
46 goma=true;;
Hall Liu90fc0b42017-03-30 11:29:44 -070047 p)
48 project=$OPTARG;;
Hall Liu2ccf2042015-12-14 16:18:10 -080049 esac
50 done
51
Hall Liu90fc0b42017-03-30 11:29:44 -070052 local build_dir=
53 local apk_loc=
54 local package_prefix=
55 local instrumentation=
56 case "$project" in
57 "telecom")
58 build_dir="packages/services/Telecomm/tests"
59 apk_loc="data/app/TelecomUnitTests/TelecomUnitTests.apk"
60 package_prefix="com.android.server.telecom.tests"
Hall Liuc8a396b2017-12-27 18:23:28 -080061 instrumentation="android.support.test.runner.AndroidJUnitRunner";;
Hall Liu90fc0b42017-03-30 11:29:44 -070062 "telephony")
63 build_dir="frameworks/opt/telephony/tests/"
64 apk_loc="data/app/FrameworksTelephonyTests/FrameworksTelephonyTests.apk"
65 package_prefix="com.android.frameworks.telephonytests"
66 instrumentation="android.support.test.runner.AndroidJUnitRunner";;
67 esac
68
Hall Liu0c4f4352016-10-13 18:33:49 -070069 local T=$(gettop)
Hall Liu2ccf2042015-12-14 16:18:10 -080070
71 if [ $install = true ] ; then
Hall Liu0c4f4352016-10-13 18:33:49 -070072 local olddir=$(pwd)
73 local emma_opt=
Brad Ebinger7bba1112017-06-08 13:57:28 -070074 local goma_opt=
75
Hall Liu2ccf2042015-12-14 16:18:10 -080076 cd $T
Hall Liu0c4f4352016-10-13 18:33:49 -070077 # Build and exit script early if build fails
78
Hall Liu2ccf2042015-12-14 16:18:10 -080079 if [ $coverage = true ] ; then
Hall Liu5b8551e2017-03-10 17:05:23 -080080 emma_opt="EMMA_INSTRUMENT=true LOCAL_EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true"
Hall Liu2ccf2042015-12-14 16:18:10 -080081 else
Hall Liu5b8551e2017-03-10 17:05:23 -080082 emma_opt="EMMA_INSTRUMENT=false"
Hall Liu2ccf2042015-12-14 16:18:10 -080083 fi
Hall Liu0c4f4352016-10-13 18:33:49 -070084
Brad Ebinger7bba1112017-06-08 13:57:28 -070085 if [ $goma = true ] ; then
86 goma_opt="USE_GOMA=true"
87 fi
88
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080089 if [ $installwdep = true ] ; then
Brad Ebinger7bba1112017-06-08 13:57:28 -070090 (export ${emma_opt}; mmma ${goma_opt} -j40 "$build_dir")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080091 else
Brad Ebinger7bba1112017-06-08 13:57:28 -070092 (export ${emma_opt}; mmm ${goma_opt} "$build_dir")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080093 fi
94 if [ $? -ne 0 ] ; then
95 echo "Make failed! try using -a instead of -i if building with coverage"
96 return
97 fi
98
Hall Liu0c4f4352016-10-13 18:33:49 -070099 # Strip off any possible aosp_ prefix from the target product
100 local canonical_product=$(sed 's/^aosp_//' <<< "$TARGET_PRODUCT")
101
Hall Liu90fc0b42017-03-30 11:29:44 -0700102 adb install -r -t "out/target/product/$canonical_product/$apk_loc"
Hall Liu2ccf2042015-12-14 16:18:10 -0800103 if [ $? -ne 0 ] ; then
104 cd "$olddir"
105 return $?
106 fi
107 cd "$olddir"
108 fi
109
Hall Liu0c4f4352016-10-13 18:33:49 -0700110 local e_options=""
Hall Liu2ccf2042015-12-14 16:18:10 -0800111 if [ -n "$class" ] ; then
Hall Liu90fc0b42017-03-30 11:29:44 -0700112 if [[ "$class" =~ "\." ]] ; then
113 e_options="${e_options} -e class ${class}"
114 else
115 e_options="${e_options} -e class ${package_prefix}.${class}"
116 fi
Hall Liu2ccf2042015-12-14 16:18:10 -0800117 fi
118 if [ $debug = true ] ; then
119 e_options="${e_options} -e debug 'true'"
120 fi
Hall Liu90fc0b42017-03-30 11:29:44 -0700121 if [ $coverage = true ] && [ $project =~ "telecom" ] ; then
Hall Liu2ccf2042015-12-14 16:18:10 -0800122 e_options="${e_options} -e coverage 'true'"
123 fi
Hall Liu90fc0b42017-03-30 11:29:44 -0700124 adb shell am instrument ${e_options} -w "$package_prefix/$instrumentation"
Hall Liu2ccf2042015-12-14 16:18:10 -0800125
Hall Liu90fc0b42017-03-30 11:29:44 -0700126 # Code coverage only enabled for Telecom.
127 if [ $coverage = true ] && [ $project =~ "telecom" ] ; then
Brad Ebinger1c59a3b2015-12-15 14:28:01 -0800128 adb root
129 adb wait-for-device
Hall Liu2ccf2042015-12-14 16:18:10 -0800130 adb pull /data/user/0/com.android.server.telecom.tests/files/coverage.ec /tmp/
Hall Liuccd78412016-02-17 18:07:21 -0800131 if [ ! -d "$T/coverage" ] ; then
132 mkdir -p "$T/coverage"
133 fi
134 java -jar "$T/prebuilts/sdk/tools/jack-jacoco-reporter.jar" \
135 --report-dir "$T/coverage/" \
136 --metadata-file "$T/out/target/common/obj/APPS/TelecomUnitTests_intermediates/coverage.em" \
137 --coverage-file "/tmp/coverage.ec" \
138 --source-dir "$T/packages/services/Telecomm/src/"
Hall Liu2ccf2042015-12-14 16:18:10 -0800139 fi
140}
Hall Liu90fc0b42017-03-30 11:29:44 -0700141
142lite_test_telecom() {
143 _lite_test_general -p telecom $@
144}
145
146lite_test_telephony() {
147 _lite_test_general -p telephony $@
148}