Esempio n. 1
0
        private bool RunTestExecutionLoop(ExecutableTestList processes, Type[] types, TestLaunchParam param)
        {
            bool bCompletedNormally = false;

            try
            {
                // Go through the list of tests...
                //for (int i = 0; i < processes.Count; i++)
                bool breakFlag = true;
                do
                {
                    breakFlag = true;
                    processes.StartExecution();
                    IEnumerator <TestInfo> curr = processes.GetUpdatableEnumerator();
                    var processNextFlag         = curr.MoveNext();
                    for (; processNextFlag;)
                    {
                        //TestInfo testInfo = processes[i];
                        var testInfo = curr.Current;
                        _currentTestInfo = testInfo;

                        /// "Stop" requested or "Halt" has not been handled at test level.
                        if (_stop)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE STOPPED");
                            bCompletedNormally = false;
                            break;
                        }

                        try
                        {
                            // Check if a pause should be done.
                            // If a pause should be done at this point and "Halt" is clicked
                            // during the pause = don't execute next test.
                            bool dispatcherLevelPause;
                            lock (_pauseSync)
                            {
                                dispatcherLevelPause = _dispatcherLevelPause;
                            }

                            if (dispatcherLevelPause)
                            {
                                // Sleep() returns TRUE if pause has been ended by clicking "Resume" and FALSE if "Halt"
                                // button has been clicked.
                                bool bContinue = Sleep();
                                if (!bContinue)
                                {
                                    System.Diagnostics.Debug.WriteLine("TEST SEQUENCE PAUSED");
                                    // Tests execution halted
                                    bCompletedNormally = false;
                                    break;
                                }
                            }

                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE before TestStarted");
                            // Report that a test is started
                            if (TestStarted != null)
                            {
                                TestStarted(testInfo);
                            }
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE TestStarted");

                            _currentTest = null;
                            BaseTest test = InitCurrentTest(testInfo, types, args);
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE InitCurrentTest");

                            // check if tests execution should be stopped
                            bool halt;
                            lock (_pauseSync)
                            {
                                halt = _delayedHalt || _stop;
                            }

                            if (halt)
                            {
                                bCompletedNormally = false;
                                System.Diagnostics.Debug.WriteLine("Handle HALT after test started");
                                break;
                            }

                            lock (_pauseSync)
                            {
                                dispatcherLevelPause = _dispatcherLevelPause;
                            }

                            if (dispatcherLevelPause)
                            {
                                // WAIT
                                bool bContinue = Sleep();
                                if (!bContinue)
                                {
                                    System.Diagnostics.Debug.WriteLine("TEST SEQUENCE PAUSED2");
                                    bCompletedNormally = false;
                                    break;
                                }
                            }

                            try
                            {
                                // start current test.
                                // (really it means that _currentTest.EntryPoint method is executed synchronously)
                                System.Diagnostics.Debug.WriteLine("TEST SEQUENCE before Start");
                                if (_currentTest == null)
                                {
                                    System.Diagnostics.Debug.WriteLine("TEST SEQUENCE Invalid Start entry point");
                                }
                                else
                                {
                                    _currentTest.Start();
                                }
                                System.Diagnostics.Debug.WriteLine("TEST SEQUENCE after Start");

                                //
                                // Feature definition process ended
                                //
                                if (testInfo.ProcessType == ProcessType.FeatureDefinition)
                                {
                                    if (test.Halted)
                                    {
                                        System.Diagnostics.Debug.WriteLine("TEST SEQUENCE HALTED");
                                        break;
                                    }
                                    else
                                    {
                                        ProfilesSupportTest pst = new ProfilesSupportTest();
                                        pst.ProfileDefinitionCompleted += pst_ProfileDefinitionCompleted;

                                        var parameters = new Dictionary <string, object>();
                                        parameters.Add("MaxPullPoints", MaxPullPoints);

                                        pst.CheckProfiles(_parameters.Profiles, _features, _scopes, parameters);

                                        //
                                        // if we run only one/several defined test (not Feature definition process, not 0 tests to run),
                                        // we'll have to display profiles support
                                        // And if profiles support have been displayed already (features defined), there is no need
                                        // to notify TestController at all
                                        //

                                        bool defineTests = (processes.Count == 1 &&
                                                            processes.Contains(FeaturesDefinitionProcess.This)) &&
                                                           _parameters.FeatureDefinition != FeatureDefinitionMode.Define;
                                        if (!_featuresDefined || defineTests)
                                        {
                                            InitConformanceTesting(param);

                                            _featuresDefined = true;

                                            List <TestInfo> tests =
                                                ConformanceLogicHandler.GetTestsByFeatures(_parameters.AllTestCases,
                                                                                           param.Features,
                                                                                           _parameters.Conformance);
                                            if (defineTests)
                                            {
                                                // define test cases via features detected
                                                processes.AddRange(tests);
                                            }
                                            ReportInitializationCompleted(tests, defineTests);
                                        }
                                    }
                                }
                            }
                            finally
                            {
                                // pause between tests. If "Halt" is clicked during the pause - exit tests execution.
                                //if (current != processes.Count)
                                if (processNextFlag = curr.MoveNext())
                                {
                                    _currentTest = null;

                                    int hndl = WaitHandle.WaitAny(new WaitHandle[] { _haltEvent },
                                                                  _parameters.TimeBetweenTests);

                                    _haltEvent.Reset();
                                    lock (_pauseSync)
                                    {
                                        halt = _delayedHalt || _stop;
                                    }
                                    if (hndl == 0 || halt)
                                    {
                                        System.Diagnostics.Debug.WriteLine("TEST SEQUENCE HALTED2");
                                        bCompletedNormally = false;
                                        processNextFlag    = false;
                                    }
                                }
                                else
                                {
                                    if (_parameters.RepeatTests)
                                    {
                                        breakFlag = false;
                                    }
                                    bCompletedNormally = true;
                                }
                            }
                        }
                        catch (System.Reflection.TargetException exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE TargetException1");
                            _currentTest.ExitTest(exc);
                            ReportException(exc);
                            if (testInfo.ProcessType == ProcessType.FeatureDefinition)
                            {
                                System.Diagnostics.Debug.WriteLine("TEST SEQUENCE TargetException2");
                                break;
                            }
                        }
                        catch (System.ArgumentException exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE ArgumentException");
                            _currentTest.ExitTest(exc);
                            ReportException(exc);
                        }
                        catch (System.Reflection.TargetParameterCountException exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE TargetParameterCountException");
                            _currentTest.ExitTest(exc);
                            ReportException(exc);
                        }
                        catch (System.MethodAccessException exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE MethodAccessException");
                            _currentTest.ExitTest(exc);
                            ReportException(exc);
                        }
                        catch (System.InvalidOperationException exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE InvalidOperationException");
                            _currentTest.ExitTest(exc);
                            ReportException(exc);
                        }
                        catch (Exception exc)
                        {
                            System.Diagnostics.Debug.WriteLine("TEST SEQUENCE Exception");
                            ReportException(exc);
                        }
                    }
                    processes.EndExecution();
                } while (_parameters.RepeatTests && !breakFlag);
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine("TEST SEQUENCE wrap Exception");
            }
            finally
            {
                //If halt command was received and handled before start of waiting on _haltEvent.
                _haltEvent.Reset();
            }

            return(bCompletedNormally);
        }