blob: 0ece427ea11180430ef068d6dfc2a88331db189b [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 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=
Hall Liu90fc0b42017-03-30 11:29:44 -070018 local project=
Hall Liu0c4f4352016-10-13 18:33:49 -070019 local install=false
20 local installwdep=false
21 local debug=false
22 local coverage=false
Hall Liu2ccf2042015-12-14 16:18:10 -080023
Hall Liu90fc0b42017-03-30 11:29:44 -070024 while getopts "c:p:hadie" opt; do
Hall Liu2ccf2042015-12-14 16:18:10 -080025 case "$opt" in
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080026 h)
27 echo "$usage"
28 return 0;;
Brad Ebinger98a44dc2015-12-15 10:57:45 -080029 \?)
Hall Liu2ccf2042015-12-14 16:18:10 -080030 echo "$usage"
31 return 0;;
32 c)
33 class=$OPTARG;;
34 d)
35 debug=true;;
36 i)
37 install=true;;
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080038 a)
39 install=true
40 installwdep=true;;
Hall Liu2ccf2042015-12-14 16:18:10 -080041 e)
42 coverage=true;;
Hall Liu90fc0b42017-03-30 11:29:44 -070043 p)
44 project=$OPTARG;;
Hall Liu2ccf2042015-12-14 16:18:10 -080045 esac
46 done
47
Hall Liu90fc0b42017-03-30 11:29:44 -070048 local build_dir=
49 local apk_loc=
50 local package_prefix=
51 local instrumentation=
52 case "$project" in
53 "telecom")
54 build_dir="packages/services/Telecomm/tests"
55 apk_loc="data/app/TelecomUnitTests/TelecomUnitTests.apk"
56 package_prefix="com.android.server.telecom.tests"
57 instrumentation="android.test.InstrumentationTestRunner";;
58 "telephony")
59 build_dir="frameworks/opt/telephony/tests/"
60 apk_loc="data/app/FrameworksTelephonyTests/FrameworksTelephonyTests.apk"
61 package_prefix="com.android.frameworks.telephonytests"
62 instrumentation="android.support.test.runner.AndroidJUnitRunner";;
63 esac
64
Hall Liu0c4f4352016-10-13 18:33:49 -070065 local T=$(gettop)
Hall Liu2ccf2042015-12-14 16:18:10 -080066
67 if [ $install = true ] ; then
Hall Liu0c4f4352016-10-13 18:33:49 -070068 local olddir=$(pwd)
69 local emma_opt=
Hall Liu2ccf2042015-12-14 16:18:10 -080070 cd $T
Hall Liu0c4f4352016-10-13 18:33:49 -070071 # Build and exit script early if build fails
72
Hall Liu2ccf2042015-12-14 16:18:10 -080073 if [ $coverage = true ] ; then
Hall Liu5b8551e2017-03-10 17:05:23 -080074 emma_opt="EMMA_INSTRUMENT=true LOCAL_EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true"
Hall Liu2ccf2042015-12-14 16:18:10 -080075 else
Hall Liu5b8551e2017-03-10 17:05:23 -080076 emma_opt="EMMA_INSTRUMENT=false"
Hall Liu2ccf2042015-12-14 16:18:10 -080077 fi
Hall Liu0c4f4352016-10-13 18:33:49 -070078
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080079 if [ $installwdep = true ] ; then
Hall Liu90fc0b42017-03-30 11:29:44 -070080 (export ${emma_opt}; mmma -j40 "$build_dir")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080081 else
Hall Liu90fc0b42017-03-30 11:29:44 -070082 (export ${emma_opt}; mmm "$build_dir")
Brad Ebinger1c59a3b2015-12-15 14:28:01 -080083 fi
84 if [ $? -ne 0 ] ; then
85 echo "Make failed! try using -a instead of -i if building with coverage"
86 return
87 fi
88
Hall Liu0c4f4352016-10-13 18:33:49 -070089 # Strip off any possible aosp_ prefix from the target product
90 local canonical_product=$(sed 's/^aosp_//' <<< "$TARGET_PRODUCT")
91
Hall Liu90fc0b42017-03-30 11:29:44 -070092 adb install -r -t "out/target/product/$canonical_product/$apk_loc"
Hall Liu2ccf2042015-12-14 16:18:10 -080093 if [ $? -ne 0 ] ; then
94 cd "$olddir"
95 return $?
96 fi
97 cd "$olddir"
98 fi
99
Hall Liu0c4f4352016-10-13 18:33:49 -0700100 local e_options=""
Hall Liu2ccf2042015-12-14 16:18:10 -0800101 if [ -n "$class" ] ; then
Hall Liu90fc0b42017-03-30 11:29:44 -0700102 if [[ "$class" =~ "\." ]] ; then
103 e_options="${e_options} -e class ${class}"
104 else
105 e_options="${e_options} -e class ${package_prefix}.${class}"
106 fi
Hall Liu2ccf2042015-12-14 16:18:10 -0800107 fi
108 if [ $debug = true ] ; then
109 e_options="${e_options} -e debug 'true'"
110 fi
Hall Liu90fc0b42017-03-30 11:29:44 -0700111 if [ $coverage = true ] && [ $project =~ "telecom" ] ; then
Hall Liu2ccf2042015-12-14 16:18:10 -0800112 e_options="${e_options} -e coverage 'true'"
113 fi
Hall Liu90fc0b42017-03-30 11:29:44 -0700114 adb shell am instrument ${e_options} -w "$package_prefix/$instrumentation"
Hall Liu2ccf2042015-12-14 16:18:10 -0800115
Hall Liu90fc0b42017-03-30 11:29:44 -0700116 # Code coverage only enabled for Telecom.
117 if [ $coverage = true ] && [ $project =~ "telecom" ] ; then
Brad Ebinger1c59a3b2015-12-15 14:28:01 -0800118 adb root
119 adb wait-for-device
Hall Liu2ccf2042015-12-14 16:18:10 -0800120 adb pull /data/user/0/com.android.server.telecom.tests/files/coverage.ec /tmp/
Hall Liuccd78412016-02-17 18:07:21 -0800121 if [ ! -d "$T/coverage" ] ; then
122 mkdir -p "$T/coverage"
123 fi
124 java -jar "$T/prebuilts/sdk/tools/jack-jacoco-reporter.jar" \
125 --report-dir "$T/coverage/" \
126 --metadata-file "$T/out/target/common/obj/APPS/TelecomUnitTests_intermediates/coverage.em" \
127 --coverage-file "/tmp/coverage.ec" \
128 --source-dir "$T/packages/services/Telecomm/src/"
Hall Liu2ccf2042015-12-14 16:18:10 -0800129 fi
130}
Hall Liu90fc0b42017-03-30 11:29:44 -0700131
132lite_test_telecom() {
133 _lite_test_general -p telecom $@
134}
135
136lite_test_telephony() {
137 _lite_test_general -p telephony $@
138}