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/RP_Assets/HDRP_Test_Def.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 string comment; public float threshold; public string relativePath; public string templatePath; public int frameWait; public int sceneListIndex; public override string ToString() { if (string.IsNullOrEmpty(comment)) return name; else return string.Format("{0}: {1}", name, comment); } } // Get additionalSceneInfo public static Dictionary GetAdditionalInfos ( string path) { Dictionary o = new Dictionary(); AdditionalTestSceneInfos additionalTestSceneInfos = AssetDatabase.LoadAssetAtPath(path); if (additionalTestSceneInfos != null) { for (int i=0 ; i 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); } // Get the additional infos var additionalInfos = GetAdditionalInfos( "Assets"+Path.Combine(filesPath.Replace(Application.dataPath, ""), "AdditionalTestSceneInfos.asset") ); // 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; string sceneNum = p.Name.Split("_"[0])[0]; TestInfo testInfo = new TestInfo() { name = p.Name, comment = additionalInfos.ContainsKey(sceneNum)? additionalInfos[sceneNum].comment:null, relativePath = splitPaths.Last(), templatePath = splitPaths.Last(), threshold = 0.02f, frameWait = 5 }; 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 { // Get the additional infos var additionalInfos = GetAdditionalInfos( Path.Combine(filesPath, "AdditionalTestSceneInfos.asset") ); for ( int i=0 ; i