internal HarnessExecutionResult Run(string[] args) { TimedTest test; HarnessExecutionResult hResult = HarnessExecutionResult.Unavailable; bool runTestsIndividually = false; m_log = new XmlLog(); // Prelim: Set the env, parse the arguments, set the result paths and set the test list. SetEnvironment(); if (args != null && args.Length > 0) { if (!ParseArguments(args, ref runTestsIndividually)) { return HarnessExecutionResult.InvalidArguments; } } SetResultPaths(); BaseTest[] testList = BuildTestList(runTestsIndividually); // Create a new harness object and set the properties. Harness harness = new Harness(IsDevEnvironment); if (m_transport != null) { harness.Transport = m_transport; } else { // harness constructor assigns default transport m_transport = harness.Transport; } if (m_device != null) { harness.Device = m_device; } else { // harness constructor assigns default device m_device = harness.Device; } // Execute each of the solution files using Harness. for (int i = 0; i < testList.Length; i++) { if (testList[i] == null) { continue; } if (this.Transport.ToLower().Contains("tcpip") && (testList[i].Name.ToLower().Contains("netinfotests.sln"))) { continue; } hResult = HarnessExecutionResult.Unavailable; int attempts = 0; while ((hResult != HarnessExecutionResult.Success && hResult != HarnessExecutionResult.Abort) && attempts++ < 3) { test = new TimedTest(testList[i], harness, m_log); // Kill any emulators running from previous runs. TerminateRunningEmulators(test, testList[i]); try { hResult = test.Execute(); if (hResult == HarnessExecutionResult.Unavailable) { Utils.WriteToEventLog("Harness returned an unavailable result after running the test: " + testList[i].Name + ". No of tries so far = " + attempts); string deviceStatus = DeviceStatus(hResult); Utils.WriteToEventLog("Device status after unavailable from harness: " + deviceStatus); } // Test did not execute because the device was dead. // If so, reset power to the device and re-run test. if (hResult == HarnessExecutionResult.NoConnection) { Utils.WriteToEventLog("Harness returned an NoConnection result after running the test: " + testList[i].Name + ". No of tries so far = " + attempts); string deviceStatus = DeviceStatus(hResult); Utils.WriteToEventLog("Device status after noconnection from harness: " + deviceStatus); } // Test did not succeed running in three attempts. if (hResult == HarnessExecutionResult.TimeOut) { Utils.WriteToEventLog("Test: " + test.Test.Name + " failed."); harness.MFTestResult = Harness.Result.Fail; GetTestResultDetails(harness, testList[i]); Console.WriteLine("Test Result: " + harness.MFTestResult); test.SendMail(); break; } // Test did not succeed running in three attempts. if (hResult != HarnessExecutionResult.Success && attempts >= 3) { Utils.WriteToEventLog("Test: " + test.Test.Name + " failed."); harness.MFTestResult = Harness.Result.Fail; GetTestResultDetails(harness, testList[i]); Console.WriteLine("Test Result: " + harness.MFTestResult); } // Test succeeded with 3 attempts or an abort was sent by harness. if ((hResult == HarnessExecutionResult.Success && attempts < 4) || (hResult == HarnessExecutionResult.Abort)) { GetTestResultDetails(harness, testList[i]); if (!string.IsNullOrEmpty(m_device)) { string deviceStatus = DeviceStatus(hResult); Utils.WriteToEventLog("Device status after running " + testList[i].Name + ": " + deviceStatus); if (!IsProfilerRun) { m_log.AddDeviceStatusToLog("Device ping result after running " + testList[i].Name + ": " + deviceStatus); } if (string.Equals(deviceStatus.ToLower(), "noconnection")) { throw new ApplicationException("Device did not reboot correctly after " + "running the test: " + testList[i].Name); } } if (!IsProfilerRun) { Console.WriteLine("Test Result: " + harness.MFTestResult); } } } catch (Exception ex) { if (ex is FileNotFoundException) { if (!IsProfilerRun) { Console.WriteLine(ex.ToString()); try { m_log.AddCommentToLog(ex.ToString()); } catch { } Utils.WriteToEventLog( string.Format("Exception in TestSystem.cs: {0}", ex.ToString())); hResult = HarnessExecutionResult.Abort; } } } // Wait for a few seconds before starting the next test when running on devices. if (!string.Equals(m_transport.ToLower(), "emulator")) { System.Threading.Thread.Sleep(5000); } } } // Update test results and logs location. m_didAllTestsPass = ((tests.FailCount > 0) || (tests.PassCount == 0)) ? false : true; UpdateLogFolder(); return hResult; }
private void TerminateRunningEmulators(TimedTest test, BaseTest bTest) { if (string.Equals(m_transport.ToLower(), "emulator")) { try { test.KillEmulator(); } catch (Exception ex) { Utils.WriteToEventLog("An exception was thrown when killing the emulator " + "before executing " + bTest.Name + " : " + ex.ToString()); } } string[] onboardFlashes = new string[] { Path.Combine(Path.GetDirectoryName(bTest.Location) , "OnBoardFlash.dat"), Path.Combine(Directory.GetCurrentDirectory() , "OnBoardFlash.dat") }; foreach (string onboardFlash in onboardFlashes) { if (File.Exists(onboardFlash)) { try { File.Delete(onboardFlash); } catch { } } } }