Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 1 | lite_test_telecom() { |
| 2 | usage=" |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 3 | Usage: lite_test_telecom [-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= |
| 18 | local install=false |
| 19 | local installwdep=false |
| 20 | local debug=false |
| 21 | local coverage=false |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 22 | |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 23 | while getopts "c:hadie" opt; do |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 24 | case "$opt" in |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 25 | h) |
| 26 | echo "$usage" |
| 27 | return 0;; |
Brad Ebinger | 98a44dc | 2015-12-15 10:57:45 -0800 | [diff] [blame] | 28 | \?) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 29 | echo "$usage" |
| 30 | return 0;; |
| 31 | c) |
| 32 | class=$OPTARG;; |
| 33 | d) |
| 34 | debug=true;; |
| 35 | i) |
| 36 | install=true;; |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 37 | a) |
| 38 | install=true |
| 39 | installwdep=true;; |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 40 | e) |
| 41 | coverage=true;; |
| 42 | esac |
| 43 | done |
| 44 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 45 | local T=$(gettop) |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 46 | |
| 47 | if [ $install = true ] ; then |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 48 | local olddir=$(pwd) |
| 49 | local emma_opt= |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 50 | cd $T |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 51 | # Build and exit script early if build fails |
| 52 | |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 53 | if [ $coverage = true ] ; then |
| 54 | emma_opt="EMMA_INSTRUMENT_STATIC=true" |
| 55 | else |
| 56 | emma_opt="EMMA_INSTRUMENT_STATIC=false" |
| 57 | fi |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 58 | |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 59 | if [ $installwdep = true ] ; then |
Hall Liu | ccd7841 | 2016-02-17 18:07:21 -0800 | [diff] [blame] | 60 | mmma -j40 "packages/services/Telecomm/tests" ${emma_opt} |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 61 | else |
Hall Liu | ccd7841 | 2016-02-17 18:07:21 -0800 | [diff] [blame] | 62 | mmm "packages/services/Telecomm/tests" ${emma_opt} |
Brad Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 63 | 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 Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 69 | # 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 73 | if [ $? -ne 0 ] ; then |
| 74 | cd "$olddir" |
| 75 | return $? |
| 76 | fi |
| 77 | cd "$olddir" |
| 78 | fi |
| 79 | |
Hall Liu | 0c4f435 | 2016-10-13 18:33:49 -0700 | [diff] [blame] | 80 | local e_options="" |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 81 | 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 Ebinger | 1c59a3b | 2015-12-15 14:28:01 -0800 | [diff] [blame] | 93 | adb root |
| 94 | adb wait-for-device |
Hall Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 95 | 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] | 96 | 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 Liu | 2ccf204 | 2015-12-14 16:18:10 -0800 | [diff] [blame] | 104 | fi |
| 105 | } |