From ee180a0ac1ed5fa76b872ab726e07e10529c7739 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 7 Apr 2023 16:55:17 -0700 Subject: [PATCH 1/6] Fix running tests against our DNNE'd NativeExports project to work in NativeAOT. --- .../ComInterfaceGenerator.Tests.csproj | 11 +++++++---- .../tests/Directory.Build.targets | 12 ++++++++++++ .../LibraryImportGenerator.Tests.csproj | 6 +++--- src/libraries/tests.proj | 6 ------ 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/Directory.Build.targets diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj index b8947960debcab..e794d85c69ad0a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj @@ -7,19 +7,22 @@ true false - - None + true - + - + + + + + diff --git a/src/libraries/System.Runtime.InteropServices/tests/Directory.Build.targets b/src/libraries/System.Runtime.InteropServices/tests/Directory.Build.targets new file mode 100644 index 00000000000000..ea5e9f3215c7ea --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/Directory.Build.targets @@ -0,0 +1,12 @@ + + + None + true + + + + + + + + diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/LibraryImportGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/LibraryImportGenerator.Tests.csproj index 3f40e8de178306..9198556a0f0257 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/LibraryImportGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/LibraryImportGenerator.Tests.csproj @@ -1,17 +1,17 @@ - + $(NetCoreAppCurrent) true true false - None + true - + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 49751adfb7ecc3..ec83814b18d8ef 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -453,12 +453,6 @@ - - - - - - From b0c9529d8ca710515ca4db642481020d8f0cb62b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 13 Apr 2023 15:13:04 -0700 Subject: [PATCH 2/6] Remove duplicate items --- .../ComInterfaceGenerator.Tests.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj index e794d85c69ad0a..1196b8372f6d67 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ComInterfaceGenerator.Tests.csproj @@ -20,9 +20,5 @@ - - - - - + From 8f296766e0fca4a468937c75087302b5a2dacc69 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 Apr 2023 16:53:01 -0700 Subject: [PATCH 3/6] The memory allocated by AllocateTypeAssociatedMemory is expected to be zeroed (CoreCLR does this). The interop source generators depend on this behavior for lazy initialization. --- .../Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs index 7516c5be134ea6..21bb0f56946062 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs @@ -274,7 +274,10 @@ public static unsafe IntPtr AllocateTypeAssociatedMemory(Type type, int size) ArgumentOutOfRangeException.ThrowIfNegative(size); // We don't support unloading; the memory will never be freed. - return (IntPtr)NativeMemory.Alloc((uint)size); + void* mem = NativeMemory.Alloc((uint)size); + NativeMemory.Clear(mem, (uint)size); + + return (IntPtr)mem; } public static void PrepareDelegate(Delegate d) From d36716de7c997efa262a178c8bdd7e9af409ab84 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 Apr 2023 17:09:06 -0700 Subject: [PATCH 4/6] Update src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs Co-authored-by: Jan Kotas --- .../Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs index 21bb0f56946062..1048c76d583a06 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs @@ -274,10 +274,7 @@ public static unsafe IntPtr AllocateTypeAssociatedMemory(Type type, int size) ArgumentOutOfRangeException.ThrowIfNegative(size); // We don't support unloading; the memory will never be freed. - void* mem = NativeMemory.Alloc((uint)size); - NativeMemory.Clear(mem, (uint)size); - - return (IntPtr)mem; + return (IntPtr)NativeMemory.AllocZeroed((uint)size); } public static void PrepareDelegate(Delegate d) From 60882ba2a82125c189db3051b976ee846bed8df3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 17 Apr 2023 10:06:14 -0700 Subject: [PATCH 5/6] Assert that memory from RuntimeHelpers.AllocateTypeAssociatedMemory is zeroed. --- .../System/Runtime/CompilerServices/RuntimeHelpersTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs index bcfc405ca04ab2..12112f88e7718d 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs @@ -370,10 +370,12 @@ public static void AllocateTypeAssociatedMemoryInvalidArguments() [Fact] [SkipOnMono("Not presently implemented on Mono")] - public static void AllocateTypeAssociatedMemoryValidArguments() + public static unsafe void AllocateTypeAssociatedMemoryValidArguments() { IntPtr memory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(RuntimeHelpersTests), 32); Assert.NotEqual(memory, IntPtr.Zero); + // Validate that the memory is zeroed out + Assert.True(new Span((void*)memory, 32).SequenceEqual(new byte[32])); } [StructLayoutAttribute(LayoutKind.Sequential)] From 48cf6ba80bac08351ac53036a9aeef4d5fa790e2 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 18 Apr 2023 11:21:01 -0700 Subject: [PATCH 6/6] Exclude ComInterfaceGenerator tests on non-Windows. --- src/libraries/tests.proj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ec83814b18d8ef..29886d166cd762 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -453,6 +453,10 @@ + + +