1 #!/bin/bash 2 3 adb="adb" 4 if [[ $# -gt 0 ]]; then 5 adb="adb $*" # for setting -e, -d or -s <serial> 6 fi 7 8 function atexit() 9 { 10 local retval=$? 11 12 if [[ $retval -eq 0 ]]; then 13 rm $log 14 else 15 echo "There were errors, please check log at $log" 16 fi 17 } 18 19 log=$(mktemp) 20 trap "atexit" EXIT 21 failures=0 22 23 function compile_module() 24 { 25 local android_mk="$1" 26 27 echo "Compiling .${android_mk:${#PWD}}" 28 ONE_SHOT_MAKEFILE="$android_mk" make -C "../../../../../" files | tee -a $log 29 if [[ ${PIPESTATUS[0]} -ne 0 ]]; then 30 exit 1 31 fi 32 } 33 34 function wait_for_boot_completed() 35 { 36 echo "Rebooting device" 37 $adb wait-for-device logcat -c 38 $adb wait-for-device logcat | grep -m 1 -e 'PowerManagerService.*bootCompleted' >/dev/null 39 } 40 41 function disable_overlay() 42 { 43 echo "Disabling overlay" 44 $adb shell rm /vendor/overlay/framework/framework-res.apk 45 $adb shell rm /data/resource-cache/vendor@overlay@framework@framework-res.apk@idmap 46 } 47 48 function enable_overlay() 49 { 50 echo "Enabling overlay" 51 $adb shell ln -s /data/app/com.android.overlaytest.overlay.apk /vendor/overlay/framework/framework-res.apk 52 } 53 54 function instrument() 55 { 56 local class="$1" 57 58 echo "Instrumenting $class" 59 $adb shell am instrument -w -e class $class com.android.overlaytest/android.test.InstrumentationTestRunner | tee -a $log 60 } 61 62 function sync() 63 { 64 echo "Syncing to device" 65 $adb remount | tee -a $log 66 $adb sync data | tee -a $log 67 } 68 69 # build and sync 70 compile_module "$PWD/OverlayTest/Android.mk" 71 compile_module "$PWD/OverlayTestOverlay/Android.mk" 72 sync 73 74 # instrument test (without overlay) 75 $adb shell stop 76 disable_overlay 77 $adb shell start 78 wait_for_boot_completed 79 instrument "com.android.overlaytest.WithoutOverlayTest" 80 81 # instrument test (with overlay) 82 $adb shell stop 83 enable_overlay 84 $adb shell start 85 wait_for_boot_completed 86 instrument "com.android.overlaytest.WithOverlayTest" 87 88 # cleanup 89 exit $(grep -c -e '^FAILURES' $log) 90