Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 1 | _lite_test_general() { |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 2 | usage=" |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 3 | Usage: $0 [-c CLASSNAME] [-d] [-a | -i] [-e], where |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 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. |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 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). |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 11 | -e Run code coverage. Coverage will be output into the coverage/ |
| 12 | directory in the repo root. |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 13 | -g Run build commands with USE_GOMA=true |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 14 | -h This help message. |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 15 | " |
| 16 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 17 | local OPTIND=1 |
| 18 | local class= |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 19 | local project= |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 20 | local install=false |
| 21 | local installwdep=false |
| 22 | local debug=false |
| 23 | local coverage=false |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 24 | local goma=false |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 25 | |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 26 | while getopts "c:p:hadieg" opt; do |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 27 | case "$opt" in |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 28 | h) |
| 29 | echo "$usage" |
| 30 | return 0;; |
Brad Ebinger | 98a44dc | 2015-12-15 10:57:45 -0800 | [diff] [blame] | 31 | \?) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 32 | echo "$usage" |
| 33 | return 0;; |
| 34 | c) |
| 35 | class=$OPTARG;; |
| 36 | d) |
| 37 | debug=true;; |
| 38 | i) |
| 39 | install=true;; |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 40 | a) |
| 41 | install=true |
| 42 | installwdep=true;; |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 43 | e) |
| 44 | coverage=true;; |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 45 | g) |
| 46 | goma=true;; |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 47 | p) |
| 48 | project=$OPTARG;; |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 49 | esac |
| 50 | done |
| 51 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 52 | 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 Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame^] | 61 | instrumentation="android.support.test.runner.AndroidJUnitRunner";; |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 62 | "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 Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 69 | local T=$(gettop) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 70 | |
| 71 | if [ $install = true ] ; then |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 72 | local olddir=$(pwd) |
| 73 | local emma_opt= |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 74 | local goma_opt= |
| 75 | |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 76 | cd $T |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 77 | # Build and exit script early if build fails |
| 78 | |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 79 | if [ $coverage = true ] ; then |
Hall Liu | 5b8551e | 2017-03-10 17:05:23 -0800 | [diff] [blame] | 80 | emma_opt="EMMA_INSTRUMENT=true LOCAL_EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 81 | else |
Hall Liu | 5b8551e | 2017-03-10 17:05:23 -0800 | [diff] [blame] | 82 | emma_opt="EMMA_INSTRUMENT=false" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 83 | fi |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 84 | |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 85 | if [ $goma = true ] ; then |
| 86 | goma_opt="USE_GOMA=true" |
| 87 | fi |
| 88 | |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 89 | if [ $installwdep = true ] ; then |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 90 | (export ${emma_opt}; mmma ${goma_opt} -j40 "$build_dir") |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 91 | else |
Brad Ebinger | 7bba111 | 2017-06-08 13:57:28 -0700 | [diff] [blame] | 92 | (export ${emma_opt}; mmm ${goma_opt} "$build_dir") |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 93 | 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 Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 99 | # Strip off any possible aosp_ prefix from the target product |
| 100 | local canonical_product=$(sed 's/^aosp_//' <<< "$TARGET_PRODUCT") |
| 101 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 102 | adb install -r -t "out/target/product/$canonical_product/$apk_loc" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 103 | if [ $? -ne 0 ] ; then |
| 104 | cd "$olddir" |
| 105 | return $? |
| 106 | fi |
| 107 | cd "$olddir" |
| 108 | fi |
| 109 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 110 | local e_options="" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 111 | if [ -n "$class" ] ; then |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 112 | 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 117 | fi |
| 118 | if [ $debug = true ] ; then |
| 119 | e_options="${e_options} -e debug 'true'" |
| 120 | fi |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 121 | if [ $coverage = true ] && [ $project =~ "telecom" ] ; then |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 122 | e_options="${e_options} -e coverage 'true'" |
| 123 | fi |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 124 | adb shell am instrument ${e_options} -w "$package_prefix/$instrumentation" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 125 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 126 | # Code coverage only enabled for Telecom. |
| 127 | if [ $coverage = true ] && [ $project =~ "telecom" ] ; then |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 128 | adb root |
| 129 | adb wait-for-device |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 130 | adb pull /data/user/0/com.android.server.telecom.tests/files/coverage.ec /tmp/ |
Hall Liu | ccd7841 | 2016-02-17 18:07:21 -0800 | [diff] [blame] | 131 | 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 139 | fi |
| 140 | } |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 141 | |
| 142 | lite_test_telecom() { |
| 143 | _lite_test_general -p telecom $@ |
| 144 | } |
| 145 | |
| 146 | lite_test_telephony() { |
| 147 | _lite_test_general -p telephony $@ |
| 148 | } |