Skip to content

fix: Android device crash tests #2098

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

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android-smoke-test-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
adb wait-for-device
adb shell input keyevent 82
adb devices -l
pwsh ./scripts/smoke-test-android.ps1 -IsIntegrationTest -WarnIfFlaky
pwsh ./scripts/smoke-test-android.ps1 -WarnIfFlaky

- name: Upload artifacts on failure
if: ${{ failure() }}
Expand Down
52 changes: 7 additions & 45 deletions scripts/smoke-test-android.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,14 @@ Write-Host "# |___/_| |_|\___/|_|\_\___| |_| |___|___/ |_| #"
Write-Host "# #"
Write-Host "#####################################################"

if ($IsIntegrationTest)
{
$BuildDir = $(GetNewProjectBuildPath)
$ApkFileName = "test.apk"
$ProcessName = "com.DefaultCompany.$(GetNewProjectName)"

if ($Action -eq "Build")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
$buildCallback = {
Write-Host "::group::Gradle build $BuildDir"
Push-Location $BuildDir
try
{
MakeExecutable "./gradlew"
& ./gradlew --info --no-daemon assembleRelease | ForEach-Object {
Write-Host " $_"
}
if (-not $?)
{
throw "Gradle execution failed"
}
Copy-Item -Path launcher/build/outputs/apk/release/launcher-release.apk -Destination $ApkFileName
}
finally
{
Pop-Location
Write-Host "::endgroup::"
}
}

$symbolServerOutput = RunWithSymbolServer -Callback $buildCallback
CheckSymbolServerOutput 'Android' $symbolServerOutput $UnityVersion
return;
}
}
else
{
$BuildDir = "samples/artifacts/builds/Android"
$ApkFileName = "IL2CPP_Player.apk"
$ProcessName = "io.sentry.samples.unityofbugs"
}
$BuildDir = $(GetNewProjectBuildPath)
$ApkFileName = "test.apk"
$ProcessName = "com.DefaultCompany.$(GetNewProjectName)"
$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerActivity"
$FallBackTestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerGameActivity"

$_ArtifactsPath = ((Test-Path env:ARTIFACTS_PATH) ? $env:ARTIFACTS_PATH : "./$BuildDir/../test-artifacts/") `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mixing relative paths ./ with absolute paths $BuildDir. Using Join-Path to resolve this.

+ $(Get-Date -Format "HHmmss")
$_ArtifactsPath = (Test-Path env:ARTIFACTS_PATH) ? $env:ARTIFACTS_PATH : (Join-Path $BuildDir "../test-artifacts/" $(Get-Date -Format "HHmmss"))

function ArtifactsPath
{
if (-not (Test-Path $_ArtifactsPath))
Expand Down Expand Up @@ -332,8 +294,8 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin
$logCache = ProcessNewLogs -newLogs $newLogs -lastLogCount ([ref]$lastLogCount) -logCache $logCache

# The SmokeTester logs "SmokeTester is quitting." in OnApplicationQuit() to reliably inform when tests finish running.
# For crash tests, we expect to see a native crash log "terminating with uncaught exception of type char const*".
if (($newLogs | Select-String "SmokeTester is quitting.") -or ($newLogs | Select-String "terminating with uncaught exception of type char const*"))
# For crash tests, we're checking for `sentry-native` logging "crash has been captured" to reliably inform when tests finished running.
if (($newLogs | Select-String "SmokeTester is quitting.") -or ($newLogs | Select-String "crash has been captured"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a log we control (from within sentry-native) so it won't change with different versions.

{
Write-Host "Process finished marker detected. Finish waiting for tests to run."
$processFinished = $true
Expand Down
14 changes: 6 additions & 8 deletions test/Scripts.Integration.Test/integration-test.ps1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole script is a utility script to run the scripts used by CI locally.

Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,16 @@ If (-not(Test-Path -Path "$(GetNewProjectPath)"))
./test/Scripts.Integration.Test/configure-sentry.ps1 "$UnityPath" -Platform $Platform -CheckSymbols
}

# Support rebuilding the integration test project. I.e. if you make changes to the SmokeTester.cs during
If ($Rebuild -or -not(Test-Path -Path $(GetNewProjectBuildPath)))
{
Write-Host "Building Project"

If (("iOS", "Android-Export") -contains $Platform)
If ("iOS" -eq $Platform)
{
# Workaround for having `exportAsGoogleAndroidProject` remain `false` in Unity 6 on first build
# We're exporting an Xcode project and building that in a separate step.
./test/Scripts.Integration.Test/build-project.ps1 -UnityPath "$UnityPath" -UnityVersion $UnityVersion -Platform $Platform
Remove-Item -Path $(GetNewProjectBuildPath) -Recurse -Force -Confirm:$false

./test/Scripts.Integration.Test/build-project.ps1 -UnityPath "$UnityPath" -UnityVersion $UnityVersion -Platform $Platform
& "./scripts/smoke-test-$($Platform -eq 'iOS' ? 'ios' : 'android').ps1" Build -IsIntegrationTest -UnityVersion $UnityVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the Android stuff here anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That script gluing all the scripts together and letting us "run CI locally".
And no, we're not exporting the Gradle project to manually build it on a different runner. We're relying on the Android Dev environment Unity comes with.

& "./scripts/smoke-test-ios.ps1" Build -IsIntegrationTest -UnityVersion $UnityVersion
}
Else
{
Expand All @@ -109,9 +107,9 @@ Switch -Regex ($Platform)
{
./test/Scripts.Integration.Test/run-smoke-test.ps1 -Smoke -Crash
}
"^(Android|Android-Export)$"
"^(Android)$"
{
./scripts/smoke-test-android.ps1 -IsIntegrationTest
./scripts/smoke-test-android.ps1
}
"^iOS$"
{
Expand Down
Loading