Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdaptivePerformanceIndexerUnitTests.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #if NUGET_MOQ_AVAILABLE
  2. using System.Collections.Generic;
  3. using Moq;
  4. using NUnit.Framework;
  5. using UnityEngine;
  6. using UnityEngine.AdaptivePerformance;
  7. using FrameTiming = UnityEngine.AdaptivePerformance.FrameTiming;
  8. namespace UnityEditor.AdaptivePerformance.Editor.Tests
  9. {
  10. public class AdaptivePerformanceIndexerUnitTests
  11. {
  12. FrameTiming ft;
  13. ThermalMetrics tm;
  14. IThermalStatus thermalStatus;
  15. IAdaptivePerformance defaultAP;
  16. AdaptivePerformanceIndexer testSubject;
  17. IPerformanceStatus defaultPerformanceStatus;
  18. AdaptivePerformanceIndexerSettings idxSettings;
  19. IAdaptivePerformanceSettings perfSettings;
  20. PerformanceStateTracker idxPerformanceStateTracker;
  21. [SetUp]
  22. public void InitializeTest()
  23. {
  24. tm = new ThermalMetrics();
  25. ft = new FrameTiming();
  26. idxSettings = new AdaptivePerformanceIndexerSettings();
  27. perfSettings = new IAdaptivePerformanceSettings();
  28. idxPerformanceStateTracker = new IndexedPerformanceStateTracker(120);
  29. defaultAP = Mock.Of<IAdaptivePerformance>();
  30. thermalStatus = Mock.Of<IThermalStatus>();
  31. defaultPerformanceStatus = Mock.Of<IPerformanceStatus>();
  32. }
  33. [Test]
  34. public void VerifyScalarCapacityWhenTwoRegisteredScalersAdded()
  35. {
  36. testSubject = InitializeTestSubject(0.25f, WarningLevel.Throttling, 0.25f, 0.55f);
  37. AdaptivePerformanceScaler sC1 = new MyPerformanceScaler();
  38. AdaptivePerformanceScaler sC2 = new MyPerformanceScaler();
  39. List<AdaptivePerformanceScaler> scalers = new List<AdaptivePerformanceScaler>();
  40. scalers.Add(sC1);
  41. scalers.Add(sC2);
  42. testSubject.GetAllRegisteredScalers(ref scalers);
  43. Assert.AreEqual(4, scalers.Capacity);
  44. }
  45. [TestCase(0.0149999997f, 0.015f, WarningLevel.Throttling, 0.25f, 0.55f, 1)]
  46. [TestCase(0f, 0f, WarningLevel.Throttling, 0.25f, 0.55f, 1)]
  47. [TestCase(0.5f, 0.5f, WarningLevel.ThrottlingImminent, 0.25f, 0.55f, 1)]
  48. [TestCase(0.5f, 0.5f, WarningLevel.ThrottlingImminent, 0.25f, 0.55f, 199)]
  49. [TestCase(0f, 0f, WarningLevel.ThrottlingImminent, 0.25f, 0.55f, 1)]
  50. [TestCase(0.370000005f, 0.37f, WarningLevel.NoWarning, -0.4f, 0.55f, 1)]
  51. [TestCase(0f, 0f, WarningLevel.NoWarning, -0.4f, 0.55f, 1)]
  52. [TestCase(0f, 0f, WarningLevel.ThrottlingImminent, -0.4f, 0.55f, 1)]
  53. [TestCase(0f, 0f, WarningLevel.ThrottlingImminent, 0.75f, 1f, 1)]
  54. [TestCase(0f, 0f, WarningLevel.ThrottlingImminent, 0.75f, 0.55f, 1)]
  55. [TestCase(0.310000002f, 0.31f, WarningLevel.ThrottlingImminent, 0.75f, 0.55f, 1)]
  56. [TestCase(0f, 0f, WarningLevel.ThrottlingImminent, 0.75f, 0.55f, 999)]
  57. [TestCase(0.310000002f, 0.31f, WarningLevel.ThrottlingImminent, 0.75f, 0.55f, 400)]
  58. public void VerifyTimeUntilNextAction_VaryingWarningsAndTrends_VaryingDelays(float expected, float idxSettingValue, WarningLevel warnLevel, float tempTrend, float avFrameTime, int numOfUpdateCalls)
  59. {
  60. testSubject = InitializeTestSubject(idxSettingValue, warnLevel, tempTrend, avFrameTime);
  61. for (int i = 0; i < numOfUpdateCalls; i++)
  62. {
  63. testSubject.Update();
  64. }
  65. Assert.AreEqual(expected, testSubject.TimeUntilNextAction);
  66. }
  67. internal AdaptivePerformanceIndexer InitializeTestSubject(float idxSettingValue, WarningLevel warnLevel, float tempTrend, float avFrameTime)
  68. {
  69. tm.WarningLevel = warnLevel;
  70. tm.TemperatureTrend = tempTrend;
  71. ft.AverageFrameTime = avFrameTime;
  72. Mock.Get(defaultPerformanceStatus).Setup(ps => ps.FrameTiming).Returns(ft);
  73. Mock.Get(thermalStatus).Setup(ts => ts.ThermalMetrics).Returns(tm);
  74. Mock.Get(defaultAP).Setup(d => d.ThermalStatus).Returns(thermalStatus);
  75. Mock.Get(defaultAP).Setup(d => d.PerformanceStatus).Returns(defaultPerformanceStatus);
  76. Holder.Instance = defaultAP;
  77. idxSettings.thermalActionDelay = idxSettingValue;
  78. perfSettings.indexerSettings = idxSettings;
  79. return new ZeroDeltaTimeAdaptivePerformanceIndexer(ref perfSettings, idxPerformanceStateTracker);
  80. }
  81. }
  82. public class MyPerformanceScaler : AdaptivePerformanceScaler
  83. {
  84. }
  85. partial class IndexedPerformanceStateTracker : PerformanceStateTracker
  86. {
  87. public IndexedPerformanceStateTracker(int sampleCapacity)
  88. : base(sampleCapacity) { }
  89. protected override float GetEffectiveTargetFrameRate()
  90. {
  91. return 0f;
  92. }
  93. }
  94. public class ZeroDeltaTimeAdaptivePerformanceIndexer : AdaptivePerformanceIndexer
  95. {
  96. internal ZeroDeltaTimeAdaptivePerformanceIndexer(ref IAdaptivePerformanceSettings settings, PerformanceStateTracker idxtracker)
  97. : base(ref settings, idxtracker) { }
  98. protected override float DeltaTime()
  99. {
  100. return 0f;
  101. }
  102. }
  103. }
  104. #endif