Example #1
0
        protected RunResult RunAndPrintSummary(TestDefinition test)
        {
            var result = Run(test);

            PrintSummary(result);
            return(result);
        }
Example #2
0
        protected RunResult Run(TestDefinition test)
        {
            //localize test settings
            var warmupCount = 0;

            if (test.WarmupCount.HasValue)
            {
                warmupCount = test.WarmupCount.Value;
            }
            var iterationCount = 100;

            if (test.IterationCount.HasValue)
            {
                iterationCount = test.IterationCount.Value;
            }
            var testName = test.TestName ?? test.GetType() + "#" + test.GetHashCode();
            var setup    = test.Setup;
            var run      = test.Run;
            var cleanup  = test.Cleanup;

            //validate
            if (run == null)
            {
                throw new ArgumentNullException(string.Format("Verify that test {0} has a run action.", testName));
            }

            //setup
            try
            {
                if (setup != null)
                {
                    setup();
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            //warmup
            try
            {
                for (var w = 0; w < warmupCount; ++w)
                {
                    run();
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            var runStopwatch       = new Stopwatch();
            var iterationStopwatch = new Stopwatch();
            var iterationCounters  = new List <IterationCounter>();

            //run
            try
            {
                for (var i = 0; i < iterationCount; ++i)
                {
                    iterationStopwatch.Restart();
                    runStopwatch.Start();

                    run();

                    runStopwatch.Stop();
                    iterationStopwatch.Stop();
                    iterationCounters.Add(
                        new IterationCounter
                    {
                        ElapsedMillis = iterationStopwatch.ElapsedMilliseconds,
                        WorkingSet    = GC.GetTotalMemory(false)
                    });
                }
            }
            catch (Exception e)
            {
                return(new RunResult(testName, e));
            }

            var result = new RunResult(testName, runStopwatch.ElapsedMilliseconds, GC.GetTotalMemory(false), iterationCounters);

            //cleanup
            try
            {
                if (cleanup != null)
                {
                    cleanup();
                }
            }
            catch (Exception e)
            {
                result.ReportedException = e;
            }

            //report
            return(result);
        }
Example #3
0
 public void Register(TestDefinition test)
 {
     Tests.Add(test);
 }