Пример #1
0
 def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
                check_error=True, cpu_affinity=None):
   status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
       cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
       timeout_retry.CurrentTimeoutThread().GetRemainingTime())
   if status != 0:
     raise device_errors.AdbCommandFailedError(
         args, output, status, device_serial)
   # This catches some errors, including when the device drops offline;
   # unfortunately adb is very inconsistent with error reporting so many
   # command failures present differently.
   if check_error and output.startswith('error:'):
     raise device_errors.AdbCommandFailedError(args, output)
   return output
Пример #2
0
def _RunSplitSelectCmd(args, timeout=None, retries=None):
    """Runs a split-select command.

  Args:
    args: A list of arguments for split-select.
    timeout: Timeout in seconds.
    retries: Number of retries.

  Returns:
    The output of the command.
  """
    cmd = [_SPLIT_SELECT_PATH] + args
    status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
        cmd,
        timeout_retry.CurrentTimeoutThread().GetRemainingTime())
    if status != 0:
        raise Exception('Failed running command %s' % str(cmd))
    return output
Пример #3
0
 def _RunAdbCmd(cls,
                arg_list,
                timeout=None,
                retries=None,
                check_error=True):
     cmd = [constants.GetAdbPath()] + arg_list
     exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
         cmd,
         timeout_retry.CurrentTimeoutThread().GetRemainingTime())
     if exit_code != 0:
         raise device_errors.AdbCommandFailedError(
             cmd, 'returned non-zero exit code %d and output %r' %
             (exit_code, output))
     # This catches some errors, including when the device drops offline;
     # unfortunately adb is very inconsistent with error reporting so many
     # command failures present differently.
     if check_error and output[:len('error:')] == 'error:':
         raise device_errors.AdbCommandFailedError(arg_list, output)
     return output
Пример #4
0
 def _RunAdbCmd(cls,
                args,
                timeout=None,
                retries=None,
                device_serial=None,
                check_error=True):
     cmd = [constants.GetAdbPath()]
     if device_serial is not None:
         cmd.extend(['-s', device_serial])
     cmd.extend(args)
     status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
         cmd,
         timeout_retry.CurrentTimeoutThread().GetRemainingTime())
     if status != 0:
         raise device_errors.AdbCommandFailedError(args, output, status,
                                                   device_serial)
     # This catches some errors, including when the device drops offline;
     # unfortunately adb is very inconsistent with error reporting so many
     # command failures present differently.
     if check_error and output.startswith('error:'):
         raise device_errors.AdbCommandFailedError(args, output)
     return output
Пример #5
0
    def _LaunchPerfTest(self, test_name):
        """Runs a perf test.

    Args:
      test_name: the name of the test to be executed.

    Returns:
      A tuple containing (Output, base_test_result.ResultType)
    """
        if not self._CheckDeviceAffinity(test_name):
            return '', base_test_result.ResultType.PASS

        try:
            logging.warning('Unmapping device ports')
            forwarder.Forwarder.UnmapAllDevicePorts(self.device)
            self.device.RestartAdbd()
        except Exception as e:
            logging.error('Exception when tearing down device %s', e)

        cmd = ('%s --device %s' %
               (self._tests['steps'][test_name]['cmd'], self.device_serial))

        if self._options.collect_chartjson_data:
            self._output_dir = tempfile.mkdtemp()
            cmd = cmd + ' --output-dir=%s' % self._output_dir

        logging.info(
            'temperature: %s (0.1 C)',
            str(self._device_battery.GetBatteryInfo().get('temperature')))
        if self._options.max_battery_temp:
            self._device_battery.LetBatteryCoolToTemperature(
                self._options.max_battery_temp)

        logging.info('Charge level: %s%%',
                     str(self._device_battery.GetBatteryInfo().get('level')))
        if self._options.min_battery_level:
            self._device_battery.ChargeDeviceToLevel(
                self._options.min_battery_level)

        logging.info('%s : %s', test_name, cmd)
        start_time = time.time()

        timeout = self._tests['steps'][test_name].get('timeout', 3600)
        if self._options.no_timeout:
            timeout = None
        logging.info('Timeout for %s test: %s', test_name, timeout)
        full_cmd = cmd
        if self._options.dry_run:
            full_cmd = 'echo %s' % cmd

        logfile = sys.stdout
        if self._options.single_step:
            # Just print a heart-beat so that the outer buildbot scripts won't timeout
            # without response.
            logfile = _HeartBeatLogger()
        cwd = os.path.abspath(constants.DIR_SOURCE_ROOT)
        if full_cmd.startswith('src/'):
            cwd = os.path.abspath(
                os.path.join(constants.DIR_SOURCE_ROOT, os.pardir))
        try:
            exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
                full_cmd, timeout, cwd=cwd, shell=True, logfile=logfile)
            json_output = self._ReadChartjsonOutput()
        except cmd_helper.TimeoutError as e:
            exit_code = -1
            output = e.output
            json_output = ''
        finally:
            self._CleanupOutputDirectory()
            if self._options.single_step:
                logfile.stop()
        end_time = time.time()
        if exit_code is None:
            exit_code = -1
        logging.info('%s : exit_code=%d in %d secs at %s', test_name,
                     exit_code, end_time - start_time, self.device_serial)

        if exit_code == 0:
            result_type = base_test_result.ResultType.PASS
        else:
            result_type = base_test_result.ResultType.FAIL
            # Since perf tests use device affinity, give the device a chance to
            # recover if it is offline after a failure. Otherwise, the master sharder
            # will remove it from the pool and future tests on this device will fail.
            try:
                self.device.WaitUntilFullyBooted(timeout=120)
            except device_errors.CommandTimeoutError as e:
                logging.error('Device failed to return after %s: %s' %
                              (test_name, e))

        actual_exit_code = exit_code
        if test_name in self._flaky_tests:
            # The exit_code is used at the second stage when printing the
            # test output. If the test is flaky, force to "0" to get that step green
            # whilst still gathering data to the perf dashboards.
            # The result_type is used by the test_dispatcher to retry the test.
            exit_code = 0

        persisted_result = {
            'name': test_name,
            'output': [output],
            'chartjson': json_output,
            'exit_code': exit_code,
            'actual_exit_code': actual_exit_code,
            'result_type': result_type,
            'start_time': start_time,
            'end_time': end_time,
            'total_time': end_time - start_time,
            'device': self.device_serial,
            'cmd': cmd,
        }
        self._SaveResult(persisted_result)

        return (output, result_type)
Пример #6
0
    def _LaunchPerfTest(self, test_name):
        """Runs a perf test.

    Args:
      test_name: the name of the test to be executed.

    Returns:
      A tuple containing (Output, base_test_result.ResultType)
    """
        if not self._CheckDeviceAffinity(test_name):
            return '', base_test_result.ResultType.PASS

        try:
            logging.warning('Unmapping device ports')
            forwarder.Forwarder.UnmapAllDevicePorts(self.device)
            self.device.old_interface.RestartAdbdOnDevice()
        except Exception as e:
            logging.error('Exception when tearing down device %s', e)

        cmd = ('%s --device %s' %
               (self._tests['steps'][test_name]['cmd'], self.device_serial))
        logging.info('%s : %s', test_name, cmd)
        start_time = datetime.datetime.now()

        timeout = 5400
        if self._options.no_timeout:
            timeout = None
        full_cmd = cmd
        if self._options.dry_run:
            full_cmd = 'echo %s' % cmd

        logfile = sys.stdout
        if self._options.single_step:
            # Just print a heart-beat so that the outer buildbot scripts won't timeout
            # without response.
            logfile = _HeartBeatLogger()
        cwd = os.path.abspath(constants.DIR_SOURCE_ROOT)
        if full_cmd.startswith('src/'):
            cwd = os.path.abspath(
                os.path.join(constants.DIR_SOURCE_ROOT, os.pardir))
        try:
            exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
                full_cmd, timeout, cwd=cwd, shell=True, logfile=logfile)
        finally:
            if self._options.single_step:
                logfile.stop()
        end_time = datetime.datetime.now()
        if exit_code is None:
            exit_code = -1
        logging.info('%s : exit_code=%d in %d secs at %s', test_name,
                     exit_code, (end_time - start_time).seconds,
                     self.device_serial)
        result_type = base_test_result.ResultType.FAIL
        if exit_code == 0:
            result_type = base_test_result.ResultType.PASS
        actual_exit_code = exit_code
        if test_name in self._flaky_tests:
            # The exit_code is used at the second stage when printing the
            # test output. If the test is flaky, force to "0" to get that step green
            # whilst still gathering data to the perf dashboards.
            # The result_type is used by the test_dispatcher to retry the test.
            exit_code = 0

        persisted_result = {
            'name': test_name,
            'output': output,
            'exit_code': exit_code,
            'actual_exit_code': actual_exit_code,
            'result_type': result_type,
            'total_time': (end_time - start_time).seconds,
            'device': self.device_serial,
            'cmd': cmd,
        }
        self._SaveResult(persisted_result)

        return (output, result_type)