using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using System.IO; using UnityEditor; using NUnit.Framework; using UnityEngine.TestTools; namespace UnityEngine.Experimental.Rendering { public class TestFrameworkTools { public static readonly string s_RootPath = Directory.GetParent(Directory.GetFiles(Application.dataPath, "SRPMARKER", SearchOption.AllDirectories).First()).ToString(); // path where the tests live public static string[] s_Path = { "Tests", "GraphicsTests", "RenderPipeline" }; public static Dictionary renderPipelineAssets = new Dictionary() { { "HDRP", "HDRenderPipeline/CommonAssets/HDRP_GraphicTests_Asset.asset" }, { "LWRP", "LightweightPipeline/LightweightPipelineAsset.asset" } }; // Renderpipeline assets used for the tests public static Dictionary renderPipelineScenesFolder = new Dictionary() { { "HDRP", "HDRenderPipeline/Scenes" }, { "LWRP", "LightweightPipeline/Scenes" } }; // info that gets generated for use // in a dod way public struct TestInfo { public string name; public float threshold; public string relativePath; public string templatePath; public int frameWait; public int sceneListIndex; public override string ToString() { return name; } } // collect the scenes that we can use public static class CollectScenes { public static IEnumerable HDRP { get { return GetScenesForPipelineID("HDRP"); } } public static IEnumerable HDRP_Params { get { return GetScenesForPipelineID("HDRP", true); } } public static IEnumerable LWRP { get { return GetScenesForPipelineID("LWRP"); } } public static IEnumerable GetScenesForPipelineID(string _pipelineID, bool fixtureParam = false) { return GetScenesForPipeline(renderPipelineScenesFolder[_pipelineID]); } public static IEnumerable GetScenesForPipeline(string _pipelinePath, bool fixtureParam = false) { var absoluteScenesPath = s_Path.Aggregate(s_RootPath, Path.Combine); var filesPath = Path.Combine(absoluteScenesPath, _pipelinePath); // find all the scenes var allPaths = Directory.GetFiles(filesPath, "*.unity", SearchOption.AllDirectories); // Convert to List for easy sorting in alphabetical order List allPaths_List = new List(allPaths); allPaths_List.Sort(); // Get the play mode scenes List playModeScenes = new List(); foreach( TestInfo ti in CollectScenesPlayMode.GetScenesForPipeline( _pipelinePath ) ) { playModeScenes.Add(ti.templatePath); } // construct all the needed test infos 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); var splitPaths = p.FullName.Split(new[] { split }, StringSplitOptions.RemoveEmptyEntries); // Filter out play mode tests from the list if (playModeScenes.Contains(splitPaths.Last())) continue; TestInfo testInfo = new TestInfo() { name = p.Name, relativePath = splitPaths.Last(), templatePath = splitPaths.Last(), threshold = 0.02f, frameWait = 100 }; if (fixtureParam) yield return new TestFixtureData(testInfo); else yield return testInfo; } } } public static class CollectScenesPlayMode { public static IEnumerable HDRP { get { return GetScenesForPipelineID("HDRP"); } } public static IEnumerable HDRP_Param { get { return GetScenesForPipelineID("HDRP", true); } } public static IEnumerable LWRP { get { return GetScenesForPipelineID("LWRP"); } } public static IEnumerable GetScenesForPipelineID(string _pipelineID, bool fixtureParam = false) { return GetScenesForPipeline(renderPipelineScenesFolder[_pipelineID]); } public static IEnumerable GetScenesForPipeline(string _pipelinePath, bool fixtureParam = false) { #if UNITY_EDITOR string absoluteScenesPath = s_Path.Aggregate(s_RootPath, Path.Combine); string assetScenesPath = absoluteScenesPath.Replace(Application.dataPath, ""); assetScenesPath = Path.Combine("Assets", assetScenesPath.Remove(0, 1)); string filesPath = Path.Combine(assetScenesPath, _pipelinePath); string listFilePath = Path.Combine(filesPath, "EditorPlayModeTests.asset"); EditorPlayModeTests listFile = (EditorPlayModeTests) AssetDatabase.LoadMainAssetAtPath(listFilePath); if ( listFile == null) { AssetDatabase.CreateAsset(ScriptableObject.CreateInstance(), listFilePath); AssetDatabase.Refresh(); yield return null; } else { for ( int i=0 ; i