Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CollectionsTestFixture.cs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using NUnit.Framework;
  2. using Unity.Burst;
  3. using Unity.Jobs.LowLevel.Unsafe;
  4. namespace Unity.Collections.Tests
  5. {
  6. internal class CollectionsTestCommonBase
  7. {
  8. AllocatorHelper<RewindableAllocator> rwdAllocatorHelper;
  9. protected AllocatorHelper<RewindableAllocator> CommonRwdAllocatorHelper => rwdAllocatorHelper;
  10. protected ref RewindableAllocator CommonRwdAllocator => ref rwdAllocatorHelper.Allocator;
  11. [SetUp]
  12. public virtual void Setup()
  13. {
  14. rwdAllocatorHelper = new AllocatorHelper<RewindableAllocator>(Allocator.Persistent);
  15. CommonRwdAllocator.Initialize(128 * 1024, true);
  16. #if UNITY_DOTSRUNTIME
  17. Unity.Runtime.TempMemoryScope.EnterScope();
  18. #endif
  19. }
  20. [TearDown]
  21. public virtual void TearDown()
  22. {
  23. CommonRwdAllocator.Dispose();
  24. rwdAllocatorHelper.Dispose();
  25. #if UNITY_DOTSRUNTIME
  26. Unity.Runtime.TempMemoryScope.ExitScope();
  27. #endif
  28. }
  29. }
  30. /// <summary>
  31. /// Collections test fixture to do setup and teardown.
  32. /// </summary>
  33. /// <remarks>
  34. /// Jobs debugger and safety checks should always be enabled when running collections tests. This fixture verifies
  35. /// those are enabled to prevent crashing the editor.
  36. /// </remarks>
  37. internal abstract class CollectionsTestFixture : CollectionsTestCommonBase
  38. {
  39. #if !UNITY_DOTSRUNTIME
  40. static string SafetyChecksMenu = "Jobs > Burst > Safety Checks";
  41. #endif
  42. private bool JobsDebuggerWasEnabled;
  43. [SetUp]
  44. public override void Setup()
  45. {
  46. base.Setup();
  47. // Many ECS tests will only pass if the Jobs Debugger enabled;
  48. // force it enabled for all tests, and restore the original value at teardown.
  49. JobsDebuggerWasEnabled = JobsUtility.JobDebuggerEnabled;
  50. JobsUtility.JobDebuggerEnabled = true;
  51. #if !UNITY_DOTSRUNTIME
  52. Assert.IsTrue(BurstCompiler.Options.EnableBurstSafetyChecks, $"Collections tests must have Burst safety checks enabled! To enable, go to {SafetyChecksMenu}");
  53. #endif
  54. }
  55. [TearDown]
  56. public override void TearDown()
  57. {
  58. JobsUtility.JobDebuggerEnabled = JobsDebuggerWasEnabled;
  59. base.TearDown();
  60. }
  61. }
  62. }