浏览代码

Merge pull request #684 from Unity-Technologies/TestRunner-SetPipelineOnce

Set the pipeline asset once for a batch of tests.
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
a5aef4e0
共有 1 个文件被更改,包括 98 次插入22 次删除
  1. 120
      Tests/GraphicsTests/Framework/Editor/TestFramework.cs

120
Tests/GraphicsTests/Framework/Editor/TestFramework.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;

}
// collect the scenes that we can use
// Renderpipeline assets used for the tests
public static Dictionary<string, string> renderPipelineAssets = new Dictionary<string, string>()
{
{ "HDRP", "HDRenderPipeline/CommonAssets/HDRP_GraphicTests_Asset.asset" },
{ "LWRP", "LightweightPipeline/LightweightPipelineAsset.asset" }
};
// Renderpipeline assets used for the tests
public static Dictionary<string, string> renderPipelineScenesFolder = new Dictionary<string, string>()
{
{ "HDRP", "HDRenderPipeline/Scenes" },
{ "LWRP", "LightweightPipeline" }
};
// collect the scenes that we can use
public static IEnumerable HDScenes
public static IEnumerable HDRP
return GetScenesForPipeline("HDRenderPipeline/Scenes");
return GetScenesForPipelineID("HDRP");
public static IEnumerable LWScenes
public static IEnumerable LWRP
return GetScenesForPipeline("LightweightPipeline");
return GetScenesForPipelineID("LWRP");
}
public static IEnumerable GetScenesForPipelineID( string _pipelineID )
{
return GetScenesForPipeline( renderPipelineScenesFolder[_pipelineID] );
}
public static IEnumerable GetScenesForPipeline(string _pipelinePath)

var filesPath = Path.Combine(absoluteScenesPath, _pipelinePath);
// find all the scenes
var allPaths = System.IO.Directory.GetFiles(filesPath, "*.unity", System.IO.SearchOption.AllDirectories);
var allPaths = Directory.GetFiles(filesPath, "*.unity", SearchOption.AllDirectories);
// Convert to List for easy sorting in alphabetical ordre
List<string> allPaths_List = new List<string>(allPaths);
allPaths_List.Sort();
foreach (var path in allPaths)
for (int i=0; i<allPaths_List.Count; ++i)
var path = allPaths_List[i];
var p = new FileInfo(path);
var split = s_Path.Aggregate("", Path.Combine);
split = string.Format("{0}{1}", split, Path.DirectorySeparatorChar);

}
}
[TearDown]
public void TearDown()
// Change the SRP before a full batch of tests
public virtual string _SRP_ID { get { return "NONE"; } }
[OneTimeSetUp]
public void OneTimeSetUp()
var testSetup = Object.FindObjectOfType<SetupSceneForRenderPipelineTest>();
if (testSetup == null)
return;
SetupRenderPipeAsset();
}
testSetup.TearDown();
[OneTimeTearDown]
public void OnTimeTearDown()
{
RestoreRenderPipeAsset();
[UnityTest]
public IEnumerator HDRP_TestScene([ValueSource(typeof(CollectScenes), "HDScenes")]TestInfo testInfo)
public static RenderPipelineAsset GetRenderPipelineAsset(string _SRP_ID)
return TestScene(testInfo);
string absolutePath = s_Path.Aggregate(s_RootPath, Path.Combine);
string filePath = Path.Combine(absolutePath, renderPipelineAssets[_SRP_ID] );
return (RenderPipelineAsset)AssetDatabase.LoadAssetAtPath(filePath, typeof(RenderPipelineAsset));
[UnityTest]
public IEnumerator LWRP_TestScene([ValueSource(typeof(CollectScenes), "LWScenes")]TestInfo testInfo)
public static RenderPipelineAsset beforeTestsRenderPipeAsset;
public static RenderPipelineAsset wantedTestsRenderPipeAsset;
public void SetupRenderPipeAsset()
return TestScene(testInfo);
Debug.Log("Set " + _SRP_ID + " render pipeline.");
beforeTestsRenderPipeAsset = UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset;
wantedTestsRenderPipeAsset = GetRenderPipelineAsset(_SRP_ID);
if (wantedTestsRenderPipeAsset != beforeTestsRenderPipeAsset)
UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset = wantedTestsRenderPipeAsset;
public IEnumerator TestScene(TestInfo testInfo)
public void RestoreRenderPipeAsset()
{
if (wantedTestsRenderPipeAsset != beforeTestsRenderPipeAsset)
UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset = beforeTestsRenderPipeAsset;
}
// the actual test
public static IEnumerator TestScene(TestInfo testInfo)
{
var prjRelativeGraphsPath = s_Path.Aggregate(s_RootPath, Path.Combine);
var filePath = Path.Combine(prjRelativeGraphsPath, testInfo.relativePath);

var testSetup = Object.FindObjectOfType<SetupSceneForRenderPipelineTest> ();
SetupSceneForRenderPipelineTest testSetup = Object.FindObjectOfType<SetupSceneForRenderPipelineTest> ();
Assert.IsNotNull(testSetup, "No SetupSceneForRenderPipelineTest in scene " + testInfo.name);
Assert.IsNotNull(testSetup.cameraToUse, "No configured camera in <SetupSceneForRenderPipelineTest>");

}
Assert.IsTrue(areEqual, "Scene from {0}, did not match .template file.", testInfo.relativePath);
testSetup.TearDown();
private bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
private static bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
{
if (fromDisk == null || captured == null)
return false;

}
float rmse = Mathf.Sqrt(sumOfSquaredColorDistances / numberOfPixels);
return rmse < threshold;
}
// Graphic Tests Subclasses that inherit the functions bot provide different SRP_ID
public class HDRP : GraphicsTests
{
public override string _SRP_ID { get { return "HDRP"; } }
[UnityTest]
public IEnumerator HDRP_Test([ValueSource(typeof(CollectScenes), "HDRP")]TestInfo testInfo)
{
return TestScene(testInfo);
}
}
public class LTRP : GraphicsTests
{
public override string _SRP_ID { get { return "LWRP"; } }
[UnityTest]
public IEnumerator LWRP_Test([ValueSource(typeof(CollectScenes), "LWRP")]TestInfo testInfo)
{
return TestScene(testInfo);
}
}
}
}
正在加载...
取消
保存