A game about forced loneliness, made by TACStudios
at master 100 lines 3.8 kB view raw
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.EventSystems; 6using UnityEngine.TestTools; 7using UnityEngine.Rendering; 8using UnityEngine.SceneManagement; 9using NUnit.Framework; 10 11namespace UnityEngine.Rendering.Tests 12{ 13 class RuntimeProfilerTestBase 14 { 15 protected const int k_NumWarmupFrames = 10; 16 protected const int k_NumFramesToRender = 30; 17 18 protected DebugFrameTiming m_DebugFrameTiming; 19 protected GameObject m_ToCleanup; 20 21 [SetUp] 22 public void Setup() 23 { 24 if (!FrameTimingManager.IsFeatureEnabled()) 25 Assert.Ignore("Frame timing stats are disabled in Player Settings, skipping test."); 26 27 if (Application.isBatchMode) 28 Assert.Ignore("Frame timing tests are not supported in batch mode, skipping test."); 29 30 // HACK #1 - really shouldn't have to do this here, but previous tests are leaking gameobjects 31 var objects = GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.InstanceID); 32 foreach (var o in objects) 33 { 34 // HACK #2 - must not destroy DebugUpdater, which happens to have an EventSystem. 35 if (o.GetComponent<EventSystem>() == null) 36 CoreUtils.Destroy(o); 37 } 38 39 m_DebugFrameTiming = new DebugFrameTiming(); 40 } 41 42 [TearDown] 43 public void TearDown() 44 { 45 if (m_ToCleanup != null) 46 CoreUtils.Destroy(m_ToCleanup); 47 } 48 49 protected IEnumerator Warmup() 50 { 51 for (int i = 0; i < k_NumWarmupFrames; i++) 52 yield return null; 53 54 m_DebugFrameTiming.Reset(); 55 } 56 } 57 58 // Fails on WebGL and Oculus Quest. 59 // Unfortunately, there is no good way to exclude Oculus Quest from the test without excluding all Android devices. 60 // https://jira.unity3d.com/browse/GFXFOUND-559 61 [UnityPlatform(exclude = new RuntimePlatform[] { RuntimePlatform.WebGLPlayer, RuntimePlatform.Android })] 62 class RuntimeProfilerTests : RuntimeProfilerTestBase 63 { 64 [UnityTest] 65 public IEnumerator RuntimeProfilerGivesNonZeroOutput() 66 { 67 if ((Application.platform == RuntimePlatform.LinuxPlayer || 68 Application.platform == RuntimePlatform.LinuxEditor) 69 && SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore) 70 { 71 Assert.Ignore("Test is failing on Linux OpenGLCore. https://jira.unity3d.com/browse/GFXFOUND-559"); 72 } 73 74 yield return Warmup(); 75 76 m_ToCleanup = new GameObject(); 77 var camera = m_ToCleanup.AddComponent<Camera>(); 78 for (int i = 0; i < k_NumFramesToRender; i++) 79 { 80 m_DebugFrameTiming.UpdateFrameTiming(); 81 82 var rr = new UnityEngine.Rendering.RenderPipeline.StandardRequest(); 83 rr.destination = RenderTexture.GetTemporary(128, 128, 24, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB); 84 rr.mipLevel = 0; 85 rr.slice = 0; 86 rr.face = CubemapFace.Unknown; 87 UnityEngine.Rendering.RenderPipeline.SubmitRenderRequest(camera, rr); 88 RenderTexture.ReleaseTemporary(rr.destination); 89 90 yield return null; 91 } 92 93 Assert.True( 94 m_DebugFrameTiming.m_BottleneckHistory.Histogram.Balanced > 0 || 95 m_DebugFrameTiming.m_BottleneckHistory.Histogram.CPU > 0 || 96 m_DebugFrameTiming.m_BottleneckHistory.Histogram.GPU > 0 || 97 m_DebugFrameTiming.m_BottleneckHistory.Histogram.PresentLimited > 0); 98 } 99 } 100}