diff --git a/src/coreclr/src/dlls/mscorrc/mscorrc.rc b/src/coreclr/src/dlls/mscorrc/mscorrc.rc index 00862c7cce68f6b0ad9369483997229d3f8e2dd0..327a5641741e6905e18be8e01047a55205be96e2 100644 --- a/src/coreclr/src/dlls/mscorrc/mscorrc.rc +++ b/src/coreclr/src/dlls/mscorrc/mscorrc.rc @@ -627,7 +627,7 @@ BEGIN IDS_EE_BADMARSHAL_NOTMARSHALABLE "The type definition of this field has layout information but has an invalid managed/unmanaged type combination or is unmarshalable." IDS_EE_BADMARSHAL_BADMETADATA "Invalid marshaling metadata." IDS_EE_BADMARSHAL_CUSTOMMARSHALER "Custom marshalers are only allowed on classes, strings, arrays, and boxed value types." - IDS_EE_BADMARSHAL_GENERICS_RESTRICTION "Generic types cannot be marshaled." + IDS_EE_BADMARSHAL_GENERICS_RESTRICTION "Non-blittable generic types cannot be marshaled." IDS_EE_BADMARSHAL_STRING_OUT "Cannot marshal a string by-value with the [Out] attribute." IDS_EE_BADMARSHALPARAM_STRINGBUILDER "Invalid managed/unmanaged type combination (StringBuilders must be paired with LPStr, LPWStr, or LPTStr)." diff --git a/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/IL/MarshalHelpers.cs index c605b6f14ce91e02bf6c65df4ed0d6eaf98bd4ae..fc857c30381be3ae3d572ec1b562903a6d91274a 100644 --- a/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/IL/MarshalHelpers.cs +++ b/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/IL/MarshalHelpers.cs @@ -334,13 +334,29 @@ public static partial class MarshalHelpers return MarshallerKind.Invalid; } - if (type.HasInstantiation) + bool isBlittable = MarshalUtils.IsBlittableType(type); + + // Blittable generics are allowed to be marshalled with the following exceptions: + // * ByReference: This represents an interior pointer and is not actually blittable + // * Nullable: We don't want to be locked into the default behavior as we may want special handling later + // * Vector64: Represents the __m64 ABI primitive which requires currently unimplemented handling + // * Vector128: Represents the __m128 ABI primitive which requires currently unimplemented handling + // * Vector256: Represents the __m256 ABI primitive which requires currently unimplemented handling + // * Vector: Has a variable size (either __m128 or __m256) and isn't readily usable for inteorp scenarios + + if (type.HasInstantiation && (!isBlittable + || InteropTypes.IsSystemByReference(context, type) + || InteropTypes.IsSystemNullable(context, type) + || InteropTypes.IsSystemRuntimeIntrinsicsVector64T(context, type) + || InteropTypes.IsSystemRuntimeIntrinsicsVector128T(context, type) + || InteropTypes.IsSystemRuntimeIntrinsicsVector256T(context, type) + || InteropTypes.IsSystemNumericsVectorT(context, type))) { // Generic types cannot be marshaled. return MarshallerKind.Invalid; } - if (MarshalUtils.IsBlittableType(type)) + if (isBlittable) { if (nativeType != NativeTypeKind.Default && nativeType != NativeTypeKind.Struct) return MarshallerKind.Invalid; diff --git a/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/InteropTypes.cs b/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/InteropTypes.cs index 63f2f2e1f2818fbf08c0e743f5223a1feb33a617..3e7d8156e3ddecd6e13ff786037e5f7fd420159b 100644 --- a/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/InteropTypes.cs +++ b/src/coreclr/src/tools/crossgen2/Common/TypeSystem/Interop/InteropTypes.cs @@ -108,6 +108,36 @@ public static bool IsSystemArgIterator(TypeSystemContext context, TypeDesc type) return IsCoreNamedType(context, type, "System", "ArgIterator"); } + public static bool IsSystemByReference(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System", "ByReference`1"); + } + + public static bool IsSystemNullable(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System", "Nullable`1"); + } + + public static bool IsSystemRuntimeIntrinsicsVector64T(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System.Runtime.Intrinsics", "Vector64`1"); + } + + public static bool IsSystemRuntimeIntrinsicsVector128T(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System.Runtime.Intrinsics", "Vector128`1"); + } + + public static bool IsSystemRuntimeIntrinsicsVector256T(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System.Runtime.Intrinsics", "Vector256`1"); + } + + public static bool IsSystemNumericsVectorT(TypeSystemContext context, TypeDesc type) + { + return IsCoreNamedType(context, type, "System.Numerics", "Vector`1"); + } + private static bool IsOrDerivesFromType(TypeDesc type, MetadataType targetType) { while (type != null) diff --git a/src/coreclr/src/vm/mlinfo.cpp b/src/coreclr/src/vm/mlinfo.cpp index 7b765d4e4f8865514365bf759c233decbd6c0937..f7f2a19a6ed5c3b6c1963b2dc3524c6ec7559adc 100644 --- a/src/coreclr/src/vm/mlinfo.cpp +++ b/src/coreclr/src/vm/mlinfo.cpp @@ -2796,7 +2796,25 @@ MarshalInfo::MarshalInfo(Module* pModule, } #endif // FEATURE_COMINTEROP - if (m_pMT->HasInstantiation()) + // Blittable generics are allowed to be marshalled with the following exceptions: + // * ByReference: This represents an interior pointer and is not actually blittable + // * Nullable: We don't want to be locked into the default behavior as we may want special handling later + // * Vector64: Represents the __m64 ABI primitive which requires currently unimplemented handling + // * Vector128: Represents the __m128 ABI primitive which requires currently unimplemented handling + // * Vector256: Represents the __m256 ABI primitive which requires currently unimplemented handling + // * Vector: Has a variable size (either __m128 or __m256) and isn't readily usable for inteorp scenarios + + if (m_pMT->HasInstantiation() && (!m_pMT->IsBlittable() + || m_pMT->HasSameTypeDefAs(g_pByReferenceClass) + || m_pMT->HasSameTypeDefAs(g_pNullableClass) + || m_pMT->HasSameTypeDefAs(MscorlibBinder::GetClass(CLASS__VECTOR64T)) + || m_pMT->HasSameTypeDefAs(MscorlibBinder::GetClass(CLASS__VECTOR128T)) + || m_pMT->HasSameTypeDefAs(MscorlibBinder::GetClass(CLASS__VECTOR256T)) +#ifndef CROSSGEN_COMPILE + // Crossgen scenarios block Vector from even being loaded + || m_pMT->HasSameTypeDefAs(MscorlibBinder::GetClass(CLASS__VECTORT)) +#endif // !CROSSGEN_COMPILE + )) { m_resID = IDS_EE_BADMARSHAL_GENERICS_RESTRICTION; IfFailGoto(E_FAIL, lFail); @@ -2916,7 +2934,7 @@ MarshalInfo::MarshalInfo(Module* pModule, if (m_ms != MARSHAL_SCENARIO_WINRT) #endif // FEATURE_COMINTEROP { - if (thElement.HasInstantiation()) + if (thElement.HasInstantiation() && !thElement.IsBlittable()) { m_resID = IDS_EE_BADMARSHAL_GENERICS_RESTRICTION; IfFailGoto(E_FAIL, lFail); diff --git a/src/coreclr/src/vm/mscorlib.h b/src/coreclr/src/vm/mscorlib.h index 5841cec9295144c07f5eef5091e2af2a2bca8cbf..575d92c4b7d05b75344c19b03bbd256a08e65579 100644 --- a/src/coreclr/src/vm/mscorlib.h +++ b/src/coreclr/src/vm/mscorlib.h @@ -499,6 +499,14 @@ DEFINE_FIELD(MARSHAL, SYSTEM_MAX_DBCS_CHAR_SIZE, SystemMax DEFINE_CLASS(NATIVELIBRARY, Interop, NativeLibrary) DEFINE_METHOD(NATIVELIBRARY, LOADLIBRARYCALLBACKSTUB, LoadLibraryCallbackStub, SM_Str_AssemblyBase_Bool_UInt_RetIntPtr) +DEFINE_CLASS(VECTOR64T, Intrinsics, Vector64`1) +DEFINE_CLASS(VECTOR128T, Intrinsics, Vector128`1) +DEFINE_CLASS(VECTOR256T, Intrinsics, Vector256`1) + +#ifndef CROSSGEN_COMPILE +DEFINE_CLASS(VECTORT, Numerics, Vector`1) +#endif // !CROSSGEN_COMPILE + DEFINE_CLASS(MEMBER, Reflection, MemberInfo) diff --git a/src/coreclr/src/vm/namespace.h b/src/coreclr/src/vm/namespace.h index 22a67f053c72bd9adbc5361cab40ae0ab79f1026..61943a96656a4a1369de08e4ed63f827a5e92e83 100644 --- a/src/coreclr/src/vm/namespace.h +++ b/src/coreclr/src/vm/namespace.h @@ -40,6 +40,7 @@ #endif // FEATURE_COMINTEROP #define g_IntrinsicsNS g_RuntimeNS ".Intrinsics" +#define g_NumericsNS g_SystemNS ".Numerics" #define g_InternalCompilerServicesNS "Internal.Runtime.CompilerServices" #define g_CompilerServicesNS g_RuntimeNS ".CompilerServices" diff --git a/src/coreclr/tests/src/Interop/CMakeLists.txt b/src/coreclr/tests/src/Interop/CMakeLists.txt index c2816c4951cf29985ea92ea89cf0a81f96dc577b..f85eff4c8f5ef0ec0542f2ad8d3a3e5f25499fd6 100644 --- a/src/coreclr/tests/src/Interop/CMakeLists.txt +++ b/src/coreclr/tests/src/Interop/CMakeLists.txt @@ -30,6 +30,7 @@ add_subdirectory(PInvoke/Miscellaneous/HandleRef) add_subdirectory(PInvoke/Miscellaneous/ThisCall) add_subdirectory(PInvoke/Miscellaneous/MultipleAssembliesWithSamePInvoke) add_subdirectory(PInvoke/CriticalHandles) +add_subdirectory(PInvoke/Generics) add_subdirectory(PInvoke/AsAny) add_subdirectory(PInvoke/SafeHandles) add_subdirectory(NativeCallable) diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/CMakeLists.txt b/src/coreclr/tests/src/Interop/PInvoke/Generics/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..60a39035ee19197f9fa6beb4c41cc02a49d30bfd --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/CMakeLists.txt @@ -0,0 +1,87 @@ +cmake_minimum_required (VERSION 2.6) +project (GenericsNative) +include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake") +if(CLR_CMAKE_TARGET_ARCH_I386) + add_definitions(-D_TARGET_X86_) + add_definitions(-D_TARGET_XARCH_) +elseif(CLR_CMAKE_TARGET_ARCH_AMD64) + add_definitions(-D_TARGET_AMD64_) + add_definitions(-D_TARGET_XARCH_) +elseif(CLR_CMAKE_TARGET_ARCH_ARM) + add_definitions(-D_TARGET_ARM_) + add_definitions(-D_TARGET_ARMARCH_) +elseif(CLR_CMAKE_TARGET_ARCH_ARM64) + add_definitions(-D_TARGET_ARM64_) + add_definitions(-D_TARGET_ARMARCH_) +endif() +set(SOURCES + GenericsNative.IUnknown.cpp + GenericsNative.NullableB.cpp + GenericsNative.NullableC.cpp + GenericsNative.NullableD.cpp + GenericsNative.NullableF.cpp + GenericsNative.NullableL.cpp + GenericsNative.NullableU.cpp + GenericsNative.Point1B.cpp + GenericsNative.Point1C.cpp + GenericsNative.Point1D.cpp + GenericsNative.Point1F.cpp + GenericsNative.Point1L.cpp + GenericsNative.Point1U.cpp + GenericsNative.Point2B.cpp + GenericsNative.Point2C.cpp + GenericsNative.Point2D.cpp + GenericsNative.Point2F.cpp + GenericsNative.Point2L.cpp + GenericsNative.Point2U.cpp + GenericsNative.Point3B.cpp + GenericsNative.Point3C.cpp + GenericsNative.Point3D.cpp + GenericsNative.Point3F.cpp + GenericsNative.Point3L.cpp + GenericsNative.Point3U.cpp + GenericsNative.Point4B.cpp + GenericsNative.Point4C.cpp + GenericsNative.Point4D.cpp + GenericsNative.Point4F.cpp + GenericsNative.Point4L.cpp + GenericsNative.Point4U.cpp + GenericsNative.SequentialClassB.cpp + GenericsNative.SequentialClassC.cpp + GenericsNative.SequentialClassD.cpp + GenericsNative.SequentialClassF.cpp + GenericsNative.SequentialClassL.cpp + GenericsNative.SequentialClassU.cpp + GenericsNative.SpanB.cpp + GenericsNative.SpanC.cpp + GenericsNative.SpanD.cpp + GenericsNative.SpanF.cpp + GenericsNative.SpanL.cpp + GenericsNative.SpanU.cpp + GenericsNative.Vector64B.cpp + GenericsNative.Vector64C.cpp + GenericsNative.Vector64D.cpp + GenericsNative.Vector64F.cpp + GenericsNative.Vector64L.cpp + GenericsNative.Vector64U.cpp + GenericsNative.Vector128B.cpp + GenericsNative.Vector128C.cpp + GenericsNative.Vector128D.cpp + GenericsNative.Vector128F.cpp + GenericsNative.Vector128L.cpp + GenericsNative.Vector128U.cpp + GenericsNative.Vector256B.cpp + GenericsNative.Vector256C.cpp + GenericsNative.Vector256D.cpp + GenericsNative.Vector256F.cpp + GenericsNative.Vector256L.cpp + GenericsNative.Vector256U.cpp + GenericsNative.VectorB.cpp + GenericsNative.VectorC.cpp + GenericsNative.VectorD.cpp + GenericsNative.VectorF.cpp + GenericsNative.VectorL.cpp + GenericsNative.VectorU.cpp +) +add_library (GenericsNative SHARED ${SOURCES}) +install (TARGETS GenericsNative DESTINATION bin) diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.IUnknown.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.IUnknown.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5788e51d7203f90c8d72cd75505c664d3697857 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.IUnknown.cpp @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +extern "C" DLL_EXPORT IUnknown* STDMETHODCALLTYPE GetIComInterface() +{ + throw "P/Invoke for IComInterface should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetIComInterfaceOut(IUnknown** pValue) +{ + throw "P/Invoke for IComInterface should be unsupported."; +} + +extern "C" DLL_EXPORT const IUnknown** STDMETHODCALLTYPE GetIComInterfacePtr() +{ + throw "P/Invoke for IComInterface should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetIComInterfaces(IUnknown** pValues, int count) +{ + throw "P/Invoke for IComInterface should be unsupported."; +} + diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableB.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9b07c1992a7af20a873c224a324aa2a0b7913fa --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableB.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableB +{ + bool hasValue; + bool value; +}; + +static NullableB NullableBValue = { }; + +extern "C" DLL_EXPORT NullableB STDMETHODCALLTYPE GetNullableB(bool hasValue, bool value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableBOut(bool hasValue, bool value, NullableB* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableB* STDMETHODCALLTYPE GetNullableBPtr(bool hasValue, bool value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableB STDMETHODCALLTYPE AddNullableB(NullableB lhs, NullableB rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableB STDMETHODCALLTYPE AddNullableBs(const NullableB* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableC.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a71912ca1806d2a89c973452462f372d32e7068d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableC.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableC +{ + bool hasValue; + char16_t value; +}; + +static NullableC NullableCValue = { }; + +extern "C" DLL_EXPORT NullableC STDMETHODCALLTYPE GetNullableC(bool hasValue, char16_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableCOut(bool hasValue, char16_t value, NullableC* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableC* STDMETHODCALLTYPE GetNullableCPtr(bool hasValue, char16_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableC STDMETHODCALLTYPE AddNullableC(NullableC lhs, NullableC rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableC STDMETHODCALLTYPE AddNullableCs(const NullableC* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableD.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..28e76cd1c4bd9f5398e16aa44c721452af7e75ce --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableD.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableD +{ + bool hasValue; + double value; +}; + +static NullableD NullableDValue = { }; + +extern "C" DLL_EXPORT NullableD STDMETHODCALLTYPE GetNullableD(bool hasValue, double value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableDOut(bool hasValue, double value, NullableD* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableD* STDMETHODCALLTYPE GetNullableDPtr(bool hasValue, double value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableD STDMETHODCALLTYPE AddNullableD(NullableD lhs, NullableD rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableD STDMETHODCALLTYPE AddNullableDs(const NullableD* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableF.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e29e0214cb24845c276c3bf7e22c16de3924c03 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableF.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableF +{ + bool hasValue; + float value; +}; + +static NullableF NullableFValue = { }; + +extern "C" DLL_EXPORT NullableF STDMETHODCALLTYPE GetNullableF(bool hasValue, float value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableFOut(bool hasValue, float value, NullableF* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableF* STDMETHODCALLTYPE GetNullableFPtr(bool hasValue, float value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableF STDMETHODCALLTYPE AddNullableF(NullableF lhs, NullableF rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableF STDMETHODCALLTYPE AddNullableFs(const NullableF* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableL.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d780e309075e7eb5ba2fdea3d435ae6e1a9312f --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableL.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableL +{ + bool hasValue; + int64_t value; +}; + +static NullableL NullableLValue = { }; + +extern "C" DLL_EXPORT NullableL STDMETHODCALLTYPE GetNullableL(bool hasValue, int64_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableLOut(bool hasValue, int64_t value, NullableL* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableL* STDMETHODCALLTYPE GetNullableLPtr(bool hasValue, int64_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableL STDMETHODCALLTYPE AddNullableL(NullableL lhs, NullableL rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableL STDMETHODCALLTYPE AddNullableLs(const NullableL* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableU.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c88ab8f89e32aed4aa87328b0387d9ab3d3f3a7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.NullableU.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct NullableU +{ + bool hasValue; + uint32_t value; +}; + +static NullableU NullableUValue = { }; + +extern "C" DLL_EXPORT NullableU STDMETHODCALLTYPE GetNullableU(bool hasValue, uint32_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetNullableUOut(bool hasValue, uint32_t value, NullableU* pValue) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT const NullableU* STDMETHODCALLTYPE GetNullableUPtr(bool hasValue, uint32_t value) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableU STDMETHODCALLTYPE AddNullableU(NullableU lhs, NullableU rhs) +{ + throw "P/Invoke for Nullable should be unsupported."; +} + +extern "C" DLL_EXPORT NullableU STDMETHODCALLTYPE AddNullableUs(const NullableU* pValues, uint32_t count) +{ + throw "P/Invoke for Nullable should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24ff26404248c95f90e2ba1bd48037838c51467e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1B.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1B +{ + bool e00; +}; + +static Point1B Point1BValue = { }; + +extern "C" DLL_EXPORT Point1B STDMETHODCALLTYPE GetPoint1B(bool e00) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1BOut(bool e00, Point1B* pValue) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point1B* STDMETHODCALLTYPE GetPoint1BPtr(bool e00) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT Point1B STDMETHODCALLTYPE AddPoint1B(Point1B lhs, Point1B rhs) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT Point1B STDMETHODCALLTYPE AddPoint1Bs(const Point1B* pValues, uint32_t count) +{ + throw "P/Invoke for Point1 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18f417ad329616d026a70acb4b5a577f00e5d377 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1C.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1C +{ + char16_t e00; +}; + +static Point1C Point1CValue = { }; + +extern "C" DLL_EXPORT Point1C STDMETHODCALLTYPE GetPoint1C(char16_t e00) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1COut(char16_t e00, Point1C* pValue) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point1C* STDMETHODCALLTYPE GetPoint1CPtr(char16_t e00) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT Point1C STDMETHODCALLTYPE AddPoint1C(Point1C lhs, Point1C rhs) +{ + throw "P/Invoke for Point1 should be unsupported."; +} + +extern "C" DLL_EXPORT Point1C STDMETHODCALLTYPE AddPoint1Cs(const Point1C* pValues, uint32_t count) +{ + throw "P/Invoke for Point1 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..26589a6425906d37e3d70fe481f12b969b0296b7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1D.cpp @@ -0,0 +1,51 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1D +{ + double e00; +}; + +static Point1D Point1DValue = { }; + +extern "C" DLL_EXPORT Point1D STDMETHODCALLTYPE GetPoint1D(double e00) +{ + return { e00 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1DOut(double e00, Point1D* pValue) +{ + *pValue = GetPoint1D(e00); +} + +extern "C" DLL_EXPORT const Point1D* STDMETHODCALLTYPE GetPoint1DPtr(double e00) +{ + GetPoint1DOut(e00, &Point1DValue); + return &Point1DValue; +} + +extern "C" DLL_EXPORT Point1D STDMETHODCALLTYPE AddPoint1D(Point1D lhs, Point1D rhs) +{ + return { lhs.e00 + rhs.e00 }; +} + +extern "C" DLL_EXPORT Point1D STDMETHODCALLTYPE AddPoint1Ds(const Point1D* pValues, uint32_t count) +{ + Point1D result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint1D(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e5b974754c7b1f1ed8734f96b571b16ba051a63 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1F.cpp @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1F +{ + float e00; +}; + +static Point1F Point1FValue = { }; + +extern "C" DLL_EXPORT Point1F STDMETHODCALLTYPE GetPoint1F(float e00) +{ + return { e00 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1FOut(float e00, Point1F* pValue) +{ + *pValue = GetPoint1F(e00); +} + +extern "C" DLL_EXPORT const Point1F* STDMETHODCALLTYPE GetPoint1FPtr(float e00) +{ + GetPoint1FOut(e00, &Point1FValue); + return &Point1FValue; +} + +extern "C" DLL_EXPORT Point1F STDMETHODCALLTYPE AddPoint1F(Point1F lhs, Point1F rhs) +{ + return { lhs.e00 + rhs.e00 }; +} + +extern "C" DLL_EXPORT Point1F STDMETHODCALLTYPE AddPoint1Fs(const Point1F* pValues, uint32_t count) +{ + Point1F result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint1F(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b70845fc412d420631d027d30b08566dd039c62 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1L.cpp @@ -0,0 +1,51 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1L +{ + int64_t e00; +}; + +static Point1L Point1LValue = { }; + +extern "C" DLL_EXPORT Point1L STDMETHODCALLTYPE GetPoint1L(int64_t e00) +{ + return { e00 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1LOut(int64_t e00, Point1L* pValue) +{ + *pValue = GetPoint1L(e00); +} + +extern "C" DLL_EXPORT const Point1L* STDMETHODCALLTYPE GetPoint1LPtr(int64_t e00) +{ + GetPoint1LOut(e00, &Point1LValue); + return &Point1LValue; +} + +extern "C" DLL_EXPORT Point1L STDMETHODCALLTYPE AddPoint1L(Point1L lhs, Point1L rhs) +{ + return { lhs.e00 + rhs.e00 }; +} + +extern "C" DLL_EXPORT Point1L STDMETHODCALLTYPE AddPoint1Ls(const Point1L* pValues, uint32_t count) +{ + Point1L result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint1L(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14527df71bd4bc9c945c21d0fbb7649c52486c62 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point1U.cpp @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point1U +{ + uint32_t e00; +}; + +static Point1U Point1UValue = { }; + +extern "C" DLL_EXPORT Point1U STDMETHODCALLTYPE GetPoint1U(uint32_t e00) +{ + return { e00 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint1UOut(uint32_t e00, Point1U* pValue) +{ + *pValue = GetPoint1U(e00); +} + +extern "C" DLL_EXPORT const Point1U* STDMETHODCALLTYPE GetPoint1UPtr(uint32_t e00) +{ + GetPoint1UOut(e00, &Point1UValue); + return &Point1UValue; +} + +extern "C" DLL_EXPORT Point1U STDMETHODCALLTYPE AddPoint1U(Point1U lhs, Point1U rhs) +{ + return { lhs.e00 + rhs.e00 }; +} + +extern "C" DLL_EXPORT Point1U STDMETHODCALLTYPE AddPoint1Us(const Point1U* pValues, uint32_t count) +{ + Point1U result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint1U(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c0ea62ad868670bf2657cf78fdc6749dc47357a --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2B.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2B +{ + bool e00; + bool e01; +}; + +static Point2B Point2BValue = { }; + +extern "C" DLL_EXPORT Point2B STDMETHODCALLTYPE GetPoint2B(bool e00, bool e01) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2BOut(bool e00, bool e01, Point2B* pValue) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point2B* STDMETHODCALLTYPE GetPoint2BPtr(bool e00, bool e01) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT Point2B STDMETHODCALLTYPE AddPoint2B(Point2B lhs, Point2B rhs) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT Point2B STDMETHODCALLTYPE AddPoint2Bs(const Point2B* pValues, uint32_t count) +{ + throw "P/Invoke for Point2 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e87050be7182887ff04d4370e9204221e8fff8be --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2C.cpp @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2C +{ + char16_t e00; + char16_t e01; +}; + +static Point2C Point2CValue = { }; + +extern "C" DLL_EXPORT Point2C STDMETHODCALLTYPE GetPoint2C(char16_t e00, char16_t e01) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2COut(char16_t e00, char16_t e01, Point2C* pValue) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point2C* STDMETHODCALLTYPE GetPoint2CPtr(char16_t e00, char16_t e01) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT Point2C STDMETHODCALLTYPE AddPoint2C(Point2C lhs, Point2C rhs) +{ + throw "P/Invoke for Point2 should be unsupported."; +} + +extern "C" DLL_EXPORT Point2C STDMETHODCALLTYPE AddPoint2Cs(const Point2C* pValues, uint32_t count) +{ + throw "P/Invoke for Point2 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13fec89a0f5d2b53e3bd34ed8412108642083f94 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2D.cpp @@ -0,0 +1,55 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2D +{ + double e00; + double e01; +}; + +static Point2D Point2DValue = { }; + +extern "C" DLL_EXPORT Point2D STDMETHODCALLTYPE GetPoint2D(double e00, double e01) +{ + return { e00, e01 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2DOut(double e00, double e01, Point2D* pValue) +{ + *pValue = GetPoint2D(e00, e01); +} + +extern "C" DLL_EXPORT const Point2D* STDMETHODCALLTYPE GetPoint2DPtr(double e00, double e01) +{ + GetPoint2DOut(e00, e01, &Point2DValue); + return &Point2DValue; +} + +extern "C" DLL_EXPORT Point2D STDMETHODCALLTYPE AddPoint2D(Point2D lhs, Point2D rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01 + }; +} + +extern "C" DLL_EXPORT Point2D STDMETHODCALLTYPE AddPoint2Ds(const Point2D* pValues, uint32_t count) +{ + Point2D result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint2D(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c22aa6158d5035f733582f03e8e15d4ebc44aecb --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2F.cpp @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2F +{ + float e00; + float e01; +}; + +static Point2F Point2FValue = { }; + +extern "C" DLL_EXPORT Point2F STDMETHODCALLTYPE GetPoint2F(float e00, float e01) +{ + return { e00, e01 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2FOut(float e00, float e01, Point2F* pValue) +{ + *pValue = GetPoint2F(e00, e01); +} + +extern "C" DLL_EXPORT const Point2F* STDMETHODCALLTYPE GetPoint2FPtr(float e00, float e01) +{ + GetPoint2FOut(e00, e01, &Point2FValue); + return &Point2FValue; +} + +extern "C" DLL_EXPORT Point2F STDMETHODCALLTYPE AddPoint2F(Point2F lhs, Point2F rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01 + }; +} + +extern "C" DLL_EXPORT Point2F STDMETHODCALLTYPE AddPoint2Fs(const Point2F* pValues, uint32_t count) +{ + Point2F result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint2F(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef6555d0d8125e82dc32c09ac0308673a750cfb7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2L.cpp @@ -0,0 +1,55 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2L +{ + int64_t e00; + int64_t e01; +}; + +static Point2L Point2LValue = { }; + +extern "C" DLL_EXPORT Point2L STDMETHODCALLTYPE GetPoint2L(int64_t e00, int64_t e01) +{ + return { e00, e01 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2LOut(int64_t e00, int64_t e01, Point2L* pValue) +{ + *pValue = GetPoint2L(e00, e01); +} + +extern "C" DLL_EXPORT const Point2L* STDMETHODCALLTYPE GetPoint2LPtr(int64_t e00, int64_t e01) +{ + GetPoint2LOut(e00, e01, &Point2LValue); + return &Point2LValue; +} + +extern "C" DLL_EXPORT Point2L STDMETHODCALLTYPE AddPoint2L(Point2L lhs, Point2L rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01 + }; +} + +extern "C" DLL_EXPORT Point2L STDMETHODCALLTYPE AddPoint2Ls(const Point2L* pValues, uint32_t count) +{ + Point2L result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint2L(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e36d7e16b1e0ccea97c2059c6695199a6843bd6 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point2U.cpp @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point2U +{ + uint32_t e00; + uint32_t e01; +}; + +static Point2U Point2UValue = { }; + +extern "C" DLL_EXPORT Point2U STDMETHODCALLTYPE GetPoint2U(uint32_t e00, uint32_t e01) +{ + return { e00, e01 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint2UOut(uint32_t e00, uint32_t e01, Point2U* pValue) +{ + *pValue = GetPoint2U(e00, e01); +} + +extern "C" DLL_EXPORT const Point2U* STDMETHODCALLTYPE GetPoint2UPtr(uint32_t e00, uint32_t e01) +{ + GetPoint2UOut(e00, e01, &Point2UValue); + return &Point2UValue; +} + +extern "C" DLL_EXPORT Point2U STDMETHODCALLTYPE AddPoint2U(Point2U lhs, Point2U rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01 + }; +} + +extern "C" DLL_EXPORT Point2U STDMETHODCALLTYPE AddPoint2Us(const Point2U* pValues, uint32_t count) +{ + Point2U result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint2U(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7e90e714e449bfe2ea48319155c5449015fd2a9 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3B.cpp @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3B +{ + bool e00; + bool e01; + bool e02; +}; + +static Point3B Point3BValue = { }; + +extern "C" DLL_EXPORT Point3B STDMETHODCALLTYPE GetPoint3B(bool e00, bool e01, bool e02) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3BOut(bool e00, bool e01, bool e02, Point3B* pValue) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point3B* STDMETHODCALLTYPE GetPoint3BPtr(bool e00, bool e01, bool e02) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT Point3B STDMETHODCALLTYPE AddPoint3B(Point3B lhs, Point3B rhs) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT Point3B STDMETHODCALLTYPE AddPoint3Bs(const Point3B* pValues, uint32_t count) +{ + throw "P/Invoke for Point3 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2601db3a51c4061c8ee2bbe543193c305348fa66 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3C.cpp @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3C +{ + char16_t e00; + char16_t e01; + char16_t e02; +}; + +static Point3C Point3CValue = { }; + +extern "C" DLL_EXPORT Point3C STDMETHODCALLTYPE GetPoint3C(char16_t e00, char16_t e01, char16_t e02) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3COut(char16_t e00, char16_t e01, char16_t e02, Point3C* pValue) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point3C* STDMETHODCALLTYPE GetPoint3CPtr(char16_t e00, char16_t e01, char16_t e02) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT Point3C STDMETHODCALLTYPE AddPoint3C(Point3C lhs, Point3C rhs) +{ + throw "P/Invoke for Point3 should be unsupported."; +} + +extern "C" DLL_EXPORT Point3C STDMETHODCALLTYPE AddPoint3Cs(const Point3C* pValues, uint32_t count) +{ + throw "P/Invoke for Point3 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3ad8211cbd9385ca0aa0efb52f2298581054540 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3D.cpp @@ -0,0 +1,57 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3D +{ + double e00; + double e01; + double e02; +}; + +static Point3D Point3DValue = { }; + +extern "C" DLL_EXPORT Point3D STDMETHODCALLTYPE GetPoint3D(double e00, double e01, double e02) +{ + return { e00, e01, e02 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3DOut(double e00, double e01, double e02, Point3D* pValue) +{ + *pValue = GetPoint3D(e00, e01, e02); +} + +extern "C" DLL_EXPORT const Point3D* STDMETHODCALLTYPE GetPoint3DPtr(double e00, double e01, double e02) +{ + GetPoint3DOut(e00, e01, e02, &Point3DValue); + return &Point3DValue; +} + +extern "C" DLL_EXPORT Point3D STDMETHODCALLTYPE AddPoint3D(Point3D lhs, Point3D rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02 + }; +} + +extern "C" DLL_EXPORT Point3D STDMETHODCALLTYPE AddPoint3Ds(const Point3D* pValues, uint32_t count) +{ + Point3D result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint3D(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b5903acaf59097e8a5a3e61cef168c64b97974e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3F.cpp @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3F +{ + float e00; + float e01; + float e02; +}; + +static Point3F Point3FValue = { }; + +extern "C" DLL_EXPORT Point3F STDMETHODCALLTYPE GetPoint3F(float e00, float e01, float e02) +{ + return { e00, e01, e02 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3FOut(float e00, float e01, float e02, Point3F* pValue) +{ + *pValue = GetPoint3F(e00, e01, e02); +} + +extern "C" DLL_EXPORT const Point3F* STDMETHODCALLTYPE GetPoint3FPtr(float e00, float e01, float e02) +{ + GetPoint3FOut(e00, e01, e02, &Point3FValue); + return &Point3FValue; +} + +extern "C" DLL_EXPORT Point3F STDMETHODCALLTYPE AddPoint3F(Point3F lhs, Point3F rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02 + }; +} + +extern "C" DLL_EXPORT Point3F STDMETHODCALLTYPE AddPoint3Fs(const Point3F* pValues, uint32_t count) +{ + Point3F result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint3F(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88ac7df78aee429908c88e178c8719ee47d22841 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3L.cpp @@ -0,0 +1,57 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3L +{ + int64_t e00; + int64_t e01; + int64_t e02; +}; + +static Point3L Point3LValue = { }; + +extern "C" DLL_EXPORT Point3L STDMETHODCALLTYPE GetPoint3L(int64_t e00, int64_t e01, int64_t e02) +{ + return { e00, e01, e02 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3LOut(int64_t e00, int64_t e01, int64_t e02, Point3L* pValue) +{ + *pValue = GetPoint3L(e00, e01, e02); +} + +extern "C" DLL_EXPORT const Point3L* STDMETHODCALLTYPE GetPoint3LPtr(int64_t e00, int64_t e01, int64_t e02) +{ + GetPoint3LOut(e00, e01, e02, &Point3LValue); + return &Point3LValue; +} + +extern "C" DLL_EXPORT Point3L STDMETHODCALLTYPE AddPoint3L(Point3L lhs, Point3L rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02 + }; +} + +extern "C" DLL_EXPORT Point3L STDMETHODCALLTYPE AddPoint3Ls(const Point3L* pValues, uint32_t count) +{ + Point3L result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint3L(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..271906b1aea0b80b79d33cf2e7d93fbf0e6bc8f8 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point3U.cpp @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point3U +{ + uint32_t e00; + uint32_t e01; + uint32_t e02; +}; + +static Point3U Point3UValue = { }; + +extern "C" DLL_EXPORT Point3U STDMETHODCALLTYPE GetPoint3U(uint32_t e00, uint32_t e01, uint32_t e02) +{ + return { e00, e01, e02 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint3UOut(uint32_t e00, uint32_t e01, uint32_t e02, Point3U* pValue) +{ + *pValue = GetPoint3U(e00, e01, e02); +} + +extern "C" DLL_EXPORT const Point3U* STDMETHODCALLTYPE GetPoint3UPtr(uint32_t e00, uint32_t e01, uint32_t e02) +{ + GetPoint3UOut(e00, e01, e02, &Point3UValue); + return &Point3UValue; +} + +extern "C" DLL_EXPORT Point3U STDMETHODCALLTYPE AddPoint3U(Point3U lhs, Point3U rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02 + }; +} + +extern "C" DLL_EXPORT Point3U STDMETHODCALLTYPE AddPoint3Us(const Point3U* pValues, uint32_t count) +{ + Point3U result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint3U(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57b45fdb0319e3a9febd3687d19e57cc5a9c8aad --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4B.cpp @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4B +{ + bool e00; + bool e01; + bool e02; + bool e03; +}; + +static Point4B Point4BValue = { }; + +extern "C" DLL_EXPORT Point4B STDMETHODCALLTYPE GetPoint4B(bool e00, bool e01, bool e02, bool e03) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4BOut(bool e00, bool e01, bool e02, bool e03, Point4B* pValue) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point4B* STDMETHODCALLTYPE GetPoint4BPtr(bool e00, bool e01, bool e02, bool e03) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT Point4B STDMETHODCALLTYPE AddPoint4B(Point4B lhs, Point4B rhs) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT Point4B STDMETHODCALLTYPE AddPoint4Bs(const Point4B* pValues, uint32_t count) +{ + throw "P/Invoke for Point4 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd4f95ce83f0c366a8038c8889e22c6d924fb9d3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4C.cpp @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4C +{ + char16_t e00; + char16_t e01; + char16_t e02; + char16_t e03; +}; + +static Point4C Point4CValue = { }; + +extern "C" DLL_EXPORT Point4C STDMETHODCALLTYPE GetPoint4C(char16_t e00, char16_t e01, char16_t e02, char16_t e03) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4COut(char16_t e00, char16_t e01, char16_t e02, char16_t e03, Point4C* pValue) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT const Point4C* STDMETHODCALLTYPE GetPoint4CPtr(char16_t e00, char16_t e01, char16_t e02, char16_t e03) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT Point4C STDMETHODCALLTYPE AddPoint4C(Point4C lhs, Point4C rhs) +{ + throw "P/Invoke for Point4 should be unsupported."; +} + +extern "C" DLL_EXPORT Point4C STDMETHODCALLTYPE AddPoint4Cs(const Point4C* pValues, uint32_t count) +{ + throw "P/Invoke for Point4 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2983afb0d257765156037c551ebd7464dbf042f0 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4D.cpp @@ -0,0 +1,59 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4D +{ + double e00; + double e01; + double e02; + double e03; +}; + +static Point4D Point4DValue = { }; + +extern "C" DLL_EXPORT Point4D STDMETHODCALLTYPE GetPoint4D(double e00, double e01, double e02, double e03) +{ + return { e00, e01, e02, e03 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4DOut(double e00, double e01, double e02, double e03, Point4D* pValue) +{ + *pValue = GetPoint4D(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const Point4D* STDMETHODCALLTYPE GetPoint4DPtr(double e00, double e01, double e02, double e03) +{ + GetPoint4DOut(e00, e01, e02, e03, &Point4DValue); + return &Point4DValue; +} + +extern "C" DLL_EXPORT Point4D STDMETHODCALLTYPE AddPoint4D(Point4D lhs, Point4D rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02, + lhs.e03 + rhs.e03 + }; +} + +extern "C" DLL_EXPORT Point4D STDMETHODCALLTYPE AddPoint4Ds(const Point4D* pValues, uint32_t count) +{ + Point4D result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint4D(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1fb6fe3da7cde207ede0d57295b0268631c2d935 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4F.cpp @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4F +{ + float e00; + float e01; + float e02; + float e03; +}; + +static Point4F Point4FValue = { }; + +extern "C" DLL_EXPORT Point4F STDMETHODCALLTYPE GetPoint4F(float e00, float e01, float e02, float e03) +{ + return { e00, e01, e02, e03 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4FOut(float e00, float e01, float e02, float e03, Point4F* pValue) +{ + *pValue = GetPoint4F(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const Point4F* STDMETHODCALLTYPE GetPoint4FPtr(float e00, float e01, float e02, float e03) +{ + GetPoint4FOut(e00, e01, e02, e03, &Point4FValue); + return &Point4FValue; +} + +extern "C" DLL_EXPORT Point4F STDMETHODCALLTYPE AddPoint4F(Point4F lhs, Point4F rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02, + lhs.e03 + rhs.e03 + }; +} + +extern "C" DLL_EXPORT Point4F STDMETHODCALLTYPE AddPoint4Fs(const Point4F* pValues, uint32_t count) +{ + Point4F result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint4F(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..950d107bd73e8e4f3340ce8fa5aa4ad4e6332536 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4L.cpp @@ -0,0 +1,59 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4L +{ + int64_t e00; + int64_t e01; + int64_t e02; + int64_t e03; +}; + +static Point4L Point4LValue = { }; + +extern "C" DLL_EXPORT Point4L STDMETHODCALLTYPE GetPoint4L(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + return { e00, e01, e02, e03 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4LOut(int64_t e00, int64_t e01, int64_t e02, int64_t e03, Point4L* pValue) +{ + *pValue = GetPoint4L(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const Point4L* STDMETHODCALLTYPE GetPoint4LPtr(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + GetPoint4LOut(e00, e01, e02, e03, &Point4LValue); + return &Point4LValue; +} + +extern "C" DLL_EXPORT Point4L STDMETHODCALLTYPE AddPoint4L(Point4L lhs, Point4L rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02, + lhs.e03 + rhs.e03 + }; +} + +extern "C" DLL_EXPORT Point4L STDMETHODCALLTYPE AddPoint4Ls(const Point4L* pValues, uint32_t count) +{ + Point4L result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint4L(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ebc45f28f59e604656e045664ed1113fa0cb9a0 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Point4U.cpp @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct Point4U +{ + uint32_t e00; + uint32_t e01; + uint32_t e02; + uint32_t e03; +}; + +static Point4U Point4UValue = { }; + +extern "C" DLL_EXPORT Point4U STDMETHODCALLTYPE GetPoint4U(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + return { e00, e01, e02, e03 }; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetPoint4UOut(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, Point4U* pValue) +{ + *pValue = GetPoint4U(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const Point4U* STDMETHODCALLTYPE GetPoint4UPtr(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + GetPoint4UOut(e00, e01, e02, e03, &Point4UValue); + return &Point4UValue; +} + +extern "C" DLL_EXPORT Point4U STDMETHODCALLTYPE AddPoint4U(Point4U lhs, Point4U rhs) +{ + return { + lhs.e00 + rhs.e00, + lhs.e01 + rhs.e01, + lhs.e02 + rhs.e02, + lhs.e03 + rhs.e03 + }; +} + +extern "C" DLL_EXPORT Point4U STDMETHODCALLTYPE AddPoint4Us(const Point4U* pValues, uint32_t count) +{ + Point4U result = { }; + + if (pValues != nullptr) + { + for (uint32_t i = 0; i < count; i++) + { + result = AddPoint4U(result, pValues[i]); + } + } + + return result; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassB.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8716e6c6e4782ed30d3c4d1fb3d6fcaeb8fc4c15 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassB.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassB +{ + bool value; +}; + +static SequentialClassB SequentialClassBValue = { }; + +extern "C" DLL_EXPORT SequentialClassB* STDMETHODCALLTYPE GetSequentialClassB(bool value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassBOut(bool value, SequentialClassB** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassB** STDMETHODCALLTYPE GetSequentialClassBPtr(bool value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassB* STDMETHODCALLTYPE AddSequentialClassB(SequentialClassB* lhs, SequentialClassB* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassB* STDMETHODCALLTYPE AddSequentialClassBs(const SequentialClassB** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassC.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c13f9758e04014683e486eb1e927701541d77593 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassC.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassC +{ + char16_t value; +}; + +static SequentialClassC SequentialClassCValue = { }; + +extern "C" DLL_EXPORT SequentialClassC* STDMETHODCALLTYPE GetSequentialClassC(char16_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassCOut(char16_t value, SequentialClassC** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassC** STDMETHODCALLTYPE GetSequentialClassCPtr(char16_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassC* STDMETHODCALLTYPE AddSequentialClassC(SequentialClassC* lhs, SequentialClassC* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassC* STDMETHODCALLTYPE AddSequentialClassCs(const SequentialClassC** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassD.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..704a86860546594e5dab79178b86608d657f5ec5 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassD.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassD +{ + double value; +}; + +static SequentialClassD SequentialClassDValue = { }; + +extern "C" DLL_EXPORT SequentialClassD* STDMETHODCALLTYPE GetSequentialClassD(double value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassDOut(double value, SequentialClassD** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassD** STDMETHODCALLTYPE GetSequentialClassDPtr(double value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassD* STDMETHODCALLTYPE AddSequentialClassD(SequentialClassD* lhs, SequentialClassD* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassD* STDMETHODCALLTYPE AddSequentialClassDs(const SequentialClassD** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassF.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1a21a51556f159961e7bef5fb0e8aa3def118e4 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassF.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassF +{ + float value; +}; + +static SequentialClassF SequentialClassFValue = { }; + +extern "C" DLL_EXPORT SequentialClassF* STDMETHODCALLTYPE GetSequentialClassF(float value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassFOut(float value, SequentialClassF** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassF** STDMETHODCALLTYPE GetSequentialClassFPtr(float value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassF* STDMETHODCALLTYPE AddSequentialClassF(SequentialClassF* lhs, SequentialClassF* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassF* STDMETHODCALLTYPE AddSequentialClassFs(const SequentialClassF** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassL.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4222b776229821f76fad0d0b876ab5ef2a06f953 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassL.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassL +{ + int64_t value; +}; + +static SequentialClassL SequentialClassLValue = { }; + +extern "C" DLL_EXPORT SequentialClassL* STDMETHODCALLTYPE GetSequentialClassL(int64_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassLOut(int64_t value, SequentialClassL** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassL** STDMETHODCALLTYPE GetSequentialClassLPtr(int64_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassL* STDMETHODCALLTYPE AddSequentialClassL(SequentialClassL* lhs, SequentialClassL* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassL* STDMETHODCALLTYPE AddSequentialClassLs(const SequentialClassL** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassU.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37719944b868ada3a942330a4a317f4bbb0df907 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SequentialClassU.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct SequentialClassU +{ + uint32_t value; +}; + +static SequentialClassU SequentialClassUValue = { }; + +extern "C" DLL_EXPORT SequentialClassU* STDMETHODCALLTYPE GetSequentialClassU(uint32_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSequentialClassUOut(uint32_t value, SequentialClassU** pValue) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT const SequentialClassU** STDMETHODCALLTYPE GetSequentialClassUPtr(uint32_t value) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassU* STDMETHODCALLTYPE AddSequentialClassU(SequentialClassU* lhs, SequentialClassU* rhs) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} + +extern "C" DLL_EXPORT SequentialClassU* STDMETHODCALLTYPE AddSequentialClassUs(const SequentialClassU** pValues, uint32_t count) +{ + throw "P/Invoke for SequentialClass should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanB.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3583e57663198dca8e74c749a85aff78e5ccb101 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanB.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceB +{ + intptr_t value; +}; + +struct SpanB +{ + ByReferenceB pointer; + int32_t length; +}; + +static SpanB SpanBValue = { }; + +extern "C" DLL_EXPORT SpanB STDMETHODCALLTYPE GetSpanB(bool e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanBOut(bool e00, SpanB* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanB* STDMETHODCALLTYPE GetSpanBPtr(bool e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanB STDMETHODCALLTYPE AddSpanB(SpanB lhs, SpanB rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanB STDMETHODCALLTYPE AddSpanBs(const SpanB* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanC.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c60d6d1ca4a8667d68864e529f747c04924d4763 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanC.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceC +{ + intptr_t value; +}; + +struct SpanC +{ + ByReferenceC pointer; + int32_t length; +}; + +static SpanC SpanCValue = { }; + +extern "C" DLL_EXPORT SpanC STDMETHODCALLTYPE GetSpanC(char16_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanCOut(char16_t e00, SpanC* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanC* STDMETHODCALLTYPE GetSpanCPtr(char16_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanC STDMETHODCALLTYPE AddSpanC(SpanC lhs, SpanC rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanC STDMETHODCALLTYPE AddSpanCs(const SpanC* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanD.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa6c890280eac5944e25c8527e045d938e175688 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanD.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceD +{ + intptr_t value; +}; + +struct SpanD +{ + ByReferenceD pointer; + int32_t length; +}; + +static SpanD SpanDValue = { }; + +extern "C" DLL_EXPORT SpanD STDMETHODCALLTYPE GetSpanD(double e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanDOut(double e00, SpanD* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanD* STDMETHODCALLTYPE GetSpanDPtr(double e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanD STDMETHODCALLTYPE AddSpanD(SpanD lhs, SpanD rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanD STDMETHODCALLTYPE AddSpanDs(const SpanD* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanF.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd3f56c8c6c7be13dec2c15011d2a654c35585f3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanF.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceF +{ + intptr_t value; +}; + +struct SpanF +{ + ByReferenceF pointer; + int32_t length; +}; + +static SpanF SpanFValue = { }; + +extern "C" DLL_EXPORT SpanF STDMETHODCALLTYPE GetSpanF(float e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanFOut(float e00, SpanF* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanF* STDMETHODCALLTYPE GetSpanFPtr(float e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanF STDMETHODCALLTYPE AddSpanF(SpanF lhs, SpanF rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanF STDMETHODCALLTYPE AddSpanFs(const SpanF* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanL.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e51aad0610dca7090cd89d5df912fbe6faebdb30 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanL.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceL +{ + intptr_t value; +}; + +struct SpanL +{ + ByReferenceL pointer; + int32_t length; +}; + +static SpanL SpanLValue = { }; + +extern "C" DLL_EXPORT SpanL STDMETHODCALLTYPE GetSpanL(int64_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanLOut(int64_t e00, SpanL* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanL* STDMETHODCALLTYPE GetSpanLPtr(int64_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanL STDMETHODCALLTYPE AddSpanL(SpanL lhs, SpanL rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanL STDMETHODCALLTYPE AddSpanLs(const SpanL* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanU.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..418e953555060188726695a35f9f86d8b9cd00f0 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.SpanU.cpp @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +struct ByReferenceU +{ + intptr_t value; +}; + +struct SpanU +{ + ByReferenceU pointer; + int32_t length; +}; + +static SpanU SpanUValue = { }; + +extern "C" DLL_EXPORT SpanU STDMETHODCALLTYPE GetSpanU(uint32_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetSpanUOut(uint32_t e00, SpanU* pValue) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT const SpanU* STDMETHODCALLTYPE GetSpanUPtr(uint32_t e00) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanU STDMETHODCALLTYPE AddSpanU(SpanU lhs, SpanU rhs) +{ + throw "P/Invoke for Span should be unsupported."; +} + +extern "C" DLL_EXPORT SpanU STDMETHODCALLTYPE AddSpanUs(const SpanU* pValues, uint32_t count) +{ + throw "P/Invoke for Span should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0bbcb419a9e4cba5a5e0c94400636346885473ca --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128B.cpp @@ -0,0 +1,103 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128i Vector128B; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + bool e00; + bool e01; + bool e02; + bool e03; + bool e04; + bool e05; + bool e06; + bool e07; + bool e08; + bool e09; + bool e10; + bool e11; + bool e12; + bool e13; + bool e14; + bool e15; + } int8x16_t; + #endif + + typedef int8x16_t Vector128B; +#else + #error Unsupported target architecture +#endif + +static Vector128B Vector128BValue = { }; + +extern "C" DLL_EXPORT Vector128B STDMETHODCALLTYPE GetVector128B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15) +{ + union { + bool value[16]; + Vector128B result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + value[8] = e08; + value[9] = e09; + value[10] = e10; + value[11] = e11; + value[12] = e12; + value[13] = e13; + value[14] = e14; + value[15] = e15; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, Vector128B* pValue) +{ + Vector128B value = GetVector128B(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128B* STDMETHODCALLTYPE GetVector128BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15) +{ + GetVector128BOut(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, &Vector128BValue); + return &Vector128BValue; +} + +extern "C" DLL_EXPORT Vector128B STDMETHODCALLTYPE AddVector128B(Vector128B lhs, Vector128B rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128B STDMETHODCALLTYPE AddVector128Bs(const Vector128B* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99af0b34dfba54d9764e1319a3e26aa869a2fb92 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128C.cpp @@ -0,0 +1,87 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128i Vector128C; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + char16_t e00; + char16_t e01; + char16_t e02; + char16_t e03; + char16_t e04; + char16_t e05; + char16_t e06; + char16_t e07; + } int16x8_t; + #endif + + typedef int16x8_t Vector128C; +#else + #error Unsupported target architecture +#endif + +static Vector128C Vector128CValue = { }; + +extern "C" DLL_EXPORT Vector128C STDMETHODCALLTYPE GetVector128C(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07) +{ + union { + char16_t value[8]; + Vector128C result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128COut(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, Vector128C* pValue) +{ + Vector128C value = GetVector128C(e00, e01, e02, e03, e04, e05, e06, e07); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128C* STDMETHODCALLTYPE GetVector128CPtr(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07) +{ + GetVector128COut(e00, e01, e02, e03, e04, e05, e06, e07, &Vector128CValue); + return &Vector128CValue; +} + +extern "C" DLL_EXPORT Vector128C STDMETHODCALLTYPE AddVector128C(Vector128C lhs, Vector128C rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128C STDMETHODCALLTYPE AddVector128Cs(const Vector128C* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a3f354b58184a47c82503c7d45a80149a542107 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128D.cpp @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128d Vector128D; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + + typedef __n128 float64x2_t; + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + double e00; + double e01; + } float64x2_t; + #endif + + typedef float64x2_t Vector128D; +#else + #error Unsupported target architecture +#endif + +static Vector128D Vector128DValue = { }; + +extern "C" DLL_EXPORT Vector128D STDMETHODCALLTYPE GetVector128D(double e00, double e01) +{ + union { + double value[2]; + Vector128D result; + }; + + value[0] = e00; + value[1] = e01; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128DOut(double e00, double e01, Vector128D* pValue) +{ + Vector128D value = GetVector128D(e00, e01); + +#if defined(_TARGET_XARCH_) + _mm_storeu_pd((double*)pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128D* STDMETHODCALLTYPE GetVector128DPtr(double e00, double e01) +{ + GetVector128DOut(e00, e01, &Vector128DValue); + return &Vector128DValue; +} + +extern "C" DLL_EXPORT Vector128D STDMETHODCALLTYPE AddVector128D(Vector128D lhs, Vector128D rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128D STDMETHODCALLTYPE AddVector128Ds(const Vector128D* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7242c9aecda30c8a5cd17e09925a1c980644f3e6 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128F.cpp @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128 Vector128F; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + float e00; + float e01; + float e02; + float e03; + } float32x4_t; + #endif + + typedef float32x4_t Vector128F; +#else + #error Unsupported target architecture +#endif + +static Vector128F Vector128FValue = { }; + +extern "C" DLL_EXPORT Vector128F STDMETHODCALLTYPE GetVector128F(float e00, float e01, float e02, float e03) +{ + union { + float value[4]; + Vector128F result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128FOut(float e00, float e01, float e02, float e03, Vector128F* pValue) +{ + Vector128F value = GetVector128F(e00, e01, e02, e03); + +#if defined(_TARGET_XARCH_) + _mm_storeu_ps((float*)pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128F* STDMETHODCALLTYPE GetVector128FPtr(float e00, float e01, float e02, float e03) +{ + GetVector128FOut(e00, e01, e02, e03, &Vector128FValue); + return &Vector128FValue; +} + +extern "C" DLL_EXPORT Vector128F STDMETHODCALLTYPE AddVector128F(Vector128F lhs, Vector128F rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128F STDMETHODCALLTYPE AddVector128Fs(const Vector128F* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..680f2d65ea69e643ce45027ed050fc8f78cb6918 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128L.cpp @@ -0,0 +1,75 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128i Vector128L; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + int64_t e00; + int64_t e01; + } int64x2_t; + #endif + + typedef int64x2_t Vector128L; +#else + #error Unsupported target architecture +#endif + +static Vector128L Vector128LValue = { }; + +extern "C" DLL_EXPORT Vector128L STDMETHODCALLTYPE GetVector128L(int64_t e00, int64_t e01) +{ + union { + int64_t value[2]; + Vector128L result; + }; + + value[0] = e00; + value[1] = e01; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128LOut(int64_t e00, int64_t e01, Vector128L* pValue) +{ + Vector128L value = GetVector128L(e00, e01); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128L* STDMETHODCALLTYPE GetVector128LPtr(int64_t e00, int64_t e01) +{ + GetVector128LOut(e00, e01, &Vector128LValue); + return &Vector128LValue; +} + +extern "C" DLL_EXPORT Vector128L STDMETHODCALLTYPE AddVector128L(Vector128L lhs, Vector128L rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128L STDMETHODCALLTYPE AddVector128Ls(const Vector128L* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d63b9e10ec9572ed8070c7a3b6caaeb8a80557bd --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector128U.cpp @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m128i Vector128U; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + uint32_t e00; + uint32_t e01; + uint32_t e02; + uint32_t e03; + } uint32x4_t; + #endif + + typedef uint32x4_t Vector128U; +#else + #error Unsupported target architecture +#endif + +static Vector128U Vector128UValue = { }; + +extern "C" DLL_EXPORT Vector128U STDMETHODCALLTYPE GetVector128U(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + union { + uint32_t value[4]; + Vector128U result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector128UOut(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, Vector128U* pValue) +{ + Vector128U value = GetVector128U(e00, e01, e02, e03); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(pValue, value); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector128U* STDMETHODCALLTYPE GetVector128UPtr(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + GetVector128UOut(e00, e01, e02, e03, &Vector128UValue); + return &Vector128UValue; +} + +extern "C" DLL_EXPORT Vector128U STDMETHODCALLTYPE AddVector128U(Vector128U lhs, Vector128U rhs) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector128U STDMETHODCALLTYPE AddVector128Us(const Vector128U* pValues, uint32_t count) +{ + throw "P/Invoke for Vector128 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d276d886a8b8af9198fe6d5ccb9821b7a8b3b5b --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256B.cpp @@ -0,0 +1,124 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256i Vector256B; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + bool e00; + bool e01; + bool e02; + bool e03; + bool e04; + bool e05; + bool e06; + bool e07; + bool e08; + bool e09; + bool e10; + bool e11; + bool e12; + bool e13; + bool e14; + bool e15; + bool e16; + bool e17; + bool e18; + bool e19; + bool e20; + bool e21; + bool e22; + bool e23; + bool e24; + bool e25; + bool e26; + bool e27; + bool e28; + bool e29; + bool e30; + bool e31; + } Vector256B; +#else + #error Unsupported target architecture +#endif + +static Vector256B Vector256BValue = { }; + +extern "C" DLL_EXPORT Vector256B STDMETHODCALLTYPE GetVector256B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31) +{ + union { + bool value[32]; + Vector256B result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + value[8] = e08; + value[9] = e09; + value[10] = e10; + value[11] = e11; + value[12] = e12; + value[13] = e13; + value[14] = e14; + value[15] = e15; + value[16] = e16; + value[17] = e17; + value[18] = e18; + value[19] = e19; + value[20] = e20; + value[21] = e21; + value[22] = e22; + value[23] = e23; + value[24] = e24; + value[25] = e25; + value[26] = e26; + value[27] = e27; + value[28] = e28; + value[29] = e29; + value[30] = e30; + value[31] = e31; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, Vector256B* pValue) +{ + Vector256B value = GetVector256B(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(((__m128i*)pValue) + 0, *(((__m128i*)&value) + 0)); + _mm_storeu_si128(((__m128i*)pValue) + 1, *(((__m128i*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256B* STDMETHODCALLTYPE GetVector256BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31) +{ + GetVector256BOut(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, &Vector256BValue); + return &Vector256BValue; +} + +extern "C" DLL_EXPORT Vector256B STDMETHODCALLTYPE AddVector256B(Vector256B lhs, Vector256B rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256B STDMETHODCALLTYPE AddVector256Bs(const Vector256B* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1dbb72e8022d37b8b092272db6cdea4585a9df79 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256C.cpp @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256i Vector256C; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + char16_t e00; + char16_t e01; + char16_t e02; + char16_t e03; + char16_t e04; + char16_t e05; + char16_t e06; + char16_t e07; + char16_t e08; + char16_t e09; + char16_t e10; + char16_t e11; + char16_t e12; + char16_t e13; + char16_t e14; + char16_t e15; + } Vector256C; +#else + #error Unsupported target architecture +#endif + +static Vector256C Vector256CValue = { }; + +extern "C" DLL_EXPORT Vector256C STDMETHODCALLTYPE GetVector256C(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15) +{ + union { + char16_t value[16]; + Vector256C result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + value[8] = e08; + value[9] = e09; + value[10] = e10; + value[11] = e11; + value[12] = e12; + value[13] = e13; + value[14] = e14; + value[15] = e15; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256COut(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15, Vector256C* pValue) +{ + Vector256C value = GetVector256C(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(((__m128i*)pValue) + 0, *(((__m128i*)&value) + 0)); + _mm_storeu_si128(((__m128i*)pValue) + 1, *(((__m128i*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256C* STDMETHODCALLTYPE GetVector256CPtr(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15) +{ + GetVector256COut(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, &Vector256CValue); + return &Vector256CValue; +} + +extern "C" DLL_EXPORT Vector256C STDMETHODCALLTYPE AddVector256C(Vector256C lhs, Vector256C rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256C STDMETHODCALLTYPE AddVector256Cs(const Vector256C* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ccca259f1b622970eb39b0c079dba062847993f0 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256D.cpp @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256d Vector256D; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + double e00; + double e01; + double e02; + double e03; + } Vector256D; +#else + #error Unsupported target architecture +#endif + +static Vector256D Vector256DValue = { }; + +extern "C" DLL_EXPORT Vector256D STDMETHODCALLTYPE GetVector256D(double e00, double e01, double e02, double e03) +{ + union { + double value[4]; + Vector256D result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256DOut(double e00, double e01, double e02, double e03, Vector256D* pValue) +{ + Vector256D value = GetVector256D(e00, e01, e02, e03); + +#if defined(_TARGET_XARCH_) + _mm_storeu_pd((double*)(((__m128d*)pValue) + 0), *(((__m128d*)&value) + 0)); + _mm_storeu_pd((double*)(((__m128d*)pValue) + 1), *(((__m128d*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256D* STDMETHODCALLTYPE GetVector256DPtr(double e00, double e01, double e02, double e03) +{ + GetVector256DOut(e00, e01, e02, e03, &Vector256DValue); + return &Vector256DValue; +} + +extern "C" DLL_EXPORT Vector256D STDMETHODCALLTYPE AddVector256D(Vector256D lhs, Vector256D rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256D STDMETHODCALLTYPE AddVector256Ds(const Vector256D* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c151b09c3493d57b7971987decf3d4a8533fd8f --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256F.cpp @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256 Vector256F; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + float e00; + float e01; + float e02; + float e03; + float e04; + float e05; + float e06; + float e07; + } Vector256F; +#else + #error Unsupported target architecture +#endif + +static Vector256F Vector256FValue = { }; + +extern "C" DLL_EXPORT Vector256F STDMETHODCALLTYPE GetVector256F(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07) +{ + union { + float value[8]; + Vector256F result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256FOut(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, Vector256F* pValue) +{ + Vector256F value = GetVector256F(e00, e01, e02, e03, e04, e05, e06, e07); + +#if defined(_TARGET_XARCH_) + _mm_storeu_ps((float*)(((__m128*)pValue) + 0), *(((__m128*)&value) + 0)); + _mm_storeu_ps((float*)(((__m128*)pValue) + 1), *(((__m128*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256F* STDMETHODCALLTYPE GetVector256FPtr(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07) +{ + GetVector256FOut(e00, e01, e02, e03, e04, e05, e06, e07, &Vector256FValue); + return &Vector256FValue; +} + +extern "C" DLL_EXPORT Vector256F STDMETHODCALLTYPE AddVector256F(Vector256F lhs, Vector256F rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256F STDMETHODCALLTYPE AddVector256Fs(const Vector256F* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a17c9600416972c523062b6d36132cb2aec3109e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256L.cpp @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256i Vector256L; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + int64_t e00; + int64_t e01; + int64_t e02; + int64_t e03; + } Vector256L; +#else + #error Unsupported target architecture +#endif + +static Vector256L Vector256LValue = { }; + +extern "C" DLL_EXPORT Vector256L STDMETHODCALLTYPE GetVector256L(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + union { + int64_t value[4]; + Vector256L result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256LOut(int64_t e00, int64_t e01, int64_t e02, int64_t e03, Vector256L* pValue) +{ + Vector256L value = GetVector256L(e00, e01, e02, e03); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(((__m128i*)pValue) + 0, *(((__m128i*)&value) + 0)); + _mm_storeu_si128(((__m128i*)pValue) + 1, *(((__m128i*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256L* STDMETHODCALLTYPE GetVector256LPtr(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + GetVector256LOut(e00, e01, e02, e03, &Vector256LValue); + return &Vector256LValue; +} + +extern "C" DLL_EXPORT Vector256L STDMETHODCALLTYPE AddVector256L(Vector256L lhs, Vector256L rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256L STDMETHODCALLTYPE AddVector256Ls(const Vector256L* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c22f3d99c0d8a5b9df8f437b7a257c1ec6c0cfd9 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector256U.cpp @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m256i Vector256U; +#elif defined(_TARGET_ARMARCH_) + typedef struct { + uint32_t e00; + uint32_t e01; + uint32_t e02; + uint32_t e03; + uint32_t e04; + uint32_t e05; + uint32_t e06; + uint32_t e07; + } Vector256U; +#else + #error Unsupported target architecture +#endif + +static Vector256U Vector256UValue = { }; + +extern "C" DLL_EXPORT Vector256U STDMETHODCALLTYPE GetVector256U(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07) +{ + union { + uint32_t value[8]; + Vector256U result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector256UOut(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07, Vector256U* pValue) +{ + Vector256U value = GetVector256U(e00, e01, e02, e03, e04, e05, e06, e07); + +#if defined(_TARGET_XARCH_) + _mm_storeu_si128(((__m128i*)pValue) + 0, *(((__m128i*)&value) + 0)); + _mm_storeu_si128(((__m128i*)pValue) + 1, *(((__m128i*)&value) + 1)); +#else + *pValue = value; +#endif +} + +extern "C" DLL_EXPORT const Vector256U* STDMETHODCALLTYPE GetVector256UPtr(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07) +{ + GetVector256UOut(e00, e01, e02, e03, e04, e05, e06, e07, &Vector256UValue); + return &Vector256UValue; +} + +extern "C" DLL_EXPORT Vector256U STDMETHODCALLTYPE AddVector256U(Vector256U lhs, Vector256U rhs) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector256U STDMETHODCALLTYPE AddVector256Us(const Vector256U* pValues, uint32_t count) +{ + throw "P/Invoke for Vector256 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64B.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98717b7122fd5f14bd9b6cedeee8fd3679ee99d9 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64B.cpp @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64B; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + int8_t e00; + int8_t e01; + int8_t e02; + int8_t e03; + int8_t e04; + int8_t e05; + int8_t e06; + int8_t e07; + } int8x8_t; + #endif + + typedef int8x8_t Vector64B; +#else + #error Unsupported target architecture +#endif + +static Vector64B Vector64BValue = { }; + +extern "C" DLL_EXPORT Vector64B STDMETHODCALLTYPE GetVector64B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07) +{ + union { + bool value[8]; + Vector64B result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + value[4] = e04; + value[5] = e05; + value[6] = e06; + value[7] = e07; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, Vector64B* pValue) +{ + *pValue = GetVector64B(e00, e01, e02, e03, e04, e05, e06, e07); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64B* STDMETHODCALLTYPE GetVector64BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07) +{ + GetVector64BOut(e00, e01, e02, e03, e04, e05, e06, e07, &Vector64BValue); + return &Vector64BValue; +} + +extern "C" DLL_EXPORT Vector64B STDMETHODCALLTYPE AddVector64B(Vector64B lhs, Vector64B rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64B STDMETHODCALLTYPE AddVector64Bs(const Vector64B* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64C.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64C.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f95c04eba24e7244fc1be169975b5068eddf977d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64C.cpp @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64C; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + int16_t e00; + int16_t e01; + int16_t e02; + int16_t e03; + } int16x4_t; + #endif + + typedef int16x4_t Vector64C; +#else + #error Unsupported target architecture +#endif + +static Vector64C Vector64CValue = { }; + +extern "C" DLL_EXPORT Vector64C STDMETHODCALLTYPE GetVector64C(char16_t e00, char16_t e01, char16_t e02, char16_t e03) +{ + union { + char16_t value[4]; + Vector64C result; + }; + + value[0] = e00; + value[1] = e01; + value[2] = e02; + value[3] = e03; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64COut(char16_t e00, char16_t e01, char16_t e02, char16_t e03, Vector64C* pValue) +{ + *pValue = GetVector64C(e00, e01, e02, e03); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64C* STDMETHODCALLTYPE GetVector64CPtr(char16_t e00, char16_t e01, char16_t e02, char16_t e03) +{ + GetVector64COut(e00, e01, e02, e03, &Vector64CValue); + return &Vector64CValue; +} + +extern "C" DLL_EXPORT Vector64C STDMETHODCALLTYPE AddVector64C(Vector64C lhs, Vector64C rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64C STDMETHODCALLTYPE AddVector64Cs(const Vector64C* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64D.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44f345aaa477509a5b0e54ddf4af2b5ef587f118 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64D.cpp @@ -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. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64D; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + + typedef __n64 float64x1_t; + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + double e00; + } float64x1_t; + #endif + + typedef float64x1_t Vector64D; +#else + #error Unsupported target architecture +#endif + +static Vector64D Vector64DValue = { }; + +extern "C" DLL_EXPORT Vector64D STDMETHODCALLTYPE GetVector64D(double e00) +{ + union { + double value[1]; + Vector64D result; + }; + + value[0] = e00; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64DOut(double e00, Vector64D* pValue) +{ + *pValue = GetVector64D(e00); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64D* STDMETHODCALLTYPE GetVector64DPtr(double e00) +{ + GetVector64DOut(e00, &Vector64DValue); + return &Vector64DValue; +} + +extern "C" DLL_EXPORT Vector64D STDMETHODCALLTYPE AddVector64D(Vector64D lhs, Vector64D rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64D STDMETHODCALLTYPE AddVector64Ds(const Vector64D* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64F.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22ba27ea24b07eeaffc544c1d5a9c284d6223260 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64F.cpp @@ -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. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64F; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + float e00; + float e01; + } float32x2_t; + #endif + + typedef float32x2_t Vector64F; +#else + #error Unsupported target architecture +#endif + +static Vector64F Vector64FValue = { }; + +extern "C" DLL_EXPORT Vector64F STDMETHODCALLTYPE GetVector64F(float e00, float e01) +{ + union { + float value[2]; + Vector64F result; + }; + + value[0] = e00; + value[1] = e01; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64FOut(float e00, float e01, Vector64F* pValue) +{ + *pValue = GetVector64F(e00, e01); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64F* STDMETHODCALLTYPE GetVector64FPtr(float e00, float e01) +{ + GetVector64FOut(e00, e01, &Vector64FValue); + return &Vector64FValue; +} + +extern "C" DLL_EXPORT Vector64F STDMETHODCALLTYPE AddVector64F(Vector64F lhs, Vector64F rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64F STDMETHODCALLTYPE AddVector64Fs(const Vector64F* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64L.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45988fedd743efe53dbbf79b0fde572952d5f33e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64L.cpp @@ -0,0 +1,71 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64L; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + int64_t e00; + } int64x1_t; + #endif + + typedef int64x1_t Vector64L; +#else + #error Unsupported target architecture +#endif + +static Vector64L Vector64LValue = { }; + +extern "C" DLL_EXPORT Vector64L STDMETHODCALLTYPE GetVector64L(int64_t e00) +{ + union { + int64_t value[1]; + Vector64L result; + }; + + value[0] = e00; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64LOut(int64_t e00, Vector64L* pValue) +{ + *pValue = GetVector64L(e00); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64L* STDMETHODCALLTYPE GetVector64LPtr(int64_t e00) +{ + GetVector64LOut(e00, &Vector64LValue); + return &Vector64LValue; +} + +extern "C" DLL_EXPORT Vector64L STDMETHODCALLTYPE AddVector64L(Vector64L lhs, Vector64L rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64L STDMETHODCALLTYPE AddVector64Ls(const Vector64L* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64U.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64U.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68019710f4446943f3b62d8759d741a7cf02b0b2 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.Vector64U.cpp @@ -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. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +#if defined(_TARGET_XARCH_) + #include + + typedef __m64 Vector64U; +#elif defined(_TARGET_ARMARCH_) + #if defined(_MSC_VER) + #if defined(_TARGET_ARM64_) + #include + #else + #include + #endif + #elif defined(_TARGET_ARM64_) + #include + #else + typedef struct { + uint32_t e00; + uint32_t e01; + } uint32x2_t; + #endif + + typedef uint32x2_t Vector64U; +#else + #error Unsupported target architecture +#endif + +static Vector64U Vector64UValue = { }; + +extern "C" DLL_EXPORT Vector64U STDMETHODCALLTYPE GetVector64U(uint32_t e00, uint32_t e01) +{ + union { + uint32_t value[2]; + Vector64U result; + }; + + value[0] = e00; + value[1] = e01; + + return result; +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVector64UOut(uint32_t e00, uint32_t e01, Vector64U* pValue) +{ + *pValue = GetVector64U(e00, e01); + +#if defined(_MSC_VER) && defined(_TARGET_X86_) + _mm_empty(); +#endif // _MSC_VER && _TARGET_X86_ +} + +extern "C" DLL_EXPORT const Vector64U* STDMETHODCALLTYPE GetVector64UPtr(uint32_t e00, uint32_t e01) +{ + GetVector64UOut(e00, e01, &Vector64UValue); + return &Vector64UValue; +} + +extern "C" DLL_EXPORT Vector64U STDMETHODCALLTYPE AddVector64U(Vector64U lhs, Vector64U rhs) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} + +extern "C" DLL_EXPORT Vector64U STDMETHODCALLTYPE AddVector64Us(const Vector64U* pValues, uint32_t count) +{ + throw "P/Invoke for Vector64 should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorB.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..935dcf40298c7a7e66dcdf176be34f8d165a6489 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorB.cpp @@ -0,0 +1,119 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + bool e00; + bool e01; + bool e02; + bool e03; + bool e04; + bool e05; + bool e06; + bool e07; + bool e08; + bool e09; + bool e10; + bool e11; + bool e12; + bool e13; + bool e14; + bool e15; +} VectorB128; + +typedef struct { + bool e00; + bool e01; + bool e02; + bool e03; + bool e04; + bool e05; + bool e06; + bool e07; + bool e08; + bool e09; + bool e10; + bool e11; + bool e12; + bool e13; + bool e14; + bool e15; + bool e16; + bool e17; + bool e18; + bool e19; + bool e20; + bool e21; + bool e22; + bool e23; + bool e24; + bool e25; + bool e26; + bool e27; + bool e28; + bool e29; + bool e30; + bool e31; +} VectorB256; + +static VectorB128 VectorB128Value = { }; +static VectorB256 VectorB256Value = { }; + +extern "C" DLL_EXPORT VectorB128 STDMETHODCALLTYPE GetVectorB128(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15) +{ + bool value[16] = { e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorB256 STDMETHODCALLTYPE GetVectorB256(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31) +{ + bool value[32] = { e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorB128Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, VectorB128* pValue) +{ + *pValue = GetVectorB128(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorB256Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, VectorB256* pValue) +{ + *pValue = GetVectorB256(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31); +} + +extern "C" DLL_EXPORT const VectorB128* STDMETHODCALLTYPE GetVectorB128Ptr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15) +{ + GetVectorB128Out(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, &VectorB128Value); + return &VectorB128Value; +} + +extern "C" DLL_EXPORT const VectorB256* STDMETHODCALLTYPE GetVectorB256Ptr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31) +{ + GetVectorB256Out(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, &VectorB256Value); + return &VectorB256Value; +} + +extern "C" DLL_EXPORT VectorB128 STDMETHODCALLTYPE AddVectorB128(VectorB128 lhs, VectorB128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorB256 STDMETHODCALLTYPE AddVectorB256(VectorB256 lhs, VectorB256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorB128 STDMETHODCALLTYPE AddVectorB128s(const VectorB128* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorB256 STDMETHODCALLTYPE AddVectorB256s(const VectorB256* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorC.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91bf54a844e7fd0a69db8e6704504e25f8040d79 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorC.cpp @@ -0,0 +1,95 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + char16_t e00; + char16_t e01; + char16_t e02; + char16_t e03; + char16_t e04; + char16_t e05; + char16_t e06; + char16_t e07; +} VectorC128; + +typedef struct { + char16_t e00; + char16_t e01; + char16_t e02; + char16_t e03; + char16_t e04; + char16_t e05; + char16_t e06; + char16_t e07; + char16_t e08; + char16_t e09; + char16_t e10; + char16_t e11; + char16_t e12; + char16_t e13; + char16_t e14; + char16_t e15; +} VectorC256; + +static VectorC128 VectorC128Value = { }; +static VectorC256 VectorC256Value = { }; + +extern "C" DLL_EXPORT VectorC128 STDMETHODCALLTYPE GetVectorC128(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07) +{ + char16_t value[8] = { e00, e01, e02, e03, e04, e05, e06, e07 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorC256 STDMETHODCALLTYPE GetVectorC256(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15) +{ + char16_t value[16] = { e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorC128Out(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, VectorC128* pValue) +{ + *pValue = GetVectorC128(e00, e01, e02, e03, e04, e05, e06, e07); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorC256Out(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15, VectorC256* pValue) +{ + *pValue = GetVectorC256(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15); +} + +extern "C" DLL_EXPORT const VectorC128* STDMETHODCALLTYPE GetVectorC128Ptr(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07) +{ + GetVectorC128Out(e00, e01, e02, e03, e04, e05, e06, e07, &VectorC128Value); + return &VectorC128Value; +} + +extern "C" DLL_EXPORT const VectorC256* STDMETHODCALLTYPE GetVectorC256Ptr(char16_t e00, char16_t e01, char16_t e02, char16_t e03, char16_t e04, char16_t e05, char16_t e06, char16_t e07, char16_t e08, char16_t e09, char16_t e10, char16_t e11, char16_t e12, char16_t e13, char16_t e14, char16_t e15) +{ + GetVectorC256Out(e00, e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, &VectorC256Value); + return &VectorC256Value; +} + +extern "C" DLL_EXPORT VectorC128 STDMETHODCALLTYPE AddVectorC128(VectorC128 lhs, VectorC128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorC256 STDMETHODCALLTYPE AddVectorC256(VectorC256 lhs, VectorC256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorC128 STDMETHODCALLTYPE AddVectorC128s(const VectorC128* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorC256 STDMETHODCALLTYPE AddVectorC256s(const VectorC256* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorD.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..58df7a4f2bf87f5988ef51ada8d5ee35bd3533df --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorD.cpp @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + double e00; + double e01; +} VectorD128; + +typedef struct { + double e00; + double e01; + double e02; + double e03; +} VectorD256; + +static VectorD128 VectorD128Value = { }; +static VectorD256 VectorD256Value = { }; + +extern "C" DLL_EXPORT VectorD128 STDMETHODCALLTYPE GetVectorD128(double e00, double e01) +{ + double value[2] = { e00, e01 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorD256 STDMETHODCALLTYPE GetVectorD256(double e00, double e01, double e02, double e03) +{ + double value[4] = { e00, e01, e02, e03 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorD128Out(double e00, double e01, VectorD128* pValue) +{ + *pValue = GetVectorD128(e00, e01); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorD256Out(double e00, double e01, double e02, double e03, VectorD256* pValue) +{ + *pValue = GetVectorD256(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const VectorD128* STDMETHODCALLTYPE GetVectorD128Ptr(double e00, double e01) +{ + GetVectorD128Out(e00, e01, &VectorD128Value); + return &VectorD128Value; +} + +extern "C" DLL_EXPORT const VectorD256* STDMETHODCALLTYPE GetVectorD256Ptr(double e00, double e01, double e02, double e03) +{ + GetVectorD256Out(e00, e01, e02, e03, &VectorD256Value); + return &VectorD256Value; +} + +extern "C" DLL_EXPORT VectorD128 STDMETHODCALLTYPE AddVectorD128(VectorD128 lhs, VectorD128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorD256 STDMETHODCALLTYPE AddVectorD256(VectorD256 lhs, VectorD256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorD128 STDMETHODCALLTYPE AddVectorD128s(const VectorD128* pValues, double count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorD256 STDMETHODCALLTYPE AddVectorD256s(const VectorD256* pValues, double count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorF.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c6f4612f54ab5023ff480371819334742f427d3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorF.cpp @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + float e00; + float e01; + float e02; + float e03; +} VectorF128; + +typedef struct { + float e00; + float e01; + float e02; + float e03; + float e04; + float e05; + float e06; + float e07; +} VectorF256; + +static VectorF128 VectorF128Value = { }; +static VectorF256 VectorF256Value = { }; + +extern "C" DLL_EXPORT VectorF128 STDMETHODCALLTYPE GetVectorF128(float e00, float e01, float e02, float e03) +{ + float value[4] = { e00, e01, e02, e03 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorF256 STDMETHODCALLTYPE GetVectorF256(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07) +{ + float value[8] = { e00, e01, e02, e03, e04, e05, e06, e07 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorF128Out(float e00, float e01, float e02, float e03, VectorF128* pValue) +{ + *pValue = GetVectorF128(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorF256Out(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, VectorF256* pValue) +{ + *pValue = GetVectorF256(e00, e01, e02, e03, e04, e05, e06, e07); +} + +extern "C" DLL_EXPORT const VectorF128* STDMETHODCALLTYPE GetVectorF128Ptr(float e00, float e01, float e02, float e03) +{ + GetVectorF128Out(e00, e01, e02, e03, &VectorF128Value); + return &VectorF128Value; +} + +extern "C" DLL_EXPORT const VectorF256* STDMETHODCALLTYPE GetVectorF256Ptr(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07) +{ + GetVectorF256Out(e00, e01, e02, e03, e04, e05, e06, e07, &VectorF256Value); + return &VectorF256Value; +} + +extern "C" DLL_EXPORT VectorF128 STDMETHODCALLTYPE AddVectorF128(VectorF128 lhs, VectorF128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorF256 STDMETHODCALLTYPE AddVectorF256(VectorF256 lhs, VectorF256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorF128 STDMETHODCALLTYPE AddVectorF128s(const VectorF128* pValues, float count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorF256 STDMETHODCALLTYPE AddVectorF256s(const VectorF256* pValues, float count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorL.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d694e3d1aab0a82070ab698576925d01c2e67477 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorL.cpp @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + int64_t e00; + int64_t e01; +} VectorL128; + +typedef struct { + int64_t e00; + int64_t e01; + int64_t e02; + int64_t e03; +} VectorL256; + +static VectorL128 VectorL128Value = { }; +static VectorL256 VectorL256Value = { }; + +extern "C" DLL_EXPORT VectorL128 STDMETHODCALLTYPE GetVectorL128(int64_t e00, int64_t e01) +{ + int64_t value[2] = { e00, e01 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorL256 STDMETHODCALLTYPE GetVectorL256(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + int64_t value[4] = { e00, e01, e02, e03 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorL128Out(int64_t e00, int64_t e01, VectorL128* pValue) +{ + *pValue = GetVectorL128(e00, e01); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorL256Out(int64_t e00, int64_t e01, int64_t e02, int64_t e03, VectorL256* pValue) +{ + *pValue = GetVectorL256(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT const VectorL128* STDMETHODCALLTYPE GetVectorL128Ptr(int64_t e00, int64_t e01) +{ + GetVectorL128Out(e00, e01, &VectorL128Value); + return &VectorL128Value; +} + +extern "C" DLL_EXPORT const VectorL256* STDMETHODCALLTYPE GetVectorL256Ptr(int64_t e00, int64_t e01, int64_t e02, int64_t e03) +{ + GetVectorL256Out(e00, e01, e02, e03, &VectorL256Value); + return &VectorL256Value; +} + +extern "C" DLL_EXPORT VectorL128 STDMETHODCALLTYPE AddVectorL128(VectorL128 lhs, VectorL128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorL256 STDMETHODCALLTYPE AddVectorL256(VectorL256 lhs, VectorL256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorL128 STDMETHODCALLTYPE AddVectorL128s(const VectorL128* pValues, int64_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorL256 STDMETHODCALLTYPE AddVectorL256s(const VectorL256* pValues, int64_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorU.cpp b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c92d705d4688a159853eaa5ff416306bf033856 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsNative.VectorU.cpp @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include + +typedef struct { + uint32_t e00; + uint32_t e01; + uint32_t e02; + uint32_t e03; +} VectorU128; + +typedef struct { + uint32_t e00; + uint32_t e01; + uint32_t e02; + uint32_t e03; + uint32_t e04; + uint32_t e05; + uint32_t e06; + uint32_t e07; +} VectorU256; + +static VectorU128 VectorU128Value = { }; +static VectorU256 VectorU256Value = { }; + +extern "C" DLL_EXPORT VectorU128 STDMETHODCALLTYPE GetVectorU128(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + uint32_t value[4] = { e00, e01, e02, e03 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT VectorU256 STDMETHODCALLTYPE GetVectorU256(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07) +{ + uint32_t value[8] = { e00, e01, e02, e03, e04, e05, e06, e07 }; + return *reinterpret_cast(value); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorU128Out(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, VectorU128* pValue) +{ + *pValue = GetVectorU128(e00, e01, e02, e03); +} + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE GetVectorU256Out(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07, VectorU256* pValue) +{ + *pValue = GetVectorU256(e00, e01, e02, e03, e04, e05, e06, e07); +} + +extern "C" DLL_EXPORT const VectorU128* STDMETHODCALLTYPE GetVectorU128Ptr(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03) +{ + GetVectorU128Out(e00, e01, e02, e03, &VectorU128Value); + return &VectorU128Value; +} + +extern "C" DLL_EXPORT const VectorU256* STDMETHODCALLTYPE GetVectorU256Ptr(uint32_t e00, uint32_t e01, uint32_t e02, uint32_t e03, uint32_t e04, uint32_t e05, uint32_t e06, uint32_t e07) +{ + GetVectorU256Out(e00, e01, e02, e03, e04, e05, e06, e07, &VectorU256Value); + return &VectorU256Value; +} + +extern "C" DLL_EXPORT VectorU128 STDMETHODCALLTYPE AddVectorU128(VectorU128 lhs, VectorU128 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorU256 STDMETHODCALLTYPE AddVectorU256(VectorU256 lhs, VectorU256 rhs) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorU128 STDMETHODCALLTYPE AddVectorU128s(const VectorU128* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} + +extern "C" DLL_EXPORT VectorU256 STDMETHODCALLTYPE AddVectorU256s(const VectorU256* pValues, uint32_t count) +{ + throw "P/Invoke for Vector should be unsupported."; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceB.cs new file mode 100644 index 0000000000000000000000000000000000000000..5788345a5f40eb2d1f0b0450e604a57933501baa --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceB.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceB(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceBOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceBRef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceBs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceBs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceB() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceB()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceBOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceBRef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceBs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceBs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceC.cs new file mode 100644 index 0000000000000000000000000000000000000000..a5a6c4d6213ea4685417c65b773beaf138aa5c0e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceC.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceC(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceCOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceCRef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceCs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceCs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceC() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceC()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceCOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceCRef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceCs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceCs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceD.cs new file mode 100644 index 0000000000000000000000000000000000000000..147739047feb3b7fd873ef89aac3035bc08398bf --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceD.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceD(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceDOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceDRef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceDs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceDs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceD() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceD()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceDOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceDRef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceDs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceDs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceF.cs new file mode 100644 index 0000000000000000000000000000000000000000..255734fec071eea3bd8396e986dbe06beac44aef --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceF.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceF(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceFOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceFRef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceFs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceFs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceF() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceF()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceFOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceFRef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceFs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceFs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceL.cs new file mode 100644 index 0000000000000000000000000000000000000000..4d695ea257fbc048ac8ebbbf42e329ba86381f64 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceL.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceL(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceLOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceLRef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceLs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceLs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceL() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceL()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceLOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceLRef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceLs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceLs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceU.cs new file mode 100644 index 0000000000000000000000000000000000000000..0b63cf929c313a5d35cbcbc405596122350045c7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.IComInterfaceU.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterface")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern IComInterface GetIComInterfaceU(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaceOut")] + public static extern void GetIComInterfaceUOut([MarshalAs(UnmanagedType.Interface)] out IComInterface value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfacePtr")] + [return: MarshalAs(UnmanagedType.Interface)] + public static extern ref readonly IComInterface GetIComInterfaceURef(); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceUs([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 1)] IComInterface[] pValues, int count); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetIComInterfaces")] + public static extern void GetIComInterfaceUs([MarshalAs(UnmanagedType.Interface)] ref IComInterface pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestIComInterfaceU() + { + Assert.Throws(() => GenericsNative.GetIComInterfaceU()); + + Assert.Throws(() => GenericsNative.GetIComInterfaceUOut(out GenericsNative.IComInterface value2)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceURef()); + + GenericsNative.IComInterface[] values = new GenericsNative.IComInterface[3]; + + Assert.Throws(() => GenericsNative.GetIComInterfaceUs(values, values.Length)); + + Assert.Throws(() => GenericsNative.GetIComInterfaceUs(ref values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs new file mode 100644 index 0000000000000000000000000000000000000000..61580bb4441cf13361861b62db421bc68535ae91 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern bool? GetNullableB(bool hasValue, bool value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableBOut(bool hasValue, bool value, bool?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableBOut(bool hasValue, bool value, out bool? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern bool?* GetNullableBPtr(bool hasValue, bool value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableBPtr")] + public static extern ref readonly bool? GetNullableBRef(bool hasValue, bool value); + + [DllImport(nameof(GenericsNative))] + public static extern bool? AddNullableB(bool? lhs, bool? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern bool? AddNullableBs(bool?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern bool? AddNullableBs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] bool?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern bool? AddNullableBs(in bool? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableB() + { + Assert.Throws(() => GenericsNative.GetNullableB(true, false)); + + Assert.Throws(() => { + bool? value2; + GenericsNative.GetNullableBOut(true, false, &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableBOut(true, false, out bool? value3)); + + Assert.Throws(() => GenericsNative.GetNullableBPtr(true, false)); + + Assert.Throws(() => GenericsNative.GetNullableBRef(true, false)); + + Assert.Throws(() => GenericsNative.AddNullableB(default, default)); + + bool?[] values = new bool?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (bool?* pValues = &values[0]) + { + GenericsNative.AddNullableBs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableBs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableBs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs new file mode 100644 index 0000000000000000000000000000000000000000..c2a33ef8918b3f908f2c941ce398eeec25d98e3d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern char? GetNullableC(bool hasValue, char value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableCOut(bool hasValue, char value, char?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableCOut(bool hasValue, char value, out char? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern char?* GetNullableCPtr(bool hasValue, char value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableCPtr")] + public static extern ref readonly char? GetNullableCRef(bool hasValue, char value); + + [DllImport(nameof(GenericsNative))] + public static extern char? AddNullableC(char? lhs, char? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern char? AddNullableCs(char?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern char? AddNullableCs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] char?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern char? AddNullableCs(in char? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableC() + { + Assert.Throws(() => GenericsNative.GetNullableC(true, '1')); + + Assert.Throws(() => { + char? value2; + GenericsNative.GetNullableCOut(true, '1', &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableCOut(true, '1', out char? value3)); + + Assert.Throws(() => GenericsNative.GetNullableCPtr(true, '1')); + + Assert.Throws(() => GenericsNative.GetNullableCRef(true, '1')); + + Assert.Throws(() => GenericsNative.AddNullableC(default, default)); + + char?[] values = new char?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (char?* pValues = &values[0]) + { + GenericsNative.AddNullableCs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableCs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableCs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs new file mode 100644 index 0000000000000000000000000000000000000000..7bf829d4abd48cd4745ce0faa0716ad8e144e700 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern double? GetNullableD(bool hasValue, double value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableDOut(bool hasValue, double value, double?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableDOut(bool hasValue, double value, out double? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern double?* GetNullableDPtr(bool hasValue, double value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableDPtr")] + public static extern ref readonly double? GetNullableDRef(bool hasValue, double value); + + [DllImport(nameof(GenericsNative))] + public static extern double? AddNullableD(double? lhs, double? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern double? AddNullableDs(double?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern double? AddNullableDs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] double?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern double? AddNullableDs(in double? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableD() + { + Assert.Throws(() => GenericsNative.GetNullableD(true, 1.0)); + + Assert.Throws(() => { + double? value2; + GenericsNative.GetNullableDOut(true, 1.0, &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableDOut(true, 1.0, out double? value3)); + + Assert.Throws(() => GenericsNative.GetNullableDPtr(true, 1.0)); + + Assert.Throws(() => GenericsNative.GetNullableDRef(true, 1.0)); + + Assert.Throws(() => GenericsNative.AddNullableD(default, default)); + + double?[] values = new double?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (double?* pValues = &values[0]) + { + GenericsNative.AddNullableDs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableDs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableDs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs new file mode 100644 index 0000000000000000000000000000000000000000..c0f2f69b43f1d80eb6590e69d2f64280636dd01b --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern float? GetNullableF(bool hasValue, float value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableFOut(bool hasValue, float value, float?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableFOut(bool hasValue, float value, out float? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern float?* GetNullableFPtr(bool hasValue, float value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableFPtr")] + public static extern ref readonly float? GetNullableFRef(bool hasValue, float value); + + [DllImport(nameof(GenericsNative))] + public static extern float? AddNullableF(float? lhs, float? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern float? AddNullableFs(float?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern float? AddNullableFs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] float?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern float? AddNullableFs(in float? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableF() + { + Assert.Throws(() => GenericsNative.GetNullableF(true, 1.0f)); + + Assert.Throws(() => { + float? value2; + GenericsNative.GetNullableFOut(true, 1.0f, &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableFOut(true, 1.0f, out float? value3)); + + Assert.Throws(() => GenericsNative.GetNullableFPtr(true, 1.0f)); + + Assert.Throws(() => GenericsNative.GetNullableFRef(true, 1.0f)); + + Assert.Throws(() => GenericsNative.AddNullableF(default, default)); + + float?[] values = new float?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (float?* pValues = &values[0]) + { + GenericsNative.AddNullableFs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableFs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableFs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs new file mode 100644 index 0000000000000000000000000000000000000000..21255d6854271d05d97660aa38186f1982782a08 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern long? GetNullableL(bool hasValue, long value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableLOut(bool hasValue, long value, long?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableLOut(bool hasValue, long value, out long? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern long?* GetNullableLPtr(bool hasValue, long value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableLPtr")] + public static extern ref readonly long? GetNullableLRef(bool hasValue, long value); + + [DllImport(nameof(GenericsNative))] + public static extern long? AddNullableL(long? lhs, long? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern long? AddNullableLs(long?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern long? AddNullableLs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] long?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern long? AddNullableLs(in long? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableL() + { + Assert.Throws(() => GenericsNative.GetNullableL(true, 1L)); + + Assert.Throws(() => { + long? value2; + GenericsNative.GetNullableLOut(true, 1L, &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableLOut(true, 1L, out long? value3)); + + Assert.Throws(() => GenericsNative.GetNullableLPtr(true, 1L)); + + Assert.Throws(() => GenericsNative.GetNullableLRef(true, 1L)); + + Assert.Throws(() => GenericsNative.AddNullableL(default, default)); + + long?[] values = new long?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (long?* pValues = &values[0]) + { + GenericsNative.AddNullableLs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableLs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableLs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs new file mode 100644 index 0000000000000000000000000000000000000000..cba3a458ebdd01573334e053110cd31af39350b7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern uint? GetNullableU(bool hasValue, uint value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableUOut(bool hasValue, uint value, uint?* pValue); + + [DllImport(nameof(GenericsNative))] + public static extern void GetNullableUOut(bool hasValue, uint value, out uint? pValue); + + [DllImport(nameof(GenericsNative))] + public static extern uint?* GetNullableUPtr(bool hasValue, uint value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableUPtr")] + public static extern ref readonly uint? GetNullableURef(bool hasValue, uint value); + + [DllImport(nameof(GenericsNative))] + public static extern uint? AddNullableU(uint? lhs, uint? rhs); + + [DllImport(nameof(GenericsNative))] + public static extern uint? AddNullableUs(uint?* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern uint? AddNullableUs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] uint?[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern uint? AddNullableUs(in uint? pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestNullableU() + { + Assert.Throws(() => GenericsNative.GetNullableU(true, 1u)); + + Assert.Throws(() => { + uint? value2; + GenericsNative.GetNullableUOut(true, 1u, &value2); + }); + + Assert.Throws(() => GenericsNative.GetNullableUOut(true, 1u, out uint? value3)); + + Assert.Throws(() => GenericsNative.GetNullableUPtr(true, 1u)); + + Assert.Throws(() => GenericsNative.GetNullableURef(true, 1u)); + + Assert.Throws(() => GenericsNative.AddNullableU(default, default)); + + uint?[] values = new uint?[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (uint?* pValues = &values[0]) + { + GenericsNative.AddNullableUs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddNullableUs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddNullableUs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs new file mode 100644 index 0000000000000000000000000000000000000000..24a3ab743ae1f2c00320efae108370648ad8362f --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1B(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1BOut(bool e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1BOut(bool e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1BPtr(bool e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1BPtr")] + public static extern ref readonly Point1 GetPoint1BRef(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1B(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Bs(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Bs(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1B() + { + Assert.Throws(() => GenericsNative.GetPoint1B(true)); + + Assert.Throws(() => { + GenericsNative.Point1 value2; + GenericsNative.GetPoint1BOut(true, &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint1BOut(true, out GenericsNative.Point1 value3)); + + Assert.Throws(() => GenericsNative.GetPoint1BPtr(true)); + + Assert.Throws(() => GenericsNative.GetPoint1BRef(true)); + + Assert.Throws(() => GenericsNative.AddPoint1B(default, default)); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.AddPoint1Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint1Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint1Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs new file mode 100644 index 0000000000000000000000000000000000000000..1f744d6809d9fa91bac076223202ce1fbb59ed88 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1C(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1COut(char e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1COut(char e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1CPtr(char e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1CPtr")] + public static extern ref readonly Point1 GetPoint1CRef(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1C(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Cs(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Cs(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1C() + { + Assert.Throws(() => GenericsNative.GetPoint1C('1')); + + Assert.Throws(() => { + GenericsNative.Point1 value2; + GenericsNative.GetPoint1COut('1', &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint1COut('1', out GenericsNative.Point1 value3)); + + Assert.Throws(() => GenericsNative.GetPoint1CPtr('1')); + + Assert.Throws(() => GenericsNative.GetPoint1CRef('1')); + + Assert.Throws(() => GenericsNative.AddPoint1C(default, default)); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.AddPoint1Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint1Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint1Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1D.cs new file mode 100644 index 0000000000000000000000000000000000000000..28f210ce4cb6584211779ed837bcbacddcf24339 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1D.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1D(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1DOut(double e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1DOut(double e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1DPtr(double e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1DPtr")] + public static extern ref readonly Point1 GetPoint1DRef(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1D(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ds(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ds(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1D() + { + GenericsNative.Point1 value = GenericsNative.GetPoint1D(1.0); + Assert.AreEqual(value.e00, 1.0); + + GenericsNative.Point1 value2; + GenericsNative.GetPoint1DOut(1.0, &value2); + Assert.AreEqual(value2.e00, 1.0); + + GenericsNative.GetPoint1DOut(1.0, out GenericsNative.Point1 value3); + Assert.AreEqual(value3.e00, 1.0); + + GenericsNative.Point1* value4 = GenericsNative.GetPoint1DPtr(1.0); + Assert.AreEqual(value4->e00, 1.0); + + ref readonly GenericsNative.Point1 value5 = ref GenericsNative.GetPoint1DRef(1.0); + Assert.AreEqual(value5.e00, 1.0); + + GenericsNative.Point1 result = GenericsNative.AddPoint1D(value, value); + Assert.AreEqual(result.e00, 2.0); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.Point1 result2 = GenericsNative.AddPoint1Ds(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0); + } + + GenericsNative.Point1 result3 = GenericsNative.AddPoint1Ds(values, values.Length); + Assert.AreEqual(result3.e00, 5.0); + + GenericsNative.Point1 result4 = GenericsNative.AddPoint1Ds(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1F.cs new file mode 100644 index 0000000000000000000000000000000000000000..511dc581ade86ed5eab8ed93ef33e3d1b9c35385 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1F.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1F(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1FOut(float e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1FOut(float e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1FPtr(float e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1FPtr")] + public static extern ref readonly Point1 GetPoint1FRef(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1F(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Fs(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Fs(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1F() + { + GenericsNative.Point1 value = GenericsNative.GetPoint1F(1.0f); + Assert.AreEqual(value.e00, 1.0f); + + GenericsNative.Point1 value2; + GenericsNative.GetPoint1FOut(1.0f, &value2); + Assert.AreEqual(value2.e00, 1.0f); + + GenericsNative.GetPoint1FOut(1.0f, out GenericsNative.Point1 value3); + Assert.AreEqual(value3.e00, 1.0f); + + GenericsNative.Point1* value4 = GenericsNative.GetPoint1FPtr(1.0f); + Assert.AreEqual(value4->e00, 1.0f); + + ref readonly GenericsNative.Point1 value5 = ref GenericsNative.GetPoint1FRef(1.0f); + Assert.AreEqual(value5.e00, 1.0f); + + GenericsNative.Point1 result = GenericsNative.AddPoint1F(value, value); + Assert.AreEqual(result.e00, 2.0f); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.Point1 result2 = GenericsNative.AddPoint1Fs(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0f); + } + + GenericsNative.Point1 result3 = GenericsNative.AddPoint1Fs(values, values.Length); + Assert.AreEqual(result3.e00, 5.0f); + + GenericsNative.Point1 result4 = GenericsNative.AddPoint1Fs(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0f); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1L.cs new file mode 100644 index 0000000000000000000000000000000000000000..6c2c06e359b5666356fee1c623482557f138d1c5 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1L.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1L(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1LOut(long e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1LOut(long e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1LPtr(long e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1LPtr")] + public static extern ref readonly Point1 GetPoint1LRef(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1L(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ls(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Ls(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1L() + { + GenericsNative.Point1 value = GenericsNative.GetPoint1L(1L); + Assert.AreEqual(value.e00, 1L); + + GenericsNative.Point1 value2; + GenericsNative.GetPoint1LOut(1L, &value2); + Assert.AreEqual(value2.e00, 1L); + + GenericsNative.GetPoint1LOut(1L, out GenericsNative.Point1 value3); + Assert.AreEqual(value3.e00, 1L); + + GenericsNative.Point1* value4 = GenericsNative.GetPoint1LPtr(1L); + Assert.AreEqual(value4->e00, 1L); + + ref readonly GenericsNative.Point1 value5 = ref GenericsNative.GetPoint1LRef(1L); + Assert.AreEqual(value5.e00, 1L); + + GenericsNative.Point1 result = GenericsNative.AddPoint1L(value, value); + Assert.AreEqual(result.e00, 2L); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.Point1 result2 = GenericsNative.AddPoint1Ls(pValues, values.Length); + Assert.AreEqual(result2.e00, 5l); + } + + GenericsNative.Point1 result3 = GenericsNative.AddPoint1Ls(values, values.Length); + Assert.AreEqual(result3.e00, 5l); + + GenericsNative.Point1 result4 = GenericsNative.AddPoint1Ls(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5l); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1U.cs new file mode 100644 index 0000000000000000000000000000000000000000..17535b55ea7ceddb8b7ab43f54ccf936d41d2393 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1U.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point1 GetPoint1U(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1UOut(uint e00, Point1* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint1UOut(uint e00, out Point1 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point1* GetPoint1UPtr(uint e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1UPtr")] + public static extern ref readonly Point1 GetPoint1URef(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1U(Point1 lhs, Point1 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Us(Point1* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point1 AddPoint1Us(in Point1 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint1U() + { + GenericsNative.Point1 value = GenericsNative.GetPoint1U(1u); + Assert.AreEqual(value.e00, 1u); + + GenericsNative.Point1 value2; + GenericsNative.GetPoint1UOut(1u, &value2); + Assert.AreEqual(value2.e00, 1u); + + GenericsNative.GetPoint1UOut(1u, out GenericsNative.Point1 value3); + Assert.AreEqual(value3.e00, 1u); + + GenericsNative.Point1* value4 = GenericsNative.GetPoint1UPtr(1u); + Assert.AreEqual(value4->e00, 1u); + + ref readonly GenericsNative.Point1 value5 = ref GenericsNative.GetPoint1URef(1u); + Assert.AreEqual(value5.e00, 1u); + + GenericsNative.Point1 result = GenericsNative.AddPoint1U(value, value); + Assert.AreEqual(result.e00, 2u); + + GenericsNative.Point1[] values = new GenericsNative.Point1[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point1* pValues = &values[0]) + { + GenericsNative.Point1 result2 = GenericsNative.AddPoint1Us(pValues, values.Length); + Assert.AreEqual(result2.e00, 5u); + } + + GenericsNative.Point1 result3 = GenericsNative.AddPoint1Us(values, values.Length); + Assert.AreEqual(result3.e00, 5u); + + GenericsNative.Point1 result4 = GenericsNative.AddPoint1Us(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5u); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs new file mode 100644 index 0000000000000000000000000000000000000000..d484b992c2a5e57aec30edd526159c3bc9462f5d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2B(bool e00, bool e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2BOut(bool e00, bool e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2BOut(bool e00, bool e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2BPtr(bool e00, bool e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2BPtr")] + public static extern ref readonly Point2 GetPoint2BRef(bool e00, bool e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2B(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Bs(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Bs(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2B() + { + Assert.Throws(() => GenericsNative.GetPoint2B(true, false)); + + Assert.Throws(() => { + GenericsNative.Point2 value2; + GenericsNative.GetPoint2BOut(true, false, &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint2BOut(true, false, out GenericsNative.Point2 value3)); + + Assert.Throws(() => GenericsNative.GetPoint2BPtr(true, false)); + + Assert.Throws(() => GenericsNative.GetPoint2BRef(true, false)); + + Assert.Throws(() => GenericsNative.AddPoint2B(default, default)); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.AddPoint2Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint2Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint2Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs new file mode 100644 index 0000000000000000000000000000000000000000..35bed8170adfa70ccb5620d7011ab25707e96a86 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2C(char e00, char e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2COut(char e00, char e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2COut(char e00, char e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2CPtr(char e00, char e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2CPtr")] + public static extern ref readonly Point2 GetPoint2CRef(char e00, char e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2C(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Cs(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Cs(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2C() + { + Assert.Throws(() => GenericsNative.GetPoint2C('1', '2')); + + Assert.Throws(() => { + GenericsNative.Point2 value2; + GenericsNative.GetPoint2COut('1', '2', &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint2COut('1', '2', out GenericsNative.Point2 value3)); + + Assert.Throws(() => GenericsNative.GetPoint2CPtr('1', '2')); + + Assert.Throws(() => GenericsNative.GetPoint2CRef('1', '2')); + + Assert.Throws(() => GenericsNative.AddPoint2C(default, default)); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.AddPoint2Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint2Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint2Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2D.cs new file mode 100644 index 0000000000000000000000000000000000000000..ac00fc24f402d561589463925c38877cd1d3e14d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2D.cs @@ -0,0 +1,91 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2D(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2DOut(double e00, double e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2DOut(double e00, double e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2DPtr(double e00, double e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2DPtr")] + public static extern ref readonly Point2 GetPoint2DRef(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2D(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ds(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ds(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2D() + { + GenericsNative.Point2 value = GenericsNative.GetPoint2D(1.0, 2.0); + Assert.AreEqual(value.e00, 1.0); + Assert.AreEqual(value.e01, 2.0); + + GenericsNative.Point2 value2; + GenericsNative.GetPoint2DOut(1.0, 2.0, &value2); + Assert.AreEqual(value2.e00, 1.0); + Assert.AreEqual(value2.e01, 2.0); + + GenericsNative.GetPoint2DOut(1.0, 2.0, out GenericsNative.Point2 value3); + Assert.AreEqual(value3.e00, 1.0); + Assert.AreEqual(value3.e01, 2.0); + + GenericsNative.Point2* value4 = GenericsNative.GetPoint2DPtr(1.0, 2.0); + Assert.AreEqual(value4->e00, 1.0); + Assert.AreEqual(value4->e01, 2.0); + + ref readonly GenericsNative.Point2 value5 = ref GenericsNative.GetPoint2DRef(1.0, 2.0); + Assert.AreEqual(value5.e00, 1.0); + Assert.AreEqual(value5.e01, 2.0); + + GenericsNative.Point2 result = GenericsNative.AddPoint2D(value, value); + Assert.AreEqual(result.e00, 2.0); + Assert.AreEqual(result.e01, 4.0); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.Point2 result2 = GenericsNative.AddPoint2Ds(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0); + Assert.AreEqual(result2.e01, 10.0); + } + + GenericsNative.Point2 result3 = GenericsNative.AddPoint2Ds(values, values.Length); + Assert.AreEqual(result3.e00, 5.0); + Assert.AreEqual(result3.e01, 10.0); + + GenericsNative.Point2 result4 = GenericsNative.AddPoint2Ds(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0); + Assert.AreEqual(result4.e01, 10.0); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2F.cs new file mode 100644 index 0000000000000000000000000000000000000000..c31a04b3100206d9da05df51aa2cf4cf84ef7a8d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2F.cs @@ -0,0 +1,91 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2F(float e00, float e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2FOut(float e00, float e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2FOut(float e00, float e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2FPtr(float e00, float e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2FPtr")] + public static extern ref readonly Point2 GetPoint2FRef(float e00, float e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2F(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Fs(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Fs(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2F() + { + GenericsNative.Point2 value = GenericsNative.GetPoint2F(1.0f, 2.0f); + Assert.AreEqual(value.e00, 1.0f); + Assert.AreEqual(value.e01, 2.0f); + + GenericsNative.Point2 value2; + GenericsNative.GetPoint2FOut(1.0f, 2.0f, &value2); + Assert.AreEqual(value2.e00, 1.0f); + Assert.AreEqual(value2.e01, 2.0f); + + GenericsNative.GetPoint2FOut(1.0f, 2.0f, out GenericsNative.Point2 value3); + Assert.AreEqual(value3.e00, 1.0f); + Assert.AreEqual(value3.e01, 2.0f); + + GenericsNative.Point2* value4 = GenericsNative.GetPoint2FPtr(1.0f, 2.0f); + Assert.AreEqual(value4->e00, 1.0f); + Assert.AreEqual(value4->e01, 2.0f); + + ref readonly GenericsNative.Point2 value5 = ref GenericsNative.GetPoint2FRef(1.0f, 2.0f); + Assert.AreEqual(value5.e00, 1.0f); + Assert.AreEqual(value5.e01, 2.0f); + + GenericsNative.Point2 result = GenericsNative.AddPoint2F(value, value); + Assert.AreEqual(result.e00, 2.0f); + Assert.AreEqual(result.e01, 4.0f); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.Point2 result2 = GenericsNative.AddPoint2Fs(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0f); + Assert.AreEqual(result2.e01, 10.0f); + } + + GenericsNative.Point2 result3 = GenericsNative.AddPoint2Fs(values, values.Length); + Assert.AreEqual(result3.e00, 5.0f); + Assert.AreEqual(result3.e01, 10.0f); + + GenericsNative.Point2 result4 = GenericsNative.AddPoint2Fs(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0f); + Assert.AreEqual(result4.e01, 10.0f); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2L.cs new file mode 100644 index 0000000000000000000000000000000000000000..12190503354823cd24f35bba7695415d0d10172d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2L.cs @@ -0,0 +1,91 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2L(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2LOut(long e00, long e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2LOut(long e00, long e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2LPtr(long e00, long e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2LPtr")] + public static extern ref readonly Point2 GetPoint2LRef(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2L(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ls(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Ls(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2L() + { + GenericsNative.Point2 value = GenericsNative.GetPoint2L(1L, 2L); + Assert.AreEqual(value.e00, 1L); + Assert.AreEqual(value.e01, 2L); + + GenericsNative.Point2 value2; + GenericsNative.GetPoint2LOut(1L, 2L, &value2); + Assert.AreEqual(value2.e00, 1L); + Assert.AreEqual(value2.e01, 2L); + + GenericsNative.GetPoint2LOut(1L, 2L, out GenericsNative.Point2 value3); + Assert.AreEqual(value3.e00, 1L); + Assert.AreEqual(value3.e01, 2L); + + GenericsNative.Point2* value4 = GenericsNative.GetPoint2LPtr(1L, 2L); + Assert.AreEqual(value4->e00, 1L); + Assert.AreEqual(value4->e01, 2L); + + ref readonly GenericsNative.Point2 value5 = ref GenericsNative.GetPoint2LRef(1L, 2L); + Assert.AreEqual(value5.e00, 1L); + Assert.AreEqual(value5.e01, 2L); + + GenericsNative.Point2 result = GenericsNative.AddPoint2L(value, value); + Assert.AreEqual(result.e00, 2L); + Assert.AreEqual(result.e01, 4L); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.Point2 result2 = GenericsNative.AddPoint2Ls(pValues, values.Length); + Assert.AreEqual(result2.e00, 5l); + Assert.AreEqual(result2.e01, 10l); + } + + GenericsNative.Point2 result3 = GenericsNative.AddPoint2Ls(values, values.Length); + Assert.AreEqual(result3.e00, 5l); + Assert.AreEqual(result3.e01, 10l); + + GenericsNative.Point2 result4 = GenericsNative.AddPoint2Ls(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5l); + Assert.AreEqual(result4.e01, 10l); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2U.cs new file mode 100644 index 0000000000000000000000000000000000000000..9cd9c87b2a151440db13ec8ff1e7ab431acf90e9 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2U.cs @@ -0,0 +1,91 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point2 GetPoint2U(uint e00, uint e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2UOut(uint e00, uint e01, Point2* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint2UOut(uint e00, uint e01, out Point2 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point2* GetPoint2UPtr(uint e00, uint e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2UPtr")] + public static extern ref readonly Point2 GetPoint2URef(uint e00, uint e01); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2U(Point2 lhs, Point2 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Us(Point2* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point2 AddPoint2Us(in Point2 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint2U() + { + GenericsNative.Point2 value = GenericsNative.GetPoint2U(1u, 2u); + Assert.AreEqual(value.e00, 1u); + Assert.AreEqual(value.e01, 2u); + + GenericsNative.Point2 value2; + GenericsNative.GetPoint2UOut(1u, 2u, &value2); + Assert.AreEqual(value2.e00, 1u); + Assert.AreEqual(value2.e01, 2u); + + GenericsNative.GetPoint2UOut(1u, 2u, out GenericsNative.Point2 value3); + Assert.AreEqual(value3.e00, 1u); + Assert.AreEqual(value3.e01, 2u); + + GenericsNative.Point2* value4 = GenericsNative.GetPoint2UPtr(1u, 2u); + Assert.AreEqual(value4->e00, 1u); + Assert.AreEqual(value4->e01, 2u); + + ref readonly GenericsNative.Point2 value5 = ref GenericsNative.GetPoint2URef(1u, 2u); + Assert.AreEqual(value5.e00, 1u); + Assert.AreEqual(value5.e01, 2u); + + GenericsNative.Point2 result = GenericsNative.AddPoint2U(value, value); + Assert.AreEqual(result.e00, 2u); + Assert.AreEqual(result.e01, 4u); + + GenericsNative.Point2[] values = new GenericsNative.Point2[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point2* pValues = &values[0]) + { + GenericsNative.Point2 result2 = GenericsNative.AddPoint2Us(pValues, values.Length); + Assert.AreEqual(result2.e00, 5u); + Assert.AreEqual(result2.e01, 10u); + } + + GenericsNative.Point2 result3 = GenericsNative.AddPoint2Us(values, values.Length); + Assert.AreEqual(result3.e00, 5u); + Assert.AreEqual(result3.e01, 10u); + + GenericsNative.Point2 result4 = GenericsNative.AddPoint2Us(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5u); + Assert.AreEqual(result4.e01, 10u); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs new file mode 100644 index 0000000000000000000000000000000000000000..4cec3bea7088ee28a692db8427e8ed15c1109561 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3B(bool e00, bool e01, bool e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3BOut(bool e00, bool e01, bool e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3BOut(bool e00, bool e01, bool e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3BPtr(bool e00, bool e01, bool e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3BPtr")] + public static extern ref readonly Point3 GetPoint3BRef(bool e00, bool e01, bool e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3B(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Bs(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Bs(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3B() + { + Assert.Throws(() => GenericsNative.GetPoint3B(true, false, true)); + + Assert.Throws(() => { + GenericsNative.Point3 value2; + GenericsNative.GetPoint3BOut(true, false, true, &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint3BOut(true, false, true, out GenericsNative.Point3 value3)); + + Assert.Throws(() => GenericsNative.GetPoint3BPtr(true, false, true)); + + Assert.Throws(() => GenericsNative.GetPoint3BRef(true, false, true)); + + Assert.Throws(() => GenericsNative.AddPoint3B(default, default)); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.AddPoint3Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint3Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint3Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs new file mode 100644 index 0000000000000000000000000000000000000000..f461443c41bc5559022d53d06d9bd0b9f34ca4f8 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3C(char e00, char e01, char e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3COut(char e00, char e01, char e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3COut(char e00, char e01, char e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3CPtr(char e00, char e01, char e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3CPtr")] + public static extern ref readonly Point3 GetPoint3CRef(char e00, char e01, char e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3C(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Cs(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Cs(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3C() + { + Assert.Throws(() => GenericsNative.GetPoint3C('1', '2', '3')); + + Assert.Throws(() => { + GenericsNative.Point3 value2; + GenericsNative.GetPoint3COut('1', '2', '3', &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint3COut('1', '2', '3', out GenericsNative.Point3 value3)); + + Assert.Throws(() => GenericsNative.GetPoint3CPtr('1', '2', '3')); + + Assert.Throws(() => GenericsNative.GetPoint3CRef('1', '2', '3')); + + Assert.Throws(() => GenericsNative.AddPoint3C(default, default)); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.AddPoint3Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint3Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint3Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3D.cs new file mode 100644 index 0000000000000000000000000000000000000000..e7809458c907d64e0d32ba0022288fc5f9b2fd16 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3D.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3D(double e00, double e01, double e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3DOut(double e00, double e01, double e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3DOut(double e00, double e01, double e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3DPtr(double e00, double e01, double e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3DPtr")] + public static extern ref readonly Point3 GetPoint3DRef(double e00, double e01, double e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3D(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ds(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ds(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3D() + { + GenericsNative.Point3 value = GenericsNative.GetPoint3D(1.0, 2.0, 3.0); + Assert.AreEqual(value.e00, 1.0); + Assert.AreEqual(value.e01, 2.0); + Assert.AreEqual(value.e02, 3.0); + + GenericsNative.Point3 value2; + GenericsNative.GetPoint3DOut(1.0, 2.0, 3.0, &value2); + Assert.AreEqual(value2.e00, 1.0); + Assert.AreEqual(value2.e01, 2.0); + Assert.AreEqual(value2.e02, 3.0); + + GenericsNative.GetPoint3DOut(1.0, 2.0, 3.0, out GenericsNative.Point3 value3); + Assert.AreEqual(value3.e00, 1.0); + Assert.AreEqual(value3.e01, 2.0); + Assert.AreEqual(value3.e02, 3.0); + + GenericsNative.Point3* value4 = GenericsNative.GetPoint3DPtr(1.0, 2.0, 3.0); + Assert.AreEqual(value4->e00, 1.0); + Assert.AreEqual(value4->e01, 2.0); + Assert.AreEqual(value4->e02, 3.0); + + ref readonly GenericsNative.Point3 value5 = ref GenericsNative.GetPoint3DRef(1.0, 2.0, 3.0); + Assert.AreEqual(value5.e00, 1.0); + Assert.AreEqual(value5.e01, 2.0); + Assert.AreEqual(value5.e02, 3.0); + + GenericsNative.Point3 result = GenericsNative.AddPoint3D(value, value); + Assert.AreEqual(result.e00, 2.0); + Assert.AreEqual(result.e01, 4.0); + Assert.AreEqual(result.e02, 6.0); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.Point3 result2 = GenericsNative.AddPoint3Ds(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0); + Assert.AreEqual(result2.e01, 10.0); + Assert.AreEqual(result2.e02, 15.0); + } + + GenericsNative.Point3 result3 = GenericsNative.AddPoint3Ds(values, values.Length); + Assert.AreEqual(result3.e00, 5.0); + Assert.AreEqual(result3.e01, 10.0); + Assert.AreEqual(result3.e02, 15.0); + + GenericsNative.Point3 result4 = GenericsNative.AddPoint3Ds(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0); + Assert.AreEqual(result4.e01, 10.0); + Assert.AreEqual(result4.e02, 15.0); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3F.cs new file mode 100644 index 0000000000000000000000000000000000000000..0c13e938167ae7f1183d011c2bb3d5f1e97b319e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3F.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3F(float e00, float e01, float e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3FOut(float e00, float e01, float e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3FOut(float e00, float e01, float e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3FPtr(float e00, float e01, float e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3FPtr")] + public static extern ref readonly Point3 GetPoint3FRef(float e00, float e01, float e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3F(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Fs(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Fs(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3F() + { + GenericsNative.Point3 value = GenericsNative.GetPoint3F(1.0f, 2.0f, 3.0f); + Assert.AreEqual(value.e00, 1.0f); + Assert.AreEqual(value.e01, 2.0f); + Assert.AreEqual(value.e02, 3.0f); + + GenericsNative.Point3 value2; + GenericsNative.GetPoint3FOut(1.0f, 2.0f, 3.0f, &value2); + Assert.AreEqual(value2.e00, 1.0f); + Assert.AreEqual(value2.e01, 2.0f); + Assert.AreEqual(value2.e02, 3.0f); + + GenericsNative.GetPoint3FOut(1.0f, 2.0f, 3.0f, out GenericsNative.Point3 value3); + Assert.AreEqual(value3.e00, 1.0f); + Assert.AreEqual(value3.e01, 2.0f); + Assert.AreEqual(value3.e02, 3.0f); + + GenericsNative.Point3* value4 = GenericsNative.GetPoint3FPtr(1.0f, 2.0f, 3.0f); + Assert.AreEqual(value4->e00, 1.0f); + Assert.AreEqual(value4->e01, 2.0f); + Assert.AreEqual(value4->e02, 3.0f); + + ref readonly GenericsNative.Point3 value5 = ref GenericsNative.GetPoint3FRef(1.0f, 2.0f, 3.0f); + Assert.AreEqual(value5.e00, 1.0f); + Assert.AreEqual(value5.e01, 2.0f); + Assert.AreEqual(value5.e02, 3.0f); + + GenericsNative.Point3 result = GenericsNative.AddPoint3F(value, value); + Assert.AreEqual(result.e00, 2.0f); + Assert.AreEqual(result.e01, 4.0f); + Assert.AreEqual(result.e02, 6.0f); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.Point3 result2 = GenericsNative.AddPoint3Fs(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0f); + Assert.AreEqual(result2.e01, 10.0f); + Assert.AreEqual(result2.e02, 15.0f); + } + + GenericsNative.Point3 result3 = GenericsNative.AddPoint3Fs(values, values.Length); + Assert.AreEqual(result3.e00, 5.0f); + Assert.AreEqual(result3.e01, 10.0f); + Assert.AreEqual(result3.e02, 15.0f); + + GenericsNative.Point3 result4 = GenericsNative.AddPoint3Fs(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0f); + Assert.AreEqual(result4.e01, 10.0f); + Assert.AreEqual(result4.e02, 15.0f); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3L.cs new file mode 100644 index 0000000000000000000000000000000000000000..91b33f8e473405409d1a64de5e7778166ccbf63b --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3L.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3L(long e00, long e01, long e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3LOut(long e00, long e01, long e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3LOut(long e00, long e01, long e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3LPtr(long e00, long e01, long e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3LPtr")] + public static extern ref readonly Point3 GetPoint3LRef(long e00, long e01, long e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3L(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ls(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Ls(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3L() + { + GenericsNative.Point3 value = GenericsNative.GetPoint3L(1L, 2L, 3L); + Assert.AreEqual(value.e00, 1L); + Assert.AreEqual(value.e01, 2L); + Assert.AreEqual(value.e02, 3L); + + GenericsNative.Point3 value2; + GenericsNative.GetPoint3LOut(1L, 2L, 3L, &value2); + Assert.AreEqual(value2.e00, 1L); + Assert.AreEqual(value2.e01, 2L); + Assert.AreEqual(value2.e02, 3L); + + GenericsNative.GetPoint3LOut(1L, 2L, 3L, out GenericsNative.Point3 value3); + Assert.AreEqual(value3.e00, 1L); + Assert.AreEqual(value3.e01, 2L); + Assert.AreEqual(value3.e02, 3L); + + GenericsNative.Point3* value4 = GenericsNative.GetPoint3LPtr(1L, 2L, 3L); + Assert.AreEqual(value4->e00, 1L); + Assert.AreEqual(value4->e01, 2L); + Assert.AreEqual(value4->e02, 3L); + + ref readonly GenericsNative.Point3 value5 = ref GenericsNative.GetPoint3LRef(1L, 2L, 3L); + Assert.AreEqual(value5.e00, 1L); + Assert.AreEqual(value5.e01, 2L); + Assert.AreEqual(value5.e02, 3L); + + GenericsNative.Point3 result = GenericsNative.AddPoint3L(value, value); + Assert.AreEqual(result.e00, 2L); + Assert.AreEqual(result.e01, 4L); + Assert.AreEqual(result.e02, 6l); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.Point3 result2 = GenericsNative.AddPoint3Ls(pValues, values.Length); + Assert.AreEqual(result2.e00, 5l); + Assert.AreEqual(result2.e01, 10l); + Assert.AreEqual(result2.e02, 15l); + } + + GenericsNative.Point3 result3 = GenericsNative.AddPoint3Ls(values, values.Length); + Assert.AreEqual(result3.e00, 5l); + Assert.AreEqual(result3.e01, 10l); + Assert.AreEqual(result3.e02, 15l); + + GenericsNative.Point3 result4 = GenericsNative.AddPoint3Ls(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5l); + Assert.AreEqual(result4.e01, 10l); + Assert.AreEqual(result4.e02, 15l); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3U.cs new file mode 100644 index 0000000000000000000000000000000000000000..9ee7de03e37b526bbf61ac203eda8e09fcca5ab0 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3U.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point3 GetPoint3U(uint e00, uint e01, uint e02); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3UOut(uint e00, uint e01, uint e02, Point3* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint3UOut(uint e00, uint e01, uint e02, out Point3 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point3* GetPoint3UPtr(uint e00, uint e01, uint e02); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3UPtr")] + public static extern ref readonly Point3 GetPoint3URef(uint e00, uint e01, uint e02); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3U(Point3 lhs, Point3 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Us(Point3* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point3 AddPoint3Us(in Point3 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint3U() + { + GenericsNative.Point3 value = GenericsNative.GetPoint3U(1u, 2u, 3u); + Assert.AreEqual(value.e00, 1u); + Assert.AreEqual(value.e01, 2u); + Assert.AreEqual(value.e02, 3u); + + GenericsNative.Point3 value2; + GenericsNative.GetPoint3UOut(1u, 2u, 3u, &value2); + Assert.AreEqual(value2.e00, 1u); + Assert.AreEqual(value2.e01, 2u); + Assert.AreEqual(value2.e02, 3u); + + GenericsNative.GetPoint3UOut(1u, 2u, 3u, out GenericsNative.Point3 value3); + Assert.AreEqual(value3.e00, 1u); + Assert.AreEqual(value3.e01, 2u); + Assert.AreEqual(value3.e02, 3u); + + GenericsNative.Point3* value4 = GenericsNative.GetPoint3UPtr(1u, 2u, 3u); + Assert.AreEqual(value4->e00, 1u); + Assert.AreEqual(value4->e01, 2u); + Assert.AreEqual(value4->e02, 3u); + + ref readonly GenericsNative.Point3 value5 = ref GenericsNative.GetPoint3URef(1u, 2u, 3u); + Assert.AreEqual(value5.e00, 1u); + Assert.AreEqual(value5.e01, 2u); + Assert.AreEqual(value5.e02, 3u); + + GenericsNative.Point3 result = GenericsNative.AddPoint3U(value, value); + Assert.AreEqual(result.e00, 2u); + Assert.AreEqual(result.e01, 4u); + Assert.AreEqual(result.e02, 6u); + + GenericsNative.Point3[] values = new GenericsNative.Point3[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point3* pValues = &values[0]) + { + GenericsNative.Point3 result2 = GenericsNative.AddPoint3Us(pValues, values.Length); + Assert.AreEqual(result2.e00, 5u); + Assert.AreEqual(result2.e01, 10u); + Assert.AreEqual(result2.e02, 15u); + } + + GenericsNative.Point3 result3 = GenericsNative.AddPoint3Us(values, values.Length); + Assert.AreEqual(result3.e00, 5u); + Assert.AreEqual(result3.e01, 10u); + Assert.AreEqual(result3.e02, 15u); + + GenericsNative.Point3 result4 = GenericsNative.AddPoint3Us(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5u); + Assert.AreEqual(result4.e01, 10u); + Assert.AreEqual(result4.e02, 15u); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs new file mode 100644 index 0000000000000000000000000000000000000000..e66be24654f366d1a9efc0441de7ae7669b5df01 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4B(bool e00, bool e01, bool e02, bool e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4BOut(bool e00, bool e01, bool e02, bool e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4BOut(bool e00, bool e01, bool e02, bool e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4BPtr(bool e00, bool e01, bool e02, bool e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4BPtr")] + public static extern ref readonly Point4 GetPoint4BRef(bool e00, bool e01, bool e02, bool e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4B(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Bs(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Bs(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4B() + { + Assert.Throws(() => GenericsNative.GetPoint4B(true, false, true, false)); + + Assert.Throws(() => { + GenericsNative.Point4 value2; + GenericsNative.GetPoint4BOut(true, false, true, false, &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint4BOut(true, false, true, false, out GenericsNative.Point4 value3)); + + Assert.Throws(() => GenericsNative.GetPoint4BPtr(true, false, true, false)); + + Assert.Throws(() => GenericsNative.GetPoint4BRef(true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddPoint4B(default, default)); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.AddPoint4Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint4Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint4Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs new file mode 100644 index 0000000000000000000000000000000000000000..7c9d297c8ec0f102bf6230e588b794628ceac591 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4C(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4COut(char e00, char e01, char e02, char e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4COut(char e00, char e01, char e02, char e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4CPtr(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4CPtr")] + public static extern ref readonly Point4 GetPoint4CRef(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4C(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Cs(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Cs(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4C() + { + Assert.Throws(() => GenericsNative.GetPoint4C('1', '2', '3', '4')); + + Assert.Throws(() => { + GenericsNative.Point4 value2; + GenericsNative.GetPoint4COut('1', '2', '3', '4', &value2); + }); + + Assert.Throws(() => GenericsNative.GetPoint4COut('1', '2', '3', '4', out GenericsNative.Point4 value3)); + + Assert.Throws(() => GenericsNative.GetPoint4CPtr('1', '2', '3', '4')); + + Assert.Throws(() => GenericsNative.GetPoint4CRef('1', '2', '3', '4')); + + Assert.Throws(() => GenericsNative.AddPoint4C(default, default)); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + default, + default, + default, + default, + default + }; + + Assert.Throws(() => { + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.AddPoint4Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddPoint4Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddPoint4Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4D.cs new file mode 100644 index 0000000000000000000000000000000000000000..262bb37c2fcaccef4970567a79809d739421adf1 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4D.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4D(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4DOut(double e00, double e01, double e02, double e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4DOut(double e00, double e01, double e02, double e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4DPtr(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4DPtr")] + public static extern ref readonly Point4 GetPoint4DRef(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4D(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ds(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ds(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4D() + { + GenericsNative.Point4 value = GenericsNative.GetPoint4D(1.0, 2.0, 3.0, 4.0); + Assert.AreEqual(value.e00, 1.0); + Assert.AreEqual(value.e01, 2.0); + Assert.AreEqual(value.e02, 3.0); + Assert.AreEqual(value.e03, 4.0); + + GenericsNative.Point4 value2; + GenericsNative.GetPoint4DOut(1.0, 2.0, 3.0, 4.0, &value2); + Assert.AreEqual(value2.e00, 1.0); + Assert.AreEqual(value2.e01, 2.0); + Assert.AreEqual(value2.e02, 3.0); + Assert.AreEqual(value2.e03, 4.0); + + GenericsNative.GetPoint4DOut(1.0, 2.0, 3.0, 4.0, out GenericsNative.Point4 value3); + Assert.AreEqual(value3.e00, 1.0); + Assert.AreEqual(value3.e01, 2.0); + Assert.AreEqual(value3.e02, 3.0); + Assert.AreEqual(value3.e03, 4.0); + + GenericsNative.Point4* value4 = GenericsNative.GetPoint4DPtr(1.0, 2.0, 3.0, 4.0); + Assert.AreEqual(value4->e00, 1.0); + Assert.AreEqual(value4->e01, 2.0); + Assert.AreEqual(value4->e02, 3.0); + Assert.AreEqual(value4->e03, 4.0); + + ref readonly GenericsNative.Point4 value5 = ref GenericsNative.GetPoint4DRef(1.0, 2.0, 3.0, 4.0); + Assert.AreEqual(value5.e00, 1.0); + Assert.AreEqual(value5.e01, 2.0); + Assert.AreEqual(value5.e02, 3.0); + Assert.AreEqual(value5.e03, 4.0); + + GenericsNative.Point4 result = GenericsNative.AddPoint4D(value, value); + Assert.AreEqual(result.e00, 2.0); + Assert.AreEqual(result.e01, 4.0); + Assert.AreEqual(result.e02, 6.0); + Assert.AreEqual(result.e03, 8.0); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.Point4 result2 = GenericsNative.AddPoint4Ds(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0); + Assert.AreEqual(result2.e01, 10.0); + Assert.AreEqual(result2.e02, 15.0); + Assert.AreEqual(result2.e03, 20.0); + } + + GenericsNative.Point4 result3 = GenericsNative.AddPoint4Ds(values, values.Length); + Assert.AreEqual(result3.e00, 5.0); + Assert.AreEqual(result3.e01, 10.0); + Assert.AreEqual(result3.e02, 15.0); + Assert.AreEqual(result3.e03, 20.0); + + GenericsNative.Point4 result4 = GenericsNative.AddPoint4Ds(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0); + Assert.AreEqual(result4.e01, 10.0); + Assert.AreEqual(result4.e02, 15.0); + Assert.AreEqual(result4.e03, 20.0); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4F.cs new file mode 100644 index 0000000000000000000000000000000000000000..1ed8626f8f44a9bfa23dac2f536d59a35511c07f --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4F.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4F(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4FOut(float e00, float e01, float e02, float e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4FOut(float e00, float e01, float e02, float e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4FPtr(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4FPtr")] + public static extern ref readonly Point4 GetPoint4FRef(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4F(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Fs(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Fs(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4F() + { + GenericsNative.Point4 value = GenericsNative.GetPoint4F(1.0f, 2.0f, 3.0f, 4.0f); + Assert.AreEqual(value.e00, 1.0f); + Assert.AreEqual(value.e01, 2.0f); + Assert.AreEqual(value.e02, 3.0f); + Assert.AreEqual(value.e03, 4.0f); + + GenericsNative.Point4 value2; + GenericsNative.GetPoint4FOut(1.0f, 2.0f, 3.0f, 4.0f, &value2); + Assert.AreEqual(value2.e00, 1.0f); + Assert.AreEqual(value2.e01, 2.0f); + Assert.AreEqual(value2.e02, 3.0f); + Assert.AreEqual(value2.e03, 4.0f); + + GenericsNative.GetPoint4FOut(1.0f, 2.0f, 3.0f, 4.0f, out GenericsNative.Point4 value3); + Assert.AreEqual(value3.e00, 1.0f); + Assert.AreEqual(value3.e01, 2.0f); + Assert.AreEqual(value3.e02, 3.0f); + Assert.AreEqual(value3.e03, 4.0f); + + GenericsNative.Point4* value4 = GenericsNative.GetPoint4FPtr(1.0f, 2.0f, 3.0f, 4.0f); + Assert.AreEqual(value4->e00, 1.0f); + Assert.AreEqual(value4->e01, 2.0f); + Assert.AreEqual(value4->e02, 3.0f); + Assert.AreEqual(value4->e03, 4.0f); + + ref readonly GenericsNative.Point4 value5 = ref GenericsNative.GetPoint4FRef(1.0f, 2.0f, 3.0f, 4.0f); + Assert.AreEqual(value5.e00, 1.0f); + Assert.AreEqual(value5.e01, 2.0f); + Assert.AreEqual(value5.e02, 3.0f); + Assert.AreEqual(value5.e03, 4.0f); + + GenericsNative.Point4 result = GenericsNative.AddPoint4F(value, value); + Assert.AreEqual(result.e00, 2.0f); + Assert.AreEqual(result.e01, 4.0f); + Assert.AreEqual(result.e02, 6.0f); + Assert.AreEqual(result.e03, 8.0f); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.Point4 result2 = GenericsNative.AddPoint4Fs(pValues, values.Length); + Assert.AreEqual(result2.e00, 5.0f); + Assert.AreEqual(result2.e01, 10.0f); + Assert.AreEqual(result2.e02, 15.0f); + Assert.AreEqual(result2.e03, 20.0f); + } + + GenericsNative.Point4 result3 = GenericsNative.AddPoint4Fs(values, values.Length); + Assert.AreEqual(result3.e00, 5.0f); + Assert.AreEqual(result3.e01, 10.0f); + Assert.AreEqual(result3.e02, 15.0f); + Assert.AreEqual(result3.e03, 20.0f); + + GenericsNative.Point4 result4 = GenericsNative.AddPoint4Fs(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5.0f); + Assert.AreEqual(result4.e01, 10.0f); + Assert.AreEqual(result4.e02, 15.0f); + Assert.AreEqual(result4.e03, 20.0f); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4L.cs new file mode 100644 index 0000000000000000000000000000000000000000..dc6ece19b7747ef6eb621849929c057108c3b990 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4L.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4L(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4LOut(long e00, long e01, long e02, long e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4LOut(long e00, long e01, long e02, long e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4LPtr(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4LPtr")] + public static extern ref readonly Point4 GetPoint4LRef(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4L(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ls(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Ls(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4L() + { + GenericsNative.Point4 value = GenericsNative.GetPoint4L(1L, 2L, 3L, 4L); + Assert.AreEqual(value.e00, 1L); + Assert.AreEqual(value.e01, 2L); + Assert.AreEqual(value.e02, 3L); + Assert.AreEqual(value.e03, 4L); + + GenericsNative.Point4 value2; + GenericsNative.GetPoint4LOut(1L, 2L, 3L, 4L, &value2); + Assert.AreEqual(value2.e00, 1L); + Assert.AreEqual(value2.e01, 2L); + Assert.AreEqual(value2.e02, 3L); + Assert.AreEqual(value2.e03, 4L); + + GenericsNative.GetPoint4LOut(1L, 2L, 3L, 4L, out GenericsNative.Point4 value3); + Assert.AreEqual(value3.e00, 1L); + Assert.AreEqual(value3.e01, 2L); + Assert.AreEqual(value3.e02, 3L); + Assert.AreEqual(value3.e03, 4L); + + GenericsNative.Point4* value4 = GenericsNative.GetPoint4LPtr(1L, 2L, 3L, 4L); + Assert.AreEqual(value4->e00, 1L); + Assert.AreEqual(value4->e01, 2L); + Assert.AreEqual(value4->e02, 3L); + Assert.AreEqual(value4->e03, 4L); + + ref readonly GenericsNative.Point4 value5 = ref GenericsNative.GetPoint4LRef(1L, 2L, 3L, 4L); + Assert.AreEqual(value5.e00, 1L); + Assert.AreEqual(value5.e01, 2L); + Assert.AreEqual(value5.e02, 3L); + Assert.AreEqual(value5.e03, 4L); + + GenericsNative.Point4 result = GenericsNative.AddPoint4L(value, value); + Assert.AreEqual(result.e00, 2L); + Assert.AreEqual(result.e01, 4L); + Assert.AreEqual(result.e02, 6l); + Assert.AreEqual(result.e03, 8l); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.Point4 result2 = GenericsNative.AddPoint4Ls(pValues, values.Length); + Assert.AreEqual(result2.e00, 5l); + Assert.AreEqual(result2.e01, 10l); + Assert.AreEqual(result2.e02, 15l); + Assert.AreEqual(result2.e03, 20l); + } + + GenericsNative.Point4 result3 = GenericsNative.AddPoint4Ls(values, values.Length); + Assert.AreEqual(result3.e00, 5l); + Assert.AreEqual(result3.e01, 10l); + Assert.AreEqual(result3.e02, 15l); + Assert.AreEqual(result3.e03, 20l); + + GenericsNative.Point4 result4 = GenericsNative.AddPoint4Ls(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5l); + Assert.AreEqual(result4.e01, 10l); + Assert.AreEqual(result4.e02, 15l); + Assert.AreEqual(result4.e03, 20l); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4U.cs new file mode 100644 index 0000000000000000000000000000000000000000..62c34ea21f8f3b13112ea5df06233fccc5e0035a --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4U.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Point4 GetPoint4U(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4UOut(uint e00, uint e01, uint e02, uint e03, Point4* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetPoint4UOut(uint e00, uint e01, uint e02, uint e03, out Point4 value); + + [DllImport(nameof(GenericsNative))] + public static extern Point4* GetPoint4UPtr(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4UPtr")] + public static extern ref readonly Point4 GetPoint4URef(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4U(Point4 lhs, Point4 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Us(Point4* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Point4 AddPoint4Us(in Point4 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestPoint4U() + { + GenericsNative.Point4 value = GenericsNative.GetPoint4U(1u, 2u, 3u, 4u); + Assert.AreEqual(value.e00, 1u); + Assert.AreEqual(value.e01, 2u); + Assert.AreEqual(value.e02, 3u); + Assert.AreEqual(value.e03, 4u); + + GenericsNative.Point4 value2; + GenericsNative.GetPoint4UOut(1u, 2u, 3u, 4u, &value2); + Assert.AreEqual(value2.e00, 1u); + Assert.AreEqual(value2.e01, 2u); + Assert.AreEqual(value2.e02, 3u); + Assert.AreEqual(value2.e03, 4u); + + GenericsNative.GetPoint4UOut(1u, 2u, 3u, 4u, out GenericsNative.Point4 value3); + Assert.AreEqual(value3.e00, 1u); + Assert.AreEqual(value3.e01, 2u); + Assert.AreEqual(value3.e02, 3u); + Assert.AreEqual(value3.e03, 4u); + + GenericsNative.Point4* value4 = GenericsNative.GetPoint4UPtr(1u, 2u, 3u, 4u); + Assert.AreEqual(value4->e00, 1u); + Assert.AreEqual(value4->e01, 2u); + Assert.AreEqual(value4->e02, 3u); + Assert.AreEqual(value4->e03, 4u); + + ref readonly GenericsNative.Point4 value5 = ref GenericsNative.GetPoint4URef(1u, 2u, 3u, 4u); + Assert.AreEqual(value5.e00, 1u); + Assert.AreEqual(value5.e01, 2u); + Assert.AreEqual(value5.e02, 3u); + Assert.AreEqual(value5.e03, 4u); + + GenericsNative.Point4 result = GenericsNative.AddPoint4U(value, value); + Assert.AreEqual(result.e00, 2u); + Assert.AreEqual(result.e01, 4u); + Assert.AreEqual(result.e02, 6u); + Assert.AreEqual(result.e03, 8u); + + GenericsNative.Point4[] values = new GenericsNative.Point4[] { + value, + value2, + value3, + *value4, + value5 + }; + + fixed (GenericsNative.Point4* pValues = &values[0]) + { + GenericsNative.Point4 result2 = GenericsNative.AddPoint4Us(pValues, values.Length); + Assert.AreEqual(result2.e00, 5u); + Assert.AreEqual(result2.e01, 10u); + Assert.AreEqual(result2.e02, 15u); + Assert.AreEqual(result2.e03, 20u); + } + + GenericsNative.Point4 result3 = GenericsNative.AddPoint4Us(values, values.Length); + Assert.AreEqual(result3.e00, 5u); + Assert.AreEqual(result3.e01, 10u); + Assert.AreEqual(result3.e02, 15u); + Assert.AreEqual(result3.e03, 20u); + + GenericsNative.Point4 result4 = GenericsNative.AddPoint4Us(in values[0], values.Length); + Assert.AreEqual(result4.e00, 5u); + Assert.AreEqual(result4.e01, 10u); + Assert.AreEqual(result4.e02, 15u); + Assert.AreEqual(result4.e03, 20u); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanB.cs new file mode 100644 index 0000000000000000000000000000000000000000..4f92f537c5e4ea17ad45a530335b095376ab0064 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanB.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanB")] + public static extern ReadOnlySpan GetReadOnlySpanB(bool e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanBOut")] + public static extern void GetReadOnlySpanBOut(bool e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanBPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanBRef(bool e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanB")] + public static extern ReadOnlySpan AddReadOnlySpanB(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanBs")] + public static extern ReadOnlySpan AddReadOnlySpanBs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanB() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanB(true)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanBOut(true, out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanBRef(true)); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanB(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanBs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanC.cs new file mode 100644 index 0000000000000000000000000000000000000000..90cc122567c77f9faedb3b30abbf6ee89a7acfd7 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanC.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanC")] + public static extern ReadOnlySpan GetReadOnlySpanC(char e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanCOut")] + public static extern void GetReadOnlySpanCOut(char e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanCPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanCRef(char e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanC")] + public static extern ReadOnlySpan AddReadOnlySpanC(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanCs")] + public static extern ReadOnlySpan AddReadOnlySpanCs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanC() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanC('1')); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanCOut('1', out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanCRef('1')); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanC(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanCs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanD.cs new file mode 100644 index 0000000000000000000000000000000000000000..e18e3a5eaacd9058a8267c07226d826babd0c13b --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanD.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanD")] + public static extern ReadOnlySpan GetReadOnlySpanD(double e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanDOut")] + public static extern void GetReadOnlySpanDOut(double e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanDPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanDRef(double e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanD")] + public static extern ReadOnlySpan AddReadOnlySpanD(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanDs")] + public static extern ReadOnlySpan AddReadOnlySpanDs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanD() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanD(1.0)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanDOut(1.0, out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanDRef(1.0)); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanD(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanDs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanF.cs new file mode 100644 index 0000000000000000000000000000000000000000..00c67d9e8507655219cdf99ddf0ca7111f7ba2ca --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanF.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanF")] + public static extern ReadOnlySpan GetReadOnlySpanF(float e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanFOut")] + public static extern void GetReadOnlySpanFOut(float e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanFPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanFRef(float e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanF")] + public static extern ReadOnlySpan AddReadOnlySpanF(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanFs")] + public static extern ReadOnlySpan AddReadOnlySpanFs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanF() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanF(1.0f)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanFOut(1.0f, out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanFRef(1.0f)); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanF(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanFs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanL.cs new file mode 100644 index 0000000000000000000000000000000000000000..0539163127cc1949d0a3638e56671c09fe24dbce --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanL.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanL")] + public static extern ReadOnlySpan GetReadOnlySpanL(long e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanLOut")] + public static extern void GetReadOnlySpanLOut(long e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanLPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanLRef(long e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanL")] + public static extern ReadOnlySpan AddReadOnlySpanL(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanLs")] + public static extern ReadOnlySpan AddReadOnlySpanLs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanL() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanL(1L)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanLOut(1L, out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanLRef(1L)); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanL(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanLs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanU.cs new file mode 100644 index 0000000000000000000000000000000000000000..3351c6d47f2bc26c06a0deb6b273ad2dab834f48 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.ReadOnlySpanU.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanU")] + public static extern ReadOnlySpan GetReadOnlySpanU(uint e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanUOut")] + public static extern void GetReadOnlySpanUOut(uint e00, out ReadOnlySpan value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanUPtr")] + public static extern ref readonly ReadOnlySpan GetReadOnlySpanURef(uint e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanU")] + public static extern ReadOnlySpan AddReadOnlySpanU(ReadOnlySpan lhs, ReadOnlySpan rhs); + + [DllImport(nameof(GenericsNative), EntryPoint = "AddSpanUs")] + public static extern ReadOnlySpan AddReadOnlySpanUs(in ReadOnlySpan pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestReadOnlySpanU() + { + Assert.Throws(() => GenericsNative.GetReadOnlySpanU(1u)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanUOut(1u, out ReadOnlySpan value3)); + + Assert.Throws(() => GenericsNative.GetReadOnlySpanURef(1u)); + + Assert.Throws(() => GenericsNative.AddReadOnlySpanU(default, default)); + + Assert.Throws(() => { + ReadOnlySpan value = default; + GenericsNative.AddReadOnlySpanUs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassB.cs new file mode 100644 index 0000000000000000000000000000000000000000..4c8b2b9f720f33b0bf8724a06e6519b27b0d4293 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassB.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassB(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassBOut(bool e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassBPtr")] + public static extern ref readonly SequentialClass GetSequentialClassBRef(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassB(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassBs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassBs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassB() + { + Assert.Throws(() => GenericsNative.GetSequentialClassB(true)); + + Assert.Throws(() => GenericsNative.GetSequentialClassBOut(true, out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassBRef(true)); + + Assert.Throws(() => GenericsNative.AddSequentialClassB(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassBs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassBs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassC.cs new file mode 100644 index 0000000000000000000000000000000000000000..0fc17a1629340b3f5a0466781b9a60d0d75c99cb --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassC.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassC(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassCOut(char e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassCPtr")] + public static extern ref readonly SequentialClass GetSequentialClassCRef(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassC(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassCs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassCs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassC() + { + Assert.Throws(() => GenericsNative.GetSequentialClassC('1')); + + Assert.Throws(() => GenericsNative.GetSequentialClassCOut('1', out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassCRef('1')); + + Assert.Throws(() => GenericsNative.AddSequentialClassC(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassCs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassCs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassD.cs new file mode 100644 index 0000000000000000000000000000000000000000..75ab889d51c233a00f037dfff145c5446319cdef --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassD.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassD(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassDOut(double e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassDPtr")] + public static extern ref readonly SequentialClass GetSequentialClassDRef(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassD(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassDs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassDs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassD() + { + Assert.Throws(() => GenericsNative.GetSequentialClassD(1.0)); + + Assert.Throws(() => GenericsNative.GetSequentialClassDOut(1.0, out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassDRef(1.0)); + + Assert.Throws(() => GenericsNative.AddSequentialClassD(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassDs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassDs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassF.cs new file mode 100644 index 0000000000000000000000000000000000000000..fd8e3e9a4245eaa9164ae7d886b3449096ab1029 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassF.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassF(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassFOut(float e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassFPtr")] + public static extern ref readonly SequentialClass GetSequentialClassFRef(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassF(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassFs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassFs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassF() + { + Assert.Throws(() => GenericsNative.GetSequentialClassF(1.0f)); + + Assert.Throws(() => GenericsNative.GetSequentialClassFOut(1.0f, out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassFRef(1.0f)); + + Assert.Throws(() => GenericsNative.AddSequentialClassF(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassFs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassFs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassL.cs new file mode 100644 index 0000000000000000000000000000000000000000..db67532c1493e9f521ba1c2c37f6c7101a6e7053 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassL.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassL(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassLOut(long e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassLPtr")] + public static extern ref readonly SequentialClass GetSequentialClassLRef(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassL(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassLs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassLs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassL() + { + Assert.Throws(() => GenericsNative.GetSequentialClassL(1L)); + + Assert.Throws(() => GenericsNative.GetSequentialClassLOut(1L, out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassLRef(1L)); + + Assert.Throws(() => GenericsNative.AddSequentialClassL(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassLs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassLs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassU.cs new file mode 100644 index 0000000000000000000000000000000000000000..5bd24570a609fccb795adf2f8a5ce21f4ea3d7cd --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SequentialClassU.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass GetSequentialClassU(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSequentialClassUOut(uint e00, out SequentialClass value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSequentialClassUPtr")] + public static extern ref readonly SequentialClass GetSequentialClassURef(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassU(SequentialClass lhs, SequentialClass rhs); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassUs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SequentialClass[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern SequentialClass AddSequentialClassUs(in SequentialClass pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSequentialClassU() + { + Assert.Throws(() => GenericsNative.GetSequentialClassU(1u)); + + Assert.Throws(() => GenericsNative.GetSequentialClassUOut(1u, out GenericsNative.SequentialClass value2)); + + Assert.Throws(() => GenericsNative.GetSequentialClassURef(1u)); + + Assert.Throws(() => GenericsNative.AddSequentialClassU(default, default)); + + GenericsNative.SequentialClass[] values = new GenericsNative.SequentialClass[] { + default, + default, + default + }; + + Assert.Throws(() => GenericsNative.AddSequentialClassUs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddSequentialClassUs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanB.cs new file mode 100644 index 0000000000000000000000000000000000000000..17778f9be43808211d74506d7fd4f5f3c6d7e23d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanB.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanB(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanBOut(bool e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanBPtr")] + public static extern ref readonly Span GetSpanBRef(bool e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanB(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanBs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanB() + { + Assert.Throws(() => GenericsNative.GetSpanB(true)); + + Assert.Throws(() => GenericsNative.GetSpanBOut(true, out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanBRef(true)); + + Assert.Throws(() => GenericsNative.AddSpanB(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanBs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanC.cs new file mode 100644 index 0000000000000000000000000000000000000000..aafb1dd954480c2ce4cbe60d837d458205f5ba38 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanC.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanC(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanCOut(char e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanCPtr")] + public static extern ref readonly Span GetSpanCRef(char e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanC(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanCs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanC() + { + Assert.Throws(() => GenericsNative.GetSpanC('1')); + + Assert.Throws(() => GenericsNative.GetSpanCOut('1', out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanCRef('1')); + + Assert.Throws(() => GenericsNative.AddSpanC(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanCs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanD.cs new file mode 100644 index 0000000000000000000000000000000000000000..e8deaa61412cbc1d90d87569b8455cabd5ab1a57 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanD.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanD(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanDOut(double e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanDPtr")] + public static extern ref readonly Span GetSpanDRef(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanD(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanDs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanD() + { + Assert.Throws(() => GenericsNative.GetSpanD(1.0)); + + Assert.Throws(() => GenericsNative.GetSpanDOut(1.0, out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanDRef(1.0)); + + Assert.Throws(() => GenericsNative.AddSpanD(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanDs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanF.cs new file mode 100644 index 0000000000000000000000000000000000000000..235d99e8c3137d719d4fb90630603e84a6b37e10 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanF.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanF(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanFOut(float e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanFPtr")] + public static extern ref readonly Span GetSpanFRef(float e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanF(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanFs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanF() + { + Assert.Throws(() => GenericsNative.GetSpanF(1.0f)); + + Assert.Throws(() => GenericsNative.GetSpanFOut(1.0f, out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanFRef(1.0f)); + + Assert.Throws(() => GenericsNative.AddSpanF(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanFs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanL.cs new file mode 100644 index 0000000000000000000000000000000000000000..47e0a3fd5aaec58dece658120272e1c7a38a3dd4 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanL.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanL(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanLOut(long e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanLPtr")] + public static extern ref readonly Span GetSpanLRef(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanL(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanLs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanL() + { + Assert.Throws(() => GenericsNative.GetSpanL(1L)); + + Assert.Throws(() => GenericsNative.GetSpanLOut(1L, out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanLRef(1L)); + + Assert.Throws(() => GenericsNative.AddSpanL(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanLs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanU.cs new file mode 100644 index 0000000000000000000000000000000000000000..85bb47931f34c6cb74039d2fe05b8a44886baf31 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.SpanU.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Doundation under one or more agreements. +// The .NET Doundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Span GetSpanU(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetSpanUOut(uint e00, out Span value); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetSpanUPtr")] + public static extern ref readonly Span GetSpanURef(uint e00); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanU(Span lhs, Span rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Span AddSpanUs(in Span pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestSpanU() + { + Assert.Throws(() => GenericsNative.GetSpanU(1u)); + + Assert.Throws(() => GenericsNative.GetSpanUOut(1u, out Span value3)); + + Assert.Throws(() => GenericsNative.GetSpanURef(1u)); + + Assert.Throws(() => GenericsNative.AddSpanU(default, default)); + + Assert.Throws(() => { + Span value = default; + GenericsNative.AddSpanUs(in value, 1); + }); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128B.cs new file mode 100644 index 0000000000000000000000000000000000000000..d67ada1e21a9520413a168ef2b29a538c54c73b8 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128B.cs @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128BPtr")] + public static extern ref readonly Vector128 GetVector128BRef(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128B(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Bs(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Bs(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128B() + { + Assert.Throws(() => GenericsNative.GetVector128B(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Vector128 value2; + GenericsNative.GetVector128BOut(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, &value2); + Vector128 tValue2 = *(Vector128*)&value2; + Assert.AreEqual(tValue2.GetElement(0), 1); + Assert.AreEqual(tValue2.GetElement(1), 0); + Assert.AreEqual(tValue2.GetElement(2), 1); + Assert.AreEqual(tValue2.GetElement(3), 0); + Assert.AreEqual(tValue2.GetElement(4), 1); + Assert.AreEqual(tValue2.GetElement(5), 0); + Assert.AreEqual(tValue2.GetElement(6), 1); + Assert.AreEqual(tValue2.GetElement(7), 0); + Assert.AreEqual(tValue2.GetElement(8), 1); + Assert.AreEqual(tValue2.GetElement(9), 0); + Assert.AreEqual(tValue2.GetElement(10), 1); + Assert.AreEqual(tValue2.GetElement(11), 0); + Assert.AreEqual(tValue2.GetElement(12), 1); + Assert.AreEqual(tValue2.GetElement(13), 0); + Assert.AreEqual(tValue2.GetElement(14), 1); + Assert.AreEqual(tValue2.GetElement(15), 0); + + Assert.Throws(() => GenericsNative.GetVector128BOut(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128BPtr(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + Vector128* tValue4 = (Vector128*)value4; + Assert.AreEqual(tValue4->GetElement(0), 1); + Assert.AreEqual(tValue4->GetElement(1), 0); + Assert.AreEqual(tValue4->GetElement(2), 1); + Assert.AreEqual(tValue4->GetElement(3), 0); + Assert.AreEqual(tValue4->GetElement(4), 1); + Assert.AreEqual(tValue4->GetElement(5), 0); + Assert.AreEqual(tValue4->GetElement(6), 1); + Assert.AreEqual(tValue4->GetElement(7), 0); + Assert.AreEqual(tValue4->GetElement(8), 1); + Assert.AreEqual(tValue4->GetElement(9), 0); + Assert.AreEqual(tValue4->GetElement(10), 1); + Assert.AreEqual(tValue4->GetElement(11), 0); + Assert.AreEqual(tValue4->GetElement(12), 1); + Assert.AreEqual(tValue4->GetElement(13), 0); + Assert.AreEqual(tValue4->GetElement(14), 1); + Assert.AreEqual(tValue4->GetElement(15), 0); + + Assert.Throws(() => GenericsNative.GetVector128BRef(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddVector128B(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128C.cs new file mode 100644 index 0000000000000000000000000000000000000000..a5e058eca445d3446c327f7854549e0faf5a1c4e --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128C.cs @@ -0,0 +1,94 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128C(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128COut(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128COut(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128CPtr(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128CPtr")] + public static extern ref readonly Vector128 GetVector128CRef(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128C(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Cs(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Cs(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128C() + { + Assert.Throws(() => GenericsNative.GetVector128C('0', '1', '2', '3', '4', '5', '6', '7')); + + Vector128 value2; + GenericsNative.GetVector128COut('0', '1', '2', '3', '4', '5', '6', '7', &value2); + Vector128 tValue2 = *(Vector128*)&value2; + Assert.AreEqual(tValue2.GetElement(0), (short)'0'); + Assert.AreEqual(tValue2.GetElement(1), (short)'1'); + Assert.AreEqual(tValue2.GetElement(2), (short)'2'); + Assert.AreEqual(tValue2.GetElement(3), (short)'3'); + Assert.AreEqual(tValue2.GetElement(4), (short)'4'); + Assert.AreEqual(tValue2.GetElement(5), (short)'5'); + Assert.AreEqual(tValue2.GetElement(6), (short)'6'); + Assert.AreEqual(tValue2.GetElement(7), (short)'7'); + + Assert.Throws(() => GenericsNative.GetVector128COut('0', '1', '2', '3', '4', '5', '6', '7', out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128CPtr('0', '1', '2', '3', '4', '5', '6', '7'); + Vector128* tValue4 = (Vector128*)value4; + Assert.AreEqual(tValue4->GetElement(0), (short)'0'); + Assert.AreEqual(tValue4->GetElement(1), (short)'1'); + Assert.AreEqual(tValue4->GetElement(2), (short)'2'); + Assert.AreEqual(tValue4->GetElement(3), (short)'3'); + Assert.AreEqual(tValue4->GetElement(4), (short)'4'); + Assert.AreEqual(tValue4->GetElement(5), (short)'5'); + Assert.AreEqual(tValue4->GetElement(6), (short)'6'); + Assert.AreEqual(tValue4->GetElement(7), (short)'7'); + + Assert.Throws(() => GenericsNative.GetVector128CRef('0', '1', '2', '3', '4', '5', '6', '7')); + + Assert.Throws(() => GenericsNative.AddVector128C(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128D.cs new file mode 100644 index 0000000000000000000000000000000000000000..c2e04aad007b29dfd1241bd94f193c8706dc3d2f --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128D.cs @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128D(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128DOut(double e00, double e01, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128DOut(double e00, double e01, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128DPtr(double e00, double e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128DPtr")] + public static extern ref readonly Vector128 GetVector128DRef(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128D(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ds(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ds(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128D() + { + Assert.Throws(() => GenericsNative.GetVector128D(1.0, 2.0)); + + Vector128 value2; + GenericsNative.GetVector128DOut(1.0, 2.0, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0); + Assert.AreEqual(value2.GetElement(1), 2.0); + + Assert.Throws(() => GenericsNative.GetVector128DOut(1.0, 2.0, out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128DPtr(1.0, 2.0); + Assert.AreEqual(value4->GetElement(0), 1.0); + Assert.AreEqual(value4->GetElement(1), 2.0); + + Assert.Throws(() => GenericsNative.GetVector128DRef(1.0, 2.0)); + + Assert.Throws(() => GenericsNative.AddVector128D(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Ds(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Ds(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Ds(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128F.cs new file mode 100644 index 0000000000000000000000000000000000000000..65caebc9bd0afebedccd7c2df8c354a5b3211ae3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128F.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128F(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128FOut(float e00, float e01, float e02, float e03, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128FOut(float e00, float e01, float e02, float e03, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128FPtr(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128FPtr")] + public static extern ref readonly Vector128 GetVector128FRef(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128F(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Fs(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Fs(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128F() + { + Assert.Throws(() => GenericsNative.GetVector128F(1.0f, 2.0f, 3.0f, 4.0f)); + + Vector128 value2; + GenericsNative.GetVector128FOut(1.0f, 2.0f, 3.0f, 4.0f, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0f); + Assert.AreEqual(value2.GetElement(1), 2.0f); + Assert.AreEqual(value2.GetElement(2), 3.0f); + Assert.AreEqual(value2.GetElement(3), 4.0f); + + Assert.Throws(() => GenericsNative.GetVector128FOut(1.0f, 2.0f, 3.0f, 4.0f, out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128FPtr(1.0f, 2.0f, 3.0f, 4.0f); + Assert.AreEqual(value4->GetElement(0), 1.0f); + Assert.AreEqual(value4->GetElement(1), 2.0f); + Assert.AreEqual(value4->GetElement(2), 3.0f); + Assert.AreEqual(value4->GetElement(3), 4.0f); + + Assert.Throws(() => GenericsNative.GetVector128FRef(1.0f, 2.0f, 3.0f, 4.0f)); + + Assert.Throws(() => GenericsNative.AddVector128F(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Fs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Fs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Fs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128L.cs new file mode 100644 index 0000000000000000000000000000000000000000..1fdb66ed1506a9e0e0c971d9806b3a58a3d27096 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128L.cs @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128L(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128LOut(long e00, long e01, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128LOut(long e00, long e01, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128LPtr(long e00, long e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128LPtr")] + public static extern ref readonly Vector128 GetVector128LRef(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128L(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ls(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Ls(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128L() + { + Assert.Throws(() => GenericsNative.GetVector128L(1L, 2L)); + + Vector128 value2; + GenericsNative.GetVector128LOut(1L, 2L, &value2); + Assert.AreEqual(value2.GetElement(0), 1L); + Assert.AreEqual(value2.GetElement(1), 2L); + + Assert.Throws(() => GenericsNative.GetVector128LOut(1L, 2L, out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128LPtr(1L, 2L); + Assert.AreEqual(value4->GetElement(0), 1L); + Assert.AreEqual(value4->GetElement(1), 2L); + + Assert.Throws(() => GenericsNative.GetVector128LRef(1L, 2L)); + + Assert.Throws(() => GenericsNative.AddVector128L(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Ls(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Ls(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Ls(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128U.cs new file mode 100644 index 0000000000000000000000000000000000000000..ef12a4163829c9a75a72e13f38ad6ec169f59233 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector128U.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector128 GetVector128U(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128UOut(uint e00, uint e01, uint e02, uint e03, Vector128* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector128UOut(uint e00, uint e01, uint e02, uint e03, out Vector128 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128* GetVector128UPtr(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector128UPtr")] + public static extern ref readonly Vector128 GetVector128URef(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128U(Vector128 lhs, Vector128 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Us(Vector128* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector128[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector128 AddVector128Us(in Vector128 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector128U() + { + Assert.Throws(() => GenericsNative.GetVector128U(1u, 2u, 3u, 4u)); + + Vector128 value2; + GenericsNative.GetVector128UOut(1u, 2u, 3u, 4u, &value2); + Assert.AreEqual(value2.GetElement(0), 1u); + Assert.AreEqual(value2.GetElement(1), 2u); + Assert.AreEqual(value2.GetElement(2), 3u); + Assert.AreEqual(value2.GetElement(3), 4u); + + Assert.Throws(() => GenericsNative.GetVector128UOut(1u, 2u, 3u, 4u, out Vector128 value3)); + + Vector128* value4 = GenericsNative.GetVector128UPtr(1u, 2u, 3u, 4u); + Assert.AreEqual(value4->GetElement(0), 1u); + Assert.AreEqual(value4->GetElement(1), 2u); + Assert.AreEqual(value4->GetElement(2), 3u); + Assert.AreEqual(value4->GetElement(3), 4u); + + Assert.Throws(() => GenericsNative.GetVector128URef(1u, 2u, 3u, 4u)); + + Assert.Throws(() => GenericsNative.AddVector128U(default, default)); + + Vector128[] values = new Vector128[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector128* pValues = &values[0]) + { + GenericsNative.AddVector128Us(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector128Us(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector128Us(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256B.cs new file mode 100644 index 0000000000000000000000000000000000000000..3e6a9840880296448bcd985da2e1eb736338f207 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256B.cs @@ -0,0 +1,142 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256BPtr")] + public static extern ref readonly Vector256 GetVector256BRef(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256B(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Bs(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Bs(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256B() + { + Assert.Throws(() => GenericsNative.GetVector256B(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Vector256 value2; + GenericsNative.GetVector256BOut(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, &value2); + Vector256 tValue2 = *(Vector256*)&value2; + Assert.AreEqual(tValue2.GetElement(0), 1); + Assert.AreEqual(tValue2.GetElement(1), 0); + Assert.AreEqual(tValue2.GetElement(2), 1); + Assert.AreEqual(tValue2.GetElement(3), 0); + Assert.AreEqual(tValue2.GetElement(4), 1); + Assert.AreEqual(tValue2.GetElement(5), 0); + Assert.AreEqual(tValue2.GetElement(6), 1); + Assert.AreEqual(tValue2.GetElement(7), 0); + Assert.AreEqual(tValue2.GetElement(8), 1); + Assert.AreEqual(tValue2.GetElement(9), 0); + Assert.AreEqual(tValue2.GetElement(10), 1); + Assert.AreEqual(tValue2.GetElement(11), 0); + Assert.AreEqual(tValue2.GetElement(12), 1); + Assert.AreEqual(tValue2.GetElement(13), 0); + Assert.AreEqual(tValue2.GetElement(14), 1); + Assert.AreEqual(tValue2.GetElement(15), 0); + Assert.AreEqual(tValue2.GetElement(16), 1); + Assert.AreEqual(tValue2.GetElement(17), 0); + Assert.AreEqual(tValue2.GetElement(18), 1); + Assert.AreEqual(tValue2.GetElement(19), 0); + Assert.AreEqual(tValue2.GetElement(20), 1); + Assert.AreEqual(tValue2.GetElement(21), 0); + Assert.AreEqual(tValue2.GetElement(22), 1); + Assert.AreEqual(tValue2.GetElement(23), 0); + Assert.AreEqual(tValue2.GetElement(24), 1); + Assert.AreEqual(tValue2.GetElement(25), 0); + Assert.AreEqual(tValue2.GetElement(26), 1); + Assert.AreEqual(tValue2.GetElement(27), 0); + Assert.AreEqual(tValue2.GetElement(28), 1); + Assert.AreEqual(tValue2.GetElement(29), 0); + Assert.AreEqual(tValue2.GetElement(30), 1); + Assert.AreEqual(tValue2.GetElement(31), 0); + + Assert.Throws(() => GenericsNative.GetVector256BOut(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256BPtr(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + Vector256* tValue4 = (Vector256*)value4; + Assert.AreEqual(tValue4->GetElement(0), 1); + Assert.AreEqual(tValue4->GetElement(1), 0); + Assert.AreEqual(tValue4->GetElement(2), 1); + Assert.AreEqual(tValue4->GetElement(3), 0); + Assert.AreEqual(tValue4->GetElement(4), 1); + Assert.AreEqual(tValue4->GetElement(5), 0); + Assert.AreEqual(tValue4->GetElement(6), 1); + Assert.AreEqual(tValue4->GetElement(7), 0); + Assert.AreEqual(tValue4->GetElement(8), 1); + Assert.AreEqual(tValue4->GetElement(9), 0); + Assert.AreEqual(tValue4->GetElement(10), 1); + Assert.AreEqual(tValue4->GetElement(11), 0); + Assert.AreEqual(tValue4->GetElement(12), 1); + Assert.AreEqual(tValue4->GetElement(13), 0); + Assert.AreEqual(tValue4->GetElement(14), 1); + Assert.AreEqual(tValue4->GetElement(15), 0); + Assert.AreEqual(tValue4->GetElement(16), 1); + Assert.AreEqual(tValue4->GetElement(17), 0); + Assert.AreEqual(tValue4->GetElement(18), 1); + Assert.AreEqual(tValue4->GetElement(19), 0); + Assert.AreEqual(tValue4->GetElement(20), 1); + Assert.AreEqual(tValue4->GetElement(21), 0); + Assert.AreEqual(tValue4->GetElement(22), 1); + Assert.AreEqual(tValue4->GetElement(23), 0); + Assert.AreEqual(tValue4->GetElement(24), 1); + Assert.AreEqual(tValue4->GetElement(25), 0); + Assert.AreEqual(tValue4->GetElement(26), 1); + Assert.AreEqual(tValue4->GetElement(27), 0); + Assert.AreEqual(tValue4->GetElement(28), 1); + Assert.AreEqual(tValue4->GetElement(29), 0); + Assert.AreEqual(tValue4->GetElement(30), 1); + Assert.AreEqual(tValue4->GetElement(31), 0); + + Assert.Throws(() => GenericsNative.GetVector256BRef(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddVector256B(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256C.cs new file mode 100644 index 0000000000000000000000000000000000000000..4d6597e7997f4c65cd7ac27dd8d5743dbd27c3ac --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256C.cs @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256C(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256COut(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256COut(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256CPtr(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256CPtr")] + public static extern ref readonly Vector256 GetVector256CRef(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256C(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Cs(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Cs(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256C() + { + Assert.Throws(() => GenericsNative.GetVector256C('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')); + + Vector256 value2; + GenericsNative.GetVector256COut('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', &value2); + Vector256 tValue2 = *(Vector256*)&value2; + Assert.AreEqual(tValue2.GetElement(0), (short)'0'); + Assert.AreEqual(tValue2.GetElement(1), (short)'1'); + Assert.AreEqual(tValue2.GetElement(2), (short)'2'); + Assert.AreEqual(tValue2.GetElement(3), (short)'3'); + Assert.AreEqual(tValue2.GetElement(4), (short)'4'); + Assert.AreEqual(tValue2.GetElement(5), (short)'5'); + Assert.AreEqual(tValue2.GetElement(6), (short)'6'); + Assert.AreEqual(tValue2.GetElement(7), (short)'7'); + Assert.AreEqual(tValue2.GetElement(8), (short)'8'); + Assert.AreEqual(tValue2.GetElement(9), (short)'9'); + Assert.AreEqual(tValue2.GetElement(10), (short)'A'); + Assert.AreEqual(tValue2.GetElement(11), (short)'B'); + Assert.AreEqual(tValue2.GetElement(12), (short)'C'); + Assert.AreEqual(tValue2.GetElement(13), (short)'D'); + Assert.AreEqual(tValue2.GetElement(14), (short)'E'); + Assert.AreEqual(tValue2.GetElement(15), (short)'F'); + + Assert.Throws(() => GenericsNative.GetVector256COut('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256CPtr('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); + Vector256* tValue4 = (Vector256*)value4; + Assert.AreEqual(tValue4->GetElement(0), (short)'0'); + Assert.AreEqual(tValue4->GetElement(1), (short)'1'); + Assert.AreEqual(tValue4->GetElement(2), (short)'2'); + Assert.AreEqual(tValue4->GetElement(3), (short)'3'); + Assert.AreEqual(tValue4->GetElement(4), (short)'4'); + Assert.AreEqual(tValue4->GetElement(5), (short)'5'); + Assert.AreEqual(tValue4->GetElement(6), (short)'6'); + Assert.AreEqual(tValue4->GetElement(7), (short)'7'); + Assert.AreEqual(tValue4->GetElement(8), (short)'8'); + Assert.AreEqual(tValue4->GetElement(9), (short)'9'); + Assert.AreEqual(tValue4->GetElement(10), (short)'A'); + Assert.AreEqual(tValue4->GetElement(11), (short)'B'); + Assert.AreEqual(tValue4->GetElement(12), (short)'C'); + Assert.AreEqual(tValue4->GetElement(13), (short)'D'); + Assert.AreEqual(tValue4->GetElement(14), (short)'E'); + Assert.AreEqual(tValue4->GetElement(15), (short)'F'); + + Assert.Throws(() => GenericsNative.GetVector256CRef('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')); + + Assert.Throws(() => GenericsNative.AddVector256C(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256D.cs new file mode 100644 index 0000000000000000000000000000000000000000..cbcbf26a3cbbbd8d095e4d42ecc7fe5087f2d4f3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256D.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256D(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256DOut(double e00, double e01, double e02, double e03, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256DOut(double e00, double e01, double e02, double e03, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256DPtr(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256DPtr")] + public static extern ref readonly Vector256 GetVector256DRef(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256D(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ds(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ds(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256D() + { + Assert.Throws(() => GenericsNative.GetVector256D(1.0, 2.0, 3.0, 4.0)); + + Vector256 value2; + GenericsNative.GetVector256DOut(1.0, 2.0, 3.0, 4.0, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0); + Assert.AreEqual(value2.GetElement(1), 2.0); + Assert.AreEqual(value2.GetElement(2), 3.0); + Assert.AreEqual(value2.GetElement(3), 4.0); + + Assert.Throws(() => GenericsNative.GetVector256DOut(1.0, 2.0, 3.0, 4.0, out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256DPtr(1.0, 2.0, 3.0, 4.0); + Assert.AreEqual(value4->GetElement(0), 1.0); + Assert.AreEqual(value4->GetElement(1), 2.0); + Assert.AreEqual(value4->GetElement(2), 3.0); + Assert.AreEqual(value4->GetElement(3), 4.0); + + Assert.Throws(() => GenericsNative.GetVector256DRef(1.0, 2.0, 3.0, 4.0)); + + Assert.Throws(() => GenericsNative.AddVector256D(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Ds(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Ds(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Ds(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256F.cs new file mode 100644 index 0000000000000000000000000000000000000000..a5b0b54982da4b399ad5b61a76bb99dccc2342fa --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256F.cs @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256F(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256FOut(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256FOut(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256FPtr(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256FPtr")] + public static extern ref readonly Vector256 GetVector256FRef(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256F(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Fs(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Fs(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256F() + { + Assert.Throws(() => GenericsNative.GetVector256F(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)); + + Vector256 value2; + GenericsNative.GetVector256FOut(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0f); + Assert.AreEqual(value2.GetElement(1), 2.0f); + Assert.AreEqual(value2.GetElement(2), 3.0f); + Assert.AreEqual(value2.GetElement(3), 4.0f); + Assert.AreEqual(value2.GetElement(4), 5.0f); + Assert.AreEqual(value2.GetElement(5), 6.0f); + Assert.AreEqual(value2.GetElement(6), 7.0f); + Assert.AreEqual(value2.GetElement(7), 8.0f); + + Assert.Throws(() => GenericsNative.GetVector256FOut(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256FPtr(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f); + Assert.AreEqual(value4->GetElement(0), 1.0f); + Assert.AreEqual(value4->GetElement(1), 2.0f); + Assert.AreEqual(value4->GetElement(2), 3.0f); + Assert.AreEqual(value4->GetElement(3), 4.0f); + Assert.AreEqual(value4->GetElement(4), 5.0f); + Assert.AreEqual(value4->GetElement(5), 6.0f); + Assert.AreEqual(value4->GetElement(6), 7.0f); + Assert.AreEqual(value4->GetElement(7), 8.0f); + + Assert.Throws(() => GenericsNative.GetVector256FRef(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)); + + Assert.Throws(() => GenericsNative.AddVector256F(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Fs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Fs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Fs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256L.cs new file mode 100644 index 0000000000000000000000000000000000000000..e679b3646df6782e31ca8dec0c0a3430f76d426a --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256L.cs @@ -0,0 +1,84 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256L(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256LOut(long e00, long e01, long e02, long e03, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256LOut(long e00, long e01, long e02, long e03, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256LPtr(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256LPtr")] + public static extern ref readonly Vector256 GetVector256LRef(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256L(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ls(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Ls(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256L() + { + Assert.Throws(() => GenericsNative.GetVector256L(1L, 2L, 3L, 4L)); + + Vector256 value2; + GenericsNative.GetVector256LOut(1L, 2L, 3L, 4L, &value2); + Assert.AreEqual(value2.GetElement(0), 1L); + Assert.AreEqual(value2.GetElement(1), 2L); + Assert.AreEqual(value2.GetElement(2), 3L); + Assert.AreEqual(value2.GetElement(3), 4L); + + Assert.Throws(() => GenericsNative.GetVector256LOut(1L, 2L, 3L, 4L, out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256LPtr(1L, 2L, 3L, 4L); + Assert.AreEqual(value4->GetElement(0), 1L); + Assert.AreEqual(value4->GetElement(1), 2L); + Assert.AreEqual(value4->GetElement(2), 3L); + Assert.AreEqual(value4->GetElement(3), 4L); + + Assert.Throws(() => GenericsNative.GetVector256LRef(1L, 2L, 3L, 4L)); + + Assert.Throws(() => GenericsNative.AddVector256L(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Ls(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Ls(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Ls(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256U.cs new file mode 100644 index 0000000000000000000000000000000000000000..42ed390455b68cc44d7b4dd65a78ac3fd89dbdbb --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector256U.cs @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector256 GetVector256U(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256UOut(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07, Vector256* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector256UOut(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07, out Vector256 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256* GetVector256UPtr(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector256UPtr")] + public static extern ref readonly Vector256 GetVector256URef(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256U(Vector256 lhs, Vector256 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Us(Vector256* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector256[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector256 AddVector256Us(in Vector256 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector256U() + { + Assert.Throws(() => GenericsNative.GetVector256U(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u)); + + Vector256 value2; + GenericsNative.GetVector256UOut(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, &value2); + Assert.AreEqual(value2.GetElement(0), 1u); + Assert.AreEqual(value2.GetElement(1), 2u); + Assert.AreEqual(value2.GetElement(2), 3u); + Assert.AreEqual(value2.GetElement(3), 4u); + Assert.AreEqual(value2.GetElement(4), 5u); + Assert.AreEqual(value2.GetElement(5), 6u); + Assert.AreEqual(value2.GetElement(6), 7u); + Assert.AreEqual(value2.GetElement(7), 8u); + + Assert.Throws(() => GenericsNative.GetVector256UOut(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, out Vector256 value3)); + + Vector256* value4 = GenericsNative.GetVector256UPtr(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u); + Assert.AreEqual(value4->GetElement(0), 1u); + Assert.AreEqual(value4->GetElement(1), 2u); + Assert.AreEqual(value4->GetElement(2), 3u); + Assert.AreEqual(value4->GetElement(3), 4u); + Assert.AreEqual(value4->GetElement(4), 5u); + Assert.AreEqual(value4->GetElement(5), 6u); + Assert.AreEqual(value4->GetElement(6), 7u); + Assert.AreEqual(value4->GetElement(7), 8u); + + Assert.Throws(() => GenericsNative.GetVector256URef(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u)); + + Assert.Throws(() => GenericsNative.AddVector256U(default, default)); + + Vector256[] values = new Vector256[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector256* pValues = &values[0]) + { + GenericsNative.AddVector256Us(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector256Us(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector256Us(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64B.cs new file mode 100644 index 0000000000000000000000000000000000000000..7ba2841298f77d045cd1cd43ae34718397e80838 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64B.cs @@ -0,0 +1,94 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64B(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64BOut(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64BPtr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64BPtr")] + public static extern ref readonly Vector64 GetVector64BRef(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64B(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Bs(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Bs(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64B() + { + Assert.Throws(() => GenericsNative.GetVector64B(true, false, true, false, true, false, true, false)); + + Vector64 value2; + GenericsNative.GetVector64BOut(true, false, true, false, true, false, true, false, &value2); + Vector64 tValue2 = *(Vector64*)&value2; + Assert.AreEqual(tValue2.GetElement(0), 1); + Assert.AreEqual(tValue2.GetElement(1), 0); + Assert.AreEqual(tValue2.GetElement(2), 1); + Assert.AreEqual(tValue2.GetElement(3), 0); + Assert.AreEqual(tValue2.GetElement(4), 1); + Assert.AreEqual(tValue2.GetElement(5), 0); + Assert.AreEqual(tValue2.GetElement(6), 1); + Assert.AreEqual(tValue2.GetElement(7), 0); + + Assert.Throws(() => GenericsNative.GetVector64BOut(true, false, true, false, true, false, true, false, out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64BPtr(true, false, true, false, true, false, true, false); + Vector64* tValue4 = (Vector64*)value4; + Assert.AreEqual(tValue4->GetElement(0), 1); + Assert.AreEqual(tValue4->GetElement(1), 0); + Assert.AreEqual(tValue4->GetElement(2), 1); + Assert.AreEqual(tValue4->GetElement(3), 0); + Assert.AreEqual(tValue4->GetElement(4), 1); + Assert.AreEqual(tValue4->GetElement(5), 0); + Assert.AreEqual(tValue4->GetElement(6), 1); + Assert.AreEqual(tValue4->GetElement(7), 0); + + Assert.Throws(() => GenericsNative.GetVector64BRef(true, false, true, false, true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddVector64B(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Bs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Bs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Bs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64C.cs new file mode 100644 index 0000000000000000000000000000000000000000..06976eaa2b044f37bc01d8d685e4188d090874c1 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64C.cs @@ -0,0 +1,86 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64C(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64COut(char e00, char e01, char e02, char e03, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64COut(char e00, char e01, char e02, char e03, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64CPtr(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64CPtr")] + public static extern ref readonly Vector64 GetVector64CRef(char e00, char e01, char e02, char e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64C(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Cs(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Cs(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64C() + { + Assert.Throws(() => GenericsNative.GetVector64C('0', '1', '2', '3')); + + Vector64 value2; + GenericsNative.GetVector64COut('0', '1', '2', '3', &value2); + Vector64 tValue2 = *(Vector64*)&value2; + Assert.AreEqual(tValue2.GetElement(0), (short)'0'); + Assert.AreEqual(tValue2.GetElement(1), (short)'1'); + Assert.AreEqual(tValue2.GetElement(2), (short)'2'); + Assert.AreEqual(tValue2.GetElement(3), (short)'3'); + + Assert.Throws(() => GenericsNative.GetVector64COut('0', '1', '2', '3', out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64CPtr('0', '1', '2', '3'); + Vector64* tValue4 = (Vector64*)value4; + Assert.AreEqual(tValue4->GetElement(0), (short)'0'); + Assert.AreEqual(tValue4->GetElement(1), (short)'1'); + Assert.AreEqual(tValue4->GetElement(2), (short)'2'); + Assert.AreEqual(tValue4->GetElement(3), (short)'3'); + + Assert.Throws(() => GenericsNative.GetVector64CRef('0', '1', '2', '3')); + + Assert.Throws(() => GenericsNative.AddVector64C(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Cs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Cs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Cs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64D.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64D.cs new file mode 100644 index 0000000000000000000000000000000000000000..69206104483657f3f8e5433f41c03c475f94c78d --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64D.cs @@ -0,0 +1,78 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64D(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64DOut(double e00, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64DOut(double e00, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64DPtr(double e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64DPtr")] + public static extern ref readonly Vector64 GetVector64DRef(double e00); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64D(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ds(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ds([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ds(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64D() + { + Assert.Throws(() => GenericsNative.GetVector64D(1.0)); + + Vector64 value2; + GenericsNative.GetVector64DOut(1.0, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0); + + Assert.Throws(() => GenericsNative.GetVector64DOut(1.0, out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64DPtr(1.0); + Assert.AreEqual(value4->GetElement(0), 1.0); + + Assert.Throws(() => GenericsNative.GetVector64DRef(1.0)); + + Assert.Throws(() => GenericsNative.AddVector64D(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Ds(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Ds(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Ds(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64F.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64F.cs new file mode 100644 index 0000000000000000000000000000000000000000..f9dc5ae45d517a95ea0c274e012216af0631549c --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64F.cs @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64F(float e00, float e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64FOut(float e00, float e01, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64FOut(float e00, float e01, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64FPtr(float e00, float e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64FPtr")] + public static extern ref readonly Vector64 GetVector64FRef(float e00, float e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64F(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Fs(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Fs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Fs(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64F() + { + Assert.Throws(() => GenericsNative.GetVector64F(1.0f, 2.0f)); + + Vector64 value2; + GenericsNative.GetVector64FOut(1.0f, 2.0f, &value2); + Assert.AreEqual(value2.GetElement(0), 1.0f); + Assert.AreEqual(value2.GetElement(1), 2.0f); + + Assert.Throws(() => GenericsNative.GetVector64FOut(1.0f, 2.0f, out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64FPtr(1.0f, 2.0f); + Assert.AreEqual(value4->GetElement(0), 1.0f); + Assert.AreEqual(value4->GetElement(1), 2.0f); + + Assert.Throws(() => GenericsNative.GetVector64FRef(1.0f, 2.0f)); + + Assert.Throws(() => GenericsNative.AddVector64F(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Fs(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Fs(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Fs(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64L.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64L.cs new file mode 100644 index 0000000000000000000000000000000000000000..4a63eb71afd15a30003c9938947d424f1395f07a --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64L.cs @@ -0,0 +1,78 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64L(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64LOut(long e00, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64LOut(long e00, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64LPtr(long e00); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64LPtr")] + public static extern ref readonly Vector64 GetVector64LRef(long e00); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64L(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ls(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ls([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Ls(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64L() + { + Assert.Throws(() => GenericsNative.GetVector64L(1L)); + + Vector64 value2; + GenericsNative.GetVector64LOut(1L, &value2); + Assert.AreEqual(value2.GetElement(0), 1L); + + Assert.Throws(() => GenericsNative.GetVector64LOut(1L, out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64LPtr(1L); + Assert.AreEqual(value4->GetElement(0), 1L); + + Assert.Throws(() => GenericsNative.GetVector64LRef(1L)); + + Assert.Throws(() => GenericsNative.AddVector64L(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Ls(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Ls(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Ls(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64U.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64U.cs new file mode 100644 index 0000000000000000000000000000000000000000..7db55fa0b661198555069842e21efaca45b7240a --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Vector64U.cs @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector64 GetVector64U(uint e00, uint e01); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64UOut(uint e00, uint e01, Vector64* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVector64UOut(uint e00, uint e01, out Vector64 value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64* GetVector64UPtr(uint e00, uint e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVector64UPtr")] + public static extern ref readonly Vector64 GetVector64URef(uint e00, uint e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64U(Vector64 lhs, Vector64 rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Us(Vector64* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Us([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector64[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector64 AddVector64Us(in Vector64 pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVector64U() + { + Assert.Throws(() => GenericsNative.GetVector64U(1u, 2u)); + + Vector64 value2; + GenericsNative.GetVector64UOut(1u, 2u, &value2); + Assert.AreEqual(value2.GetElement(0), 1u); + Assert.AreEqual(value2.GetElement(1), 2u); + + Assert.Throws(() => GenericsNative.GetVector64UOut(1u, 2u, out Vector64 value3)); + + Vector64* value4 = GenericsNative.GetVector64UPtr(1u, 2u); + Assert.AreEqual(value4->GetElement(0), 1u); + Assert.AreEqual(value4->GetElement(1), 2u); + + Assert.Throws(() => GenericsNative.GetVector64URef(1u, 2u)); + + Assert.Throws(() => GenericsNative.AddVector64U(default, default)); + + Vector64[] values = new Vector64[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector64* pValues = &values[0]) + { + GenericsNative.AddVector64Us(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVector64Us(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVector64Us(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorB.cs new file mode 100644 index 0000000000000000000000000000000000000000..ae6e45830e3613fd184de00c9953a8248a824dcc --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorB.cs @@ -0,0 +1,251 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorB128(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorB256(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorB128Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorB256Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorB128Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorB256Out(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorB128Ptr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorB256Ptr(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorB128Ptr")] + public static extern ref readonly Vector GetVectorB128Ref(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorB256Ptr")] + public static extern ref readonly Vector GetVectorB256Ref(bool e00, bool e01, bool e02, bool e03, bool e04, bool e05, bool e06, bool e07, bool e08, bool e09, bool e10, bool e11, bool e12, bool e13, bool e14, bool e15, bool e16, bool e17, bool e18, bool e19, bool e20, bool e21, bool e22, bool e23, bool e24, bool e25, bool e26, bool e27, bool e28, bool e29, bool e30, bool e31); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorB256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorB() + { + if (Vector.Count == 32) + { + TestVectorB256(); + } + else + { + Assert.AreEqual(Vector.Count, 16); + TestVectorB128(); + } + } + + private static void TestVectorB128() + { + Assert.Throws(() => GenericsNative.GetVectorB128(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Vector value2; + GenericsNative.GetVectorB128Out(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, &value2); + Vector tValue2 = *(Vector*)&value2; + Assert.AreEqual(tValue2[0], 1); + Assert.AreEqual(tValue2[1], 0); + Assert.AreEqual(tValue2[2], 1); + Assert.AreEqual(tValue2[3], 0); + Assert.AreEqual(tValue2[4], 1); + Assert.AreEqual(tValue2[5], 0); + Assert.AreEqual(tValue2[6], 1); + Assert.AreEqual(tValue2[7], 0); + Assert.AreEqual(tValue2[8], 1); + Assert.AreEqual(tValue2[9], 0); + Assert.AreEqual(tValue2[10], 1); + Assert.AreEqual(tValue2[11], 0); + Assert.AreEqual(tValue2[12], 1); + Assert.AreEqual(tValue2[13], 0); + Assert.AreEqual(tValue2[14], 1); + Assert.AreEqual(tValue2[15], 0); + + Assert.Throws(() => GenericsNative.GetVectorB128Out(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorB128Ptr(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + Vector* tValue4 = (Vector*)value4; + Assert.AreEqual((*tValue4)[0], 1); + Assert.AreEqual((*tValue4)[1], 0); + Assert.AreEqual((*tValue4)[2], 1); + Assert.AreEqual((*tValue4)[3], 0); + Assert.AreEqual((*tValue4)[4], 1); + Assert.AreEqual((*tValue4)[5], 0); + Assert.AreEqual((*tValue4)[6], 1); + Assert.AreEqual((*tValue4)[7], 0); + Assert.AreEqual((*tValue4)[8], 1); + Assert.AreEqual((*tValue4)[9], 0); + Assert.AreEqual((*tValue4)[10], 1); + Assert.AreEqual((*tValue4)[11], 0); + Assert.AreEqual((*tValue4)[12], 1); + Assert.AreEqual((*tValue4)[13], 0); + Assert.AreEqual((*tValue4)[14], 1); + Assert.AreEqual((*tValue4)[15], 0); + + Assert.Throws(() => GenericsNative.GetVectorB128Ref(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddVectorB128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorB128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorB128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorB128s(in values[0], values.Length)); + } + + private static void TestVectorB256() + { + Assert.Throws(() => GenericsNative.GetVectorB256(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Vector value2; + GenericsNative.GetVectorB256Out(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, &value2); + Vector tValue2 = *(Vector*)&value2; + Assert.AreEqual(tValue2[0], 1); + Assert.AreEqual(tValue2[1], 0); + Assert.AreEqual(tValue2[2], 1); + Assert.AreEqual(tValue2[3], 0); + Assert.AreEqual(tValue2[4], 1); + Assert.AreEqual(tValue2[5], 0); + Assert.AreEqual(tValue2[6], 1); + Assert.AreEqual(tValue2[7], 0); + Assert.AreEqual(tValue2[8], 1); + Assert.AreEqual(tValue2[9], 0); + Assert.AreEqual(tValue2[10], 1); + Assert.AreEqual(tValue2[11], 0); + Assert.AreEqual(tValue2[12], 1); + Assert.AreEqual(tValue2[13], 0); + Assert.AreEqual(tValue2[14], 1); + Assert.AreEqual(tValue2[15], 0); + Assert.AreEqual(tValue2[16], 1); + Assert.AreEqual(tValue2[17], 0); + Assert.AreEqual(tValue2[18], 1); + Assert.AreEqual(tValue2[19], 0); + Assert.AreEqual(tValue2[20], 1); + Assert.AreEqual(tValue2[21], 0); + Assert.AreEqual(tValue2[22], 1); + Assert.AreEqual(tValue2[23], 0); + Assert.AreEqual(tValue2[24], 1); + Assert.AreEqual(tValue2[25], 0); + Assert.AreEqual(tValue2[26], 1); + Assert.AreEqual(tValue2[27], 0); + Assert.AreEqual(tValue2[28], 1); + Assert.AreEqual(tValue2[29], 0); + Assert.AreEqual(tValue2[30], 1); + Assert.AreEqual(tValue2[31], 0); + + Assert.Throws(() => GenericsNative.GetVectorB256Out(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorB256Ptr(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false); + Vector* tValue4 = (Vector*)value4; + Assert.AreEqual((*tValue4)[0], 1); + Assert.AreEqual((*tValue4)[1], 0); + Assert.AreEqual((*tValue4)[2], 1); + Assert.AreEqual((*tValue4)[3], 0); + Assert.AreEqual((*tValue4)[4], 1); + Assert.AreEqual((*tValue4)[5], 0); + Assert.AreEqual((*tValue4)[6], 1); + Assert.AreEqual((*tValue4)[7], 0); + Assert.AreEqual((*tValue4)[8], 1); + Assert.AreEqual((*tValue4)[9], 0); + Assert.AreEqual((*tValue4)[10], 1); + Assert.AreEqual((*tValue4)[11], 0); + Assert.AreEqual((*tValue4)[12], 1); + Assert.AreEqual((*tValue4)[13], 0); + Assert.AreEqual((*tValue4)[14], 1); + Assert.AreEqual((*tValue4)[15], 0); + Assert.AreEqual((*tValue4)[16], 1); + Assert.AreEqual((*tValue4)[17], 0); + Assert.AreEqual((*tValue4)[18], 1); + Assert.AreEqual((*tValue4)[19], 0); + Assert.AreEqual((*tValue4)[20], 1); + Assert.AreEqual((*tValue4)[21], 0); + Assert.AreEqual((*tValue4)[22], 1); + Assert.AreEqual((*tValue4)[23], 0); + Assert.AreEqual((*tValue4)[24], 1); + Assert.AreEqual((*tValue4)[25], 0); + Assert.AreEqual((*tValue4)[26], 1); + Assert.AreEqual((*tValue4)[27], 0); + Assert.AreEqual((*tValue4)[28], 1); + Assert.AreEqual((*tValue4)[29], 0); + Assert.AreEqual((*tValue4)[30], 1); + Assert.AreEqual((*tValue4)[31], 0); + + Assert.Throws(() => GenericsNative.GetVectorB256Ref(true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false)); + + Assert.Throws(() => GenericsNative.AddVectorB256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorB256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorB256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorB256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorC.cs new file mode 100644 index 0000000000000000000000000000000000000000..58f28cb36b75b0bf39c4bb52725cbac0259cf3a8 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorC.cs @@ -0,0 +1,203 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorC128(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorC256(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorC128Out(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorC256Out(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorC128Out(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorC256Out(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorC128Ptr(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorC256Ptr(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorC128Ptr")] + public static extern ref readonly Vector GetVectorC128Ref(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorC256Ptr")] + public static extern ref readonly Vector GetVectorC256Ref(char e00, char e01, char e02, char e03, char e04, char e05, char e06, char e07, char e08, char e09, char e10, char e11, char e12, char e13, char e14, char e15); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorC256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorC() + { + if (Vector.Count == 16) + { + TestVectorC256(); + } + else + { + Assert.AreEqual(Vector.Count, 8); + TestVectorC128(); + } + } + + private static void TestVectorC128() + { + Assert.Throws(() => GenericsNative.GetVectorC128('0', '1', '2', '3', '4', '5', '6', '7')); + + Vector value2; + GenericsNative.GetVectorC128Out('0', '1', '2', '3', '4', '5', '6', '7', &value2); + Vector tValue2 = *(Vector*)&value2; + Assert.AreEqual(tValue2[0], (short)'0'); + Assert.AreEqual(tValue2[1], (short)'1'); + Assert.AreEqual(tValue2[2], (short)'2'); + Assert.AreEqual(tValue2[3], (short)'3'); + Assert.AreEqual(tValue2[4], (short)'4'); + Assert.AreEqual(tValue2[5], (short)'5'); + Assert.AreEqual(tValue2[6], (short)'6'); + Assert.AreEqual(tValue2[7], (short)'7'); + + Assert.Throws(() => GenericsNative.GetVectorC128Out('0', '1', '2', '3', '4', '5', '6', '7', out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorC128Ptr('0', '1', '2', '3', '4', '5', '6', '7'); + Vector* tValue4 = (Vector*)value4; + Assert.AreEqual((*tValue4)[0], (short)'0'); + Assert.AreEqual((*tValue4)[1], (short)'1'); + Assert.AreEqual((*tValue4)[2], (short)'2'); + Assert.AreEqual((*tValue4)[3], (short)'3'); + Assert.AreEqual((*tValue4)[4], (short)'4'); + Assert.AreEqual((*tValue4)[5], (short)'5'); + Assert.AreEqual((*tValue4)[6], (short)'6'); + Assert.AreEqual((*tValue4)[7], (short)'7'); + + Assert.Throws(() => GenericsNative.GetVectorC128Ref('0', '1', '2', '3', '4', '5', '6', '7')); + + Assert.Throws(() => GenericsNative.AddVectorC128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorC128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorC128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorC128s(in values[0], values.Length)); + } + + private static void TestVectorC256() + { + Assert.Throws(() => GenericsNative.GetVectorC256('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')); + + Vector value2; + GenericsNative.GetVectorC256Out('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', &value2); + Vector tValue2 = *(Vector*)&value2; + Assert.AreEqual(tValue2[0], (short)'0'); + Assert.AreEqual(tValue2[1], (short)'1'); + Assert.AreEqual(tValue2[2], (short)'2'); + Assert.AreEqual(tValue2[3], (short)'3'); + Assert.AreEqual(tValue2[4], (short)'4'); + Assert.AreEqual(tValue2[5], (short)'5'); + Assert.AreEqual(tValue2[6], (short)'6'); + Assert.AreEqual(tValue2[7], (short)'7'); + Assert.AreEqual(tValue2[8], (short)'8'); + Assert.AreEqual(tValue2[9], (short)'9'); + Assert.AreEqual(tValue2[10], (short)'A'); + Assert.AreEqual(tValue2[11], (short)'B'); + Assert.AreEqual(tValue2[12], (short)'C'); + Assert.AreEqual(tValue2[13], (short)'D'); + Assert.AreEqual(tValue2[14], (short)'E'); + Assert.AreEqual(tValue2[15], (short)'F'); + + Assert.Throws(() => GenericsNative.GetVectorC256Out('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorC256Ptr('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); + Vector* tValue4 = (Vector*)value4; + Assert.AreEqual((*tValue4)[0], (short)'0'); + Assert.AreEqual((*tValue4)[1], (short)'1'); + Assert.AreEqual((*tValue4)[2], (short)'2'); + Assert.AreEqual((*tValue4)[3], (short)'3'); + Assert.AreEqual((*tValue4)[4], (short)'4'); + Assert.AreEqual((*tValue4)[5], (short)'5'); + Assert.AreEqual((*tValue4)[6], (short)'6'); + Assert.AreEqual((*tValue4)[7], (short)'7'); + Assert.AreEqual((*tValue4)[8], (short)'8'); + Assert.AreEqual((*tValue4)[9], (short)'9'); + Assert.AreEqual((*tValue4)[10], (short)'A'); + Assert.AreEqual((*tValue4)[11], (short)'B'); + Assert.AreEqual((*tValue4)[12], (short)'C'); + Assert.AreEqual((*tValue4)[13], (short)'D'); + Assert.AreEqual((*tValue4)[14], (short)'E'); + Assert.AreEqual((*tValue4)[15], (short)'F'); + + Assert.Throws(() => GenericsNative.GetVectorC256Ref('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')); + + Assert.Throws(() => GenericsNative.AddVectorC256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorC256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorC256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorC256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorD.cs new file mode 100644 index 0000000000000000000000000000000000000000..7c4af5e7254f1cdeea266a9699d912de4e765c12 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorD.cs @@ -0,0 +1,163 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorD128(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorD256(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorD128Out(double e00, double e01, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorD256Out(double e00, double e01, double e02, double e03, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorD128Out(double e00, double e01, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorD256Out(double e00, double e01, double e02, double e03, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorD128Ptr(double e00, double e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorD256Ptr(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorD128Ptr")] + public static extern ref readonly Vector GetVectorD128Ref(double e00, double e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorD256Ptr")] + public static extern ref readonly Vector GetVectorD256Ref(double e00, double e01, double e02, double e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorD256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorD() + { + if (Vector.Count == 4) + { + TestVectorD256(); + } + else + { + Assert.AreEqual(Vector.Count, 2); + TestVectorD128(); + } + } + + private static void TestVectorD128() + { + Assert.Throws(() => GenericsNative.GetVectorD128(1.0, 2.0)); + + Vector value2; + GenericsNative.GetVectorD128Out(1.0, 2.0, &value2); + Assert.AreEqual(value2[0], 1.0); + Assert.AreEqual(value2[1], 2.0); + + Assert.Throws(() => GenericsNative.GetVectorD128Out(1.0, 2.0, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorD128Ptr(1.0, 2.0); + Assert.AreEqual((*value4)[0], 1.0); + Assert.AreEqual((*value4)[1], 2.0); + + Assert.Throws(() => GenericsNative.GetVectorD128Ref(1.0, 2.0)); + + Assert.Throws(() => GenericsNative.AddVectorD128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorD128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorD128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorD128s(in values[0], values.Length)); + } + + private static void TestVectorD256() + { + Assert.Throws(() => GenericsNative.GetVectorD256(1.0, 2.0, 3.0, 4.0)); + + Vector value2; + GenericsNative.GetVectorD256Out(1.0, 2.0, 3.0, 4.0, &value2); + Assert.AreEqual(value2[0], 1.0); + Assert.AreEqual(value2[1], 2.0); + Assert.AreEqual(value2[2], 3.0); + Assert.AreEqual(value2[3], 4.0); + + Assert.Throws(() => GenericsNative.GetVectorD256Out(1.0, 2.0, 3.0, 4.0, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorD256Ptr(1.0, 2.0, 3.0, 4.0); + Assert.AreEqual((*value4)[0], 1.0); + Assert.AreEqual((*value4)[1], 2.0); + Assert.AreEqual((*value4)[2], 3.0); + Assert.AreEqual((*value4)[3], 4.0); + + Assert.Throws(() => GenericsNative.GetVectorD256Ref(1.0, 2.0, 3.0, 4.0)); + + Assert.Throws(() => GenericsNative.AddVectorD256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorD256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorD256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorD256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorF.cs new file mode 100644 index 0000000000000000000000000000000000000000..696d7e6a325a6f978c0f8bab62b3791d4dfcfb16 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorF.cs @@ -0,0 +1,175 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorF128(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorF256(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorF128Out(float e00, float e01, float e02, float e03, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorF256Out(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorF128Out(float e00, float e01, float e02, float e03, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorF256Out(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorF128Ptr(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorF256Ptr(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorF128Ptr")] + public static extern ref readonly Vector GetVectorF128Ref(float e00, float e01, float e02, float e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorF256Ptr")] + public static extern ref readonly Vector GetVectorF256Ref(float e00, float e01, float e02, float e03, float e04, float e05, float e06, float e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorF256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorF() + { + if (Vector.Count == 8) + { + TestVectorF256(); + } + else + { + Assert.AreEqual(Vector.Count, 4); + TestVectorF128(); + } + } + + private static void TestVectorF128() + { + Assert.Throws(() => GenericsNative.GetVectorF128(1.0f, 2.0f, 3.0f, 4.0f)); + + Vector value2; + GenericsNative.GetVectorF128Out(1.0f, 2.0f, 3.0f, 4.0f, &value2); + Assert.AreEqual(value2[0], 1.0f); + Assert.AreEqual(value2[1], 2.0f); + Assert.AreEqual(value2[2], 3.0f); + Assert.AreEqual(value2[3], 4.0f); + + Assert.Throws(() => GenericsNative.GetVectorF128Out(1.0f, 2.0f, 3.0f, 4.0f, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorF128Ptr(1.0f, 2.0f, 3.0f, 4.0f); + Assert.AreEqual((*value4)[0], 1.0f); + Assert.AreEqual((*value4)[1], 2.0f); + Assert.AreEqual((*value4)[2], 3.0f); + Assert.AreEqual((*value4)[3], 4.0f); + + Assert.Throws(() => GenericsNative.GetVectorF128Ref(1.0f, 2.0f, 3.0f, 4.0f)); + + Assert.Throws(() => GenericsNative.AddVectorF128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorF128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorF128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorF128s(in values[0], values.Length)); + } + + private static void TestVectorF256() + { + Assert.Throws(() => GenericsNative.GetVectorF256(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)); + + Vector value2; + GenericsNative.GetVectorF256Out(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, &value2); + Assert.AreEqual(value2[0], 1.0f); + Assert.AreEqual(value2[1], 2.0f); + Assert.AreEqual(value2[2], 3.0f); + Assert.AreEqual(value2[3], 4.0f); + Assert.AreEqual(value2[4], 5.0f); + Assert.AreEqual(value2[5], 6.0f); + Assert.AreEqual(value2[6], 7.0f); + Assert.AreEqual(value2[7], 8.0f); + + Assert.Throws(() => GenericsNative.GetVectorF256Out(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorF256Ptr(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f); + Assert.AreEqual((*value4)[0], 1.0f); + Assert.AreEqual((*value4)[1], 2.0f); + Assert.AreEqual((*value4)[2], 3.0f); + Assert.AreEqual((*value4)[3], 4.0f); + Assert.AreEqual((*value4)[4], 5.0f); + Assert.AreEqual((*value4)[5], 6.0f); + Assert.AreEqual((*value4)[6], 7.0f); + Assert.AreEqual((*value4)[7], 8.0f); + + Assert.Throws(() => GenericsNative.GetVectorF256Ref(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)); + + Assert.Throws(() => GenericsNative.AddVectorF256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorF256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorF256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorF256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorL.cs new file mode 100644 index 0000000000000000000000000000000000000000..9afb3fd6483f6636f9f6881516bcd369e2fa49c6 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorL.cs @@ -0,0 +1,163 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorL128(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorL256(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorL128Out(long e00, long e01, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorL256Out(long e00, long e01, long e02, long e03, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorL128Out(long e00, long e01, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorL256Out(long e00, long e01, long e02, long e03, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorL128Ptr(long e00, long e01); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorL256Ptr(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorL128Ptr")] + public static extern ref readonly Vector GetVectorL128Ref(long e00, long e01); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorL256Ptr")] + public static extern ref readonly Vector GetVectorL256Ref(long e00, long e01, long e02, long e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorL256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorL() + { + if (Vector.Count == 4) + { + TestVectorL256(); + } + else + { + Assert.AreEqual(Vector.Count, 2); + TestVectorL128(); + } + } + + private static void TestVectorL128() + { + Assert.Throws(() => GenericsNative.GetVectorL128(1L, 2L)); + + Vector value2; + GenericsNative.GetVectorL128Out(1L, 2L, &value2); + Assert.AreEqual(value2[0], 1L); + Assert.AreEqual(value2[1], 2L); + + Assert.Throws(() => GenericsNative.GetVectorL128Out(1L, 2L, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorL128Ptr(1L, 2L); + Assert.AreEqual((*value4)[0], 1L); + Assert.AreEqual((*value4)[1], 2L); + + Assert.Throws(() => GenericsNative.GetVectorL128Ref(1L, 2L)); + + Assert.Throws(() => GenericsNative.AddVectorL128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorL128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorL128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorL128s(in values[0], values.Length)); + } + + private static void TestVectorL256() + { + Assert.Throws(() => GenericsNative.GetVectorL256(1L, 2L, 3L, 4L)); + + Vector value2; + GenericsNative.GetVectorL256Out(1L, 2L, 3L, 4L, &value2); + Assert.AreEqual(value2[0], 1L); + Assert.AreEqual(value2[1], 2L); + Assert.AreEqual(value2[2], 3L); + Assert.AreEqual(value2[3], 4L); + + Assert.Throws(() => GenericsNative.GetVectorL256Out(1L, 2L, 3L, 4L, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorL256Ptr(1L, 2L, 3L, 4L); + Assert.AreEqual((*value4)[0], 1L); + Assert.AreEqual((*value4)[1], 2L); + Assert.AreEqual((*value4)[2], 3L); + Assert.AreEqual((*value4)[3], 4L); + + Assert.Throws(() => GenericsNative.GetVectorL256Ref(1L, 2L, 3L, 4L)); + + Assert.Throws(() => GenericsNative.AddVectorL256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorL256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorL256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorL256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorU.cs new file mode 100644 index 0000000000000000000000000000000000000000..8bab664a2491eb09cae429185ee758ee9f9cbe92 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.VectorU.cs @@ -0,0 +1,175 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using TestLibrary; + +unsafe partial class GenericsNative +{ + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorU128(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector GetVectorU256(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorU128Out(uint e00, uint e01, uint e02, uint e03, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorU256Out(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07, Vector* value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorU128Out(uint e00, uint e01, uint e02, uint e03, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern void GetVectorU256Out(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07, out Vector value); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorU128Ptr(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative))] + public static extern Vector* GetVectorU256Ptr(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorU128Ptr")] + public static extern ref readonly Vector GetVectorU128Ref(uint e00, uint e01, uint e02, uint e03); + + [DllImport(nameof(GenericsNative), EntryPoint = "GetVectorU256Ptr")] + public static extern ref readonly Vector GetVectorU256Ref(uint e00, uint e01, uint e02, uint e03, uint e04, uint e05, uint e06, uint e07); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU128(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU256(Vector lhs, Vector rhs); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU128s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU256s(Vector* pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU128s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU256s([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Vector[] pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU128s(in Vector pValues, int count); + + [DllImport(nameof(GenericsNative))] + public static extern Vector AddVectorU256s(in Vector pValues, int count); +} + +unsafe partial class GenericsTest +{ + private static void TestVectorU() + { + if (Vector.Count == 8) + { + TestVectorU256(); + } + else + { + Assert.AreEqual(Vector.Count, 4); + TestVectorU128(); + } + } + + private static void TestVectorU128() + { + Assert.Throws(() => GenericsNative.GetVectorU128(1u, 2u, 3u, 4u)); + + Vector value2; + GenericsNative.GetVectorU128Out(1u, 2u, 3u, 4u, &value2); + Assert.AreEqual(value2[0], 1u); + Assert.AreEqual(value2[1], 2u); + Assert.AreEqual(value2[2], 3u); + Assert.AreEqual(value2[3], 4u); + + Assert.Throws(() => GenericsNative.GetVectorU128Out(1u, 2u, 3u, 4u, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorU128Ptr(1u, 2u, 3u, 4u); + Assert.AreEqual((*value4)[0], 1u); + Assert.AreEqual((*value4)[1], 2u); + Assert.AreEqual((*value4)[2], 3u); + Assert.AreEqual((*value4)[3], 4u); + + Assert.Throws(() => GenericsNative.GetVectorU128Ref(1u, 2u, 3u, 4u)); + + Assert.Throws(() => GenericsNative.AddVectorU128(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorU128s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorU128s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorU128s(in values[0], values.Length)); + } + + private static void TestVectorU256() + { + Assert.Throws(() => GenericsNative.GetVectorU256(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u)); + + Vector value2; + GenericsNative.GetVectorU256Out(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, &value2); + Assert.AreEqual(value2[0], 1u); + Assert.AreEqual(value2[1], 2u); + Assert.AreEqual(value2[2], 3u); + Assert.AreEqual(value2[3], 4u); + Assert.AreEqual(value2[4], 5u); + Assert.AreEqual(value2[5], 6u); + Assert.AreEqual(value2[6], 7u); + Assert.AreEqual(value2[7], 8u); + + Assert.Throws(() => GenericsNative.GetVectorU256Out(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, out Vector value3)); + + Vector* value4 = GenericsNative.GetVectorU256Ptr(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u); + Assert.AreEqual((*value4)[0], 1u); + Assert.AreEqual((*value4)[1], 2u); + Assert.AreEqual((*value4)[2], 3u); + Assert.AreEqual((*value4)[3], 4u); + Assert.AreEqual((*value4)[4], 5u); + Assert.AreEqual((*value4)[5], 6u); + Assert.AreEqual((*value4)[6], 7u); + Assert.AreEqual((*value4)[7], 8u); + + Assert.Throws(() => GenericsNative.GetVectorU256Ref(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u)); + + Assert.Throws(() => GenericsNative.AddVectorU256(default, default)); + + Vector[] values = new Vector[] { + default, + value2, + default, + *value4, + default, + }; + + Assert.Throws(() => { + fixed (Vector* pValues = &values[0]) + { + GenericsNative.AddVectorU256s(pValues, values.Length); + } + }); + + Assert.Throws(() => GenericsNative.AddVectorU256s(values, values.Length)); + + Assert.Throws(() => GenericsNative.AddVectorU256s(in values[0], values.Length)); + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..602f203bb7f88cade053b8416b2528de5f9f0e7b --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.cs @@ -0,0 +1,243 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; + +unsafe partial class GenericsNative +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IComInterface where T : unmanaged + { + } + + public struct Point1 where T : struct + { + public T e00; + } + + public struct Point2 where T : struct + { + public T e00; + public T e01; + } + + public struct Point3 where T : struct + { + public T e00; + public T e01; + public T e02; + } + + public struct Point4 where T : struct + { + public T e00; + public T e01; + public T e02; + public T e03; + } + + [StructLayout(LayoutKind.Sequential)] + public class SequentialClass where T : struct + { + public T e00; + } +} + +unsafe partial class GenericsTest +{ + public static int Main(string[] args) + { + try + { + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceB(); + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceC(); + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceD(); + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceF(); + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceL(); + Console.WriteLine("Testing IComInterface"); + TestIComInterfaceU(); + Console.WriteLine(); + + Console.WriteLine("Testing Nullable"); + TestNullableB(); + Console.WriteLine("Testing Nullable"); + TestNullableC(); + Console.WriteLine("Testing Nullable"); + TestNullableD(); + Console.WriteLine("Testing Nullable"); + TestNullableF(); + Console.WriteLine("Testing Nullable"); + TestNullableL(); + Console.WriteLine("Testing Nullable"); + TestNullableU(); + Console.WriteLine(); + + Console.WriteLine("Testing Point1"); + TestPoint1B(); + Console.WriteLine("Testing Point1"); + TestPoint1C(); + Console.WriteLine("Testing Point1"); + TestPoint1D(); + Console.WriteLine("Testing Point1"); + TestPoint1F(); + Console.WriteLine("Testing Point1"); + TestPoint1L(); + Console.WriteLine("Testing Point1"); + TestPoint1U(); + Console.WriteLine(); + + Console.WriteLine("Testing Point2"); + TestPoint2B(); + Console.WriteLine("Testing Point2"); + TestPoint2C(); + Console.WriteLine("Testing Point2"); + TestPoint2D(); + Console.WriteLine("Testing Point2"); + TestPoint2F(); + Console.WriteLine("Testing Point2"); + TestPoint2L(); + Console.WriteLine("Testing Point2"); + TestPoint2U(); + Console.WriteLine(); + + Console.WriteLine("Testing Point3"); + TestPoint3B(); + Console.WriteLine("Testing Point3"); + TestPoint3C(); + Console.WriteLine("Testing Point3"); + TestPoint3D(); + Console.WriteLine("Testing Point3"); + TestPoint3F(); + Console.WriteLine("Testing Point3"); + TestPoint3L(); + Console.WriteLine("Testing Point3"); + TestPoint3U(); + Console.WriteLine(); + + Console.WriteLine("Testing Point4"); + TestPoint4B(); + Console.WriteLine("Testing Point4"); + TestPoint4C(); + Console.WriteLine("Testing Point4"); + TestPoint4D(); + Console.WriteLine("Testing Point4"); + TestPoint4F(); + Console.WriteLine("Testing Point4"); + TestPoint4L(); + Console.WriteLine("Testing Point4"); + TestPoint4U(); + Console.WriteLine(); + + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanB(); + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanC(); + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanD(); + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanF(); + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanL(); + Console.WriteLine("Testing ReadOnlySpan"); + TestReadOnlySpanU(); + Console.WriteLine(); + + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassB(); + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassC(); + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassD(); + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassF(); + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassL(); + Console.WriteLine("Testing SequentialClass"); + TestSequentialClassU(); + Console.WriteLine(); + + Console.WriteLine("Testing Span"); + TestSpanB(); + Console.WriteLine("Testing Span"); + TestSpanC(); + Console.WriteLine("Testing Span"); + TestSpanD(); + Console.WriteLine("Testing Span"); + TestSpanF(); + Console.WriteLine("Testing Span"); + TestSpanL(); + Console.WriteLine("Testing Span"); + TestSpanU(); + Console.WriteLine(); + + Console.WriteLine("Testing Vector64"); + TestVector64B(); + Console.WriteLine("Testing Vector64"); + TestVector64C(); + Console.WriteLine("Testing Vector64"); + TestVector64D(); + Console.WriteLine("Testing Vector64"); + TestVector64F(); + Console.WriteLine("Testing Vector64"); + TestVector64L(); + Console.WriteLine("Testing Vector64"); + TestVector64U(); + Console.WriteLine(); + + Console.WriteLine("Testing Vector128"); + TestVector128B(); + Console.WriteLine("Testing Vector128"); + TestVector128C(); + Console.WriteLine("Testing Vector128"); + TestVector128D(); + Console.WriteLine("Testing Vector128"); + TestVector128F(); + Console.WriteLine("Testing Vector128"); + TestVector128L(); + Console.WriteLine("Testing Vector128"); + TestVector128U(); + Console.WriteLine(); + + Console.WriteLine("Testing Vector256"); + TestVector256B(); + Console.WriteLine("Testing Vector256"); + TestVector256C(); + Console.WriteLine("Testing Vector256"); + TestVector256D(); + Console.WriteLine("Testing Vector256"); + TestVector256F(); + Console.WriteLine("Testing Vector256"); + TestVector256L(); + Console.WriteLine("Testing Vector256"); + TestVector256U(); + Console.WriteLine(); + + Console.WriteLine("Testing Vector"); + TestVectorB(); + Console.WriteLine("Testing Vector"); + TestVectorC(); + Console.WriteLine("Testing Vector"); + TestVectorD(); + Console.WriteLine("Testing Vector"); + TestVectorF(); + Console.WriteLine("Testing Vector"); + TestVectorL(); + Console.WriteLine("Testing Vector"); + TestVectorU(); + Console.WriteLine(); + } + catch (System.Exception ex) + { + Console.WriteLine(ex); + return 0; + } + return 100; + } +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.csproj b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.csproj new file mode 100644 index 0000000000000000000000000000000000000000..588b6faf362325a6027b2d00f482f9e42c4701fc --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.csproj @@ -0,0 +1,15 @@ + + + + + true + exe + $(DefineConstants);STATIC + + + + + + + +