Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorIvan Povazan <55002338+ivanpovazan@users.noreply.github.com>2022-06-01 19:09:22 +0300
committerGitHub <noreply@github.com>2022-06-01 19:09:22 +0300
commit549b4314c9ea92c124b5a8dc88a881f7fdc52274 (patch)
tree4a79191eea6538944bc462e5594639b2a222028c /src/tests
parent874f7aa355b7425fdded2cbcd9809255d62a745b (diff)
[mono] Support array parameter types of custom attributes in Mono AOT compiler (#69759)
- mono_reflection_create_custom_attr_data_args_noalloc now supports decoding array type parameters of custom attributes - mono_reflection_create_custom_attr_data_args_noalloc is refactored to use MonoDecodeCustomAttr - MonoDecodeCustomAttr encapsulates all the information of the decoded custom attribute parameters - initial support for UnmanagedCallConvAttribute: native-to-managed wrapper generation now takes into account applied custom attributes by updating the method's signature Fixes [#52977](https://github.com/dotnet/runtime/issues/52977)
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Interop/CMakeLists.txt1
-rw-r--r--src/tests/Interop/UnmanagedCallersOnly_MonoAot/CMakeLists.txt10
-rw-r--r--src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotDll.cpp17
-rw-r--r--src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.cs73
-rw-r--r--src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.csproj14
-rw-r--r--src/tests/issues.targets6
6 files changed, 121 insertions, 0 deletions
diff --git a/src/tests/Interop/CMakeLists.txt b/src/tests/Interop/CMakeLists.txt
index 2d9e84209b2..6d66d38a5a1 100644
--- a/src/tests/Interop/CMakeLists.txt
+++ b/src/tests/Interop/CMakeLists.txt
@@ -35,6 +35,7 @@ add_subdirectory(PInvoke/SafeHandles)
add_subdirectory(PInvoke/Vector2_3_4)
add_subdirectory(UnmanagedCallConv)
add_subdirectory(UnmanagedCallersOnly)
+add_subdirectory(UnmanagedCallersOnly_MonoAot)
add_subdirectory(PrimitiveMarshalling/Bool)
add_subdirectory(PrimitiveMarshalling/UIntPtr)
add_subdirectory(ArrayMarshalling/BoolArray)
diff --git a/src/tests/Interop/UnmanagedCallersOnly_MonoAot/CMakeLists.txt b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/CMakeLists.txt
new file mode 100644
index 00000000000..719a46c9fba
--- /dev/null
+++ b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/CMakeLists.txt
@@ -0,0 +1,10 @@
+project (UnmanagedCallersOnly_MonoAotDll)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+set(SOURCES UnmanagedCallersOnly_MonoAotDll.cpp )
+
+# add the executable
+add_library (UnmanagedCallersOnly_MonoAotDll SHARED ${SOURCES})
+target_link_libraries(UnmanagedCallersOnly_MonoAotDll ${LINK_LIBRARIES_ADDITIONAL})
+
+# add the install targets
+install (TARGETS UnmanagedCallersOnly_MonoAotDll DESTINATION bin)
diff --git a/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotDll.cpp b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotDll.cpp
new file mode 100644
index 00000000000..d3ead331faf
--- /dev/null
+++ b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotDll.cpp
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#include <platformdefines.h>
+
+typedef int (__stdcall *CALLBACKPROC_STDCALL)(int n);
+typedef int (__cdecl *CALLBACKPROC_CDECL)(int n);
+
+extern "C" DLL_EXPORT int STDMETHODCALLTYPE CallManagedProc_Stdcall(CALLBACKPROC_STDCALL pCallbackProc, int n)
+{
+ return pCallbackProc(n);
+}
+
+extern "C" DLL_EXPORT int STDMETHODCALLTYPE CallManagedProc_Cdecl(CALLBACKPROC_CDECL pCallbackProc, int n)
+{
+ return pCallbackProc(n);
+}
diff --git a/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.cs b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.cs
new file mode 100644
index 00000000000..60c7412307e
--- /dev/null
+++ b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.cs
@@ -0,0 +1,73 @@
+// 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 System.Collections.Generic;
+using System.Diagnostics;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Threading;
+using Xunit;
+
+// Stripped-down variant of Interop/UnmanagedCallersOnly/* test used for testing Mono AOT support for UnmanagedCallersOnly attribute
+public unsafe class Program
+{
+ public static class UnmanagedCallersOnly_MonoAotDll
+ {
+ [DllImport(nameof(UnmanagedCallersOnly_MonoAotDll))]
+ public static extern int CallManagedProc_Stdcall(delegate* unmanaged[Stdcall]<int, int> callbackProc, int n);
+
+ [DllImport(nameof(UnmanagedCallersOnly_MonoAotDll))]
+ public static extern int CallManagedProc_Cdecl(delegate* unmanaged[Cdecl]<int, int> callbackProc, int n);
+ }
+
+ public static int Main(string[] args)
+ {
+ var result = 100;
+
+ result += TestUnmanagedCallersOnlyValid_CallConvStdcall();
+ result += TestUnmanagedCallersOnlyValid_CallConvCdecl();
+
+ return result;
+ }
+
+ [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
+ public static int ManagedDoubleCallback_Stdcall(int n)
+ {
+ return DoubleImpl(n);
+ }
+
+ [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
+ public static int ManagedDoubleCallback_Cdecl(int n)
+ {
+ return DoubleImpl(n);
+ }
+
+ private static int DoubleImpl(int n)
+ {
+ return 2 * n;
+ }
+
+ public static int TestUnmanagedCallersOnlyValid_CallConvStdcall()
+ {
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_CallConvStdcall)}...");
+
+ int n = 12345;
+ int expected = DoubleImpl(n);
+ int actual = UnmanagedCallersOnly_MonoAotDll.CallManagedProc_Stdcall(&ManagedDoubleCallback_Stdcall, n);
+
+ return expected == actual ? 0 : -1;
+ }
+
+ public static int TestUnmanagedCallersOnlyValid_CallConvCdecl()
+ {
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_CallConvCdecl)}...");
+
+ int n = 12345;
+ int expected = DoubleImpl(n);
+ int actual = UnmanagedCallersOnly_MonoAotDll.CallManagedProc_Cdecl(&ManagedDoubleCallback_Cdecl, n);
+
+ return expected == actual ? 0 : -1;
+ }
+}
diff --git a/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.csproj b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.csproj
new file mode 100644
index 00000000000..8932cacf53f
--- /dev/null
+++ b/src/tests/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="UnmanagedCallersOnly_MonoAotTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <!-- This is needed to make sure native binary gets installed in the right location -->
+ <CMakeProjectReference Include="CMakeLists.txt" />
+ <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ </ItemGroup>
+</Project>
diff --git a/src/tests/issues.targets b/src/tests/issues.targets
index dc23d912237..f2ad66e9823 100644
--- a/src/tests/issues.targets
+++ b/src/tests/issues.targets
@@ -3363,6 +3363,9 @@
<ExcludeList Include = "$(XunitTestBinBase)/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest/**">
<Issue>https://github.com/dotnet/runtime/issues/41519</Issue>
</ExcludeList>
+ <ExcludeList Include = "$(XunitTestBinBase)/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest/**">
+ <Issue>https://github.com/dotnet/runtime/issues/41519</Issue>
+ </ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/CodeGenBringUpTests/LocallocLarge_d/**">
<Issue>https://github.com/dotnet/runtime/issues/41472</Issue>
</ExcludeList>
@@ -3726,6 +3729,9 @@
<ExcludeList Include = "$(XunitTestBinBase)/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest/**">
<Issue>needs triage</Issue>
</ExcludeList>
+ <ExcludeList Include = "$(XunitTestBinBase)/Interop/UnmanagedCallersOnly_MonoAot/UnmanagedCallersOnly_MonoAotTest/**">
+ <Issue>needs triage</Issue>
+ </ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/CheckProjects/CheckProjects/**">
<Issue>needs triage</Issue>
</ExcludeList>