/// <summary> /// Method for running tests in the background. /// </summary> void RunTests() { // types description for test class constructor Type[] types = new Type[] { typeof(TestLaunchParam) }; bool bCompletedNormally = false; // 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.Features.AddRange(_parameters.Features); 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.AdvancedPrameters = _parameters.AdvancedPrameters; // parameters for constructor. object[] args = new object[] { param }; int current = 0; List <TestInfo> processes = new List <TestInfo>(); if (!_featuresDefined) { processes.Add(FeaturesDefinitionProcess.This); System.Diagnostics.Debug.WriteLine("SECURITY: NONE"); param.Security = Security.None; } else { if (_features.Contains(Feature.Digest)) { 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 = _parameters.TestCases.Count == 0 && !_parameters.FeatureDefinition; 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 (!(_parameters.TestCases.Count == 1 && _parameters.TestCases[0].ProcessType == ProcessType.FeatureDefinition)) { processes.AddRange(_parameters.TestCases); } } // Go through the list of tests... for (int i = 0; i < processes.Count; i++) { TestInfo testInfo = processes[i]; _currentTestInfo = testInfo; /// "Stop" requested or "Halt" has not been handled at test level. if (_stop) { 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) { // Tests execution halted bCompletedNormally = false; break; } } // Report that a test is started if (TestStarted != null) { TestStarted(testInfo); } _currentTest = null; BaseTest test = InitCurrentTest(testInfo, types, args); // check if tests execution should be stopped bool halt; lock (_pauseSync) { halt = _delayedHalt; } if (halt) { bCompletedNormally = false; break; } lock (_pauseSync) { dispatcherLevelPause = _dispatcherLevelPause; } if (dispatcherLevelPause) { // WAIT bool bContinue = Sleep(); if (!bContinue) { bCompletedNormally = false; break; } } // start current test. // (really it means that _currentTest.EntryPoint method is executed synchronously) _currentTest.Start(); current++; // // Feature definition process ended // if (testInfo.ProcessType == ProcessType.FeatureDefinition) { if (test.Halted) { break; } else { ProfilesSupportTest pst = new ProfilesSupportTest(); pst.ProfileDefinitionCompleted += new ProfilesSupportTest.ProfileDefinitionCompletedHandler(pst_ProfileDefinitionCompleted); pst.CheckProfiles(_parameters.Profiles, _features, _scopes); // // 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 = _parameters.TestCases.Count == 0 && !_parameters.FeatureDefinition; 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); } } } // pause between tests. If "Halt" is clicked during the pause - exit tests execution. if (current != processes.Count) { _currentTest = null; int hndl = WaitHandle.WaitAny(new WaitHandle[] { _haltEvent }, _parameters.TimeBetweenTests); _haltEvent.Reset(); lock (_pauseSync) { halt = _delayedHalt; } if (hndl == 0 || halt) { bCompletedNormally = false; break; } } else { bCompletedNormally = true; } } catch (System.Reflection.TargetException exc) { _currentTest.ExitTest(exc); ReportException(exc); if (testInfo.ProcessType == ProcessType.FeatureDefinition) { break; } } catch (System.ArgumentException exc) { _currentTest.ExitTest(exc); ReportException(exc); } catch (System.Reflection.TargetParameterCountException exc) { _currentTest.ExitTest(exc); ReportException(exc); } catch (System.MethodAccessException exc) { _currentTest.ExitTest(exc); ReportException(exc); } catch (System.InvalidOperationException exc) { _currentTest.ExitTest(exc); ReportException(exc); } catch (Exception exc) { ReportException(exc); } } // all tests are performed. _state = TestState.Idle; if (TestSuiteCompleted != null && !_shutDownInProgress) { TestSuiteCompleted(_parameters, bCompletedNormally); } }
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); }