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

[NativeAot] Bring up a dozen or so libraries tests #73363

Merged
merged 3 commits into from
Aug 5, 2022
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
2 changes: 1 addition & 1 deletion eng/testing/tests.singlefile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
<IlcFrameworkPath>$(NetCoreAppCurrentTestHostSharedFrameworkPath)</IlcFrameworkPath>
<NoWarn>$(NoWarn);IL3050;IL3051;IL3052;IL3055;IL1005;IL3002</NoWarn>
<NoWarn>$(NoWarn);IL3050;IL3051;IL3052;IL3054;IL3055;IL1005;IL3002</NoWarn>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,18 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
TypeDesc baseType = key.BaseType;
while (baseType != null)
{
TypeDefinition baseTypeDef = reader.GetTypeDefinition(((EcmaType)baseType.GetTypeDefinition()).Handle);
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, baseTypeDef.GetCustomAttributes());
var ecmaBaseType = (EcmaType)baseType.GetTypeDefinition();
TypeDefinition baseTypeDef = ecmaBaseType.MetadataReader.GetTypeDefinition(ecmaBaseType.Handle);
MichalStrehovsky marked this conversation as resolved.
Show resolved Hide resolved
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaBaseType.MetadataReader, baseTypeDef.GetCustomAttributes());
baseType = baseType.BaseType;
}

// And inherit them from interfaces
foreach (DefType runtimeInterface in key.RuntimeInterfaces)
{
TypeDefinition interfaceTypeDef = reader.GetTypeDefinition(((EcmaType)runtimeInterface.GetTypeDefinition()).Handle);
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, interfaceTypeDef.GetCustomAttributes());
var ecmaInterface = (EcmaType)runtimeInterface.GetTypeDefinition();
TypeDefinition interfaceTypeDef = ecmaInterface.MetadataReader.GetTypeDefinition(ecmaInterface.Handle);
typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaInterface.MetadataReader, interfaceTypeDef.GetCustomAttributes());
}
}
catch (TypeSystemException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto

protected override string GetName(NodeFactory factory)
{
return $"Getting embedded descriptor file from {_module.GetDisplayName()}";
return $"Getting embedded descriptor file from {_module.ToString()}";
}

public override bool InterestingForDynamicDependencyAnalysis => false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
}
}

// Runtime reflection stack needs to obtain the type handle of the field
// (but there's no type handles for function pointers)
TypeDesc fieldTypeToCheck = _field.FieldType;
while (fieldTypeToCheck.IsParameterizedType)
fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;

if (!fieldTypeToCheck.IsFunctionPointer)
dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
if (!_field.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any))
{
// Runtime reflection stack needs to obtain the type handle of the field
// (but there's no type handles for function pointers)
TypeDesc fieldTypeToCheck = _field.FieldType;
while (fieldTypeToCheck.IsParameterizedType)
fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;

if (!fieldTypeToCheck.IsFunctionPointer)
dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
}

return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using FluentAssertions;
using System;
using System.IO;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -76,7 +77,8 @@ public void LoadLoadsExtraPaths()
context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana");
}

[Fact]
// Load method is marked RequiresAssemblyFiles so this test doesn't make sense on single file
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))]
public void LoadCanLoadANonEntryAssembly()
{
var loader = new DependencyContextLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<EnableDefaultItems>true</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Extensions.FileSystemGlobbing.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Directives>
<Application>
<Assembly Name="System.Private.CoreLib">
<!-- called by xUnit's Assert.Equal -->
<Type Name="System.IEquatable`1[[Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch,Microsoft.Extensions.FileSystemGlobbing]]" Dynamic="Required All" />
</Assembly>
</Application>
</Directives>
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void CreateHostBuilderPattern_CanFindHostBuilder()
[Fact]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CreateHostBuilderPatternTestSite.Program))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Host))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void CreateHostBuilderPattern_CanFindServiceProvider()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(CreateHostBuilderPatternTestSite.Program).Assembly);
Expand Down Expand Up @@ -137,6 +138,7 @@ public void CreateHostBuilderPattern__Invalid_CantFindServiceProvider()

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

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

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

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

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

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void NoSpecialEntryPointPatternCanRunInParallel()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ public void HostServicesSameServiceProviderAsInHostBuilder()
var hostBuilder = Host.CreateDefaultBuilder();
var host = hostBuilder.Build();

var type = hostBuilder.GetType();
// Use typeof so that trimming can see the field being used below
var type = typeof(HostBuilder);
Assert.Equal(hostBuilder.GetType(), type);
var field = type.GetField("_appServices", BindingFlags.Instance | BindingFlags.NonPublic)!;
var appServicesFromHostBuilder = (IServiceProvider)field.GetValue(hostBuilder)!;
Assert.Same(appServicesFromHostBuilder, host.Services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ public async Task HostShutsDownWhenTokenTriggers()
Assert.Equal(1, service.DisposeCount);
}

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

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
{
var service = new Mock<IHostedService>();
Expand Down Expand Up @@ -628,7 +630,8 @@ public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
}
}

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

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

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

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

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

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void ThrowExceptionForCustomImplementationOfIHostApplicationLifetime()
{
var hostApplicationLifetimeMock = new Mock<IHostApplicationLifetime>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Extensions.Logging.Testing;
using Moq;
using Xunit;
Expand All @@ -9,7 +10,8 @@ namespace Microsoft.Extensions.Logging.Test
{
public class LoggerFactoryExtensionsTest
{
[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_CallsCreateWithCorrectName()
{
Expand All @@ -28,7 +30,8 @@ public void LoggerFactoryCreateOfT_CallsCreateWithCorrectName()
factory.Verify(f => f.CreateLogger(expected));
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_SingleGeneric_CallsCreateWithCorrectName()
{
Expand All @@ -44,7 +47,8 @@ public void LoggerFactoryCreateOfT_SingleGeneric_CallsCreateWithCorrectName()
Assert.NotNull(logger);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_TwoGenerics_CallsCreateWithCorrectName()
{
Expand Down Expand Up @@ -115,7 +119,8 @@ public void CreatesLoggerName_OnMultipleTypeArgumentGenericType_CreatesWithoutGe
}


[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_CallsCreateWithCorrectName()
{
Expand All @@ -134,7 +139,8 @@ public void LoggerFactoryCreate_CallsCreateWithCorrectName()
factory.Verify(f => f.CreateLogger(expected));
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_SingleGeneric_CallsCreateWithCorrectName()
{
Expand All @@ -150,7 +156,8 @@ public void LoggerFactoryCreate_SingleGeneric_CallsCreateWithCorrectName()
Assert.NotNull(logger);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_TwoGenerics_CallsCreateWithCorrectName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public void LoggerCanGetProviderAfterItIsCreated()
Assert.Equal(new[] { "provider1.Test-Hello" }, store);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void ScopesAreNotCreatedForDisabledLoggers()
{
Expand All @@ -150,7 +151,8 @@ public void ScopesAreNotCreatedForDisabledLoggers()
logger.Verify(l => l.BeginScope(It.IsAny<object>()), Times.Never);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void ScopesAreNotCreatedWhenScopesAreDisabled()
{
Expand All @@ -175,7 +177,8 @@ public void ScopesAreNotCreatedWhenScopesAreDisabled()
logger.Verify(l => l.BeginScope(It.IsAny<object>()), Times.Never);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void ScopesAreNotCreatedInIScopeProviderWhenScopesAreDisabled()
{
Expand Down Expand Up @@ -208,7 +211,8 @@ public void ScopesAreNotCreatedInIScopeProviderWhenScopesAreDisabled()
Assert.Equal(0, scopeCount);
}

[Fact]
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void CaptureScopesIsReadFromConfiguration()
{
Expand Down
Loading