-
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathruntime.Tests.ps1
More file actions
211 lines (192 loc) · 7.86 KB
/
Copy pathruntime.Tests.ps1
File metadata and controls
211 lines (192 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# This file contains test cases for https://pester.dev/
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. $PSScriptRoot/common.ps1
Describe 'Console app NativeAOT (<framework>)' -ForEach @(
@{ framework = 'net8.0' }
) {
BeforeAll {
$path = './console-app'
DotnetNew 'console' $path $framework
@'
using Sentry;
using Sentry.Extensibility;
using Sentry.Protocol.Envelopes;
// Initialize the Sentry SDK. (It is not necessary to dispose it.)
SentrySdk.Init(options =>
{
options.Dsn = args[0];
options.Debug = true;
options.Transport = new FakeTransport();
});
if (args.Length > 1 && !string.IsNullOrEmpty(args[1]))
{
#pragma warning disable CS0618
var crashType = (CrashType)Enum.Parse(typeof(CrashType), args[1]);
SentrySdk.CauseCrash(crashType);
#pragma warning restore CS0618
}
internal class FakeTransport : ITransport
{
public virtual Task SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken = default)
{
envelope.Serialize(Console.OpenStandardOutput(), null);
return Task.CompletedTask;
}
}
'@ | Out-File $path/Program.cs
function getConsoleAppPath()
{
if ($IsMacOS)
{
$arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64'
return "./console-app/bin/Release/$framework/osx-$arch/publish/console-app"
}
elseif ($IsWindows)
{
if ("Arm64".Equals([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()))
{
return "./console-app/bin/Release/$framework/win-arm64/publish/console-app.exe"
}
else
{
return "./console-app/bin/Release/$framework/win-x64/publish/console-app.exe"
}
}
else
{
if ("Arm64".Equals([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()))
{
return "./console-app/bin/Release/$framework/linux-arm64/publish/console-app"
}
elseif ((ldd --version 2>&1) -match 'musl')
{
return "./console-app/bin/Release/$framework/linux-musl-x64/publish/console-app"
}
else
{
return "./console-app/bin/Release/$framework/linux-x64/publish/console-app"
}
}
}
function publishConsoleApp([bool]$SentryNative = $true)
{
dotnet publish console-app `
-c Release `
--nologo `
--framework $framework `
-p:SentryNative=$($SentryNative.ToString().ToLower()) `
| ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0)
{
throw 'Failed to publish the test app project.'
}
}
function runConsoleApp([bool]$IsAOT = $true, [string]$CrashType = 'Managed', [string]$Dsn = 'http://key@127.0.0.1:9999/123')
{
if ($IsAOT)
{
$executable = getConsoleAppPath
If (!(Test-Path $executable))
{
publishConsoleApp
}
}
else
{
$executable = "dotnet run --project $path -c Release --framework $framework"
}
$executable += " $Dsn $CrashType"
Write-Host "::group::Executing $executable"
try
{
Invoke-Expression "$executable 2>&1" | ForEach-Object {
Write-Host " $_"
$_
}
}
finally
{
Write-Host '::endgroup::'
}
}
}
It 'sends native debug images' {
runConsoleApp | Should -AnyElementMatch '"debug_meta":{"images":\[{"type":"(pe|elf|macho)","image_addr":"0x[a-f0-9]+","image_size":[0-9]+,"debug_id":"[a-f0-9\-]+"'
}
It 'sends stack trace native addresses' {
runConsoleApp | Should -AnyElementMatch '"stacktrace":{"frames":\[{"image_addr":"0x[a-f0-9]+","instruction_addr":"0x[a-f0-9]+"}'
}
It 'publish directory contains expected files' {
$path = getConsoleAppPath
Test-Path $path | Should -BeTrue
$items = Get-ChildItem -Path (Get-Item $path).DirectoryName
$exeExtension = $IsWindows ? '.exe' : ''
$debugExtension = $IsWindows ? '.pdb' : $IsMacOS ? '.dSYM' : '.dbg'
$items | ForEach-Object { $_.Name } | Sort-Object -Unique | Should -Be (@(
"console-app$exeExtension", "console-app$debugExtension") | Sort-Object -Unique)
}
It "'dotnet publish' produces an app that's recognized as AOT by Sentry (SentryNative=<_>)" -ForEach @($false, $true) {
publishConsoleApp $_
$output = runConsoleApp
$output | Should -AnyElementMatch 'This looks like a Native AOT application build.'
$output | Should -Not -AnyElementMatch 'System.DllNotFoundException: Unable to load (shared library|DLL) ''sentry-native'' or one of its dependencies'
if ($_)
{
$output | Should -AnyElementMatch 'Initializing sentry native'
}
else
{
$output | Should -Not -AnyElementMatch 'Initializing sentry native'
}
}
It "'dotnet run' produces an app that's recognized as JIT by Sentry" {
runConsoleApp $false | Should -AnyElementMatch 'This doesn''t look like a Native AOT application build.'
}
It 'Produces the expected exception (Managed, AOT=<_>)' -ForEach @($true, $false) {
runConsoleApp $_ 'Managed' | Should -AnyElementMatch '{"type":"System.ApplicationException","value":"This exception was caused deliberately by SentrySdk.CauseCrash\(CrashType.Managed\)."'
}
It 'Produces the expected exception (Native)' {
# The first run triggers a native error. This error is captured by sentry-native and stored stored for the next run.
runConsoleApp $true 'Native' | Should -AnyElementMatch 'Triggering a deliberate exception'
# On the next run, we use a mock Sentry HTTP server to receive the native crash.
$result = Invoke-SentryServer {
Param([string]$url)
runConsoleApp $true '' ($url.Replace('http://', 'http://key@') + '/0')
}
$result.HasErrors() | Should -BeFalse
$result.ScriptOutput | Should -AnyElementMatch "Native SDK reported: 'crashedLastRun': 'True'"
$type = $IsWindows ? 'EXCEPTION_ACCESS_VIOLATION' : 'SIGSEGV'
$result.Envelopes() | Should -AnyElementMatch "`"exception`":{`"values`":\[{`"type`":`"$type`""
}
}
# This ensures we don't have a regression for https://github.com/getsentry/sentry-dotnet/issues/2825
Describe 'Console app regression (missing System.Reflection.Metadata)' {
AfterAll {
dotnet remove ./net4-console/console-app.csproj package Sentry
}
It 'Ensure System.Reflection.Metadata is not missing' {
$path = './net4-console'
Remove-Item -Recurse -Force -Path @("$path/bin", "$path/obj") -ErrorAction SilentlyContinue
AddPackageReference $path 'Sentry'
function runConsoleApp()
{
$executable = "dotnet run --project $path -c Release"
Write-Host "::group::Executing $executable"
try
{
Invoke-Expression $executable | ForEach-Object {
Write-Host " $_"
$_
}
}
finally
{
Write-Host '::endgroup::'
}
}
$output = runConsoleApp
$output | Should -Not -AnyElementMatch 'Could not load file or assembly.'
$output | Should -AnyElementMatch '"exception":{"values":\[{"type":"System.ApplicationException","value":"Something happened!"'
}
}