Skip to content

Commit

Permalink
Move many interop tests to run in-proc and move many to built in the …
Browse files Browse the repository at this point in the history
…merged runner itself (#94109)
  • Loading branch information
jkoritzinsky authored Dec 7, 2023
1 parent b54a38f commit 3a3b0d2
Show file tree
Hide file tree
Showing 268 changed files with 1,869 additions and 2,628 deletions.
4 changes: 4 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ public static bool IsNonZeroLowerBoundArraySupported
public static bool IsMonoLLVMAOT => _variant == "llvmaot";
public static bool IsMonoLLVMFULLAOT => _variant == "llvmfullaot";
public static bool IsMonoInterpreter => _variant == "monointerpreter";

// These platforms have not had their infrastructure updated to support native test assets.
public static bool PlatformDoesNotSupportNativeTestAssets =>
OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS() || OperatingSystem.IsAndroid() || OperatingSystem.IsBrowser() || OperatingSystem.IsWasi();
}
}
31 changes: 31 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static bool Verbose
public static bool IsX64 => (RuntimeInformation.ProcessArchitecture == Architecture.X64);
public static bool IsArm => (RuntimeInformation.ProcessArchitecture == Architecture.Arm);
public static bool IsArm64 => (RuntimeInformation.ProcessArchitecture == Architecture.Arm64);
public static bool IsXArch => IsX86 || IsX64;

public static bool IsWindows => OperatingSystem.IsWindows();
public static bool IsLinux => OperatingSystem.IsLinux();
Expand Down Expand Up @@ -95,6 +96,7 @@ public static bool IsWindowsIoTCore
public static bool IsMonoRuntime => Type.GetType("Mono.RuntimeStructs") != null;
public static bool IsNotMonoRuntime => !IsMonoRuntime;
public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported;
public static bool IsNotNativeAot => !IsNativeAot;

public static bool HasAssemblyFiles => !string.IsNullOrEmpty(typeof(Utilities).Assembly.Location);
public static bool IsSingleFile => !HasAssemblyFiles;
Expand Down Expand Up @@ -438,6 +440,8 @@ public static int ExecuteAndUnload(string assemblyPath, string[] args, Action<As

exitCode = ExecuteAndUnloadInternal(assemblyPath, args, unloadingCallback, out alcWeakRef);

// Run the GC and finalizer a few times to ensure that any complicated
// object trees and runtime data structures that may keep the ALC alive are freed.
for (int i = 0; i < 8 && alcWeakRef.IsAlive; i++)
{
GC.Collect();
Expand All @@ -456,5 +460,32 @@ public static int ExecuteAndUnload(string assemblyPath, string[] args, Action<As

return exitCode;
}

private static void ExecuteAndUnloadInternal(string assemblyPath, string typeName, string methodName, object[] args, out WeakReference alcWeakRef)
{
AssemblyLoadContext alc = new AssemblyLoadContext($"[{assemblyPath}]{typeName}.{methodName}", true);
alcWeakRef = new WeakReference(alc);

Assembly asm = alc.LoadFromAssemblyPath(assemblyPath);
Type testType = asm.GetType(typeName);
testType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static).Invoke(null, args);
alc.Unload();
}

public static void ExecuteAndUnload(string assemblyPath, string typeName, string methodName, params object[] args)
{
WeakReference alcWeakRef;
ExecuteAndUnloadInternal(assemblyPath, typeName, methodName, args, out alcWeakRef);

// Run the GC and finalizer a few times to ensure that any complicated
// object trees and runtime data structures that may keep the ALC alive are freed.
for (int i = 0; i < 8 && alcWeakRef.IsAlive; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

Assert.False(alcWeakRef.IsAlive);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using TestLibrary;
using Xunit;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class MarshalBoolArray
{
#region"variable"
Expand Down Expand Up @@ -78,7 +79,7 @@ private static bool TestMethod_CallBackOut(int size, bool[] array)
[DllImport("MarshalBoolArrayNative")]
private static extern bool DoCallBackInOut(CallBackInOut callback);
private delegate bool CallBackInOut([In]int size, [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeConst = SIZE)] bool[] array);

private static bool TestMethod_CallBackInOut(int size, bool[] array)
{
bool retVal = true;
Expand Down Expand Up @@ -115,7 +116,7 @@ private static bool TestMethod_CallBackInOut(int size, bool[] array)
[DllImport("MarshalBoolArrayNative")]
private static extern bool DoCallBackRefIn(CallBackRefIn callback);
private delegate bool CallBackRefIn([In]int size, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] ref bool[] array);

private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
{
bool retVal = true;
Expand All @@ -129,7 +130,7 @@ private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
//Since now the sizeconst doesnt support on ref,so only check the first item instead.
//Unhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #2': Cannot use SizeParamIndex for ByRef array parameters.
//for (int i = 0; i < size; ++i) //Reverse PInvoke, true,false,true false,true
//{
//{
// if ((0 == i % 2) && !array[i])
// {
// ReportFailure("Failed on the Managed Side:TestMethod_CallBackRefIn. The " + (i + 1) + "st Item failed", true.ToString(), false.ToString());
Expand All @@ -152,7 +153,7 @@ private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
[DllImport("MarshalBoolArrayNative")]
private static extern bool DoCallBackRefOut(CallBackRefOut callback);
private delegate bool CallBackRefOut([In]int size, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] out bool[] array);

private static bool TestMethod_CallBackRefOut(int size, out bool[] array)
{
bool retVal = true;
Expand All @@ -175,7 +176,7 @@ private static bool TestMethod_CallBackRefOut(int size, out bool[] array)
[DllImport("MarshalBoolArrayNative")]
private static extern bool DoCallBackRefInOut(CallBackRefInOut callback);
private delegate bool CallBackRefInOut([In]int size, [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] ref bool[] array);

private static bool TestMethod_CallBackRefInOut(int size, ref bool[] array)
{
bool retVal = true;
Expand Down Expand Up @@ -219,10 +220,11 @@ private static bool TestMethod_CallBackRefInOut(int size, ref bool[] array)

[System.Security.SecuritySafeCritical]
[Fact]
[OuterLoop]
public static void TestEntryPoint()
{
bool retVal = true;

//TestFramework.BeginScenario("Reverse PInvoke with In attribute");
if (!DoCallBackIn(new CallBackIn(TestMethod_CallBackIn)))
{
Expand Down

This file was deleted.

6 changes: 4 additions & 2 deletions src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

#pragma warning disable CS0612, CS0618

public class Tester
[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class SafeArrayMarshallingTest
{
[Fact]
[ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsBuiltInComEnabled))]
[SkipOnMono("Requires COM support")]
public static int TestEntryPoint()
{
try
Expand Down
15 changes: 0 additions & 15 deletions src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.csproj

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions src/tests/Interop/BestFitMapping/BestFitMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TestLibrary;
using Xunit;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class BestFitMapping
{

Expand Down
4 changes: 4 additions & 0 deletions src/tests/Interop/COM/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
<IlasmRoundTripIncompatible>true</IlasmRoundTripIncompatible>
<!-- The tests are unhappy with where we lay out the executable -->
<NativeAotIncompatible>true</NativeAotIncompatible>
<!-- We must run these apps from this project as an entrypoint. -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>

<PropertyGroup Condition="'$(UseManagedCOMServer)' == 'true'">
<CLRTestScriptLocalCoreShim>true</CLRTestScriptLocalCoreShim>
<RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<!-- These tests modify the global runtime state with the mock host policy. -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<!-- Uses a custom AppManifest -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<ApplicationManifest>App.manifest</ApplicationManifest>
<UseManagedCOMServer>true</UseManagedCOMServer>
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Interop/COM/NativeClients/DefaultInterfaces.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CMakeProjectReference -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<CMakeProjectReference Include="DefaultInterfaces/CMakeLists.txt" />
<ProjectReference Include="../NETServer/NETServer.DefaultInterfaces.ilproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Interop/COM/NativeClients/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<CLRTestIsHosted>false</CLRTestIsHosted>
<NativeAotIncompatible>true</NativeAotIncompatible>
<!-- The true entrypoint for these tests is a native executable -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Interop/COM/NativeClients/Dispatch.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CMakeProjectReference -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<CMakeProjectReference Include="Dispatch/CMakeLists.txt" />
<ProjectReference Include="../NETServer/NETServer.csproj" />
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Interop/COM/NativeClients/Events.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CMakeProjectReference -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<CMakeProjectReference Include="Events/CMakeLists.txt" />
<ProjectReference Include="../NETServer/NETServer.csproj" />
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Interop/COM/NativeClients/Licensing.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CMakeProjectReference -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<CMakeProjectReference Include="Licensing/CMakeLists.txt" />
<ProjectReference Include="../NETServer/NETServer.csproj" />
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Interop/COM/NativeClients/Primitives.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CMakeProjectReference -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<CMakeProjectReference Include="Primitives/CMakeLists.txt" />
<ProjectReference Include="../NETServer/NETServer.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/tests/Interop/DisabledRuntimeMarshalling/AutoLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace DisabledRuntimeMarshalling;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class PInvokes_AutoLayout
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace DisabledRuntimeMarshalling;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class FunctionPointers
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingDisabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class DelegatesFromExternalAssembly
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace DisabledRuntimeMarshalling;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class Generics
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingDisabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class PInvokes
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingDisabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class UnmanagedCallersOnly
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingEnabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class DelegatesFromExternalAssembly
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingEnabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class PInvokes
{
public static bool IsWindowsX86Process => OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.X86;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingDisabled;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public unsafe class UnmanagedCallersOnly
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using Xunit;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class Test
{
private const string RelativeSubdirectoryName = "RelativeNative";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for UnloadabilityIncompatible, CLRTestBashEnvironmentVariable, CMakeProjectReference -->
<!--
This test has dependencies on specific file layouts relative to the executable.
It also sets specific loader environment variables.
-->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- The test cannot be run twice in the same process since it moves a native dll that it uses for pinvoke later -->
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using Xunit;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class ExactSpellingTest
{
class Ansi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using Xunit;

[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
public class DllImportSearchPathsTest
{
private static string Subdirectory => Path.Combine(NativeLibraryToLoad.GetDirectory(), "subdirectory");
Expand Down
Loading

0 comments on commit 3a3b0d2

Please sign in to comment.