using TestLibrary;
using Xunit;
- class Program
+ class Program : IDisposable
{
class TestComWrappers : ComWrappers
{
}
}
+ public void Dispose() => ForceGC();
+
static void ForceGC()
{
// Trigger the GC multiple times and then
}
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateComInterfaceCreation()
+ [Fact]
+ public void ValidateComInterfaceCreation()
{
Console.WriteLine($"Running {nameof(ValidateComInterfaceCreation)}...");
}
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateComInterfaceCreationRoundTrip()
+ [Fact]
+ public void ValidateComInterfaceCreationRoundTrip()
{
Console.WriteLine($"Running {nameof(ValidateComInterfaceCreationRoundTrip)}...");
Assert.Equal(0, count);
}
- static void ValidateComObjectExtendsManagedLifetime()
+ [Fact]
+ public void ValidateComObjectExtendsManagedLifetime()
{
Console.WriteLine($"Running {nameof(ValidateComObjectExtendsManagedLifetime)}...");
// hits zero ref count does not mean future calls to GetOrCreateComInterfaceForObject
// should return an unusable object.
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateCreatingAComInterfaceForObjectAfterTheFirstIsFree()
+ [Fact]
+ public void ValidateCreatingAComInterfaceForObjectAfterTheFirstIsFree()
{
Console.WriteLine($"Running {nameof(ValidateCreatingAComInterfaceForObjectAfterTheFirstIsFree)}...");
}
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateFallbackQueryInterface()
+ [Fact]
+ public void ValidateFallbackQueryInterface()
{
Console.WriteLine($"Running {nameof(ValidateFallbackQueryInterface)}...");
Assert.Equal(0, count);
}
- static void ValidateCreateObjectCachingScenario()
+ [Fact]
+ public void ValidateCreateObjectCachingScenario()
{
Console.WriteLine($"Running {nameof(ValidateCreateObjectCachingScenario)}...");
// Verify that if a GC nulls the contents of a weak GCHandle but has not yet
// run finializers to remove that GCHandle from the cache, the state of the system is valid.
- static void ValidateCreateObjectWeakHandleCacheCleanUp()
+ [Fact]
+ public void ValidateCreateObjectWeakHandleCacheCleanUp()
{
Console.WriteLine($"Running {nameof(ValidateCreateObjectWeakHandleCacheCleanUp)}...");
}
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateMappingAPIs()
+ [Fact]
+ public void ValidateMappingAPIs()
{
Console.WriteLine($"Running {nameof(ValidateMappingAPIs)}...");
}
[MethodImpl(MethodImplOptions.NoInlining)]
- static void ValidateWrappersInstanceIsolation()
+ [Fact]
+ public void ValidateWrappersInstanceIsolation()
{
Console.WriteLine($"Running {nameof(ValidateWrappersInstanceIsolation)}...");
Marshal.Release(trackerObjRaw);
}
- static void ValidatePrecreatedExternalWrapper()
+ [Fact]
+ public void ValidatePrecreatedExternalWrapper()
{
Console.WriteLine($"Running {nameof(ValidatePrecreatedExternalWrapper)}...");
});
}
- static void ValidateExternalWrapperCacheCleanUp()
+ [Fact]
+ public void ValidateExternalWrapperCacheCleanUp()
{
Console.WriteLine($"Running {nameof(ValidateExternalWrapperCacheCleanUp)}...");
}
}
- static void ValidateSuppliedInnerNotAggregation()
+ [Fact]
+ public void ValidateSuppliedInnerNotAggregation()
{
Console.WriteLine($"Running {nameof(ValidateSuppliedInnerNotAggregation)}...");
});
}
- static void ValidateIUnknownImpls()
+ [Fact]
+ public void ValidateIUnknownImpls()
=> TestComWrappers.ValidateIUnknownImpls();
class BadComWrappers : ComWrappers
}
}
- static void ValidateBadComWrapperImpl()
+ [Fact]
+ public void ValidateBadComWrapperImpl()
{
Console.WriteLine($"Running {nameof(ValidateBadComWrapperImpl)}...");
Marshal.Release(trackerObjRaw);
}
- static void ValidateRuntimeTrackerScenario()
+ [Fact]
+ public void ValidateRuntimeTrackerScenario()
{
Console.WriteLine($"Running {nameof(ValidateRuntimeTrackerScenario)}...");
ForceGC();
}
- static void ValidateQueryInterfaceAfterManagedObjectCollected()
+ [Fact]
+ public void ValidateQueryInterfaceAfterManagedObjectCollected()
{
Console.WriteLine($"Running {nameof(ValidateQueryInterfaceAfterManagedObjectCollected)}...");
}
}
- static void ValidateAggregationWithComObject()
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/85137", typeof(Utilities), nameof(Utilities.IsNativeAot))]
+ [Fact]
+ public void ValidateAggregationWithComObject()
{
Console.WriteLine($"Running {nameof(ValidateAggregationWithComObject)}...");
Assert.Equal(0, allocTracker.GetCount());
}
- static void ValidateAggregationWithReferenceTrackerObject()
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/85137", typeof(Utilities), nameof(Utilities.IsNativeAot))]
+ [Fact]
+ public void ValidateAggregationWithReferenceTrackerObject()
{
Console.WriteLine($"Running {nameof(ValidateAggregationWithReferenceTrackerObject)}...");
Assert.Equal(0, allocTracker.GetCount());
}
-
- static int Main()
- {
- try
- {
- ValidateComInterfaceCreation();
- ValidateComInterfaceCreationRoundTrip();
- ValidateComObjectExtendsManagedLifetime();
- ValidateCreatingAComInterfaceForObjectAfterTheFirstIsFree();
- ValidateFallbackQueryInterface();
- ValidateCreateObjectCachingScenario();
- ValidateCreateObjectWeakHandleCacheCleanUp();
- ValidateMappingAPIs();
- ValidateWrappersInstanceIsolation();
- ValidatePrecreatedExternalWrapper();
- ValidateExternalWrapperCacheCleanUp();
- ValidateSuppliedInnerNotAggregation();
- ValidateIUnknownImpls();
- ValidateBadComWrapperImpl();
- ValidateRuntimeTrackerScenario();
- ValidateQueryInterfaceAfterManagedObjectCollected();
-
- // Tracked by https://github.com/dotnet/runtime/issues/74620
- if (!TestLibrary.Utilities.IsNativeAot)
- {
- ValidateAggregationWithComObject();
- ValidateAggregationWithReferenceTrackerObject();
- }
-
- // Ensure all objects have been cleaned up.
- ForceGC();
- }
- catch (Exception e)
- {
- Console.WriteLine($"Test Failure: {e}");
- return 101;
- }
-
- return 100;
- }
}
}