Skip to content

Commit

Permalink
Start running System.Runtime trimming tests (#101592)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored May 6, 2024
1 parent 41efa20 commit 84b3339
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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 @@ -650,7 +650,6 @@
<!-- We need to go over these disablements: https://github.com/dotnet/runtime/issues/101228 -->
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Private.Xml.Linq\tests\TrimmingTests\System.Xml.Linq.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

0 comments on commit 84b3339

Please sign in to comment.