説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UnsafeStreamTests.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using NUnit.Framework;
  2. using Unity.Burst;
  3. using Unity.Collections;
  4. using Unity.Collections.LowLevel.Unsafe;
  5. using Unity.Collections.Tests;
  6. using Unity.Jobs;
  7. internal class UnsafeStreamTests : CollectionsTestCommonBase
  8. {
  9. [Test]
  10. public void UnsafeStream_CustomAllocatorTest()
  11. {
  12. AllocatorManager.Initialize();
  13. var allocatorHelper = new AllocatorHelper<CustomAllocatorTests.CountingAllocator>(AllocatorManager.Persistent);
  14. ref var allocator = ref allocatorHelper.Allocator;
  15. allocator.Initialize();
  16. using (var container = new UnsafeStream(1, allocator.Handle))
  17. {
  18. }
  19. Assert.IsTrue(allocator.WasUsed);
  20. allocator.Dispose();
  21. allocatorHelper.Dispose();
  22. AllocatorManager.Shutdown();
  23. }
  24. [BurstCompile]
  25. struct BurstedCustomAllocatorJob : IJob
  26. {
  27. [NativeDisableUnsafePtrRestriction]
  28. public unsafe CustomAllocatorTests.CountingAllocator* Allocator;
  29. public void Execute()
  30. {
  31. unsafe
  32. {
  33. using (var container = new UnsafeStream(1, Allocator->Handle))
  34. {
  35. }
  36. }
  37. }
  38. }
  39. [Test]
  40. public unsafe void UnsafeStream_BurstedCustomAllocatorTest()
  41. {
  42. AllocatorManager.Initialize();
  43. var allocatorHelper = new AllocatorHelper<CustomAllocatorTests.CountingAllocator>(AllocatorManager.Persistent);
  44. ref var allocator = ref allocatorHelper.Allocator;
  45. allocator.Initialize();
  46. var allocatorPtr = (CustomAllocatorTests.CountingAllocator*)UnsafeUtility.AddressOf<CustomAllocatorTests.CountingAllocator>(ref allocator);
  47. unsafe
  48. {
  49. var handle = new BurstedCustomAllocatorJob {Allocator = allocatorPtr}.Schedule();
  50. handle.Complete();
  51. }
  52. Assert.IsTrue(allocator.WasUsed);
  53. allocator.Dispose();
  54. allocatorHelper.Dispose();
  55. AllocatorManager.Shutdown();
  56. }
  57. }