def RunTest(self, test):
     raw_result = None
     start_date_ms = None
     results = base_test_result.TestRunResults()
     timeout = (self._GetIndividualTestTimeoutSecs(test) *
                self._GetIndividualTestTimeoutScale(test) *
                self.tool.GetTimeoutScale())
     try:
         self.TestSetup(test)
         start_date_ms = int(time.time()) * 1000
         raw_result = self._RunTest(test, timeout)
         duration_ms = int(time.time()) * 1000 - start_date_ms
         status_code = raw_result.GetStatusCode()
         if status_code:
             if self.options.screenshot_failures:
                 self._TakeScreenshot(test)
             log = raw_result.GetFailureReason()
             if not log:
                 log = 'No information.'
             result_type = base_test_result.ResultType.FAIL
             package = self.adb.DismissCrashDialogIfNeeded()
             # Assume test package convention of ".test" suffix
             if package and package in self.test_pkg.GetPackageName():
                 result_type = base_test_result.ResultType.CRASH
             result = test_result.InstrumentationTestResult(test,
                                                            result_type,
                                                            start_date_ms,
                                                            duration_ms,
                                                            log=log)
         else:
             result = test_result.InstrumentationTestResult(
                 test, base_test_result.ResultType.PASS, start_date_ms,
                 duration_ms)
         results.AddResult(result)
     # Catch exceptions thrown by StartInstrumentation().
     # See ../../third_party/android/testrunner/adb_interface.py
     except (android_commands.errors.WaitForResponseTimedOutError,
             android_commands.errors.DeviceUnresponsiveError,
             android_commands.errors.InstrumentationError), e:
         if start_date_ms:
             duration_ms = int(time.time()) * 1000 - start_date_ms
         else:
             start_date_ms = int(time.time()) * 1000
             duration_ms = 0
         message = str(e)
         if not message:
             message = 'No information.'
         results.AddResult(
             test_result.InstrumentationTestResult(
                 test,
                 base_test_result.ResultType.CRASH,
                 start_date_ms,
                 duration_ms,
                 log=message))
         raw_result = None
Exemple #2
0
 def RunTest(self, test):
     raw_result = None
     start_date_ms = None
     results = base_test_result.TestRunResults()
     timeout = (self._GetIndividualTestTimeoutSecs(test) *
                self._GetIndividualTestTimeoutScale(test) *
                self.tool.GetTimeoutScale())
     try:
         self.TestSetup(test)
         start_date_ms = int(time.time()) * 1000
         raw_result = self._RunTest(test, timeout)
         duration_ms = int(time.time()) * 1000 - start_date_ms
         status_code = raw_result.GetStatusCode()
         if status_code:
             log = raw_result.GetFailureReason()
             if not log:
                 log = 'No information.'
             if (self.options.screenshot_failures
                     or log.find('INJECT_EVENTS perm') >= 0):
                 self._TakeScreenshot(test)
             result = test_result.InstrumentationTestResult(
                 test,
                 base_test_result.ResultType.FAIL,
                 start_date_ms,
                 duration_ms,
                 log=log)
         else:
             result = test_result.InstrumentationTestResult(
                 test, base_test_result.ResultType.PASS, start_date_ms,
                 duration_ms)
         results.AddResult(result)
     # Catch exceptions thrown by StartInstrumentation().
     # See ../../third_party/android/testrunner/adb_interface.py
     except (android_commands.errors.WaitForResponseTimedOutError,
             android_commands.errors.DeviceUnresponsiveError,
             android_commands.errors.InstrumentationError), e:
         if start_date_ms:
             duration_ms = int(time.time()) * 1000 - start_date_ms
         else:
             start_date_ms = int(time.time()) * 1000
             duration_ms = 0
         message = str(e)
         if not message:
             message = 'No information.'
         results.AddResult(
             test_result.InstrumentationTestResult(
                 test,
                 base_test_result.ResultType.CRASH,
                 start_date_ms,
                 duration_ms,
                 log=message))
         raw_result = None