Skip to content

Commit 3a3b0d2

Browse files
authored
Move many interop tests to run in-proc and move many to built in the merged runner itself (#94109)
1 parent b54a38f commit 3a3b0d2

File tree

268 files changed

+1869
-2628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+1869
-2628
lines changed

src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@ public static bool IsNonZeroLowerBoundArraySupported
5151
public static bool IsMonoLLVMAOT => _variant == "llvmaot";
5252
public static bool IsMonoLLVMFULLAOT => _variant == "llvmfullaot";
5353
public static bool IsMonoInterpreter => _variant == "monointerpreter";
54+
55+
// These platforms have not had their infrastructure updated to support native test assets.
56+
public static bool PlatformDoesNotSupportNativeTestAssets =>
57+
OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS() || OperatingSystem.IsAndroid() || OperatingSystem.IsBrowser() || OperatingSystem.IsWasi();
5458
}
5559
}

src/tests/Common/CoreCLRTestLibrary/Utilities.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static bool Verbose
6363
public static bool IsX64 => (RuntimeInformation.ProcessArchitecture == Architecture.X64);
6464
public static bool IsArm => (RuntimeInformation.ProcessArchitecture == Architecture.Arm);
6565
public static bool IsArm64 => (RuntimeInformation.ProcessArchitecture == Architecture.Arm64);
66+
public static bool IsXArch => IsX86 || IsX64;
6667

6768
public static bool IsWindows => OperatingSystem.IsWindows();
6869
public static bool IsLinux => OperatingSystem.IsLinux();
@@ -95,6 +96,7 @@ public static bool IsWindowsIoTCore
9596
public static bool IsMonoRuntime => Type.GetType("Mono.RuntimeStructs") != null;
9697
public static bool IsNotMonoRuntime => !IsMonoRuntime;
9798
public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported;
99+
public static bool IsNotNativeAot => !IsNativeAot;
98100

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

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

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

457461
return exitCode;
458462
}
463+
464+
private static void ExecuteAndUnloadInternal(string assemblyPath, string typeName, string methodName, object[] args, out WeakReference alcWeakRef)
465+
{
466+
AssemblyLoadContext alc = new AssemblyLoadContext($"[{assemblyPath}]{typeName}.{methodName}", true);
467+
alcWeakRef = new WeakReference(alc);
468+
469+
Assembly asm = alc.LoadFromAssemblyPath(assemblyPath);
470+
Type testType = asm.GetType(typeName);
471+
testType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static).Invoke(null, args);
472+
alc.Unload();
473+
}
474+
475+
public static void ExecuteAndUnload(string assemblyPath, string typeName, string methodName, params object[] args)
476+
{
477+
WeakReference alcWeakRef;
478+
ExecuteAndUnloadInternal(assemblyPath, typeName, methodName, args, out alcWeakRef);
479+
480+
// Run the GC and finalizer a few times to ensure that any complicated
481+
// object trees and runtime data structures that may keep the ALC alive are freed.
482+
for (int i = 0; i < 8 && alcWeakRef.IsAlive; i++)
483+
{
484+
GC.Collect();
485+
GC.WaitForPendingFinalizers();
486+
}
487+
488+
Assert.False(alcWeakRef.IsAlive);
489+
}
459490
}
460491
}

src/tests/Interop/ArrayMarshalling/BoolArray/MarshalBoolArrayTest.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using TestLibrary;
1818
using Xunit;
1919

20+
[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
2021
public class MarshalBoolArray
2122
{
2223
#region"variable"
@@ -78,7 +79,7 @@ private static bool TestMethod_CallBackOut(int size, bool[] array)
7879
[DllImport("MarshalBoolArrayNative")]
7980
private static extern bool DoCallBackInOut(CallBackInOut callback);
8081
private delegate bool CallBackInOut([In]int size, [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeConst = SIZE)] bool[] array);
81-
82+
8283
private static bool TestMethod_CallBackInOut(int size, bool[] array)
8384
{
8485
bool retVal = true;
@@ -115,7 +116,7 @@ private static bool TestMethod_CallBackInOut(int size, bool[] array)
115116
[DllImport("MarshalBoolArrayNative")]
116117
private static extern bool DoCallBackRefIn(CallBackRefIn callback);
117118
private delegate bool CallBackRefIn([In]int size, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] ref bool[] array);
118-
119+
119120
private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
120121
{
121122
bool retVal = true;
@@ -129,7 +130,7 @@ private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
129130
//Since now the sizeconst doesnt support on ref,so only check the first item instead.
130131
//Unhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #2': Cannot use SizeParamIndex for ByRef array parameters.
131132
//for (int i = 0; i < size; ++i) //Reverse PInvoke, true,false,true false,true
132-
//{
133+
//{
133134
// if ((0 == i % 2) && !array[i])
134135
// {
135136
// ReportFailure("Failed on the Managed Side:TestMethod_CallBackRefIn. The " + (i + 1) + "st Item failed", true.ToString(), false.ToString());
@@ -152,7 +153,7 @@ private static bool TestMethod_CallBackRefIn(int size, ref bool[] array)
152153
[DllImport("MarshalBoolArrayNative")]
153154
private static extern bool DoCallBackRefOut(CallBackRefOut callback);
154155
private delegate bool CallBackRefOut([In]int size, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] out bool[] array);
155-
156+
156157
private static bool TestMethod_CallBackRefOut(int size, out bool[] array)
157158
{
158159
bool retVal = true;
@@ -175,7 +176,7 @@ private static bool TestMethod_CallBackRefOut(int size, out bool[] array)
175176
[DllImport("MarshalBoolArrayNative")]
176177
private static extern bool DoCallBackRefInOut(CallBackRefInOut callback);
177178
private delegate bool CallBackRefInOut([In]int size, [In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] ref bool[] array);
178-
179+
179180
private static bool TestMethod_CallBackRefInOut(int size, ref bool[] array)
180181
{
181182
bool retVal = true;
@@ -219,10 +220,11 @@ private static bool TestMethod_CallBackRefInOut(int size, ref bool[] array)
219220

220221
[System.Security.SecuritySafeCritical]
221222
[Fact]
223+
[OuterLoop]
222224
public static void TestEntryPoint()
223225
{
224226
bool retVal = true;
225-
227+
226228
//TestFramework.BeginScenario("Reverse PInvoke with In attribute");
227229
if (!DoCallBackIn(new CallBackIn(TestMethod_CallBackIn)))
228230
{

src/tests/Interop/ArrayMarshalling/BoolArray/MarshalBoolArrayTest.csproj

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
#pragma warning disable CS0612, CS0618
1111

12-
public class Tester
12+
[ActiveIssue("https://github.com/dotnet/runtime/issues/91388", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
13+
public class SafeArrayMarshallingTest
1314
{
14-
[Fact]
15+
[ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsBuiltInComEnabled))]
16+
[SkipOnMono("Requires COM support")]
1517
public static int TestEntryPoint()
1618
{
1719
try

src/tests/Interop/ArrayMarshalling/SafeArray/SafeArrayTest.csproj

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/tests/Interop/ArrayMarshalling/StructArray/MarshalStructArrayTest.csproj

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/tests/Interop/BestFitMapping/BestFitMapping.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using TestLibrary;
99
using Xunit;
1010

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

src/tests/Interop/COM/Directory.Build.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
<IlasmRoundTripIncompatible>true</IlasmRoundTripIncompatible>
99
<!-- The tests are unhappy with where we lay out the executable -->
1010
<NativeAotIncompatible>true</NativeAotIncompatible>
11+
<!-- We must run these apps from this project as an entrypoint. -->
12+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
1113
</PropertyGroup>
1214

1315
<PropertyGroup Condition="'$(UseManagedCOMServer)' == 'true'">
1416
<CLRTestScriptLocalCoreShim>true</CLRTestScriptLocalCoreShim>
1517
<RequiresMockHostPolicy>true</RequiresMockHostPolicy>
18+
<!-- These tests modify the global runtime state with the mock host policy. -->
19+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
1620
</PropertyGroup>
1721

1822
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />

src/tests/Interop/COM/NETClients/ConsumeNETServer/ConsumeNETServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
3+
<!-- Uses a custom AppManifest -->
44
<RequiresProcessIsolation>true</RequiresProcessIsolation>
55
<ApplicationManifest>App.manifest</ApplicationManifest>
66
<UseManagedCOMServer>true</UseManagedCOMServer>

0 commit comments

Comments
 (0)