Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Android smoke test #1865

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
49 changes: 44 additions & 5 deletions .github/workflows/android-smoke-test-wrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,66 @@ on:
type: string

jobs:
# needs.try-*.outputs.status == 'failed' => Smoke test failed, no need to retry.
# needs.try-*.result == 'failure' => CI Setup failed.
try-1:
uses: ./.github/workflows/android-smoke-test.yml
with:
unity-version: ${{ inputs.unity-version }}
api-level: ${{ inputs.api-level }}
try: 1

try-2:
try-1-check-failed:
runs-on: ubuntu-latest
needs: [try-1]
if: ${{ needs.try-1.result == 'failure' }}
if: ${{ needs.try-1.outputs.status != 'success' }}
steps:
- name: Check failed
run: |
if [[ "${{ needs.try-1.outputs.status }}" == "failed" ]]; then
echo "Smoke test failed."
exit 1
fi

try-2:
needs: [try-1-check-failed]
uses: ./.github/workflows/android-smoke-test.yml
with:
unity-version: ${{ inputs.unity-version }}
api-level: ${{ inputs.api-level }}
try: 2
try: 2

try-3:
try-2-check-failed:
runs-on: ubuntu-latest
needs: [try-2]
if: ${{ needs.try-2.result == 'failure' }}
if: ${{ needs.try-2.outputs.status != 'success' }}
steps:
- name: Check failed
run: |
if [[ "${{ needs.try-2.outputs.status }}" == "failed" ]]; then
echo "Smoke test failed."
exit 1
fi

try-3:
needs: [try-2-check-failed]
uses: ./.github/workflows/android-smoke-test.yml
with:
unity-version: ${{ inputs.unity-version }}
api-level: ${{ inputs.api-level }}
try: 3

try-3-check-status:
runs-on: ubuntu-latest
needs: [try-3]
steps:
- name: Check final result
run: |
if [[ "${{ needs.try-3.outputs.status }}" == "flaky" || "${{ needs.try-3.outputs.status }}" == "crashed" ]]; then
echo "Job status is flaky or crashed. Exiting with code 78."
exit 78
fi
if [[ "${{ needs.try-2.outputs.status }}" == "failed" ]]; then
echo "Smoke test failed."
exit 1
fi
66 changes: 53 additions & 13 deletions .github/workflows/android-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ on:
type: number
# Map the workflow outputs to job outputs
outputs:
outcome:
description:
value: ${{ jobs.run.outputs.outcome }}
status:
description: "The outcome status of the smoke test"
value: ${{ jobs.run.outputs.status }}

jobs:
run:
name: try-${{ inputs.try }}
runs-on: macos-latest
runs-on: ubuntu-latest
env:
ARTIFACTS_PATH: samples/IntegrationTest/test-artifacts/
HOMEBREW_NO_INSTALL_CLEANUP: 1
Expand All @@ -31,7 +31,14 @@ jobs:
outcome: ${{ steps.smoke-test.outcome }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Not required for MacOS.
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Download test app artifact
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -64,22 +71,55 @@ jobs:
"target=$target" >> $env:GITHUB_OUTPUT
"api-level=$apiLevel" >> $env:GITHUB_OUTPUT
"label=$($label ?? $apiLevel)" >> $env:GITHUB_OUTPUT

- name: create Android Emulator Image
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # [email protected]
with:
api-level: ${{ steps.config.outputs.api-level }}
target: ${{ steps.config.outputs.target }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
arch: x86_64
script: |
adb wait-for-device
adb shell input keyevent 82
adb devices -l
echo "Generated AVD snapshot for caching."

- name: Android API ${{ steps.config.outputs.label }} emulator setup + Smoke test
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # [email protected]

- name: Wait for Emulator to Close
env:
EMULATOR_NAME: emulator-5554
run: |
Write-Output "Waiting for emulator $env:EMULATOR_NAME to close..."
$retries = 0
$maxRetries = 60 # Adjust timeout (60 x 5 seconds = 5 minutes)
while ($true) {
$devices = adb devices | Select-String -Pattern $env:EMULATOR_NAME
if (-not $devices) {
Write-Output "Emulator $env:EMULATOR_NAME is offline."
break
}
if ($retries -ge $maxRetries) {
Write-Error "Timeout: Emulator $env:EMULATOR_NAME did not go offline after $(($maxRetries * 5)) seconds."
exit 1
}
Write-Output "Emulator $env:EMULATOR_NAME is still running. Retrying in 5 seconds... ($retries/$maxRetries)"
Start-Sleep -Seconds 5
$retries++
}

- name: Android API ${{ steps.config.outputs.label }} Smoke test
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # [email protected]
id: smoke-test
timeout-minutes: 40
continue-on-error: true
with:
api-level: ${{ steps.config.outputs.api-level }}
target: ${{ steps.config.outputs.target }}
force-avd-creation: false
ram-size: 2048M
arch: x86_64
cores: 3
emulator-boot-timeout: 1800
disk-size: 4096M # Some runs have out of storage error when installing the smoke test.
emulator-options: -no-snapshot-save -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -accel on
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: pwsh ./scripts/smoke-test-android.ps1 -IsIntegrationTest -WarnIfFlaky

Expand Down
18 changes: 15 additions & 3 deletions scripts/smoke-test-android.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else
$ApkFileName = "IL2CPP_Player.apk"
$ProcessName = "io.sentry.samples.unityofbugs"
}
$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerActivity"
$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerGameActivity"

$_ArtifactsPath = ((Test-Path env:ARTIFACTS_PATH) ? $env:ARTIFACTS_PATH : "./$BuildDir/../test-artifacts/") `
+ $(Get-Date -Format "HHmmss")
Expand All @@ -77,7 +77,13 @@ function ArtifactsPath
if (Test-Path env:CI)
{
# Take Screenshot of VM to verify emulator start
screencapture "$(ArtifactsPath)/host-screenshot.jpg"
if ($IsMacOS)
{
screencapture "$(ArtifactsPath)/host-screenshot.jpg"
}
else {
Write-Warning "Screenshot functionality is not implemented for this platform."
}
}

function TakeScreenshot([string] $deviceId)
Expand Down Expand Up @@ -348,7 +354,13 @@ foreach ($device in $DeviceList)
adb -s $device logcat -c
}

adb -s $device shell am start -n $TestActivityName -e test $Name
Write-Host "Starting app $TestActivityName"
$output = & adb -s $device shell am start -n $TestActivityName -e test $Name 2>&1
if ($output -match "Error type 3" -or $output -match "Activity class \{$TestActivityName\} does not exist.") {
ExitNow "failed" "Activity does not exist"
} else {
Write-Host "Activity started successfully."
}
#despite calling start, the app might not be started yet.

$timedOut = $true
Expand Down
Loading