From 7864ef8e53c06f38862bf933f84bbd8b8b9b4ae5 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 12 May 2022 16:24:11 -0700 Subject: [PATCH 1/5] Test fix for GetMemberWithSameMetadataDefinitionAs --- .../TypeInfos/RuntimeTypeInfo.GetMember.cs | 22 ++++++++++++++----- .../System.Reflection/tests/TypeInfoTests.cs | 2 +- src/libraries/tests.proj | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs index 9c5741413ba55d..e79e6c0b7092c1 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.GetMember.cs @@ -123,7 +123,22 @@ public sealed override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberIn if (member is null) throw new ArgumentNullException(nameof(member)); - MemberInfo result = member.MemberType switch + // Need to walk up the inheritance chain if member is not found + // Leverage the existing cache mechanism of per type to store members + RuntimeTypeInfo? runtimeType = this; + while (runtimeType != null) + { + MemberInfo result = runtimeType.GetDeclaredMemberWithSameMetadataDefinitionAs(member); + if (result != null) + return result; + runtimeType = runtimeType.BaseType as RuntimeTypeInfo; + } + throw new ArgumentException(SR.Format(SR.Arg_MemberInfoNotFound, member.Name), nameof(member)); + } + + private MemberInfo GetDeclaredMemberWithSameMetadataDefinitionAs(MemberInfo member) + { + return member.MemberType switch { MemberTypes.Method => QueryMemberWithSameMetadataDefinitionAs(member), MemberTypes.Constructor => QueryMemberWithSameMetadataDefinitionAs(member), @@ -133,11 +148,6 @@ public sealed override MemberInfo GetMemberWithSameMetadataDefinitionAs(MemberIn MemberTypes.NestedType => QueryMemberWithSameMetadataDefinitionAs(member), _ => null, }; - - if (result is null) - throw new ArgumentException(SR.Format(SR.Arg_MemberInfoNotFound, member.Name), nameof(member)); - - return result; } private M QueryMemberWithSameMetadataDefinitionAs(MemberInfo member) where M : MemberInfo diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index fb0bccb86c4708..24220a3513662f 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -1656,7 +1656,7 @@ private static (Type, Type) CreateGeneratedTypes() } [Theory, MemberData(nameof(GetMemberWithSameMetadataDefinitionAsData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/67533", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/69244", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public void GetMemberWithSameMetadataDefinitionAs(Type openGenericType, Type closedGenericType, bool checkDeclaringType) { BindingFlags all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 73d607611079d6..7e99ece4957a1f 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -379,6 +379,7 @@ + From 47c686b7ca154eb88915682177edb72de6c5921e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 13 May 2022 06:00:25 -0700 Subject: [PATCH 2/5] Validate the nativeaot library test is on --- src/libraries/System.Reflection/tests/TypeInfoTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index 24220a3513662f..33c6d121164ae2 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -1613,6 +1613,7 @@ public static IEnumerable SZArrayOrNotTypes() [Theory, MemberData(nameof(SZArrayOrNotTypes))] public void IsSZArray(Type type, bool expected) { + if (PlatformDetection.IsNativeAot) throw new ArgumentException("Temp validation to ensure nativeaot run is on the PR checks"); Assert.Equal(expected, type.GetTypeInfo().IsSZArray); } From ac1c231a599cf5e6f8112cd5bffadb28f4a1fd0b Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 13 May 2022 10:56:30 -0700 Subject: [PATCH 3/5] fail PR take 2 --- src/libraries/System.Reflection/tests/TypeInfoTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index 33c6d121164ae2..7271a592ff4ff4 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -1613,7 +1613,9 @@ public static IEnumerable SZArrayOrNotTypes() [Theory, MemberData(nameof(SZArrayOrNotTypes))] public void IsSZArray(Type type, bool expected) { - if (PlatformDetection.IsNativeAot) throw new ArgumentException("Temp validation to ensure nativeaot run is on the PR checks"); + // @TODO - remvove, checking native aot testing works by deliberately failing + if (PlatformDetection.IsNativeAot) + Assert.Equal(!expected, type.GetTypeInfo().IsSZArray); Assert.Equal(expected, type.GetTypeInfo().IsSZArray); } @@ -1657,7 +1659,7 @@ private static (Type, Type) CreateGeneratedTypes() } [Theory, MemberData(nameof(GetMemberWithSameMetadataDefinitionAsData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/69244", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + //[ActiveIssue("https://github.com/dotnet/runtime/issues/69244", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public void GetMemberWithSameMetadataDefinitionAs(Type openGenericType, Type closedGenericType, bool checkDeclaringType) { BindingFlags all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; From cc3b31289458ae8e0380eb69946493e649df1b6e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 13 May 2022 15:35:36 -0700 Subject: [PATCH 4/5] get reflection tests clean --- .../System.Reflection/tests/ConstructorInfoTests.cs | 1 + src/libraries/System.Reflection/tests/TypeInfoTests.cs | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs index e6d59b787cc564..c4990637fe85fa 100644 --- a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs +++ b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs @@ -115,6 +115,7 @@ public void Invoke_OneDimensionalArray() [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/67457", TestRuntimes.Mono)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/69336", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public void Invoke_OneDimensionalArray_NegativeLengths_ThrowsOverflowException() { ConstructorInfo[] constructors = GetConstructors(typeof(object[])); diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index 7271a592ff4ff4..24220a3513662f 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -1613,9 +1613,6 @@ public static IEnumerable SZArrayOrNotTypes() [Theory, MemberData(nameof(SZArrayOrNotTypes))] public void IsSZArray(Type type, bool expected) { - // @TODO - remvove, checking native aot testing works by deliberately failing - if (PlatformDetection.IsNativeAot) - Assert.Equal(!expected, type.GetTypeInfo().IsSZArray); Assert.Equal(expected, type.GetTypeInfo().IsSZArray); } @@ -1659,7 +1656,7 @@ private static (Type, Type) CreateGeneratedTypes() } [Theory, MemberData(nameof(GetMemberWithSameMetadataDefinitionAsData))] - //[ActiveIssue("https://github.com/dotnet/runtime/issues/69244", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/69244", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public void GetMemberWithSameMetadataDefinitionAs(Type openGenericType, Type closedGenericType, bool checkDeclaringType) { BindingFlags all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; From 945e1d5c4c7e038eb23cb20f8a57a3f4857cbeb4 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Sun, 15 May 2022 04:17:27 -0700 Subject: [PATCH 5/5] add doc info to test a library in native aot --- docs/workflow/building/coreclr/nativeaot.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/workflow/building/coreclr/nativeaot.md b/docs/workflow/building/coreclr/nativeaot.md index af4be7e7985952..4c9646a76d6d82 100644 --- a/docs/workflow/building/coreclr/nativeaot.md +++ b/docs/workflow/building/coreclr/nativeaot.md @@ -77,6 +77,9 @@ Sometimes it's handy to be able to rebuild the managed test manually or run the For more advanced scenarios, look for at [Building Test Subsets](../../testing/coreclr/windows-test-instructions.md#building-test-subsets) and [Generating Core_Root](../../testing/coreclr/windows-test-instructions.md#generating-core_root) +### Running library tests +Build library tests by passing the `libs.tests` subset together with the `/p:TestNativeAot=true` to build the libraries, i.e. `clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime+libs+libs.tests /p:TestNativeAot=true` together with the full arguments as specified [above](#building). Then, to run a specific library, go to the tests directory of the library and run the usual command to run tests for the library (see [Running tests for a single library](../../testing/libraries/testing.md#running-tests-for-a-single-library)) but add the `/p:TestNativeAot=true`, i.e. `dotnet.cmd build /t:Test /p:TestNativeAot=true`. + ## Design Documentation - [ILC Compiler Architecture](../../../design/coreclr/botr/ilc-architecture.md)