Esempio n. 1
0
        public void PlayerLogDoesNotContainShaderCompilationLog()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();
            var shadersAuditor = projectAuditor.GetAuditor <ShadersAuditor>();
            var result         = shadersAuditor.ParsePlayerLog(m_PlayerLogWithNoCompilationResource.relativePath, new ProjectIssue[0]);

            Assert.False(result);
        }
Esempio n. 2
0
        public void BuildReportIsSupported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var auditor        = projectAuditor.GetAuditor <BuildAuditor>();
            var isSupported    = auditor.IsSupported();

#if UNITY_2019_4_OR_NEWER
            Assert.True(isSupported);
#else
            Assert.False(isSupported);
#endif
        }
Esempio n. 3
0
        public static ProjectIssue[] Analyze(IssueCategory category)
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var auditor        = projectAuditor.GetAuditor(category);
            var config         = ScriptableObject.CreateInstance <ProjectAuditorConfig>();

            config.AnalyzeInBackground = false;
            auditor.Initialize(config);

            var foundIssues = new List <ProjectIssue>();

            auditor.Audit(issue => {
                foundIssues.Add(issue);
            });

            return(foundIssues.Where(i => i.category == category).ToArray());
        }
Esempio n. 4
0
        public void RuleTestPass()
        {
            var projectAuditor  = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var settingsAuditor = projectAuditor.GetAuditor <SettingsAuditor>();
            var descriptors     = settingsAuditor.GetDescriptors();
            var config          = ScriptableObject.CreateInstance <ProjectAuditorConfig>();
            var firstDescriptor = descriptors.FirstOrDefault();

            // make sure there are no rules
            var rule = config.GetRule(firstDescriptor);

            Assert.IsNull(rule);

            var filter = "dummy";

            // add rule with a filter.
            config.AddRule(new Rule
            {
                id       = firstDescriptor.id,
                severity = Rule.Severity.None,
                filter   = filter
            });

            // search for non-specific rule for this descriptor
            rule = config.GetRule(firstDescriptor);
            Assert.IsNull(rule);

            // search for specific rule
            rule = config.GetRule(firstDescriptor, filter);
            Assert.IsNotNull(rule);

            // add rule with no filter, which will replace any specific rule
            config.AddRule(new Rule
            {
                id       = firstDescriptor.id,
                severity = Rule.Severity.None
            });

            // search for specific rule again
            rule = config.GetRule(firstDescriptor, filter);
            Assert.IsNull(rule);

            // search for non-specific rule again
            rule = config.GetRule(firstDescriptor);
            Assert.IsNotNull(rule);

            // try to delete specific rule which has been already replaced by non-specific one
            config.ClearRules(firstDescriptor, filter);

            // generic rule should still exist
            rule = config.GetRule(firstDescriptor);
            Assert.IsNotNull(rule);

            // try to delete non-specific rule
            config.ClearRules(firstDescriptor);
            rule = config.GetRule(firstDescriptor);
            Assert.IsNull(rule);

            Assert.AreEqual(0, config.NumRules);

            config.AddRule(new Rule
            {
                id       = firstDescriptor.id,
                severity = Rule.Severity.None
            });
            Assert.AreEqual(1, config.NumRules);

            config.ClearAllRules();

            Assert.AreEqual(0, config.NumRules);
        }
Esempio n. 5
0
        public void UnusedVariantsAreReported()
        {
            var buildPath = FileUtil.GetUniqueTempPathInProject();

            Directory.CreateDirectory(buildPath);
            var buildPlayerOptions = new BuildPlayerOptions
            {
                scenes           = new string[] {},
                locationPathName = Path.Combine(buildPath, "test"),
                target           = EditorUserBuildSettings.activeBuildTarget,
                targetGroup      = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget),
                options          = BuildOptions.Development
            };
            var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

            Assert.True(buildReport.summary.result == BuildResult.Succeeded);

            Directory.Delete(buildPath, true);

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            projectAuditor.Audit();

            var shadersAndVariants = new List <ProjectIssue>();
            var shadersAuditor     = projectAuditor.GetAuditor <ShadersAuditor>();
            var completed          = false;

            shadersAuditor.Audit(shadersAndVariants.Add,
                                 () =>
            {
                completed = true;
            });
            Assert.True(completed);

            var variants = shadersAndVariants.Where(i => i.description.Equals("Custom/MyTestShader") && i.category == IssueCategory.ShaderVariants).ToArray();
            var result   = shadersAuditor.ParsePlayerLog(m_PlayerLogResource.relativePath, variants);

            Assert.True(result, "No compiled shader variants found in player log.");

            var shaderCompilerPlatforms    = variants.Select(v => v.GetCustomProperty((int)ShaderVariantProperty.Platform)).Distinct();
            var numShaderCompilerPlatforms = shaderCompilerPlatforms.Count();

            Assert.AreEqual(5 * numShaderCompilerPlatforms, variants.Length);

            var unusedVariants = variants.Where(i => !i.GetCustomPropertyAsBool((int)ShaderVariantProperty.Compiled)).ToArray();

            foreach (var plat in shaderCompilerPlatforms)
            {
                var unusedVariantsForPlatform = unusedVariants.Where(v => v.GetCustomProperty((int)ShaderVariantProperty.Platform).Equals(plat)).ToArray();

                Assert.AreEqual(2, unusedVariantsForPlatform.Length);
                Assert.True(unusedVariantsForPlatform[0].GetCustomProperty((int)ShaderVariantProperty.PassName).Equals("MyTestShader/Pass"));
                Assert.True(unusedVariantsForPlatform[0].GetCustomProperty((int)ShaderVariantProperty.Keywords).Equals("KEYWORD_B"));
#if UNITY_2019_1_OR_NEWER
                Assert.True(unusedVariantsForPlatform[1].GetCustomProperty((int)ShaderVariantProperty.PassName).Equals("Pass 1"));
#else
                Assert.True(unusedVariantsForPlatform[1].GetCustomProperty((int)ShaderVariantProperty.PassName).Equals(string.Empty));
#endif
                Assert.True(unusedVariantsForPlatform[1].GetCustomProperty((int)ShaderVariantProperty.Keywords).Equals(ShadersAuditor.k_NoKeywords));
            }
        }
Esempio n. 6
0
        private void OnEnable()
        {
            m_ProjectAuditor = new ProjectAuditor();

            var assemblyNames = m_ProjectAuditor.GetAuditor <ScriptAuditor>().assemblyNames.ToList();

            assemblyNames.Sort();
            m_AssemblyNames = assemblyNames.ToArray();

            if (m_AssemblySelection == null)
            {
                m_AssemblySelection = new TreeViewSelection();

                if (!string.IsNullOrEmpty(m_AssemblySelectionSummary))
                {
                    if (m_AssemblySelectionSummary == "All")
                    {
                        m_AssemblySelection.SetAll(m_AssemblyNames);
                    }
                    else if (m_AssemblySelectionSummary != "None")
                    {
                        string[] assemblies = m_AssemblySelectionSummary.Split(new string[] { ", " }, StringSplitOptions.None);
                        foreach (string assembly in assemblies)
                        {
                            m_AssemblySelection.selection.Add(assembly);
                        }
                    }
                }
                else if (m_AssemblyNames.Contains(m_DefaultAssemblyName))
                {
                    m_AssemblySelection.Set(m_DefaultAssemblyName);
                }
                else
                {
                    m_AssemblySelection.SetAll(m_AssemblyNames);
                }
            }

            if (m_AreaSelection == null)
            {
                m_AreaSelection = new TreeViewSelection();
                if (!string.IsNullOrEmpty(m_AreaSelectionSummary))
                {
                    if (m_AreaSelectionSummary == "All")
                    {
                        m_AreaSelection.SetAll(m_AreaNames);
                    }
                    else if (m_AreaSelectionSummary != "None")
                    {
                        string[] areas = m_AreaSelectionSummary.Split(new string[] { ", " }, StringSplitOptions.None);
                        foreach (string area in areas)
                        {
                            m_AreaSelection.selection.Add(area);
                        }
                    }
                }
                else
                {
                    m_AreaSelection.SetAll(m_AreaNames);
                }
            }

            m_CallHierarchyView = new CallHierarchyView(new TreeViewState());

            RefreshDisplay();
        }