-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AOT] Added publishAOT test app to ensure OpenTelemetry SDK is AOT sa…
…fe. (#4392)
- Loading branch information
Showing
5 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<PublishAot>true</PublishAot> | ||
<TrimmerSingleWarn>false</TrimmerSingleWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Api.ProviderBuilderExtensions" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Api" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.Console" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.InMemory" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.Jaeger" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.Prometheus.HttpListener" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.Zipkin" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Exporter.ZPages" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Extensions.Hosting" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Extensions.Propagators" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.AspNetCore" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.GrpcNetClient" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.Http" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.SqlClient" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.SemanticConventions" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry.Shims.OpenTracing" /> | ||
<TrimmerRootAssembly Include="OpenTelemetry" /> | ||
|
||
<TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Path="$(RepoRoot)\src\%(Identity)\%(Identity).csproj" /> | ||
<ProjectReference Include="@(TrimmerRootAssembly->'%(Path)')" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <copyright file="Program.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
Console.WriteLine("Hello, World!"); |
91 changes: 91 additions & 0 deletions
91
test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// <copyright file="AotCompatibilityTests.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System.Diagnostics; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace OpenTelemetry.AotCompatibility.Tests | ||
{ | ||
public class AotCompatibilityTests | ||
{ | ||
private readonly ITestOutputHelper testOutputHelper; | ||
|
||
public AotCompatibilityTests(ITestOutputHelper testOutputHelper) | ||
{ | ||
this.testOutputHelper = testOutputHelper; | ||
} | ||
|
||
/// <summary> | ||
/// This test ensures that the intended APIs of the OpenTelemetry.AotCompatibility.TestApp libraries are | ||
/// trimming and NativeAOT compatible. | ||
/// | ||
/// This test follows the instructions in https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#show-all-warnings-with-sample-application | ||
/// | ||
/// If this test fails, it is due to adding trimming and/or AOT incompatible changes | ||
/// to code that is supposed to be compatible. | ||
/// | ||
/// To diagnose the problem, inspect the test output which will contain the trimming and AOT errors. For example: | ||
/// | ||
/// error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors'. | ||
/// </summary> | ||
[Fact] | ||
public void EnsureAotCompatibility() | ||
{ | ||
string[] paths = { @"..", "..", "..", "..", "OpenTelemetry.AotCompatibility.TestApp" }; | ||
string testAppPath = Path.Combine(paths); | ||
string testAppProject = "OpenTelemetry.AotCompatibility.TestApp.csproj"; | ||
|
||
// ensure we run a clean publish every time | ||
DirectoryInfo testObjDir = new DirectoryInfo(Path.Combine(testAppPath, "obj")); | ||
if (testObjDir.Exists) | ||
{ | ||
testObjDir.Delete(recursive: true); | ||
} | ||
|
||
var process = new Process | ||
{ | ||
// set '-nodereuse:false /p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI | ||
StartInfo = new ProcessStartInfo("dotnet", $"publish {testAppProject} --self-contained -nodereuse:false /p:UseSharedCompilation=false") | ||
{ | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
WorkingDirectory = testAppPath, | ||
}, | ||
}; | ||
|
||
var expectedOutput = new System.Text.StringBuilder(); | ||
process.OutputDataReceived += (sender, e) => | ||
{ | ||
if (!string.IsNullOrEmpty(e.Data)) | ||
{ | ||
this.testOutputHelper.WriteLine(e.Data); | ||
expectedOutput.AppendLine(e.Data); | ||
} | ||
}; | ||
|
||
process.Start(); | ||
process.BeginOutputReadLine(); | ||
|
||
Assert.True(process.WaitForExit(milliseconds: 180_000), "dotnet publish command timed out after 180 seconds."); | ||
Assert.True(process.ExitCode == 0, "Publishing the AotCompatibility app failed. See test output for more details."); | ||
|
||
var warnings = expectedOutput.ToString().Split('\n', '\r').Where(line => line.Contains("warning IL")); | ||
Assert.Equal(77, warnings.Count()); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/OpenTelemetry.AotCompatibility.Tests/OpenTelemetry.AotCompatibility.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>Test to ensure AOT compatilibity.</Description> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPkgVer)" /> | ||
<PackageReference Include="xunit" Version="$(XUnitPkgVer)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioPkgVer)"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXUnitCliVer)" /> | ||
</ItemGroup> | ||
|
||
</Project> |