- Introduce `CombinedDependenciesJob` for efficient dependency handling and memory management - Add `ScheduleCustom<T>` for user-defined job execution/free logic - Refactor `JobInfo` and `JobDataPool<T>` for safer resource management and custom function support - Improve SPMD extension type constraint formatting - Update SPMD project content path and increment assembly versions - Add unit tests for combined dependencies and custom jobs - Remove `[Timeout]` from tests to prevent spurious failures - Add TODO for future `WideLane` optimizations - Replace legacy .sln with .slnx for better solution structure
90 lines
2.2 KiB
C#
90 lines
2.2 KiB
C#
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Buffer;
|
|
|
|
[TestClass]
|
|
[DoNotParallelize]
|
|
public class TestAllocationManager
|
|
{
|
|
[TestMethod]
|
|
public void PersistentAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Persistent);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Persistent);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TempAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Temp);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Temp);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
|
|
AllocationManager.ResetTempAllocator();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void FreeListAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.FreeList);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.FreeList);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void StackAllocationTest()
|
|
{
|
|
var thread = new Thread(() =>
|
|
{
|
|
var scope = AllocationManager.CreateStackScope();
|
|
var ptr1 = new MemoryBlock(1024, 8, scope.AllocationHandle);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
|
|
Thread.Sleep(100); // Simulate some work
|
|
|
|
ptr1.Dispose();
|
|
scope.Dispose();
|
|
});
|
|
|
|
thread.Start();
|
|
|
|
var scope = AllocationManager.CreateStackScope();
|
|
Assert.AreEqual(0u, scope.OriginalOffset);
|
|
|
|
var ptr2 = new MemoryBlock(1024, 8, scope.AllocationHandle);
|
|
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr2.Dispose();
|
|
scope.Dispose();
|
|
|
|
thread.Join();
|
|
}
|
|
}
|