Skip to content

Instantly share code, notes, and snippets.

@blazsolar
Last active August 24, 2018 08:23
Show Gist options
  • Save blazsolar/5ab8f89bb4a8ace692395446789943fd to your computer and use it in GitHub Desktop.
Save blazsolar/5ab8f89bb4a8ace692395446789943fd to your computer and use it in GitHub Desktop.
Handling CI emulators
#!/usr/bin/expect -f
set device [lindex $argv 0]
set token [lindex $argv 1]
spawn telnet localhost $device
expect "OK"
send "auth $token\n"
expect "OK"
send "kill\n"
interact
#!/bin/bash
dir="$(cd "$(dirname "$0")" && pwd)"
token=$(head -n 1 ~/.emulator_console_auth_token)
for device in `adb devices -l | tail -n +2 | cut -d" " -f 1 | cut -d"-" -f 2`; do
echo "Killing $device"
expect $dir/kill-emulators.expect $device $token
done
#!/bin/bash
echo "Start emulator"
emulator -avd $1 -no-window -no-audio -wipe-data -no-boot-anim -qemu -m 1024 -smp 4 &
emaulatorPid=$!
echo "Wait for device"
until timeout 2s adb wait-for-device
do
ps --pid $emaulatorPid &> /dev/null
if [ $? -eq 0 ]; then
echo "..."
else
exit 1
fi
done
echo "Wait for boot"
# boot=$(adb shell getprop sys.boot_completed | tr -d '\r')
boot=$(adb shell getprop dev.bootcomplete | tr -d '\r')
while [ "$boot" != "1" ]; do
sleep 2
boot=$(adb shell getprop sys.boot_completed | tr -d '\r')
done
echo "Unlock device"
adb shell input keyevent 82
echo "Done"
@blazsolar
Copy link
Author

start-emulator.sh will start emulator passed in as first parameter. It will wait for emulator to boot up and unlock it. If emulator process is killed during that process script will exit with code 1.

kill-emulators.sh will kill all running emulators by telnet-int to them, authenticating and then killing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment