Skip to content

Commit 54a08b1

Browse files
authored
Merge pull request #1245 from unoplatform/dev/jonpryor/jonp-add-Android+Skia+NativeAOT-instrumentation-test
2 parents b8544a4 + 4244648 commit 54a08b1

7 files changed

Lines changed: 352 additions & 117 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Android.App;
2+
using Android.OS;
3+
using Android.Runtime;
4+
5+
namespace Uno.Gallery
6+
{
7+
[Instrumentation(Name = "my.MainInstrumentation")]
8+
public class MainInstrumentation : Android.App.Instrumentation
9+
{
10+
public MainInstrumentation(IntPtr handle, JniHandleOwnership ownership)
11+
: base(handle, ownership)
12+
{
13+
}
14+
15+
public override void OnCreate(Bundle? savedInstanceState)
16+
{
17+
base.OnCreate(savedInstanceState);
18+
Finish(Result.Ok, null);
19+
}
20+
}
21+
}

‎azure-pipelines.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ stages:
251251
jobs:
252252
- template: build/stage-uitests-android.yml
253253

254+
- stage: Android_Skia_NativeAOT_Instrumentation_Tests
255+
displayName: 'Android+Skia+NativeAOT Instrumentation Tests'
256+
dependsOn: []
257+
jobs:
258+
- template: build/stage-tests-android.yml
259+
254260
- ${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/canaries/dev') }}:
255261
- template: build/templates/canary-publish/stage-publish-wasm-canary.yml
256262
- template: build/templates/canary-publish/stage-publish-ios-canary.yml
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Prepare and launch the Android Emulator
2+
#
3+
# Usage:
4+
#
5+
# source build/scripts/android-sdk-emu.inc.sh
6+
#
7+
# Input Environment Variables:
8+
#
9+
# BUILD_ARTIFACTSTAGINGDIRECTORY: Required
10+
# BUILD_SOURCESDIRECTORY: Required
11+
# ANDROID_SIMULATOR_APILEVEL: Optional; The Android API level to target for the emulator. Default is API-28.
12+
# ANDROID_SIMULATOR_ABI: Optional; The Android ABI to target for the emulator. Default is x86_64.
13+
# CMDLINETOOLS: Optional; Android SDK cmdlinetools package name to install.
14+
# Default is commandlinetools-mac-8512546_latest.zip on macOS and commandlinetools-linux-8512546_latest.zip on Linux.
15+
#
16+
# Output Environment Variables:
17+
#
18+
# ANDROID_HOME, ANDROID_SDK_ROOT: Where an Android SDK is provisioned; subdir of $BUILD_SOURCESDIRECTORY
19+
# ANDROID_SERIAL: If an emulator is started, the serial identifier to use for adb commands targeting that emulator
20+
# Note: used *automatically* by `adb`; see `adb --help` for details.
21+
# CMDLINETOOLS: Android SDK cmdlinetools package name that was installed.
22+
# LATEST_CMDLINE_TOOLS_PATH: Path to Android SDK cmdlinetools installation
23+
# UNO_UITEST_PLATFORM: The platform being tested (Android)
24+
# UNO_UITEST_SCREENSHOT_PATH: Where screenshots/etc. should be copied to; subdir of $BUILD_ARTIFACTSTAGINGDIRECTORY
25+
26+
# Override Android SDK tooling
27+
28+
# also used for log files
29+
export ANDROID_HOME="$BUILD_SOURCESDIRECTORY/build/android-sdk"
30+
export ANDROID_SDK_ROOT="$BUILD_SOURCESDIRECTORY/build/android-sdk"
31+
export LATEST_CMDLINE_TOOLS_PATH="$ANDROID_SDK_ROOT/cmdline-tools/latest"
32+
export UNO_EMULATOR_INSTALLED="$BUILD_SOURCESDIRECTORY/build/.emulator_started"
33+
export UNO_UITEST_PLATFORM=Android
34+
export UNO_UITEST_SCREENSHOT_PATH="$BUILD_ARTIFACTSTAGINGDIRECTORY/screenshots/android"
35+
36+
if [ -z "${CMDLINETOOLS:-}" ]; then
37+
case `uname` in
38+
Darwin)
39+
export CMDLINETOOLS="commandlinetools-mac-8512546_latest.zip"
40+
;;
41+
Linux)
42+
export CMDLINETOOLS="commandlinetools-linux-8512546_latest.zip"
43+
;;
44+
*)
45+
echo "Unsupported OS: `uname`. Please set the CMDLINETOOLS environment variable to the appropriate cmdline-tools Android SDK package basename for your OS."
46+
exit 1
47+
;;
48+
esac
49+
fi
50+
51+
mkdir -p "$ANDROID_HOME"
52+
53+
if [ -d "$LATEST_CMDLINE_TOOLS_PATH" ]; then
54+
rm -rf "$LATEST_CMDLINE_TOOLS_PATH"
55+
fi
56+
57+
wget "https://dl.google.com/android/repository/$CMDLINETOOLS"
58+
unzip "$CMDLINETOOLS" -d "$ANDROID_HOME/cmdline-tools"
59+
rm "$CMDLINETOOLS"
60+
mv "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools" "$LATEST_CMDLINE_TOOLS_PATH"
61+
62+
if [[ -f "$ANDROID_HOME/platform-tools/platform-tools/adb" ]]; then
63+
# It appears that the platform-tools 29.0.6 are extracting into an incorrect path
64+
mv "$ANDROID_HOME/platform-tools/platform-tools"/* "$ANDROID_HOME/platform-tools"
65+
fi
66+
67+
export ANDROID_SIMULATOR_APILEVEL="${ANDROID_SIMULATOR_APILEVEL:-28}"
68+
export ANDROID_SIMULATOR_ABI="${ANDROID_SIMULATOR_ABI:-x86_64}"
69+
70+
AVD_NAME=xamarin_android_emulator
71+
AVD_CONFIG_FILE="$HOME/.android/avd/$AVD_NAME.avd/config.ini"
72+
SDK_MGR_TOOLS_FLAG=.sdk_toolkit_installed
73+
EMU_UPDATE_FILE="$HOME/.android/emu-update-last-check.ini"
74+
75+
mkdir -p "$UNO_UITEST_SCREENSHOT_PATH"
76+
77+
install_android_sdk() {
78+
SIMULATOR_APILEVEL="$1"
79+
80+
if [[ ! -f "$SDK_MGR_TOOLS_FLAG" ]]; then
81+
touch "$SDK_MGR_TOOLS_FLAG"
82+
83+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'tools'| tr '\r' '\n' | uniq
84+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'platform-tools' | tr '\r' '\n' | uniq
85+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'build-tools;36.0.0' | tr '\r' '\n' | uniq
86+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'extras;android;m2repository' | tr '\r' '\n' | uniq
87+
fi
88+
89+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install "platforms;android-$SIMULATOR_APILEVEL" | tr '\r' '\n' | uniq
90+
echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install "system-images;android-$SIMULATOR_APILEVEL;google_apis_playstore;$ANDROID_SIMULATOR_ABI" | tr '\r' '\n' | uniq
91+
}
92+
93+
if [[ ! -f "$EMU_UPDATE_FILE" ]]; then
94+
touch "$EMU_UPDATE_FILE"
95+
fi
96+
97+
if [[ -f "$AVD_CONFIG_FILE" ]]; then
98+
99+
echo "warning: not creating new AVD, as config file already exists at $AVD_CONFIG_FILE."
100+
echo "warning: If the emulator fails to start or work correctly, try deleting the AVD and letting this script create it again."
101+
102+
else
103+
# Install AVD files
104+
install_android_sdk "$ANDROID_SIMULATOR_APILEVEL"
105+
install_android_sdk 36
106+
107+
if [[ -f "$ANDROID_HOME/platform-tools/platform-tools/adb" ]]; then
108+
# It appears that the platform-tools 29.0.6 are extracting into an incorrect path
109+
mv "$ANDROID_HOME/platform-tools/platform-tools"/* "$ANDROID_HOME/platform-tools"
110+
fi
111+
112+
AVD_IMAGE_NAME="system-images;android-$ANDROID_SIMULATOR_APILEVEL;google_apis_playstore;$ANDROID_SIMULATOR_ABI"
113+
114+
# Create emulator
115+
echo "no" | "$LATEST_CMDLINE_TOOLS_PATH/bin/avdmanager" create avd -n "$AVD_NAME" \
116+
--abi "$ANDROID_SIMULATOR_ABI" -k "$AVD_IMAGE_NAME" --sdcard 128M --force
117+
118+
# based on https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#hardware
119+
# >> Agents that run macOS images are provisioned on Mac pros with a 3 core CPU, 14 GB of RAM, and 14 GB of SSD disk space.
120+
echo "hw.cpu.ncore=3" >> "$AVD_CONFIG_FILE"
121+
122+
# Bump the heap size as the tests are stressing the application
123+
echo "vm.heapSize=256M" >> "$AVD_CONFIG_FILE"
124+
125+
"$ANDROID_HOME/emulator/emulator" -list-avds
126+
127+
echo "Checking for hardware acceleration"
128+
"$ANDROID_HOME/emulator/emulator" -accel-check
129+
fi
130+
131+
# kickstart ADB
132+
if "$ANDROID_HOME/platform-tools/adb" devices | grep -v 'List of devices attached' | grep device >/dev/null 2>&1 ; then
133+
# we have an existing device/emulator; restart it to avoid running first-time tasks
134+
"$ANDROID_HOME/platform-tools/adb" reboot
135+
136+
# Wait for the emulator to finish booting
137+
source "$BUILD_SOURCESDIRECTORY/build/scripts/android-uitest-wait-systemui.sh" 500
138+
else
139+
echo "Starting emulator"
140+
141+
# Start emulator in background
142+
nohup "$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -skin 1280x800 -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim > "$UNO_UITEST_SCREENSHOT_PATH/android-emulator-log.txt" 2>&1 &
143+
144+
# Wait for the emulator to finish booting
145+
source "$BUILD_SOURCESDIRECTORY/build/scripts/android-uitest-wait-systemui.sh" 500
146+
147+
export ANDROID_SERIAL=$("$ANDROID_HOME/platform-tools/adb" devices | grep -v 'List of devices attached' | grep emulator- | awk '{print $1}' | tail -n 1)
148+
fi
149+
150+
# Wait for the emulator to finish booting
151+
source "$BUILD_SOURCESDIRECTORY/build/scripts/android-uitest-wait-systemui.sh" 500
152+
153+
"$ANDROID_HOME/platform-tools/adb" devices
154+
echo "Emulator started"
155+
156+
echo "Device System Properties:"
157+
"$ANDROID_HOME/platform-tools/adb" shell getprop

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
IFS=$'\n\t'
5+
6+
# `adb install` requires signed APK files, so only look for them
7+
APK_FROM_ARTIFACT="$(ls "$UNO_TEST_ANDROIDAPK_BASEPATH"/*-Signed.apk 2>/dev/null | head -n 1 || true)"
8+
APK_FROM_LOCAL="$(ls "$BUILD_SOURCESDIRECTORY/Uno.Gallery/bin/Release/net10.0-android/android-x64/publish"/*-Signed.apk 2>/dev/null | head -n 1 || true)"
9+
10+
if [ -f "$APK_FROM_ARTIFACT" ]; then
11+
export UNO_TEST_ANDROIDAPK_PATH="$APK_FROM_ARTIFACT"
12+
elif [ -f "$APK_FROM_LOCAL" ]; then
13+
export UNO_TEST_ANDROIDAPK_PATH="$APK_FROM_LOCAL"
14+
else
15+
echo "ERROR: APK not found (neither artifact nor local publish)."
16+
exit 1
17+
fi
18+
19+
echo "Using APK: $UNO_TEST_ANDROIDAPK_PATH"
20+
21+
# Need API-34 not API-28 to work around: https://github.com/unoplatform/uno/pull/22571
22+
export ANDROID_SIMULATOR_APILEVEL=34
23+
24+
source "$BUILD_SOURCESDIRECTORY/build/scripts/android-sdk-emu.inc.sh"
25+
26+
"$ANDROID_HOME/platform-tools/adb" install -r "$UNO_TEST_ANDROIDAPK_PATH"
27+
28+
package_name=$("$LATEST_CMDLINE_TOOLS_PATH/bin/apkanalyzer" manifest application-id "$UNO_TEST_ANDROIDAPK_PATH")
29+
30+
INSTRUMENTATION_OUTPUT=$("$ANDROID_HOME/platform-tools/adb" shell am instrument -w $package_name/my.MainInstrumentation || true)
31+
echo "Instrumentation output:"
32+
echo "$INSTRUMENTATION_OUTPUT"
33+
34+
## Dump the emulator's system log
35+
"$ANDROID_HOME/platform-tools/adb" shell logcat -d > "$BUILD_ARTIFACTSTAGINGDIRECTORY/android-device-log.txt"
36+
37+
# if we created the emulator instance, kill it
38+
if [ -n "${ANDROID_SERIAL:-}" ]; then
39+
echo "Shutting down emulator $ANDROID_SERIAL"
40+
"$ANDROID_HOME/platform-tools/adb" emu kill
41+
fi
42+
43+
if echo "$INSTRUMENTATION_OUTPUT" | grep -q "INSTRUMENTATION_CODE: -1"; then
44+
echo "SUCCESS: Instrumentation completed successfully (INSTRUMENTATION_CODE: -1)"
45+
else
46+
echo "ERROR: Expected 'INSTRUMENTATION_CODE: -1' not found in instrumentation output."
47+
exit 1
48+
fi

‎build/scripts/android-uitest-build.sh‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ else
5555
publish_extra+=("/p:AndroidUseAssemblyStore=false" "/p:RunAOTCompilation=false" "/p:PublishTrimmed=false" "/p:AndroidUseSharedRuntime=false")
5656
fi
5757

58-
dotnet publish -f net10.0-android -p:TargetFrameworkOverride=net10.0-android -p:UseNativeRendering=true "${publish_extra[@]}" \
59-
/p:AndroidPackageFormat=apk /p:RuntimeIdentifier=android-x64 /p:IsUiAutomationMappingEnabled=true \
58+
if [ "${SKIA:-0}" = "1" ]; then
59+
publish_extra+=("-p:UseSkiaRendering=true")
60+
else
61+
publish_extra+=("-p:UseNativeRendering=true" "/p:IsUiAutomationMappingEnabled=true")
62+
fi
63+
64+
dotnet publish -f net10.0-android -p:TargetFrameworkOverride=net10.0-android "${publish_extra[@]}" \
65+
/p:AndroidPackageFormat=apk /p:RuntimeIdentifier=android-x64 \
6066
-bl:"$BUILD_ARTIFACTSTAGINGDIRECTORY/android-app${BINLOG_SUFFIX}.binlog"

0 commit comments

Comments
 (0)