Skip to content

Commit f566f8c

Browse files
test: Android Emulator wait boot timeout
1 parent bd2789d commit f566f8c

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

build/ci/.azure-devops-android-tests.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
# TARGETPLATFORM_NAME: net6
180180
# ALLOW_RERUN: false
181181
# UITEST_TEST_TIMEOUT: '2600000'
182-
# FAILBUILD_ON_FAILURE: false # false until https://github.com/unoplatform/uno/issues/5873 and https://github.com/dotnet/runtime/pull/55681 are released
182+
# FAILBUILD_ON_FAILURE: false # false until https://github.com/unoplatform/uno/issues/5873 and https://github.com/dotnet/runtime/pull/55681 are released
183183

184184
# Android 10 testing is disabled because of https://github.com/microsoft/appcenter/issues/1451
185185
# Android_10.0:
@@ -218,6 +218,13 @@ jobs:
218218
xCodeRoot: ${{ parameters.xCodeRoot }}
219219
XamarinSDKVersion: ${{ parameters.XamarinSDKVersion }}
220220

221+
- task: PowerShell@2
222+
displayName: 'Install coreutils'
223+
inputs:
224+
targetType: inline
225+
script: |
226+
brew install coreutils
227+
221228
- task: PowerShell@2
222229
displayName: 'Fill Rerun Variable'
223230
inputs:
@@ -248,7 +255,7 @@ jobs:
248255
UITEST_TEST_TIMEOUT: "$(UITEST_TEST_TIMEOUT)"
249256
SAMPLEAPP_ARTIFACT_NAME: "$(SAMPLEAPP_ARTIFACT_NAME)"
250257
TARGETPLATFORM_NAME: "$(TARGETPLATFORM_NAME)"
251-
258+
252259
- task: PublishTestResults@2
253260
condition: always()
254261
inputs:
@@ -275,7 +282,7 @@ jobs:
275282
UITEST_TEST_TIMEOUT: "$(UITEST_TEST_TIMEOUT)"
276283
SAMPLEAPP_ARTIFACT_NAME: "$(SAMPLEAPP_ARTIFACT_NAME)"
277284
TARGETPLATFORM_NAME: "$(TARGETPLATFORM_NAME)"
278-
285+
279286
- task: PublishTestResults@2
280287
condition: eq(variables.ALLOW_RERUN, 'true')
281288
inputs:

build/test-scripts/android-uitest-run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ then
103103
nohup $ANDROID_HOME/emulator/emulator -avd "$AVD_NAME" -skin 1280x800 -memory 2048 -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim > /dev/null 2>&1 &
104104

105105
# Wait for the emulator to finish booting
106-
source $BUILD_SOURCESDIRECTORY/build/test-scripts/android-uitest-wait-systemui.sh
106+
source $BUILD_SOURCESDIRECTORY/build/test-scripts/android-uitest-wait-systemui.sh 500
107107

108108
else
109109
# Restart the emulator to avoid running first-time tasks
110110
$ANDROID_HOME/platform-tools/adb reboot
111111

112112
# Wait for the emulator to finish booting
113-
source $BUILD_SOURCESDIRECTORY/build/test-scripts/android-uitest-wait-systemui.sh
113+
source $BUILD_SOURCESDIRECTORY/build/test-scripts/android-uitest-wait-systemui.sh 500
114114
fi
115115

116116
# list active devices

build/test-scripts/android-uitest-wait-systemui.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#!/usr/bin/env bash
2-
2+
BOOT_TIMEOUT=$1
33
retry() {
4-
local -r -i max_attempts="$1"; shift
4+
local -r -i max_attempts="$1";shift 1
55
local -i attempt_num=1
6-
until "$@"
6+
local -a COMMANDS=( timeout $BOOT_TIMEOUT )
7+
8+
while (( "$#" )); do
9+
local arg="$1";
10+
if [[ "$arg" = *" "* ]]; then
11+
COMMANDS+=( $( printf "\''%s'\'" "$arg" ) )
12+
else
13+
COMMANDS+=( "$arg" )
14+
fi
15+
shift
16+
done
17+
18+
until "${COMMANDS[@]}"
719
do
820
if ((attempt_num==max_attempts))
921
then
@@ -17,13 +29,13 @@ retry() {
1729
}
1830

1931
echo ""
20-
echo "[Waiting for device to boot]"
32+
echo "[Waiting for device to boot] timeout $BOOT_TIMEOUT sec"
2133

2234
if [ $ANDROID_SIMULATOR_APILEVEL -gt 25 ];
23-
then
24-
retry 3 $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; [[ "$SECONDS" -lt 300 ]]; do sleep 1; done; input keyevent 82'
35+
then
36+
retry 3 "$ANDROID_HOME/platform-tools/adb" wait-for-device shell 'echo "emulator is attached, wait boot completated"; while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]] && [[ "$SECONDS" -lt 300 ]]; do sleep 1; done; input keyevent 82; echo "boot is completated."'
2537
else
26-
retry 3 $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; [[ "$SECONDS" -lt 300 ]]; do sleep 1; done; input keyevent 82'
38+
retry 3 "$ANDROID_HOME/platform-tools/adb" wait-for-device shell 'echo "emulator is attached, wait boot completated"; while [[ -z $(getprop sys.boot_completed) ]] && [[ "$SECONDS" -lt 300 ]]; do sleep 1; done; input keyevent 82; echo "boot is completated."'
2739
fi
2840

2941
# Wait for com.android.systemui to become available,
@@ -39,7 +51,7 @@ START_TIME=$SECONDS
3951
while [[ -z ${LAUNCHER_READY} ]]; do
4052

4153
if [ $ANDROID_SIMULATOR_APILEVEL -ge 29 ];
42-
then
54+
then
4355
UI_FOCUS=`$ANDROID_HOME/platform-tools/adb shell dumpsys window 2>/dev/null | grep -E 'mCurrentFocus|mFocusedApp'`
4456
else
4557
UI_FOCUS=`$ANDROID_HOME/platform-tools/adb shell dumpsys window windows 2>/dev/null | grep -i mCurrentFocus`
@@ -72,9 +84,9 @@ while [[ -z ${LAUNCHER_READY} ]]; do
7284
echo "Waiting for launcher..."
7385
sleep 3
7486

75-
# For some reason the messaging app can be brought up in front
76-
# (DEBUG) Current focus: mCurrentFocus=Window{1170051 u0 com.google.android.apps.messaging/com.google.android.apps.messaging.ui.ConversationListActivity}
77-
# Try bringing back the home screen to check on the launcher.
87+
# For some reason the messaging app can be brought up in front
88+
# (DEBUG) Current focus: mCurrentFocus=Window{1170051 u0 com.google.android.apps.messaging/com.google.android.apps.messaging.ui.ConversationListActivity}
89+
# Try bringing back the home screen to check on the launcher.
7890
$ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_HOME
7991
;;
8092
esac

0 commit comments

Comments
 (0)