1#!/bin/bash 2 3adb="adb" 4if [[ $# -gt 0 ]]; then 5 adb="adb $*" # for setting -e, -d or -s <serial> 6fi 7 8function 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 19log=$(mktemp) 20trap "atexit" EXIT 21failures=0 22 23function 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 34function 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 41function 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 48function 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 54function 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 62function 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 70compile_module "$PWD/OverlayTest/Android.mk" 71compile_module "$PWD/OverlayTestOverlay/Android.mk" 72sync 73 74# instrument test (without overlay) 75$adb shell stop 76disable_overlay 77$adb shell start 78wait_for_boot_completed 79instrument "com.android.overlaytest.WithoutOverlayTest" 80 81# instrument test (with overlay) 82$adb shell stop 83enable_overlay 84$adb shell start 85wait_for_boot_completed 86instrument "com.android.overlaytest.WithOverlayTest" 87 88# cleanup 89exit $(grep -c -e '^FAILURES' $log) 90