Skip to content

Commit a279152

Browse files
committed
Improve emulator startup diagnostics and failure handling
1 parent 4e9bc48 commit a279152

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

scripts/run-android-instrumentation-tests.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,19 @@ if ! "$AVDMANAGER" list avd | grep -q "Name: $AVD_NAME"; then
135135
fi
136136

137137
log "Starting AVD $AVD_NAME in headless mode"
138+
EMU_LOG="$TMPDIR/$AVD_NAME.log"
139+
: >"$EMU_LOG"
138140
"$EMU_BIN" -avd "$AVD_NAME" -no-boot-anim -no-audio -no-snapshot -no-window -gpu swiftshader_indirect -netfast \
139-
>/tmp/$AVD_NAME.log 2>&1 &
141+
>"$EMU_LOG" 2>&1 &
140142
EMU_PID=$!
143+
dump_emulator_log() {
144+
if [ -f "$EMU_LOG" ]; then
145+
log "Emulator log tail ($EMU_LOG):"
146+
tail -n 200 "$EMU_LOG" | while IFS= read -r line; do
147+
echo "[run-android-instrumentation-tests] | $line"
148+
done
149+
fi
150+
}
141151
cleanup() {
142152
log "Cleaning up emulator"
143153
if [ -n "${EMULATOR_SERIAL:-}" ]; then
@@ -152,8 +162,13 @@ trap cleanup EXIT
152162
log "Waiting for emulator to register with adb"
153163
"$ADB_BIN" start-server >/dev/null 2>&1 || true
154164

155-
ADB_DEVICE_TIMEOUT=120
165+
ADB_DEVICE_TIMEOUT=180
156166
for _ in $(seq 1 "$ADB_DEVICE_TIMEOUT"); do
167+
if ! kill -0 "$EMU_PID" >/dev/null 2>&1; then
168+
log "Emulator process exited before appearing in adb" >&2
169+
dump_emulator_log
170+
exit 1
171+
fi
157172
EMULATOR_SERIAL=$("$ADB_BIN" devices | awk 'NR>1 && /^emulator-/{print $1; exit}') || true
158173
if [ -n "${EMULATOR_SERIAL:-}" ]; then
159174
break
@@ -163,6 +178,7 @@ done
163178

164179
if [ -z "${EMULATOR_SERIAL:-}" ]; then
165180
log "Emulator did not appear in adb devices within ${ADB_DEVICE_TIMEOUT}s" >&2
181+
dump_emulator_log
166182
exit 1
167183
fi
168184

@@ -173,11 +189,17 @@ for _ in $(seq 1 120); do
173189
if [ "$BOOT_COMPLETED" = "1" ]; then
174190
break
175191
fi
192+
if ! kill -0 "$EMU_PID" >/dev/null 2>&1; then
193+
log "Emulator process exited before boot completed" >&2
194+
dump_emulator_log
195+
exit 1
196+
fi
176197
sleep 5
177198
done
178199

179200
if [ "$BOOT_COMPLETED" != "1" ]; then
180201
log "Emulator did not boot in the allotted time" >&2
202+
dump_emulator_log
181203
exit 1
182204
fi
183205

0 commit comments

Comments
 (0)