Exemple #1
0
    def _TriggerSetUp(self):
        """Set up the triggering of a test run."""
        logging.info('Triggering test run.')

        if self._env.device_type == 'Android':
            default_runner_type = 'android_robot'
        elif self._env.device_type == 'iOS':
            default_runner_type = 'ios_robot'
        else:
            raise remote_device_helper.RemoteDeviceError(
                'Unknown device type: %s' % self._env.device_type)

        self._app_id = self._UploadAppToDevice(
            self._test_instance.app_under_test)
        if not self._env.runner_type:
            runner_type = default_runner_type
            logging.info('Using default runner type: %s', default_runner_type)
        else:
            runner_type = self._env.runner_type

        self._test_id = self._UploadTestToDevice('android_robot',
                                                 None,
                                                 app_id=self._app_id)
        config_body = {'duration': self._test_instance.minutes}
        self._SetTestConfig(runner_type, config_body)
 def _DetectPlatformErrors(self, results):
     if not self._results['results']['pass']:
         if any(
                 _SHORT_MSG_RE.search(l)
                 for l in self._results['results']['output'].splitlines()):
             self._LogLogcat()
             for line in self._results['results']['output'].splitlines():
                 if _LONG_MSG_RE.search(line):
                     results.AddResult(
                         base_test_result.BaseTestResult(
                             line.split('=')[1],
                             base_test_result.ResultType.CRASH))
                     break
             else:
                 results.AddResult(
                     base_test_result.BaseTestResult(
                         'Unknown platform error detected.',
                         base_test_result.ResultType.UNKNOWN))
         elif self._DidDeviceGoOffline():
             self._LogLogcat()
             self._LogAdbTraceLog()
             raise remote_device_helper.RemoteDeviceError(
                 'Remote service unable to reach device.',
                 is_infra_error=True)
         else:
             results.AddResult(
                 base_test_result.BaseTestResult(
                     'Remote Service detected error.',
                     base_test_result.ResultType.UNKNOWN))
    def _ParseTestResults(self):
        logging.info('Parsing results from stdout.')
        results = base_test_result.TestRunResults()
        output = self._results['results']['output'].splitlines()
        output = (l[len(self._INSTRUMENTATION_STREAM_LEADER):] for l in output
                  if l.startswith(self._INSTRUMENTATION_STREAM_LEADER))
        results_list = self._test_instance.ParseGTestOutput(output)
        results.AddResults(results_list)
        if self._env.only_output_failures:
            logging.info('See logcat for more results information.')
        if not self._results['results']['pass']:
            if any(
                    _NATIVE_CRASH_RE.search(l)
                    for l in self._results['results']['output'].splitlines()):
                logging.critical('Native crash detected. Printing Logcat.')
                self._LogLogcat()
                results.AddResult(
                    base_test_result.BaseTestResult(
                        'Remote Service detected native crash.',
                        base_test_result.ResultType.CRASH))
            elif self._DidDeviceGoOffline():
                self._LogLogcat()
                self._LogAdbTraceLog()
                raise remote_device_helper.RemoteDeviceError(
                    'Remote service unable to reach device.',
                    is_infra_error=True)
            else:
                results.AddResult(
                    base_test_result.BaseTestResult(
                        'Remote Service detected error.',
                        base_test_result.ResultType.UNKNOWN))

        return results
Exemple #4
0
 def _DetectPlatformErrors(self, results):
     if not self._results['results']['pass']:
         crash_msg = None
         for line in self._results['results']['output'].splitlines():
             m = _LONG_MSG_RE.search(line)
             if m:
                 crash_msg = m.group(1)
                 break
             m = _SHORT_MSG_RE.search(line)
             if m:
                 crash_msg = m.group(1)
         if crash_msg:
             self._LogLogcat()
             results.AddResult(
                 base_test_result.BaseTestResult(
                     crash_msg, base_test_result.ResultType.CRASH))
         elif self._DidDeviceGoOffline():
             self._LogLogcat()
             self._LogAdbTraceLog()
             raise remote_device_helper.RemoteDeviceError(
                 'Remote service unable to reach device.',
                 is_infra_error=True)
         else:
             # Remote service is reporting a failure, but no failure in results obj.
             if results.DidRunPass():
                 results.AddResult(
                     base_test_result.BaseTestResult(
                         'Remote service detected error.',
                         base_test_result.ResultType.UNKNOWN))
    def RunTests(self):
        """Run the test."""
        if self._env.trigger:
            with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
                                                    logging.WARNING):
                test_start_res = appurify_sanitized.api.tests_run(
                    self._env.token, self._env.device_type_id, self._app_id,
                    self._test_id)
            remote_device_helper.TestHttpResponse(test_start_res,
                                                  'Unable to run test.')
            self._test_run_id = test_start_res.json(
            )['response']['test_run_id']
            logging.info('Test run id: %s' % self._test_run_id)

        if self._env.collect:
            current_status = ''
            timeout_counter = 0
            heartbeat_counter = 0
            while self._GetTestStatus(self._test_run_id) != self.COMPLETE:
                if self._results['detailed_status'] != current_status:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    current_status = self._results['detailed_status']
                    timeout_counter = 0
                    heartbeat_counter = 0
                if heartbeat_counter > self.HEARTBEAT_INTERVAL:
                    logging.info('Test status: %s',
                                 self._results['detailed_status'])
                    heartbeat_counter = 0

                timeout = self._env.timeouts.get(current_status,
                                                 self._env.timeouts['unknown'])
                if timeout_counter > timeout:
                    raise remote_device_helper.RemoteDeviceError(
                        'Timeout while in %s state for %s seconds' %
                        (current_status, timeout),
                        is_infra_error=True)
                time.sleep(self.WAIT_TIME)
                timeout_counter += self.WAIT_TIME
                heartbeat_counter += self.WAIT_TIME
            self._DownloadTestResults(self._env.results_path)

            if self._results['results']['exception']:
                raise remote_device_helper.RemoteDeviceError(
                    self._results['results']['exception'], is_infra_error=True)

            return self._ParseTestResults()
  def _GetTestByName(self, test_name):
    """Gets test_id for specific test.

    Args:
      test_name: Test to find the ID of.
    """
    test_list_res = appurify.api.tests_list(self._env.token)
    remote_device_helper.TestHttpResponse(test_list_res,
                                          'Unable to get tests list.')
    for test in test_list_res.json()['response']:
      if test['test_type'] == test_name:
        return test['test_id']
    raise remote_device_helper.RemoteDeviceError(
        'No test found with name %s' % (test_name))
Exemple #7
0
 def _NoDeviceFound(self):
   self._PrintAvailableDevices(self._GetDeviceList())
   raise remote_device_helper.RemoteDeviceError(
       'No device found.', is_infra_error=True)
Exemple #8
0
 def _NoDeviceFound(self, device_list):
     self._PrintAvailableDevices(device_list)
     raise remote_device_helper.RemoteDeviceError('No device found.')