Skip to content

Commit 10a0c91

Browse files
Improve Android Emulator Robustness (#19310)
Disabling animations sometimes cant happen right after a slow boot. Moving disabling animations to the script where we can retry. Did some general cleaning of other possible sources of flakiness as well. Authored with codex
1 parent 15da1d1 commit 10a0c91

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

.github/workflows/_android.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ jobs:
109109
ram-size: 16384M
110110
heap-size: 12288M
111111
force-avd-creation: false
112-
disable-animations: true
113-
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
112+
# The action's built-in animation disabling runs immediately after
113+
# boot and is not retried. Software-emulated boots can briefly drop
114+
# adb there, so scripts/run_android_emulator.sh handles it instead.
115+
disable-animations: false
116+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
114117
emulator-boot-timeout: 900

scripts/run_android_emulator.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,43 @@ set -ex
1010
# This script is originally adopted from https://github.com/pytorch/pytorch/blob/main/android/run_tests.sh
1111
ADB_PATH=$ANDROID_HOME/platform-tools/adb
1212

13+
adb_shell_with_retries() {
14+
local attempts="$1"
15+
shift
16+
17+
for ((i = 1; i <= attempts; i++)); do
18+
if "$ADB_PATH" shell "$@"; then
19+
return 0
20+
fi
21+
sleep 5
22+
"$ADB_PATH" wait-for-device
23+
done
24+
25+
return 1
26+
}
27+
1328
echo "Waiting for emulator boot to complete"
1429
# shellcheck disable=SC2016
1530
$ADB_PATH wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 5; done;'
31+
$ADB_PATH wait-for-device
32+
33+
echo "Unlock emulator and disable animations"
34+
adb_shell_with_retries 5 input keyevent 82 || true
35+
adb_shell_with_retries 5 settings put global window_animation_scale 0.0 || true
36+
adb_shell_with_retries 5 settings put global transition_animation_scale 0.0 || true
37+
adb_shell_with_retries 5 settings put global animator_duration_scale 0.0 || true
1638

1739
# The device will be created by ReactiveCircus/android-emulator-runner GHA
1840
echo "List all running emulators"
1941
$ADB_PATH devices
2042

21-
adb uninstall org.pytorch.executorch.test || true
22-
adb install -t android-test-debug-androidTest.apk
43+
"$ADB_PATH" uninstall org.pytorch.executorch.test || true
44+
"$ADB_PATH" install -t android-test-debug-androidTest.apk
2345

24-
adb logcat -c
25-
adb shell am instrument -w -r \
46+
"$ADB_PATH" logcat -c
47+
"$ADB_PATH" shell am instrument -w -r \
2648
org.pytorch.executorch.test/androidx.test.runner.AndroidJUnitRunner >result.txt 2>&1
27-
adb logcat -d > logcat.txt
49+
"$ADB_PATH" logcat -d > logcat.txt
2850
cat logcat.txt
2951
grep -q FAILURES result.txt && cat result.txt
3052
grep -q FAILURES result.txt && exit -1

0 commit comments

Comments
 (0)