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 | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 13 | -h This help message. |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 14 | " |
| 15 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 16 | local OPTIND=1 |
| 17 | local class= |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 18 | local project= |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 19 | local install=false |
| 20 | local installwdep=false |
| 21 | local debug=false |
| 22 | local coverage=false |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 23 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 24 | while getopts "c:p:hadie" opt; do |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 25 | case "$opt" in |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 26 | h) |
| 27 | echo "$usage" |
| 28 | return 0;; |
Brad Ebinger | 98a44dc | 2015-12-15 10:57:45 -0800 | [diff] [blame] | 29 | \?) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 30 | echo "$usage" |
| 31 | return 0;; |
| 32 | c) |
| 33 | class=$OPTARG;; |
| 34 | d) |
| 35 | debug=true;; |
| 36 | i) |
| 37 | install=true;; |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 38 | a) |
| 39 | install=true |
| 40 | installwdep=true;; |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 41 | e) |
| 42 | coverage=true;; |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 43 | p) |
| 44 | project=$OPTARG;; |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 45 | esac |
| 46 | done |
| 47 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 48 | 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 Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 65 | local T=$(gettop) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 66 | |
| 67 | if [ $install = true ] ; then |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 68 | local olddir=$(pwd) |
| 69 | local emma_opt= |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 70 | cd $T |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 71 | # Build and exit script early if build fails |
| 72 | |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 73 | if [ $coverage = true ] ; then |
Hall Liu | 5b8551e | 2017-03-10 17:05:23 -0800 | [diff] [blame] | 74 | 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] | 75 | else |
Hall Liu | 5b8551e | 2017-03-10 17:05:23 -0800 | [diff] [blame] | 76 | emma_opt="EMMA_INSTRUMENT=false" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 77 | fi |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 78 | |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 79 | if [ $installwdep = true ] ; then |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 80 | (export ${emma_opt}; mmma -j40 "$build_dir") |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 81 | else |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 82 | (export ${emma_opt}; mmm "$build_dir") |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 83 | 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 Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 89 | # Strip off any possible aosp_ prefix from the target product |
| 90 | local canonical_product=$(sed 's/^aosp_//' <<< "$TARGET_PRODUCT") |
| 91 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 92 | adb install -r -t "out/target/product/$canonical_product/$apk_loc" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 93 | if [ $? -ne 0 ] ; then |
| 94 | cd "$olddir" |
| 95 | return $? |
| 96 | fi |
| 97 | cd "$olddir" |
| 98 | fi |
| 99 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 100 | local e_options="" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 101 | if [ -n "$class" ] ; then |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 102 | 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 107 | fi |
| 108 | if [ $debug = true ] ; then |
| 109 | e_options="${e_options} -e debug 'true'" |
| 110 | fi |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 111 | if [ $coverage = true ] && [ $project =~ "telecom" ] ; then |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 112 | e_options="${e_options} -e coverage 'true'" |
| 113 | fi |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 114 | adb shell am instrument ${e_options} -w "$package_prefix/$instrumentation" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 115 | |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 116 | # Code coverage only enabled for Telecom. |
| 117 | if [ $coverage = true ] && [ $project =~ "telecom" ] ; then |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 118 | adb root |
| 119 | adb wait-for-device |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 120 | 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] | 121 | 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 129 | fi |
| 130 | } |
Hall Liu | 90fc0b4 | 2017-03-30 11:29:44 -0700 | [diff] [blame] | 131 | |
| 132 | lite_test_telecom() { |
| 133 | _lite_test_general -p telecom $@ |
| 134 | } |
| 135 | |
| 136 | lite_test_telephony() { |
| 137 | _lite_test_general -p telephony $@ |
| 138 | } |