Beispiel #1
0
def UpdateDependency(dependency,
                     dep_local_path,
                     version,
                     os_name=None,
                     arch_name=None):
    config = os.path.join(util.GetTelemetryDir(), 'telemetry', 'internal',
                          'binary_dependencies.json')

    if not os_name:
        assert not arch_name, 'arch_name is specified but not os_name'
        os_name = py_utils.GetHostOsName()
        arch_name = py_utils.GetHostArchName()
    else:
        assert arch_name, 'os_name is specified but not arch_name'

    dep_platform = '%s_%s' % (os_name, arch_name)

    c = base_config.BaseConfig(config, writable=True)
    try:
        old_version = c.GetVersion(dependency, dep_platform)
        print 'Updating from version: {}'.format(old_version)
    except ValueError:
        raise RuntimeError((
            'binary_dependencies.json entry for %s missing or invalid; please add '
            'it first! (need download_path and path_within_archive)') %
                           dep_platform)

    if dep_local_path:
        c.AddCloudStorageDependencyUpdateJob(dependency,
                                             dep_platform,
                                             dep_local_path,
                                             version=version,
                                             execute_job=True)
    def _GetGoBinaryPath(self, replay_options):
        """Gets the _go_binary_path if it already set, or downloads it."""
        if USE_LOCAL_WPR in replay_options:
            # Build WPR
            go_folder = os.path.join(_WPR_DIR, 'src')
            cur_cwd = os.getcwd()
            os.chdir(go_folder)
            try:
                print subprocess.check_output(
                    ['go', 'build',
                     os.path.join(go_folder, 'wpr.go')])
            except subprocess.CalledProcessError:
                exit(1)
            os.chdir(cur_cwd)

            return os.path.join(go_folder, 'wpr')

        if not ReplayServer._go_binary_path:
            downloader = self._GetDownloader()
            if not downloader:
                raise RuntimeError('downloader should not be None '
                                   'while _go_binary_path is None')
            ReplayServer._go_binary_path = downloader(
                'wpr_go', py_utils.GetHostOsName(), py_utils.GetHostArchName())
        return ReplayServer._go_binary_path
Beispiel #3
0
  def FlashFirmware(self, hex_path, avrdude_config_path):
    """Flashes the BattOr using an avrdude config at config_path with the new
       firmware at hex_path.
    """
    assert not self._battor_shell, 'Cannot flash BattOr with open shell'

    avrdude_binary = self._dm.FetchPath(
        'avrdude_binary',
        '%s_%s' % (py_utils.GetHostOsName(), py_utils.GetHostArchName()))
    # Sanitize hex file path for windows. It contains <drive>:/ which avrdude
    # is not capable of handling.
    _, hex_path = os.path.splitdrive(hex_path)
    avr_cmd = [
        avrdude_binary,
        '-e',  # Specify to erase data on chip.
        '-p', self._BATTOR_PARTNO,  # Specify AVR device.
        # Specify which microcontroller programmer to use.
        '-c', self._BATTOR_PROGRAMMER,
        '-b', self._BATTOR_BAUDRATE,  # Specify the baud rate to communicate at.
        '-P', self._battor_path,  # Serial path to the battor.
        # Command to execute with hex file and path to hex file.
        '-U', 'flash:w:%s' % hex_path,
        '-C', avrdude_config_path, # AVRdude config file path.
        '2>&1'  # All output goes to stderr for some reason.
    ]
    try:
      subprocess.check_output(avr_cmd)
    except subprocess.CalledProcessError as e:
      raise BattOrFlashError('BattOr flash failed with return code %s.'
                             % e.returncode)

    self._git_hash = None
    return True
Beispiel #4
0
def _IsChromeOSLocalMode(os_name):
  """Determines if we're running telemetry on a Chrome OS device.

  Used to differentiate local mode (telemetry running on the CrOS DUT) from
  remote mode (running telemetry on another platform that communicates with
  the CrOS DUT over SSH).
  """
  return os_name == 'chromeos' and py_utils.GetHostOsName() == 'chromeos'
def _GetHostPlatform():
    os_name = py_utils.GetHostOsName()
    # If we're running directly on a Chrome OS device, fetch the binaries for
    # linux instead, which should be compatible with CrOS.
    if os_name in ['chromeos', 'linux']:
        arch = _GetHostArch()
        if arch == 'x86_64':
            return 'linux'
        return 'linux_' + arch
    return os_name
 def _GetGoBinaryPath(self):
     """Gets the _go_binary_path if it already set, or downloads it."""
     if not ReplayServer._go_binary_path:
         downloader = self._GetDownloader()
         if not downloader:
             raise RuntimeError('downloader should not be None '
                                'while _go_binary_path is None')
         ReplayServer._go_binary_path = downloader(
             'wpr_go', py_utils.GetHostOsName(), py_utils.GetHostArchName())
     return ReplayServer._go_binary_path
Beispiel #7
0
    def __init__(self,
                 target_platform,
                 android_device=None,
                 battor_path=None,
                 battor_map_file=None,
                 battor_map=None,
                 serial_log_bucket=None,
                 autoflash=True):
        """Constructor.

    Args:
      target_platform: Platform BattOr is attached to.
      android_device: Serial number of Android device.
      battor_path: Path to BattOr device.
      battor_map_file: File giving map of [device serial: BattOr path]
      battor_map: Map of [device serial: BattOr path]
      serial_log_bucket: The cloud storage bucket to which BattOr agent serial
        logs are uploaded on failure.

    Attributes:
      _battor_path: Path to BattOr. Typically similar to /tty/USB0.
      _battor_agent_binary: Path to the BattOr agent binary used to communicate
        with the BattOr.
      _tracing: A bool saying if tracing has been started.
      _battor_shell: A subprocess running the battor_agent_binary
      _trace_results_path: Path to BattOr trace results file.
      _serial_log_bucket: Cloud storage bucket to which BattOr agent serial logs
        are uploaded on failure.
      _serial_log_file: Temp file for the BattOr agent serial log.
    """
        self._battor_path = self._GetBattOrPath(target_platform,
                                                android_device, battor_path,
                                                battor_map_file, battor_map)
        config = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'battor_binary_dependencies.json')

        self._dm = dependency_manager.DependencyManager(
            [dependency_manager.BaseConfig(config)])
        self._battor_agent_binary = self._dm.FetchPath(
            'battor_agent_binary',
            '%s_%s' % (py_utils.GetHostOsName(), py_utils.GetHostArchName()))

        self._autoflash = autoflash
        self._serial_log_bucket = serial_log_bucket
        self._tracing = False
        self._battor_shell = None
        self._trace_results_path = None
        self._start_tracing_time = None
        self._stop_tracing_time = None
        self._trace_results = None
        self._serial_log_file = None
        self._target_platform = target_platform
        self._git_hash = None

        atexit_with_log.Register(self.KillBattOrShell)
    def setUp(self):
        self._platform = py_utils.GetHostOsName()
        self._battor_list = None

        if self._platform == 'linux':
            device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap()
            self._battor_list = battor_device_mapping.GetBattOrList(
                device_tree)

        if not battor_wrapper.IsBattOrConnected(self._platform):
            self._battor_list = []
Beispiel #9
0
  def _AddMissingURLsToArchive(self, replay_out_file):
    existing_wpr = self._ExistingWpr()
    if not existing_wpr:
      return

    missing_urls = _ExtractMissingURLsFromLog(replay_out_file)
    if not missing_urls:
      return

    if not self.wpr_go_bin:
      self.wpr_go_bin = (
        binary_manager.BinaryManager([TELEMETRY_BIN_DEPS_CONFIG]).FetchPath(
        'wpr_go', py_utils.GetHostArchName(), py_utils.GetHostOsName()))
    subprocess.check_call([self.wpr_go_bin, 'add', existing_wpr] + missing_urls)
Beispiel #10
0
    def __init__(self, archive_path, replay_host, http_port, https_port,
                 replay_options):
        """Initialize ReplayServer.

    Args:
      archive_path: a path to a specific WPR archive (required).
      replay_host: the hostname to serve traffic.
      http_port: an integer port on which to serve HTTP traffic. May be zero
          to let the OS choose an available port.
      https_port: an integer port on which to serve HTTPS traffic. May be zero
          to let the OS choose an available port.
      replay_options: an iterable of options strings to forward to replay.py.
    """
        self.archive_path = archive_path
        self._replay_host = replay_host
        self._started_ports = {}  # a dict such as {'http': 80, 'https': 443}

        # A temporary path for storing stdout & stderr of the webpagereplay
        # subprocess.
        self._temp_log_file_path = None

        go_binary_path = binary_manager.FetchPath('wpr_go',
                                                  py_utils.GetHostArchName(),
                                                  py_utils.GetHostOsName())

        self._cmd_line = self._GetCommandLine(go_binary_path, http_port,
                                              https_port, replay_options,
                                              archive_path)

        if 'record' in replay_options:
            self._CheckPath('archive directory',
                            os.path.dirname(self.archive_path))
        elif not os.path.exists(self.archive_path):
            self._CheckPath('archive file', self.archive_path)

        self.replay_process = None
 def _GetGoBinaryPath(cls):
     if not cls._go_binary_path:
         cls._go_binary_path = binary_manager.FetchPath(
             'wpr_go', py_utils.GetHostArchName(), py_utils.GetHostOsName())
     return cls._go_binary_path
Beispiel #12
0
 def setUp(self):
   self.archive_path = binary_manager.FetchPath(
       'example_domain_wpr_go_archive',
       py_utils.GetHostArchName(),
       py_utils.GetHostOsName())
Beispiel #13
0
def FetchBinaryDependencies(
    platform, client_configs, fetch_reference_chrome_binary):
  """ Fetch all binary dependenencies for the given |platform|.

  Note: we don't fetch browser binaries by default because the size of the
  binary is about 2Gb, and it requires cloud storage permission to
  chrome-telemetry bucket.

  Args:
    platform: an instance of telemetry.core.platform
    client_configs: A list of paths (string) to dependencies json files.
    fetch_reference_chrome_binary: whether to fetch reference chrome binary for
      the given platform.
  """
  configs = [
      dependency_manager.BaseConfig(TELEMETRY_PROJECT_CONFIG),
  ]
  dep_manager = dependency_manager.DependencyManager(configs)
  os_name = platform.GetOSName()
  # If we're running directly on a Chrome OS device, fetch the binaries for
  # linux instead, which should be compatible with CrOS. Otherwise, if we're
  # running remotely on CrOS, fetch the binaries for the host platform like
  # we do with android below.
  if _IsChromeOSLocalMode(os_name):
    os_name = 'linux'
  target_platform = '%s_%s' % (os_name, platform.GetArchName())
  dep_manager.PrefetchPaths(target_platform)

  host_platform = None
  fetch_devil_deps = False
  if os_name in ('android', 'chromeos'):
    host_platform = '%s_%s' % (
        py_utils.GetHostOsName(), py_utils.GetHostArchName())
    dep_manager.PrefetchPaths(host_platform)
    if os_name == 'android':
      if host_platform == 'linux_x86_64':
        fetch_devil_deps = True
      else:
        logging.error('Devil only supports 64 bit linux as a host platform. '
                      'Android tests may fail.')

  if fetch_reference_chrome_binary:
    _FetchReferenceBrowserBinary(platform)

  # For now, handle client config separately because the BUILD.gn & .isolate of
  # telemetry tests in chromium src failed to include the files specified in its
  # client config.
  # (https://github.com/catapult-project/catapult/issues/2192)
  # For now this is ok because the client configs usually don't include cloud
  # storage infos.
  # TODO(nednguyen): remove the logic of swallowing exception once the issue is
  # fixed on Chromium side.
  if client_configs:
    manager = dependency_manager.DependencyManager(
        list(dependency_manager.BaseConfig(c) for c in client_configs))
    try:
      manager.PrefetchPaths(target_platform)
      if host_platform is not None:
        manager.PrefetchPaths(host_platform)

    except dependency_manager.NoPathFoundError as e:
      logging.error('Error when trying to prefetch paths for %s: %s',
                    target_platform, e.message)

  if fetch_devil_deps:
    devil_env.config.Initialize()
    devil_env.config.PrefetchPaths(arch=platform.GetArchName())
    devil_env.config.PrefetchPaths()
Beispiel #14
0
 def _GetGoBinaryPath(cls, downloader):
     if not cls._go_binary_path:
         cls._go_binary_path = downloader('wpr_go',
                                          py_utils.GetHostOsName(),
                                          py_utils.GetHostArchName())
     return cls._go_binary_path
Beispiel #15
0
 def testConsistentHostPlatformInfo(self):
   self.assertEquals(platform.GetHostPlatform().GetOSName(),
                     py_utils.GetHostOsName())
   self.assertEquals(platform.GetHostPlatform().GetArchName(),
                     py_utils.GetHostArchName())
def GetWPRArchiveFromConfig(test_name, config):
  """Downloads the wpr archive from given config and test name."""
  return binary_manager.BinaryManager(config).FetchPath(
      test_name, py_utils.GetHostOsName(), py_utils.GetHostArchName())