Exemple #1
0
        private HarnessExecutionResult HarnessResult(Exception ex)
        {
            // Dispose engine on all exceptions so that the device is not locked for next automation.
            Close();

            Console.WriteLine("\tERROR: " + ex.ToString());
            m_log.AddCommentToLog("A Exception was thrown when running the test: " + ex.ToString());

            if (ex is IOException &&
                ex.Message.ToLower().Contains("request failed"))
            {
                // The request got aborted on the device somehow. In this case, we will rerun the test.
                // Send an unavailable result.
                return(HarnessExecutionResult.Unavailable);
            }

            if ((ex is ApplicationException &&
                 ex.Message.Contains("Could not find the specified device for the harness to connect to.")) ||
                (ex.Message.ToLower().Contains("connection failed")))
            {
                return(HarnessExecutionResult.NoConnection);
            }

            return(HarnessExecutionResult.Abort);
        }
Exemple #2
0
        private void KillProcesses(bool isComExceptionThrown)
        {
            bool emCrash = KillEmulator();

            foreach (Process p in Process.GetProcessesByName("DW20"))
            {
                p.Kill();
                if (emCrash)
                {
                    m_didEmulatorCrash     = true;
                    m_test.EmulatorCrashed = true;
                }
            }

            if (m_didTestTimeOut || isComExceptionThrown)
            {
                try
                {
                    m_harness.SaveLogFile(m_test.Location);
                }
                catch (Exception ex)
                {
                    try
                    {
                        m_log.AddCommentToLog("An exception was thrown trying to save the log file: " + ex.ToString());
                    }
                    catch
                    {
                    }
                    Utils.WriteToEventLog(string.Format("An exception was thrown in TimedTest: {0}", ex.ToString()));
                }
            }
        }
            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;
            }