diff --git a/integration-test/android.Tests.ps1 b/integration-test/android.Tests.ps1 index 30e7009378..018a7843fc 100644 --- a/integration-test/android.Tests.ps1 +++ b/integration-test/android.Tests.ps1 @@ -12,39 +12,37 @@ BeforeDiscovery { $script:emulator = Get-AndroidEmulatorId } -Describe 'MAUI app' -ForEach @( - @{ tfm = "net9.0-android35.0" } +Describe 'MAUI app (, )' -ForEach @( + @{ tfm = "net9.0-android35.0"; configuration = "Release" } + @{ tfm = "net9.0-android35.0"; configuration = "Debug" } ) -Skip:(-not $script:emulator) { BeforeAll { Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force Push-Location $PSScriptRoot/mobile-app - function InstallAndroidApp - { - param([string] $Dsn) - $dsn = $Dsn.Replace('http://', 'http://key@') + '/0' + # replace {{SENTRY_DSN}} in MauiProgram.cs + (Get-Content MauiProgram.cs) ` + -replace '\{\{SENTRY_DSN\}\}', 'http://key@127.0.0.1:8000/0' ` + | Set-Content MauiProgram.cs - # replace {{SENTRY_DSN}} in MauiProgram.cs - (Get-Content MauiProgram.cs) ` - -replace '\{\{SENTRY_DSN\}\}', $dsn ` - | Set-Content MauiProgram.cs + $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower() + $rid = "android-$arch" - $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower() - $rid = "android-$arch" + Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj" + dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj ` + --configuration $configuration ` + --framework $tfm ` + --runtime $rid + | ForEach-Object { Write-Host $_ } + Write-Host '::endgroup::' + $LASTEXITCODE | Should -Be 0 - Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj" - dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj ` - --configuration Release ` - --framework $tfm ` - --runtime $rid - | ForEach-Object { Write-Host $_ } - Write-Host '::endgroup::' - $LASTEXITCODE | Should -Be 0 - - Write-Host "::group::Install bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk" + function InstallAndroidApp + { + Write-Host "::group::Install bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk" xharness android install -v ` - --app bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk ` + --app bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk ` --package-name io.sentry.dotnet.maui.device.integrationtestapp ` --output-directory=test_output | ForEach-Object { Write-Host $_ } @@ -58,35 +56,25 @@ Describe 'MAUI app' -ForEach @( [string] $Dsn, [string] $TestArg = 'None' ) + Write-Host "::group::Run Android app (TestArg=$TestArg)" + $dsn = $Dsn.Replace('http://', 'http://key@') + '/0' + xharness android adb -v ` + -- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity ` + -e SENTRY_DSN $dsn ` + -e SENTRY_TEST_ARG $TestArg + | ForEach-Object { Write-Host $_ } + Write-Host '::endgroup::' + $LASTEXITCODE | Should -Be 0 - try + do { - # Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator - $port = $Dsn.Split(':')[2].Split('/')[0] - xharness android adb -v -- reverse tcp:$port tcp:$port - - Write-Host "::group::Run Android app (TestArg=$TestArg)" - xharness android adb -v ` - -- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity ` - -e SENTRY_TEST_ARG $TestArg - | ForEach-Object { Write-Host $_ } - Write-Host '::endgroup::' - $LASTEXITCODE | Should -Be 0 + Write-Host "Waiting for app..." + Start-Sleep -Seconds 1 - do - { - Write-Host "Waiting for app..." - Start-Sleep -Seconds 1 + $procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', '' + $activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp" - $procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', '' - $activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp" - - } while ($procid -and $activity) - } - finally - { - xharness android adb -v -- reverse --remove-all - } + } while ($procid -and $activity) } function UninstallAndroidApp @@ -111,20 +99,27 @@ Describe 'MAUI app' -ForEach @( Write-Host '::endgroup::' } } + + # Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator + xharness android adb -v -- reverse tcp:8000 tcp:8000 } AfterAll { Pop-Location + xharness android adb -v -- reverse --remove tcp:8000 + } + + BeforeEach { + InstallAndroidApp } AfterEach { UninstallAndroidApp } - It 'Managed crash' { + It 'Managed crash ()' { $result = Invoke-SentryServer { param([string]$url) - InstallAndroidApp -Dsn $url RunAndroidApp -Dsn $url -TestArg "Managed" RunAndroidApp -Dsn $url } @@ -133,12 +128,12 @@ Describe 'MAUI app' -ForEach @( $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`"" $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" + $result.Envelopes() | Should -HaveCount 1 } - It 'Java crash' { + It 'Java crash ()' { $result = Invoke-SentryServer { param([string]$url) - InstallAndroidApp -Dsn $url RunAndroidApp -Dsn $url -TestArg "Java" RunAndroidApp -Dsn $url } @@ -147,12 +142,12 @@ Describe 'MAUI app' -ForEach @( $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"RuntimeException`"" $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`"" + $result.Envelopes() | Should -HaveCount 1 } - It 'Native crash' { + It 'Native crash ()' { $result = Invoke-SentryServer { param([string]$url) - InstallAndroidApp -Dsn $url RunAndroidApp -Dsn $url -TestArg "Native" RunAndroidApp -Dsn $url } @@ -161,12 +156,12 @@ Describe 'MAUI app' -ForEach @( $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"SIG[A-Z]+`"" # SIGILL (x86_64), SIGTRAP (arm64-v8a) $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`"" + $result.Envelopes() | Should -HaveCount 1 } - It 'Null reference exception' { + It 'Null reference exception ()' { $result = Invoke-SentryServer { param([string]$url) - InstallAndroidApp -Dsn $url RunAndroidApp -Dsn $url -TestArg "NullReferenceException" RunAndroidApp -Dsn $url } @@ -174,7 +169,12 @@ Describe 'MAUI app' -ForEach @( Dump-ServerErrors -Result $result $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`"" - # TODO: fix redundant RuntimeException (#3954) - { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw + # TODO: fix redundant SIGSEGV in Release (#3954) + if ($configuration -eq "Release") { + { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw + } else { + $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" + $result.Envelopes() | Should -HaveCount 1 + } } } diff --git a/integration-test/ios.Tests.ps1 b/integration-test/ios.Tests.ps1 index b7dae6ba27..ae694f4a41 100644 --- a/integration-test/ios.Tests.ps1 +++ b/integration-test/ios.Tests.ps1 @@ -11,8 +11,9 @@ BeforeDiscovery { $script:simulator = Get-IosSimulatorUdid -PreferredStates @('Booted') } -Describe 'iOS app ()' -ForEach @( - @{ tfm = "net9.0-ios18.0" } +Describe 'iOS app (, )' -ForEach @( + @{ tfm = "net9.0-ios18.0"; configuration = "Release" } + @{ tfm = "net9.0-ios18.0"; configuration = "Debug" } ) -Skip:(-not $script:simulator) { BeforeAll { . $PSScriptRoot/../scripts/device-test-utils.ps1 @@ -26,7 +27,7 @@ Describe 'iOS app ()' -ForEach @( Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj" dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj ` - --configuration Release ` + --configuration $configuration ` --framework $tfm ` --runtime $rid | ForEach-Object { Write-Host $_ } @@ -35,9 +36,9 @@ Describe 'iOS app ()' -ForEach @( function InstallIosApp { - Write-Host "::group::Install bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app" + Write-Host "::group::Install bin/$configuration/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app" xcrun simctl install $simulator ` - bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app + bin/$configuration/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app | ForEach-Object { Write-Host $_ } Write-Host '::endgroup::' $LASTEXITCODE | Should -Be 0 @@ -86,7 +87,7 @@ Describe 'iOS app ()' -ForEach @( UninstallIosApp } - It 'captures managed crash' { + It 'captures managed crash ()' { $result = Invoke-SentryServer { param([string]$url) RunIosApp -Dsn $url -TestArg "Managed" @@ -97,9 +98,10 @@ Describe 'iOS app ()' -ForEach @( $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`"" # TODO: fix redundant SIGABRT (#3954) { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" } | Should -Throw + { $result.Envelopes() | Should -HaveCount 1 } | Should -Throw } - It 'captures native crash' { + It 'captures native crash ()' { $result = Invoke-SentryServer { param([string]$url) RunIosApp -Dsn $url -TestArg "Native" @@ -109,9 +111,10 @@ Describe 'iOS app ()' -ForEach @( $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"EXC_[A-Z_]+`"" $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`"" + $result.Envelopes() | Should -HaveCount 1 } - It 'captures null reference exception' { + It 'captures null reference exception ()' { $result = Invoke-SentryServer { param([string]$url) RunIosApp -Dsn $url -TestArg "NullReferenceException" @@ -120,7 +123,12 @@ Describe 'iOS app ()' -ForEach @( $result.HasErrors() | Should -BeFalse $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`"" - # TODO: fix redundant EXC_BAD_ACCESS (#3954) - { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw + # TODO: fix redundant EXC_BAD_ACCESS in Release (#3954) + if ($configuration -eq 'Release') { + { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw + } else { + $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" + $result.Envelopes() | Should -HaveCount 1 + } } } diff --git a/integration-test/net9-maui/MainPage.xaml.cs b/integration-test/net9-maui/MainPage.xaml.cs index 857d370195..fd47bd30d8 100644 --- a/integration-test/net9-maui/MainPage.xaml.cs +++ b/integration-test/net9-maui/MainPage.xaml.cs @@ -39,6 +39,8 @@ protected override void OnAppearing() SentrySdk.Close(); #if ANDROID + // prevent auto-restart + Platform.CurrentActivity?.FinishAffinity(); Process.KillProcess(Process.MyPid()); #elif IOS System.Environment.Exit(0); diff --git a/integration-test/net9-maui/MauiProgram.cs b/integration-test/net9-maui/MauiProgram.cs index 3d34a90ce8..766f64f6a1 100644 --- a/integration-test/net9-maui/MauiProgram.cs +++ b/integration-test/net9-maui/MauiProgram.cs @@ -17,6 +17,9 @@ public static MauiApp CreateMauiApp() #endif options.Debug = false; options.DiagnosticLevel = SentryLevel.Error; + // predictable crash envelopes only + options.SendClientReports = false; + options.AutoSessionTracking = false; }) .ConfigureFonts(fonts => { diff --git a/integration-test/net9-maui/Platforms/Android/MainActivity.cs b/integration-test/net9-maui/Platforms/Android/MainActivity.cs index c848964a0f..b59e6b60ec 100644 --- a/integration-test/net9-maui/Platforms/Android/MainActivity.cs +++ b/integration-test/net9-maui/Platforms/Android/MainActivity.cs @@ -18,6 +18,7 @@ protected override void OnCreate(Bundle? savedInstanceState) { base.OnCreate(savedInstanceState); + System.Environment.SetEnvironmentVariable("SENTRY_DSN", Intent?.GetStringExtra("SENTRY_DSN")); System.Environment.SetEnvironmentVariable("SENTRY_TEST_ARG", Intent?.GetStringExtra("SENTRY_TEST_ARG")); } } diff --git a/integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj b/integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj index 757aef448e..ed6ab044f6 100644 --- a/integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj +++ b/integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj @@ -16,6 +16,9 @@ false false + + true + Sentry.Maui.Device.IntegrationTestApp