CTS: Fix emulator not killed after test.
Bug:
Change-Id: Ie6beaa8db22b9971b75423cbbdf88204c89b9bcf
diff --git a/scripts/aosp_helper.sh b/scripts/aosp_helper.sh
index d375953..cfebfca 100755
--- a/scripts/aosp_helper.sh
+++ b/scripts/aosp_helper.sh
@@ -17,7 +17,12 @@
if [[ "$TASK" == "make" ]]; then
make "$@"
elif [[ "$TASK" == "emulator" ]]; then
- emulator "$@"
+ # Launch emulator in bg and kill it in a trap
+ # otherwise it won't get killed when this parent process is killed
+ emulator "$@" &
+ emulator_pid=$!
+ trap "kill $emulator_pid; exit 1" 2 15
+ while true; do sleep 5; done
elif [[ "$TASK" == "run-cts" ]]; then
adb wait-for-device
adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'