Esempio n. 1
0
        public static String GetDescription(TestAgent test, Object container, Object testedObject)
        {
            if (test.DescriptorMethod == null)
            {
                return String.Empty;
            }

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            var description = (String)test.DescriptorMethod.Invoke(container, invokeParameters);
            return description;
        }
Esempio n. 2
0
        private TestAgent(TestAgent prototype)
        {
            ContainerType = prototype.ContainerType;
            MilestoneCount = prototype.MilestoneCount;
            IterationCount = prototype.IterationCount;
            Mode = prototype.Mode;
            Label = prototype.Label;
            Metrics = prototype.Metrics;
            Id = prototype.Id;
            TestedType = prototype.TestedType;

            if (prototype.TestUnits != null)
            {
                TestUnits = new List<TestUnit>(prototype.TestUnits);
            }
            if (prototype.MilestonePreparingMethods != null)
            {
                MilestonePreparingMethods = new List<MethodInfo>(prototype.MilestonePreparingMethods);
            }
            if (prototype.MilestoneFinalizingMethods != null)
            {
                MilestoneFinalizingMethods = new List<MethodInfo>(prototype.MilestoneFinalizingMethods);
            }
            if (prototype.IterationPreparingMethods != null)
            {
                IterationPreparingMethods = new List<MethodInfo>(prototype.IterationPreparingMethods);
            }
            if (prototype.IterationFinalizingMethods != null)
            {
                IterationFinalizingMethods = new List<MethodInfo>(prototype.IterationFinalizingMethods);
            }
            if (prototype.TestPreparingMethods != null)
            {
                TestPreparingMethods = new List<MethodInfo>(prototype.TestPreparingMethods);
            }
            if (prototype.TestFinalizingMethods != null)
            {
                TestFinalizingMethods = new List<MethodInfo>(prototype.TestFinalizingMethods);
            }
            MilestoneLabelMethod = prototype.MilestoneLabelMethod;
            DescriptorMethod = prototype.DescriptorMethod;
        }
Esempio n. 3
0
        public static String GetMilestoneLabel(TestAgent test, Object container, Object testedObject, Int32 milestoneIndex)
        {
            if (test.MilestoneLabelMethod == null)
            {
                return milestoneIndex.ToString();
            }

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                invokeParameters = new Object[2] { testedObject, milestoneIndex };
            }
            else
            {
                invokeParameters = new Object[1] { milestoneIndex };
            }

            var label = (String)test.MilestoneLabelMethod.Invoke(container, invokeParameters);
            return label;
        }
Esempio n. 4
0
        public void AddTest(TestAgent test, String description)
        {
            _currentTestResult = new TestResult(test, description);

            _currentTestResult.MilestoneCount = test.MilestoneCount;
            _currentTestResult.IterationCount = test.IterationCount;
            _currentTestResult.Mode = test.Mode;

            _currentTestResult.LineDictionary = new Dictionary<Guid, String>();
            foreach (var testUnit in test.TestUnits)
            {
                _currentTestResult.LineDictionary.Add(testUnit.Id, testUnit.Label);
            }
            _currentTestResult.MilestoneLabels = new String[test.MilestoneCount];
            _currentTestResult.AllResults = new List<PassResult>();

            _testResultList.Add(_currentTestResult);

            _currentMilestoneIndex = -1;
        }
Esempio n. 5
0
        private TestAgent FillTestAgent(Type t, TestContainerAttribute tcAttribute)
        {
            var agent = new TestAgent(t, tcAttribute, _warningHandler);

            var allMethods = t.GetMethods();
            foreach (var method in allMethods)
            {
                agent.AddMethodIfMatches(method);
            }
            agent.CompleteFilling();

            return agent.IsValid ? agent : null;
        }
Esempio n. 6
0
 public TestAgent Clone()
 {
     var clone = new TestAgent(this);
     return clone;
 }
Esempio n. 7
0
        public static void InvokeIterationFinalizing(TestAgent test, Object container, ref Object testedObject)
        {
            if (test.IterationFinalizingMethods == null)
            {
                return;
            }

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            foreach (var iterationFinalizingMethod in test.IterationFinalizingMethods)
            {
                iterationFinalizingMethod.Invoke(container, invokeParameters);
            }
        }
Esempio n. 8
0
        private void RunRegularTest(TestAgent test)
        {
            var milestoneCount = (test.MilestoneCount > 0) ? test.MilestoneCount : 1;
            var iterationCount = (test.IterationCount > 0) ? test.IterationCount : 1;

            var ctor = test.ContainerType.GetConstructor(Type.EmptyTypes);
            var container = ctor.Invoke(null);

            Object testedObject = InvokeTestPreparing(test, container);
            var description = GetDescription(test, container, testedObject);
            _resultHandler.AddTest(test, description);
            for (int m = 0; m < milestoneCount; m++)
            {
                InvokeMilestonePreparing(test, container, ref testedObject, m);
                var label = GetMilestoneLabel(test, container, testedObject, m);
                _resultHandler.AddMilestoneData(label);
                for (int i = -1; i < iterationCount; i++)
                {
                    InvokeIterationPreparing(test, container, ref testedObject, i);
                    foreach (var testUnit in test.TestUnits)
                    {
                        DoRegularTest(test, testUnit, container, testedObject, i);
                    }
                    InvokeIterationFinalizing(test, container, ref testedObject);
                }
                InvokeMilestoneFinalizing(test, container, ref testedObject);
            }
            InvokeTestFinalizing(test, container, testedObject);
        }
Esempio n. 9
0
        private void RunJITTest(TestAgent test)
        {
            var milestoneCount = (test.MilestoneCount > 0) ? test.MilestoneCount : 1;
            var iterationCount = (test.IterationCount > 0) ? test.IterationCount : 1;

            var compatibleIds = (from e in test.TestUnits
                                 where !e.Incompatible
                                 select e.Id).ToList();

            var incompatibleIds = (from e in test.TestUnits
                                 where e.Incompatible
                                 select e.Id).ToList();

            var ctor = test.ContainerType.GetConstructor(Type.EmptyTypes);
            var container = ctor.Invoke(null);

            Object testedObject = InvokeTestPreparing(test, container);
            var description = GetDescription(test, container, testedObject);
            _resultHandler.AddTest(test, description);
            for (int m = 0; m < milestoneCount; m++)
            {
                var label = GetMilestoneLabel(test, container, testedObject, m);
                _resultHandler.AddMilestoneData(label);
                test.ClearMerkers();
                for (int i = 0; i < iterationCount; i++)
                {
                    if (compatibleIds.Count > 0)
                    {
                        test.SetMarkers(compatibleIds);
                        DoJITTest(test, milestoneCount, iterationCount);
                        test.ClearMerkers();
                    }

                    foreach (var id in incompatibleIds)
                    {
                        test.SetMarker(id);
                        DoJITTest(test, milestoneCount, iterationCount);
                        test.ClearMerkers();
                    }
                }
            }
        }
Esempio n. 10
0
        private void DoRegularTest(TestAgent test, TestUnit testUnit, Object container, Object testedObject, Int32 iterationIndex)
        {
            var timeMonitor = new Stopwatch();
            var memoryMonitor = new MemoryMonitor();

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            memoryMonitor.Prepare();
            memoryMonitor.Start();
            timeMonitor.Start();
            var result = testUnit.TestMethod.Invoke(container, invokeParameters);
            timeMonitor.Stop();
            memoryMonitor.Stop();

            //skip results of first call storing
            if (iterationIndex != -1)
            {
                bool isValid = true;
                if (testUnit.ValidatorMethod != null)
                {
                    invokeParameters = new Object[1] { result };
                    isValid = (bool)testUnit.ValidatorMethod.Invoke(container, invokeParameters);
                }

                var runResult = new PassResult(timeMonitor.Elapsed, memoryMonitor.Usage, test.Metrics, isValid);
                _resultHandler.AddResult(runResult, testUnit.Id, iterationIndex);

                _progressHandler.PortionDone();
            }
        }
Esempio n. 11
0
        private void DoJITTest(TestAgent test, uint milestoneCount, uint iterationCount)
        {
            var outPipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);
            var inPipeServer = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
            var outClientHandler = outPipeServer.GetClientHandleAsString();
            var inClientHandler = inPipeServer.GetClientHandleAsString();

            var workerProcess = new Process();
            workerProcess.StartInfo.FileName = _jitesterPath;
            workerProcess.StartInfo.UseShellExecute = false;

            workerProcess.StartInfo.Arguments = String.Concat(
                outClientHandler, " ",
                inClientHandler, " ",
                milestoneCount, " ",
                iterationCount, " ",
                test.ContainerType.Assembly.Location);

            workerProcess.Start();

            outPipeServer.DisposeLocalCopyOfClientHandle();
            inPipeServer.DisposeLocalCopyOfClientHandle();

            var binFormatter = new BinaryFormatter();
            binFormatter.Serialize(outPipeServer, test);

            outPipeServer.WaitForPipeDrain();

            var resObj = binFormatter.Deserialize(inPipeServer);
            var results = resObj as List<PassResult>;

            foreach (var result in results)
            {
                _resultHandler.AddResult(result);
                _progressHandler.PortionDone();
            }
        }
Esempio n. 12
0
        public static Object InvokeTestPreparing(TestAgent test, Object container)
        {
            Object testedObject = null;
            if (test.TestPreparingMethods == null)
            {
                if (test.TestedType != null)
                {
                    var ctor = test.TestedType.GetConstructor(Type.EmptyTypes);
                    testedObject = ctor.Invoke(null);
                }
                return testedObject;
            }

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                var ctor = test.TestedType.GetConstructor(Type.EmptyTypes);
                testedObject = ctor.Invoke(null);
                invokeParameters = new Object[1] { testedObject };
            }

            foreach (var testPreparingMethod in test.TestPreparingMethods)
            {
                testPreparingMethod.Invoke(container, invokeParameters);
            }

            return testedObject;
        }
Esempio n. 13
0
        public static void InvokeMilestonePreparing(TestAgent test, Object container, ref Object testedObject, Int32 milestoneIndex)
        {
            if (test.MilestonePreparingMethods == null)
            {
                if (test.TestedType != null && testedObject == null)
                {
                    var ctor = test.TestedType.GetConstructor(Type.EmptyTypes);
                    testedObject = ctor.Invoke(null);
                }
                return;
            }

            Object[] invokeParameters = null;
            if (test.TestedType != null)
            {
                if (testedObject == null)
                {
                    var ctor = test.TestedType.GetConstructor(Type.EmptyTypes);
                    testedObject = ctor.Invoke(null);
                }
                invokeParameters = new Object[2] { testedObject, milestoneIndex };
            }
            else
            {
                invokeParameters = new Object[1] { milestoneIndex };
            }

            foreach (var milestonePreparingMethod in test.MilestonePreparingMethods)
            {
                milestonePreparingMethod.Invoke(container, invokeParameters);
            }
        }
Esempio n. 14
0
        private static PassResult DoJITTest(TestAgent agent, TestUnit testUnit, Object container, Object testedObject, Int32 iterationIndex)
        {
            var timeMonitor = new Stopwatch();
            var memoryMonitor = new MemoryMonitor();

            Object[] invokeParameters = null;
            if (agent.TestedType != null)
            {
                invokeParameters = new Object[1] { testedObject };
            }

            //todo: Create delegates to call instead of Invoking
            //Test test = (Test)Delegate.CreateDelegate(typeof(Test), container, testUnit.TestMethod);
            Object result = null;

            Assembly.Load("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            memoryMonitor.Prepare();
            memoryMonitor.Start();
            timeMonitor.Start();
            result = testUnit.TestMethod.Invoke(container, invokeParameters);
            //test();
            timeMonitor.Stop();
            memoryMonitor.Stop();

            bool isValid = true;
            if (testUnit.ValidatorMethod != null)
            {
                invokeParameters = new Object[1] { result };
                isValid = (bool)testUnit.ValidatorMethod.Invoke(container, invokeParameters);
            }

            var runResult = new PassResult(timeMonitor.Elapsed, memoryMonitor.Usage, agent.Metrics, isValid);
            return runResult;
        }