Skip to content

Commit b13e6ef

Browse files
[NativeAot] Bring up a dozen or so libraries tests (#73363)
This time found some product issues and fixed them.
1 parent 5cdb322 commit b13e6ef

File tree

33 files changed

+174
-80
lines changed

33 files changed

+174
-80
lines changed

eng/testing/tests.singlefile.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
2727
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
2828
<IlcFrameworkPath>$(NetCoreAppCurrentTestHostSharedFrameworkPath)</IlcFrameworkPath>
29-
<NoWarn>$(NoWarn);IL3050;IL3051;IL3052;IL3055;IL1005;IL3002</NoWarn>
29+
<NoWarn>$(NoWarn);IL3050;IL3051;IL3052;IL3054;IL3055;IL1005;IL3002</NoWarn>
3030
<TrimmerSingleWarn>false</TrimmerSingleWarn>
3131
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
3232

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,18 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
311311
TypeDesc baseType = key.BaseType;
312312
while (baseType != null)
313313
{
314-
TypeDefinition baseTypeDef = reader.GetTypeDefinition(((EcmaType)baseType.GetTypeDefinition()).Handle);
315-
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, baseTypeDef.GetCustomAttributes());
314+
var ecmaBaseType = (EcmaType)baseType.GetTypeDefinition();
315+
TypeDefinition baseTypeDef = ecmaBaseType.MetadataReader.GetTypeDefinition(ecmaBaseType.Handle);
316+
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaBaseType.MetadataReader, baseTypeDef.GetCustomAttributes());
316317
baseType = baseType.BaseType;
317318
}
318319

319320
// And inherit them from interfaces
320321
foreach (DefType runtimeInterface in key.RuntimeInterfaces)
321322
{
322-
TypeDefinition interfaceTypeDef = reader.GetTypeDefinition(((EcmaType)runtimeInterface.GetTypeDefinition()).Handle);
323-
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, interfaceTypeDef.GetCustomAttributes());
323+
var ecmaInterface = (EcmaType)runtimeInterface.GetTypeDefinition();
324+
TypeDefinition interfaceTypeDef = ecmaInterface.MetadataReader.GetTypeDefinition(ecmaInterface.Handle);
325+
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaInterface.MetadataReader, interfaceTypeDef.GetCustomAttributes());
324326
}
325327
}
326328
catch (TypeSystemException)

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EmbeddedTrimmingDescriptorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
6060

6161
protected override string GetName(NodeFactory factory)
6262
{
63-
return $"Getting embedded descriptor file from {_module.GetDisplayName()}";
63+
return $"Getting embedded descriptor file from {_module.ToString()}";
6464
}
6565

6666
public override bool InterestingForDynamicDependencyAnalysis => false;

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
8383
}
8484
}
8585

86-
// Runtime reflection stack needs to obtain the type handle of the field
87-
// (but there's no type handles for function pointers)
88-
TypeDesc fieldTypeToCheck = _field.FieldType;
89-
while (fieldTypeToCheck.IsParameterizedType)
90-
fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;
91-
92-
if (!fieldTypeToCheck.IsFunctionPointer)
93-
dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
86+
if (!_field.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any))
87+
{
88+
// Runtime reflection stack needs to obtain the type handle of the field
89+
// (but there's no type handles for function pointers)
90+
TypeDesc fieldTypeToCheck = _field.FieldType;
91+
while (fieldTypeToCheck.IsParameterizedType)
92+
fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;
93+
94+
if (!fieldTypeToCheck.IsFunctionPointer)
95+
dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
96+
}
9497

9598
return dependencies;
9699
}

src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextLoaderTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using FluentAssertions;
5+
using System;
56
using System.IO;
67
using System.Reflection;
78
using Xunit;
@@ -76,7 +77,8 @@ public void LoadLoadsExtraPaths()
7677
context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana");
7778
}
7879

79-
[Fact]
80+
// Load method is marked RequiresAssemblyFiles so this test doesn't make sense on single file
81+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))]
8082
public void LoadCanLoadANonEntryAssembly()
8183
{
8284
var loader = new DependencyContextLoader();

src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/Microsoft.Extensions.FileSystemGlobbing.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<EnableDefaultItems>true</EnableDefaultItems>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<RdXmlFile Include="default.rd.xml" />
10+
</ItemGroup>
11+
812
<ItemGroup>
913
<ProjectReference Include="..\src\Microsoft.Extensions.FileSystemGlobbing.csproj" />
1014
</ItemGroup>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Directives>
2+
<Application>
3+
<Assembly Name="System.Private.CoreLib">
4+
<!-- called by xUnit's Assert.Equal -->
5+
<Type Name="System.IEquatable`1[[Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch,Microsoft.Extensions.FileSystemGlobbing]]" Dynamic="Required All" />
6+
</Assembly>
7+
</Application>
8+
</Directives>

src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void CreateHostBuilderPattern_CanFindHostBuilder()
108108
[Fact]
109109
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CreateHostBuilderPatternTestSite.Program))]
110110
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Host))]
111+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
111112
public void CreateHostBuilderPattern_CanFindServiceProvider()
112113
{
113114
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(CreateHostBuilderPatternTestSite.Program).Assembly);
@@ -137,6 +138,7 @@ public void CreateHostBuilderPattern__Invalid_CantFindServiceProvider()
137138

138139
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
139140
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
141+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
140142
public void NoSpecialEntryPointPattern()
141143
{
142144
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);
@@ -235,6 +237,7 @@ public void NoSpecialEntryPointPatternHangs()
235237

236238
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
237239
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPatternMainNoArgs.Program))]
240+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
238241
public void NoSpecialEntryPointPatternMainNoArgs()
239242
{
240243
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPatternMainNoArgs.Program).Assembly, s_WaitTimeout);
@@ -244,6 +247,8 @@ public void NoSpecialEntryPointPatternMainNoArgs()
244247
}
245248

246249
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
250+
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "TopLevelStatements")]
251+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
247252
public void TopLevelStatements()
248253
{
249254
var assembly = Assembly.Load("TopLevelStatements");
@@ -254,6 +259,7 @@ public void TopLevelStatements()
254259
}
255260

256261
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
262+
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "TopLevelStatementsTestsTimeout")]
257263
public void TopLevelStatementsTestsTimeout()
258264
{
259265
var assembly = Assembly.Load("TopLevelStatementsTestsTimeout");
@@ -264,6 +270,8 @@ public void TopLevelStatementsTestsTimeout()
264270
}
265271

266272
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
273+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
274+
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "ApplicationNameSetFromArgument")]
267275
public void ApplicationNameSetFromArgument()
268276
{
269277
Assembly assembly = Assembly.Load("ApplicationNameSetFromArgument");
@@ -276,6 +284,7 @@ public void ApplicationNameSetFromArgument()
276284

277285
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
278286
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
287+
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
279288
public void NoSpecialEntryPointPatternCanRunInParallel()
280289
{
281290
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ public void HostServicesSameServiceProviderAsInHostBuilder()
644644
var hostBuilder = Host.CreateDefaultBuilder();
645645
var host = hostBuilder.Build();
646646

647-
var type = hostBuilder.GetType();
647+
// Use typeof so that trimming can see the field being used below
648+
var type = typeof(HostBuilder);
649+
Assert.Equal(hostBuilder.GetType(), type);
648650
var field = type.GetField("_appServices", BindingFlags.Instance | BindingFlags.NonPublic)!;
649651
var appServicesFromHostBuilder = (IServiceProvider)field.GetValue(hostBuilder)!;
650652
Assert.Same(appServicesFromHostBuilder, host.Services);

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ public async Task HostShutsDownWhenTokenTriggers()
565565
Assert.Equal(1, service.DisposeCount);
566566
}
567567

568-
[Fact]
568+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
569+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
569570
public async Task HostStopAsyncCanBeCancelledEarly()
570571
{
571572
var service = new Mock<IHostedService>();
@@ -596,7 +597,8 @@ public async Task HostStopAsyncCanBeCancelledEarly()
596597
}
597598
}
598599

599-
[Fact]
600+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
601+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
600602
public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
601603
{
602604
var service = new Mock<IHostedService>();
@@ -628,7 +630,8 @@ public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
628630
}
629631
}
630632

631-
[Fact]
633+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
634+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
632635
public async Task WebHostStopAsyncUsesDefaultTimeoutIfNoTokenProvided()
633636
{
634637
var service = new Mock<IHostedService>();
@@ -1151,7 +1154,8 @@ public async Task Host_InvokesConfigureServicesMethodsOnlyOnce()
11511154
}
11521155
}
11531156

1154-
[Fact]
1157+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
1158+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
11551159
public void Dispose_DisposesAppConfigurationProviders()
11561160
{
11571161
var providerMock = new Mock<ConfigurationProvider>().As<IDisposable>();
@@ -1175,7 +1179,8 @@ public void Dispose_DisposesAppConfigurationProviders()
11751179
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
11761180
}
11771181

1178-
[Fact]
1182+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
1183+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
11791184
public void Dispose_DisposesHostConfigurationProviders()
11801185
{
11811186
var providerMock = new Mock<ConfigurationProvider>().As<IDisposable>();
@@ -1250,7 +1255,8 @@ public async Task HostCallsDisposeAsyncOnServiceProviderWhenDisposeAsyncCalled()
12501255
}
12511256
}
12521257

1253-
[Fact]
1258+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
1259+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
12541260
public async Task DisposeAsync_DisposesAppConfigurationProviders()
12551261
{
12561262
var providerMock = new Mock<ConfigurationProvider>().As<IDisposable>();
@@ -1274,7 +1280,8 @@ public async Task DisposeAsync_DisposesAppConfigurationProviders()
12741280
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
12751281
}
12761282

1277-
[Fact]
1283+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
1284+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
12781285
public async Task DisposeAsync_DisposesHostConfigurationProviders()
12791286
{
12801287
var providerMock = new Mock<ConfigurationProvider>().As<IDisposable>();
@@ -1298,7 +1305,8 @@ public async Task DisposeAsync_DisposesHostConfigurationProviders()
12981305
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
12991306
}
13001307

1301-
[Fact]
1308+
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
1309+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
13021310
public void ThrowExceptionForCustomImplementationOfIHostApplicationLifetime()
13031311
{
13041312
var hostApplicationLifetimeMock = new Mock<IHostApplicationLifetime>();

0 commit comments

Comments
 (0)