Skip to content

Commit 84b3339

Browse files
Start running System.Runtime trimming tests (#101592)
1 parent 41efa20 commit 84b3339

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/InvariantGlobalizationTrue.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Globalization;
66
using System.Reflection;
7+
using System.Runtime.CompilerServices;
78

89
/// <summary>
910
/// Ensures setting InvariantGlobalization = true still works in a trimmed app.
@@ -27,6 +28,18 @@ static int Main(string[] args)
2728
{
2829
return -3;
2930
}
31+
32+
// The rest of this code depends on a property of IL level trimming that keeps reflection
33+
// metadata for anything that is statically reachable. It's not applicable if we're not doing that
34+
// kind of trimming. Approximate what kind of trimming are we doing.
35+
if (GetMethodSecretly(typeof(Program), nameof(GetCoreLibType)) == null)
36+
{
37+
// Sanity check: we only expect this for native AOT; IsDynamicCodeSupported approximates that.
38+
if (RuntimeFeature.IsDynamicCodeSupported)
39+
throw new Exception();
40+
41+
return 100;
42+
}
3043

3144
// Ensure the internal GlobalizationMode class is trimmed correctly.
3245
Type globalizationMode = GetCoreLibType("System.Globalization.GlobalizationMode");
@@ -65,4 +78,8 @@ static int Main(string[] args)
6578
// The intention of this method is to ensure the trimmer doesn't preserve the Type.
6679
private static Type GetCoreLibType(string name) =>
6780
typeof(object).Assembly.GetType(name, throwOnError: false);
81+
82+
// The intention is to look for a method on a type in a way that trimming cannot detect.
83+
private static MethodBase GetMethodSecretly(Type type, string name) =>
84+
type.GetMethod(name, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
6885
}

src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
and tested with this test. Issue https://github.com/dotnet/runtime/issues/48849 is
4444
tracking investigation on why this test is failing if not skipped. -->
4545
<SkipOnTestRuntimes>browser-wasm</SkipOnTestRuntimes>
46+
<!-- https://github.com/dotnet/runtime/issues/68714 -->
47+
<NativeAotIncompatible>true</NativeAotIncompatible>
4648
</TestConsoleAppSourceFiles>
4749
<TestConsoleAppSourceFiles Include="VerifyResourcesGetTrimmedTest.cs">
4850
<!-- Setting the Trimming feature switch to make sure that the Resources get trimmed by the trimmer
@@ -51,6 +53,8 @@
5153
</TestConsoleAppSourceFiles>
5254
<TestConsoleAppSourceFiles Include="TypeBuilderComDisabled.cs">
5355
<DisabledProperties>BuiltInComInteropSupport</DisabledProperties>
56+
<!-- Reflection.Emit doesn't work with native AOT -->
57+
<NativeAotIncompatible>true</NativeAotIncompatible>
5458
</TestConsoleAppSourceFiles>
5559
<TestConsoleAppSourceFiles Include="NullabilityInfoContextSupportFalse.cs">
5660
<DisabledProperties>NullabilityInfoContextSupport</DisabledProperties>
@@ -62,6 +66,8 @@
6266
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
6367
<TestConsoleAppSourceFiles Include="UseWindowsThreadPoolFalse.cs">
6468
<DisabledFeatureSwitches>System.Threading.ThreadPool.UseWindowsThreadPool</DisabledFeatureSwitches>
69+
<!-- https://github.com/dotnet/runtime/issues/101591 -->
70+
<NativeAotIncompatible>true</NativeAotIncompatible>
6571
</TestConsoleAppSourceFiles>
6672
<TestConsoleAppSourceFiles Include="UseWindowsThreadPoolTrue.cs">
6773
<EnabledFeatureSwitches>System.Threading.ThreadPool.UseWindowsThreadPool</EnabledFeatureSwitches>

src/libraries/tests.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@
650650
<!-- We need to go over these disablements: https://github.com/dotnet/runtime/issues/101228 -->
651651
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Private.Xml.Linq\tests\TrimmingTests\System.Xml.Linq.TrimmingTests.proj" />
652652
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Private.Xml\tests\TrimmingTests\System.Private.Xml.TrimmingTests.proj" />
653-
<ProjectExclusions Condition="'$(RunNativeAotTestApps)' == 'true'" Include="$(MSBuildThisFileDirectory)\System.Runtime\tests\System.Runtime.Tests\TrimmingTests\System.Runtime.TrimmingTests.proj" />
654653

655654
<TrimmingTestProjects Include="$(MSBuildThisFileDirectory)*\tests\**\*.TrimmingTests.proj"
656655
Exclude="@(ProjectExclusions)"

0 commit comments

Comments
 (0)