Esempio n. 1
0
        public TestsTree()
        {
            InitializeComponent();

            _selectedTests  = new ExecutableTestList();
            _selectedGroups = new List <string>();
            _testNodes      = new Dictionary <TestInfo, TreeNode>();
            _colouredNodes  = new List <TreeNode>();

            _groupNodes = new List <TreeNode>();

            _completedTestFont = new Font(tvTestCases.Font.FontFamily, tvTestCases.Font.Size, FontStyle.Bold);
        }
Esempio n. 2
0
 public TestSuiteParameters()
 {
     _testCases    = new ExecutableTestList();
     _allTestCases = new ExecutableTestList();
     _profiles     = new List <IProfileDefinition>();
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Method for running tests in the background.
        /// </summary>
        void RunTests()
        {
            TrafficListener.ResetStatistics();
            System.Diagnostics.Debug.WriteLine("RunTests started");
            //_haltEvent.Reset();
            // types description for test class constructor
            Type[] types = new Type[] { typeof(TestLaunchParam) };

            // parameters as defined in TestEngine.
            TestLaunchParam param = new TestLaunchParam();

            param.ServiceAddress      = _parameters.Address;
            param.CameraIp            = _parameters.CameraIP;
            param.CameraUUID          = _parameters.CameraUUID;
            param.NIC                 = _parameters.NetworkInterfaceController;
            param.MessageTimeout      = _parameters.MessageTimeout;
            param.RebootTimeout       = _parameters.RebootTimeout;
            param.UserName            = _parameters.UserName;
            param.Password            = _parameters.Password;
            param.UseUTCTimestamp     = _parameters.UseUTCTimestamp;
            param.Operator            = _parameters.Operator;
            param.VideoForm           = _parameters.VideoForm;
            param.EnvironmentSettings = _parameters.EnvironmentSettings;
            param.PTZNodeToken        = _parameters.PTZNodeToken;
            param.UseEmbeddedPassword = _parameters.UseEmbeddedPassword;
            param.Password1           = _parameters.Password1;
            param.Password2           = _parameters.Password2;
            param.OperationDelay      = _parameters.OperationDelay;
            param.RecoveryDelay       = _parameters.RecoveryDelay;
            param.SecureMethod        = _parameters.SecureMethod;
            param.SubscriptionTimeout = _parameters.SubscriptionTimeout;
            param.EventTopic          = _parameters.EventTopic;
            param.TopicNamespaces     = _parameters.TopicNamespaces;

            param.RelayOutputDelayTimeMonostable = _parameters.RelayOutputDelayTimeMonostable;
            param.RecordingToken = _parameters.RecordingToken;
            param.SearchTimeout  = _parameters.SearchTimeout;
            param.MetadataFilter = _parameters.MetadataFilter;
            param.RetentionTime  = _parameters.RetentionTime;

            param.AdvancedPrameters = _parameters.AdvancedParameters;

            // parameters for constructor.
            args = new object[] { param };

            param.DeclaredScopes.AddRange(_scopes);

            ExecutableTestList processes = _parameters.TestCases;
            bool featuresDefined         = _featuresDefined;

            switch (_parameters.FeatureDefinition)
            {
            case FeatureDefinitionMode.Default:
                param.Features.AddRange(_features);
                break;

            case FeatureDefinitionMode.AssumeSupported:
                featuresDefined             = true;
                param.FeatureDefinitionMode = Base.Definitions.FeatureDefinitionMode.AllSupported;
                break;

            case FeatureDefinitionMode.AssumeNotSupported:
                param.FeatureDefinitionMode = Base.Definitions.FeatureDefinitionMode.AllNotSupported;
                featuresDefined             = true;
                break;
            }

            if (!featuresDefined)
            {
                if (!processes.Contains(FeaturesDefinitionProcess.This))
                {
                    processes.Add(FeaturesDefinitionProcess.This);
                }

                System.Diagnostics.Debug.WriteLine("SECURITY: NONE");
                param.Security = Security.None;
            }
            else
            {
                if (processes.Contains(FeaturesDefinitionProcess.This))
                {
                    processes.Remove(FeaturesDefinitionProcess.This);
                }

                // if "Assume all supported", Digest also is assumed to be supported !!!
                if (_features.Contains(Feature.Digest) || _parameters.FeatureDefinition == Tests.Engine.FeatureDefinitionMode.AssumeSupported)
                {
                    System.Diagnostics.Debug.WriteLine("SECURITY: DIGEST");
                    param.Security = Security.Digest;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("SECURITY: WS-USERNAME");
                    param.Security = Security.WS;
                }
                //
                // we HAVE features => Controller is notified already about profile.
                // so, if we just run some tests - there is no reason to colour profiles tree
                // or select tests in test tree.
                //
                bool defineTests = (processes.Count == 1 && processes.Contains(FeaturesDefinitionProcess.This)) && _parameters.FeatureDefinition != FeatureDefinitionMode.Define;
                if (defineTests)
                {
                    List <Feature> features = new List <Feature>();
                    features.AddRange(_features);
                    features.AddRange(_undefinedFeatures);

                    // define test cases via features detected
                    List <TestInfo> tests = ConformanceLogicHandler.GetTestsByFeatures(_parameters.AllTestCases, features, _parameters.Conformance);
                    // no tests in list, not a feature definition process - add tests to list
                    _parameters.TestCases.AddRange(tests);
                    // notify anyway (?)
                    // - really, notify if not notified previously...

                    ReportInitializationCompleted(tests, defineTests);
                }
            }
//            if (_parameters.TestCases.Count > 0)
//            {
//                // if this is a request to run tests, not only feature definition
//                if (!(_parameters.TestCases.Count == 1 && _parameters.TestCases.First().ProcessType == ProcessType.FeatureDefinition ))
//                {
//                    processes.AddRange(_parameters.TestCases);
//                }
//            }

            var bCompletedNormally = RunTestExecutionLoop(processes, types, param);

            // all tests are performed.
            _state = TestState.Idle;

            if (TestSuiteCompleted != null && !_shutDownInProgress)
            {
                TestSuiteCompleted(_parameters, bCompletedNormally);
            }
            System.Diagnostics.Debug.WriteLine("RunTests stopped");

/*
 *          int Max;
 *          int Median;
 *          int Mean;
 *          TrafficListener.GetAggregated(out Max, out Median, out Mean);
 *          System.Diagnostics.Debug.WriteLine(string.Format("RunTests stopped with Max={0}, Median={1} and Mean={2}", Max, Median, Mean));
 */
        }