Skip to content

Enabling 9 new libraries tests for NativeAOT #72167

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

Merged
merged 7 commits into from
Jul 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static object NewObject(RuntimeTypeHandle typeHandle)
|| eeType == EETypePtr.EETypePtrOf<string>()
)
return null;
if (eeType.IsByRefLike)
throw new System.Reflection.TargetException();
return RuntimeImports.RhNewObject(eeType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
public static bool IsAssemblyLoadingSupported => !IsNativeAot;
public static bool IsMethodBodySupported => !IsNativeAot;
public static bool IsDebuggerTypeProxyAttributeSupported => !IsNativeAot;
public static bool HasAssemblyFiles => !string.IsNullOrEmpty(typeof(PlatformDetection).Assembly.Location);
public static bool HasHostExecutable => HasAssemblyFiles; // single-file don't have a host

private static volatile Tuple<bool> s_lazyNonZeroLowerBoundArraySupported;
public static bool IsNonZeroLowerBoundArraySupported
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/System.Buffers/tests/ArrayPool/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ public static void RentingSpecificLengthsYieldsExpectedLengths(int requestedMini
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
public static bool Is64BitProcessAndRemoteExecutorSupported => PlatformDetection.Is64BitProcess && RemoteExecutor.IsSupported;

[ConditionalTheory(nameof(Is64BitProcessAndRemoteExecutorSupported))]
[InlineData(1024 * 1024 * 1024 - 1, true)]
[InlineData(1024 * 1024 * 1024, true)]
[InlineData(1024 * 1024 * 1024 + 1, false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static void TestBugFix914998()
Assert.Equal(1, BlockingCollection<int>.TryTakeFromAny(producerArray, out ignored, -1));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void TestDebuggerAttributes()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(new BlockingCollection<int>());
Expand All @@ -181,7 +181,7 @@ public static void TestDebuggerAttributes()
Assert.Equal(col, items);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void TestDebuggerAttributes_Null()
{
Type proxyType = DebuggerAttributes.GetProxyType(new BlockingCollection<int>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public static void TestConstructor()
Assert.Equal(1, dictionary.Values.Count);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void TestDebuggerAttributes()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(new ConcurrentDictionary<string, int>());
Expand All @@ -635,7 +635,7 @@ public static void TestDebuggerAttributes()
Assert.Equal(dict, items);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void TestDebuggerAttributes_Null()
{
Type proxyType = DebuggerAttributes.GetProxyType(new ConcurrentDictionary<string, int>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public void ManyConcurrentAddsTakes_ForceContentionWithGetEnumerator(int initial
Assert.Equal(initialCount, c.Count);
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
[InlineData(0)]
[InlineData(10)]
public void DebuggerAttributes_Success(int count)
Expand All @@ -966,7 +966,7 @@ public void DebuggerAttributes_Success(int count)
Assert.Equal(c, items.Cast<int>());
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public void DebuggerTypeProxy_Ctor_NullArgument_Throws()
{
IProducerConsumerCollection<int> c = CreateProducerConsumerCollection();
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Drawing.Common/tests/BitmapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ public void GetHicon_Disposed_ThrowsArgumentException()

[ConditionalFact(Helpers.IsDrawingSupported)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "In .NET Framework we use GDI 1.0")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/72165", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void SaveWmfAsPngDoesntChangeImageBoundaries()
{
if (PlatformDetection.IsWindows7)
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Drawing.Common/tests/IconTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ void VerifyPngNotSupported()
}
else
{
VerifyPngNotSupported();
if (AppContext.TryGetSwitch(DontSupportPngFramesInIcons, out bool enabled) && enabled)
VerifyPngNotSupported();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;net48</TargetFrameworks>
<IgnoreForCI Condition="'$(TargetsMobile)' == 'true'">true</IgnoreForCI>
</PropertyGroup>
<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="BitmapTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void EmptyStringInput()
Assert.Null(font);
}

[ConditionalFact(Helpers.IsDrawingSupported)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
public void GetFontPropsSorted()
{
// The order provided since .NET Framework
Expand Down
14 changes: 14 additions & 0 deletions src/libraries/System.Drawing.Common/tests/default.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Directives>
<Application>
<Assembly Name="System.Private.CoreLib">
<!-- called by xUnit's Assert.Equal -->
<Type Name="System.IEquatable`1[[System.Drawing.Color,System.Drawing.Primitives]]" Dynamic="Required All" />
<Type Name="System.IEquatable`1[[System.Drawing.RectangleF,System.Drawing.Primitives]]" Dynamic="Required All" />
<Type Name="System.IEquatable`1[[System.Drawing.PointF,System.Drawing.Primitives]]" Dynamic="Required All" />
</Assembly>
<Assembly Name="System.Drawing.Common.Tests">
<Type Name="System.Drawing.Tests.FontTests+LOGFONT" MarshalStructure="Required All" />
<Type Name="System.Drawing.Tests.FontTests+UnblittableLOGFONT" MarshalStructure="Required All" />
</Assembly>
</Application>
</Directives>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<EnableLibraryImportGenerator>true</EnableLibraryImportGenerator>
</PropertyGroup>
<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MemoryMappedFile.CreateFromFile.Tests.cs" />
<Compile Include="MemoryMappedFile.CreateOrOpen.Tests.cs" />
Expand Down
51 changes: 51 additions & 0 deletions src/libraries/System.IO.MemoryMappedFiles/tests/default.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Directives>
<Application>
<Assembly Name="System.Linq">
<!-- called by xUnit in obscure MemberData scenarios -->
<Type Name="System.Linq.Enumerable">
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.IO.MemoryMappedFiles.MemoryMappedFileAccess,System.IO.MemoryMappedFiles" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.IO.MemoryMappedFiles.MemoryMappedFileAccess,System.IO.MemoryMappedFiles" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.IO.MemoryMappedFiles.MemoryMappedFileOptions,System.IO.MemoryMappedFiles" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.IO.MemoryMappedFiles.MemoryMappedFileOptions,System.IO.MemoryMappedFiles" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.String,System.Private.CoreLib" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.String,System.Private.CoreLib" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.Int64,System.Private.CoreLib" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.Int64,System.Private.CoreLib" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.Boolean,System.Private.CoreLib" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.Boolean,System.Private.CoreLib" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.IO.HandleInheritability,System.Private.CoreLib" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.IO.HandleInheritability,System.Private.CoreLib" />
</Method>
<Method Name="Cast" Dynamic="Required All">
<GenericArgument Name="System.IO.FileMode,System.Private.CoreLib" />
</Method>
<Method Name="ToArray" Dynamic="Required All">
<GenericArgument Name="System.IO.FileMode,System.Private.CoreLib" />
</Method>
</Type>
</Assembly>
</Application>
</Directives>
8 changes: 4 additions & 4 deletions src/libraries/System.Memory.Data/tests/BinaryDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void MaxStreamLengthRespected()
var data = BinaryData.FromStream(new OverFlowStream(offset: int.MaxValue - 1000));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
public void CanCreateBinaryDataFromCustomType()
{
TestModel payload = new TestModel { A = "value", B = 5, C = true, D = null };
Expand All @@ -342,7 +342,7 @@ void AssertData(BinaryData data)
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
public void CanSerializeNullData()
{
BinaryData data = new BinaryData(jsonSerializable: null);
Expand Down Expand Up @@ -399,7 +399,7 @@ public void CreateThrowsOnNullArray()
Assert.Contains("data", ex.Message);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
public void ToObjectHandlesBOM()
{
TestModel payload = new TestModel { A = "string", B = 42, C = true };
Expand All @@ -415,7 +415,7 @@ public void ToObjectHandlesBOM()
Assert.Equal(payload.C, model.C);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
public void ToObjectThrowsExceptionOnIncompatibleType()
{
TestModel payload = new TestModel { A = "value", B = 5, C = true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void GetArrayDataReference_NullInput_ThrowsNullRef()
Assert.Throws<NullReferenceException>(() => MemoryMarshal.GetArrayDataReference((Array)null));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNonZeroLowerBoundArraySupported))]
public static void GetArrayDataReference_NonEmptyInput_ReturnsRefToFirstElement()
{
// szarray
Expand Down Expand Up @@ -50,7 +50,7 @@ public static unsafe void GetArrayDataReference_EmptyInput_ReturnsRefToWhereFirs
Assert.True(Unsafe.AreSame(ref theRef, ref theMdArrayRef));
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNonZeroLowerBoundArraySupported))]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
Expand Down
16 changes: 12 additions & 4 deletions src/libraries/System.Memory/tests/Span/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ public static void BinaryPrimitives_StaticWithSpanArgument()
[Fact]
public static void MemoryMarshal_GenericStaticReturningSpan()
{
Type type = typeof(MemoryMarshal);
MethodInfo createSpanMethod = typeof(MemoryMarshal).GetMethod(nameof(MemoryMarshal.CreateSpan));

int value = 0;
ref int refInt = ref value;

MethodInfo method = type.GetMethod(nameof(MemoryMarshal.CreateSpan)).MakeGenericMethod((refInt.GetType()));
Assert.Throws<NotSupportedException>(() => method.Invoke(null, new object[] { null, 0 }));
Type refIntType = refInt.GetType();

if (PlatformDetection.IsNativeAot)
{
Assert.Throws<NotSupportedException>(() => createSpanMethod.MakeGenericMethod(refIntType));
}
else
{
MethodInfo method = createSpanMethod.MakeGenericMethod(refIntType);
Assert.Throws<NotSupportedException>(() => method.Invoke(null, new object[] { null, 0 }));
}
}

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Memory/tests/System.Memory.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
</PropertyGroup>
<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArrayBufferWriter\ArrayBufferWriterTests.Byte.cs" />
<Compile Include="ArrayBufferWriter\ArrayBufferWriterTests.Char.cs" />
Expand Down
18 changes: 6 additions & 12 deletions src/libraries/System.Memory/tests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ public static void AssertThrows<E, T>(Span<T> span, AssertThrowsAction<T> action
try
{
action(span);
Assert.False(true, "Expected exception: " + typeof(E).GetType());
Assert.False(true, $"Expected exception: {typeof(E)}");
}
catch (E)
catch (Exception ex)
{
}
catch (Exception wrongException)
{
Assert.False(true, "Wrong exception thrown: Expected " + typeof(E).GetType() + ": Actual: " + wrongException.GetType());
Assert.True(ex is E, $"Wrong exception thrown. Expected: {typeof(E)} Actual: {ex.GetType()}");
}
}

Expand Down Expand Up @@ -112,14 +109,11 @@ public static void AssertThrows<E, T>(ReadOnlySpan<T> span, AssertThrowsActionRe
try
{
action(span);
Assert.False(true, "Expected exception: " + typeof(E).GetType());
}
catch (E)
{
Assert.False(true, $"Expected exception: {typeof(E)}");
}
catch (Exception wrongException)
catch (Exception ex)
{
Assert.False(true, "Wrong exception thrown: Expected " + typeof(E).GetType() + ": Actual: " + wrongException.GetType());
Assert.True(ex is E, $"Wrong exception thrown. Expected: {typeof(E)} Actual: {ex.GetType()}");
}
}

Expand Down
55 changes: 55 additions & 0 deletions src/libraries/System.Memory/tests/default.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Directives>
<Application>
<Assembly Name="System.Private.CoreLib">
<!-- xUnit needs for Assert.Equals -->
<Type Name="System.IEquatable`1[[System.Range,System.Private.CoreLib]]" Dynamic="Required All" />
</Assembly>

<Assembly Name="System.Memory.Tests">
<Type Name="System.SpanTests.SpanTests">
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Byte, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.SByte, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.UInt16, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Int16, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.UInt32, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.UInt64, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Int64, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.IntPtr, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.UIntPtr, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Char, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Boolean, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Single, System.Private.CoreLib" />
</Method>
<Method Name="Sort" Dynamic="Required All">
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>
</Type>
</Assembly>
</Application>
</Directives>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace System.Reflection.Metadata.Decoding.Tests
{
public class CustomAttributeDecoderTests
{
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/60579", TestPlatforms.iOS | TestPlatforms.tvOS)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Type assembly name is different on .NET Framework.")]
public void TestCustomAttributeDecoder()
Expand Down
Loading