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

Start running System.Runtime trimming tests #101592

Merged
merged 1 commit into from
May 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;

/// <summary>
/// Ensures setting InvariantGlobalization = true still works in a trimmed app.
Expand All @@ -27,6 +28,18 @@ static int Main(string[] args)
{
return -3;
}

// The rest of this code depends on a property of IL level trimming that keeps reflection
// metadata for anything that is statically reachable. It's not applicable if we're not doing that
// kind of trimming. Approximate what kind of trimming are we doing.
if (GetMethodSecretly(typeof(Program), nameof(GetCoreLibType)) == null)
{
// Sanity check: we only expect this for native AOT; IsDynamicCodeSupported approximates that.
if (RuntimeFeature.IsDynamicCodeSupported)
throw new Exception();

return 100;
}

// Ensure the internal GlobalizationMode class is trimmed correctly.
Type globalizationMode = GetCoreLibType("System.Globalization.GlobalizationMode");
Expand Down Expand Up @@ -65,4 +78,8 @@ static int Main(string[] args)
// The intention of this method is to ensure the trimmer doesn't preserve the Type.
private static Type GetCoreLibType(string name) =>
typeof(object).Assembly.GetType(name, throwOnError: false);

// The intention is to look for a method on a type in a way that trimming cannot detect.
private static MethodBase GetMethodSecretly(Type type, string name) =>
type.GetMethod(name, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
and tested with this test. Issue https://github.com/dotnet/runtime/issues/48849 is
tracking investigation on why this test is failing if not skipped. -->
<SkipOnTestRuntimes>browser-wasm</SkipOnTestRuntimes>
<!-- https://github.com/dotnet/runtime/issues/68714 -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="VerifyResourcesGetTrimmedTest.cs">
<!-- Setting the Trimming feature switch to make sure that the Resources get trimmed by the trimmer
Expand All @@ -51,6 +53,8 @@
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="TypeBuilderComDisabled.cs">
<DisabledProperties>BuiltInComInteropSupport</DisabledProperties>
<!-- Reflection.Emit doesn't work with native AOT -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="NullabilityInfoContextSupportFalse.cs">
<DisabledProperties>NullabilityInfoContextSupport</DisabledProperties>
Expand All @@ -62,6 +66,8 @@
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<TestConsoleAppSourceFiles Include="UseWindowsThreadPoolFalse.cs">
<DisabledFeatureSwitches>System.Threading.ThreadPool.UseWindowsThreadPool</DisabledFeatureSwitches>
<!-- https://github.com/dotnet/runtime/issues/101591 -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="UseWindowsThreadPoolTrue.cs">
<EnabledFeatureSwitches>System.Threading.ThreadPool.UseWindowsThreadPool</EnabledFeatureSwitches>
Expand Down
1 change: 0 additions & 1 deletion src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Private.Xml.Linq\tests\TrimmingTests\System.Xml.Linq.TrimmingTests.proj" />
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Linq.Expressions\tests\TrimmingTests\System.Linq.Expressions.TrimmingTests.proj" />
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Private.Xml\tests\TrimmingTests\System.Private.Xml.TrimmingTests.proj" />
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Runtime\tests\System.Runtime.Tests\TrimmingTests\System.Runtime.TrimmingTests.proj" />

<TrimmingTestProjects Include="$(MSBuildThisFileDirectory)*\tests\**\*.TrimmingTests.proj"
Exclude="@(ProjectExclusions)"
Expand Down
Loading