Browse Source

Merge pull request #1960 from SixLabors/af/externalize-RentReturnRelease_SubsequentRentReturnsDifferentHandles

Move RentReturnRelease_SubsequentRentReturnsDifferentHandles out of process
pull/1970/head
James Jackson-South 5 years ago
committed by GitHub
parent
commit
ffa35c3698
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs

64
tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedMemoryPoolTests.cs

@ -245,43 +245,45 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
cleanup.Register(b1); cleanup.Register(b1);
} }
public static readonly bool IsNotMacOS = !TestEnvironment.IsOSX; [Theory]
// TODO: Investigate MacOS failures
[ConditionalTheory(nameof(IsNotMacOS))]
[InlineData(false)] [InlineData(false)]
[InlineData(true)] [InlineData(true)]
public void RentReturnRelease_SubsequentRentReturnsDifferentHandles(bool multiple) public void RentReturnRelease_SubsequentRentReturnsDifferentHandles(bool multiple)
{ {
var pool = new UniformUnmanagedMemoryPool(16, 16); RemoteExecutor.Invoke(RunTest, multiple.ToString()).Dispose();
using var cleanup = new CleanupUtil(pool);
UnmanagedMemoryHandle b0 = pool.Rent();
IntPtr h0 = b0.Handle;
UnmanagedMemoryHandle b1 = pool.Rent();
IntPtr h1 = b1.Handle;
pool.Return(b0);
pool.Return(b1);
pool.Release();
// Do some unmanaged allocations to make sure new pool buffers are different:
IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray();
cleanup.Register(dummy);
if (multiple) static void RunTest(string multipleInner)
{ {
UnmanagedMemoryHandle b = pool.Rent(); var pool = new UniformUnmanagedMemoryPool(16, 16);
cleanup.Register(b); using var cleanup = new CleanupUtil(pool);
Assert.NotEqual(h0, b.Handle); UnmanagedMemoryHandle b0 = pool.Rent();
Assert.NotEqual(h1, b.Handle); IntPtr h0 = b0.Handle;
} UnmanagedMemoryHandle b1 = pool.Rent();
else IntPtr h1 = b1.Handle;
{ pool.Return(b0);
UnmanagedMemoryHandle[] b = pool.Rent(2); pool.Return(b1);
cleanup.Register(b); pool.Release();
Assert.NotEqual(h0, b[0].Handle);
Assert.NotEqual(h1, b[0].Handle); // Do some unmanaged allocations to make sure new pool buffers are different:
Assert.NotEqual(h0, b[1].Handle); IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray();
Assert.NotEqual(h1, b[1].Handle); cleanup.Register(dummy);
if (bool.Parse(multipleInner))
{
UnmanagedMemoryHandle b = pool.Rent();
cleanup.Register(b);
Assert.NotEqual(h0, b.Handle);
Assert.NotEqual(h1, b.Handle);
}
else
{
UnmanagedMemoryHandle[] b = pool.Rent(2);
cleanup.Register(b);
Assert.NotEqual(h0, b[0].Handle);
Assert.NotEqual(h1, b[0].Handle);
Assert.NotEqual(h0, b[1].Handle);
Assert.NotEqual(h1, b[1].Handle);
}
} }
} }

Loading…
Cancel
Save