internal static void EndTest(Test test)
        {
            if (test.IsSuite)
            {
                return;
            }
            if (test.FullName != Active.TestName)
            {
                return;
            }
            DisposeMeasurements();
            Active.CalculateStatisticalValues();
            Active.EndTime = Utils.DateToInt(DateTime.Now);
            if (OnTestEnded != null)
            {
                OnTestEnded();
            }
            Active.LogOutput();

            TestContext.Out.WriteLine("##performancetestresult:" + JsonUtility.ToJson(Active));
            Active = null;
        }
Esempio n. 2
0
        internal static void EndTest(ITest test)
        {
            if (test.IsSuite)
            {
                return;
            }

            if (Active.m_PerformanceTestHelper != null && Active.m_PerformanceTestHelper.gameObject != null)
            {
                UnityEngine.Object.DestroyImmediate(Active.m_PerformanceTestHelper.gameObject);
            }

            DisposeMeasurements();
            Active.CalculateStatisticalValues();
            OnTestEnded?.Invoke();
            Active.LogOutput();

            TestContext.Out.WriteLine("##performancetestresult2:" + Active.Serialize());
            PlayerCallbacks.LogMetadata();
            Active = null;
            GC.Collect();
        }
Esempio n. 3
0
        internal static void StartTest(ITest currentTest)
        {
            if (currentTest.IsSuite)
            {
                return;
            }

            var go = new GameObject("PerformanceTestHelper");

            go.hideFlags = HideFlags.HideAndDontSave;
            var performanceTestHelper = go.AddComponent <PerformanceTestHelper>();

            var test = new PerformanceTest
            {
                Name       = currentTest.FullName,
                Categories = currentTest.GetAllCategoriesFromTest(),
                Version    = GetVersion(currentTest),
                m_PerformanceTestHelper = performanceTestHelper
            };

            Active = test;
            performanceTestHelper.ActiveTest = test;
        }
        public TestListTableItem(int id, int depth, string displayName, PerformanceTest test) : base(id, depth,
                                                                                                     displayName)
        {
            this.test = test;

            deviation = 0f;
            if (test != null)
            {
                foreach (var sample in test.SampleGroups)
                {
                    if (sample.Definition.Name == "Time")
                    {
                        deviation = sample.StandardDeviation;
                        median    = sample.Median;
                        break;
                    }

                    if (sample.Samples.Count <= 1)
                    {
                        median = sample.Median;
                        break;
                    }

                    if (sample.StandardDeviation > deviation)
                    {
                        standardDeviation = sample.StandardDeviation;
                    }

                    double thisDeviation = sample.StandardDeviation / sample.Median;
                    if (thisDeviation > deviation)
                    {
                        deviation = thisDeviation;
                        median    = sample.Median;
                    }
                }
            }
        }
Esempio n. 5
0
 public PerformanceTest()
 {
     Active = this;
 }
        public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
        {
            PerformanceTest.StartTest(context.CurrentTest);

            var unityContext = (UnityTestExecutionContext)context;
            var state        = unityContext.SetUpTearDownState;

            if (state == null)
            {
                // We do not expect a state to exist in playmode
                state = ScriptableObject.CreateInstance <EnumerableSetUpTearDownCommandState>();
            }

            while (state.NextSetUpStepIndex < SetUps.Length)
            {
                var methodInfo = SetUps[state.NextSetUpStepIndex];
                var enumerator = Run(context, methodInfo);
                SetEnumeratorPC(enumerator, state.NextSetUpStepPc);

                var logScope = new LogScope();

                while (true)
                {
                    try
                    {
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        state.TestHasRun = true;
                        Debug.LogException(ex);
                        context.CurrentResult.SetResult(ResultState.Failure, ex.Message);
                        break;
                    }

                    state.NextSetUpStepPc = GetEnumeratorPC(enumerator);
                    yield return(enumerator.Current);
                }

                if (logScope.AnyFailingLogs())
                {
                    state.TestHasRun = true;
                    context.CurrentResult.SetResult(ResultState.Failure);
                }

                logScope.Dispose();

                state.NextSetUpStepIndex++;
                state.NextSetUpStepPc = 0;
            }

            if (!state.TestHasRun)
            {
                if (innerCommand is IEnumerableTestMethodCommand)
                {
                    var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
                    foreach (var iterator in executeEnumerable)
                    {
                        yield return(iterator);
                    }
                }
                else
                {
                    context.CurrentResult = innerCommand.Execute(context);
                }

                state.TestHasRun = true;
            }

            if (!state.TestTearDownStarted)
            {
                state.CurrentTestResultStatus = context.CurrentResult.ResultState.Status;
                state.CurrentTestResultLabel  = context.CurrentResult.ResultState.Label;
                state.CurrentTestResultSite   = context.CurrentResult.ResultState.Site;
                state.CurrentTestMessage      = context.CurrentResult.Message;
                state.CurrentTestStrackTrace  = context.CurrentResult.StackTrace;
            }

            while (state.NextTearDownStepIndex < TearDowns.Length)
            {
                state.TestTearDownStarted = true;
                var methodInfo = TearDowns[state.NextTearDownStepIndex];
                var enumerator = Run(context, methodInfo);
                SetEnumeratorPC(enumerator, state.NextTearDownStepPc);

                var logScope = new LogScope();

                while (true)
                {
                    try
                    {
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogException(ex);
                        context.CurrentResult.SetResult(ResultState.Failure, ex.Message);
                        break;
                    }

                    state.NextTearDownStepPc = GetEnumeratorPC(enumerator);
                    yield return(enumerator.Current);
                }

                if (logScope.AnyFailingLogs())
                {
                    state.TestHasRun = true;
                    context.CurrentResult.SetResult(ResultState.Failure);
                }

                logScope.Dispose();

                state.NextTearDownStepIndex++;
                state.NextTearDownStepPc = 0;
            }

            context.CurrentResult.SetResult(
                new ResultState(state.CurrentTestResultStatus, state.CurrentTestResultLabel,
                                state.CurrentTestResultSite), state.CurrentTestMessage, state.CurrentTestStrackTrace);
            state.Reset();
            if (PerformanceTest.Active.Failed)
            {
                context.CurrentResult.SetResult(ResultState.Failure);
            }
            PerformanceTest.EndTest(context.CurrentTest);
        }
 public IEnumerator BeforeTest(ITest test)
 {
     PerformanceTest.StartTest(test);
     yield return(null);
 }
Esempio n. 8
0
 public IEnumerator AfterTest(ITest test)
 {
     PerformanceTest.EndTest(test);
     yield return(null);
 }
Esempio n. 9
0
        public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
        {
            PerformanceTest.StartTest(context.CurrentTest);
            var logCollector = new LogScope();

            if (!(innerCommand is IEnumerableTestMethodCommand))
            {
                Execute(context);
                yield break;
            }

            var enumerableTestMethodCommand = (IEnumerableTestMethodCommand)innerCommand;

            IEnumerable executeEnumerable;

            try
            {
                executeEnumerable = enumerableTestMethodCommand.ExecuteEnumerable(context);
            }
            catch (Exception e)
            {
                context.CurrentResult.RecordException(e);
                yield break;
            }

            foreach (var step in executeEnumerable)
            {
                try
                {
                    if (logCollector.AnyFailingLogs())
                    {
                        var failingLog = logCollector.FailingLogs[0];
                        throw new UnhandledLogMessageException(failingLog);
                    }
                }
                catch (Exception e)
                {
                    context.CurrentResult.RecordException(e);
                    break;
                }

                yield return(step);
            }

            try
            {
                if (logCollector.AnyFailingLogs())
                {
                    var failingLog = logCollector.FailingLogs[0];
                    throw new UnhandledLogMessageException(failingLog);
                }

                logCollector.ProcessExpectedLogs();
                if (logCollector.ExpectedLogs.Count > 0)
                {
                    throw new UnexpectedLogMessageException(LogScope.Current.ExpectedLogs.Peek());
                }
            }
            catch (Exception exception)
            {
                context.CurrentResult.RecordException(exception);
            }

            logCollector.Dispose();
            if (PerformanceTest.Active.Failed)
            {
                context.CurrentResult.SetResult(ResultState.Failure);
            }
            PerformanceTest.EndTest(context.CurrentTest);
        }