Exemple #1
0
def FindDependencies(target_paths, options):
  # Verify arguments.
  for target_path in target_paths:
    if not os.path.exists(target_path):
      raise ValueError('Path does not exist: %s' % target_path)

  dependencies = path_set.PathSet()

  # Including Telemetry's major entry points will (hopefully) include Telemetry
  # and all its dependencies. If the user doesn't pass any arguments, we just
  # have Telemetry.
  dependencies |= FindPythonDependencies(os.path.realpath(
    os.path.join(path.GetTelemetryDir(), 'telemetry', 'benchmark_runner.py')))
  dependencies |= FindPythonDependencies(os.path.realpath(
    os.path.join(path.GetTelemetryDir(),
                 'telemetry', 'unittest_util', 'run_tests.py')))
  dependencies |= FindBootstrapDependencies(path.GetTelemetryDir())

  # Add dependencies.
  for target_path in target_paths:
    base_dir = os.path.dirname(os.path.realpath(target_path))

    dependencies.add(base_dir)
    dependencies |= FindBootstrapDependencies(base_dir)
    dependencies |= FindPythonDependencies(target_path)
    if options.include_page_set_data:
      dependencies |= FindPageSetDependencies(base_dir)

  # Remove excluded files.
  dependencies -= FindExcludedFiles(set(dependencies), options)

  return dependencies
def IppetPath():
    # Look for pre-installed IPPET.
    ippet_path = path.FindInstalledWindowsApplication(
        os.path.join('Intel', 'Intel(R) Platform Power Estimation Tool',
                     'ippet.exe'))
    if ippet_path:
        return ippet_path

    # Look for IPPET installed previously by this script.
    ippet_path = os.path.join(path.GetTelemetryDir(), 'bin', 'win', 'ippet',
                              'ippet.exe')
    if path.IsExecutable(ippet_path):
        return ippet_path

    # Install IPPET.
    zip_path = os.path.join(path.GetTelemetryDir(), 'bin', 'win', 'ippet.zip')
    cloud_storage.GetIfChanged(zip_path, bucket=cloud_storage.PUBLIC_BUCKET)
    with zipfile.ZipFile(zip_path, 'r') as zip_file:
        zip_file.extractall(os.path.dirname(zip_path))
    os.remove(zip_path)

    if path.IsExecutable(ippet_path):
        return ippet_path

    return None
def FindDependencies(target_paths, options):
    # Verify arguments.
    for target_path in target_paths:
        if not os.path.exists(target_path):
            raise ValueError('Path does not exist: %s' % target_path)

    dependencies = path_set.PathSet()

    # Including __init__.py will include Telemetry and its dependencies.
    # If the user doesn't pass any arguments, we just have Telemetry.
    dependencies |= FindPythonDependencies(
        os.path.realpath(
            os.path.join(path.GetTelemetryDir(), 'telemetry', '__init__.py')))
    dependencies |= FindBootstrapDependencies(path.GetTelemetryDir())

    # Add dependencies.
    for target_path in target_paths:
        base_dir = os.path.dirname(os.path.realpath(target_path))

        dependencies.add(base_dir)
        dependencies |= FindBootstrapDependencies(base_dir)
        dependencies |= FindPythonDependencies(target_path)
        if options.include_page_set_data:
            dependencies |= FindPageSetDependencies(base_dir)

    # Remove excluded files.
    dependencies -= FindExcludedFiles(set(dependencies), options)

    return dependencies
def _InstallWinRing0():
    """WinRing0 is used for reading MSRs."""
    executable_dir = os.path.dirname(sys.executable)

    python_is_64_bit = sys.maxsize > 2**32
    dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll'
    dll_path = os.path.join(executable_dir, dll_file_name)

    os_is_64_bit = platform.machine().endswith('64')
    driver_file_name = 'WinRing0x64.sys' if os_is_64_bit else 'WinRing0.sys'
    driver_path = os.path.join(executable_dir, driver_file_name)

    # Check for WinRing0 and download if needed.
    if not (os.path.exists(dll_path) and os.path.exists(driver_path)):
        win_binary_dir = os.path.join(path.GetTelemetryDir(), 'bin', 'win')
        zip_path = os.path.join(win_binary_dir, 'winring0.zip')
        cloud_storage.GetIfChanged(zip_path,
                                   bucket=cloud_storage.PUBLIC_BUCKET)
        try:
            with zipfile.ZipFile(zip_path, 'r') as zip_file:
                # Install DLL.
                if not os.path.exists(dll_path):
                    zip_file.extract(dll_file_name, executable_dir)
                # Install kernel driver.
                if not os.path.exists(driver_path):
                    zip_file.extract(driver_file_name, executable_dir)
        finally:
            os.remove(zip_path)
Exemple #5
0
def ZipDependencies(target_paths, dependencies, options):
  base_dir = os.path.dirname(os.path.realpath(path.GetChromiumSrcDir()))

  with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file:
    # Add dependencies to archive.
    for dependency_path in dependencies:
      path_in_archive = os.path.join(
          'telemetry', os.path.relpath(dependency_path, base_dir))
      zip_file.write(dependency_path, path_in_archive)

    # Add symlinks to executable paths, for ease of use.
    for target_path in target_paths:
      link_info = zipfile.ZipInfo(
          os.path.join('telemetry', os.path.basename(target_path)))
      link_info.create_system = 3  # Unix attributes.
      # 010 is regular file, 0111 is the permission bits rwxrwxrwx.
      link_info.external_attr = 0100777 << 16  # Octal.

      relative_path = os.path.relpath(target_path, base_dir)
      link_script = (
          '#!/usr/bin/env python\n\n'
          'import os\n'
          'import sys\n\n\n'
          'script = os.path.join(os.path.dirname(__file__), \'%s\')\n'
          'os.execv(sys.executable, [sys.executable, script] + sys.argv[1:])'
        % relative_path)

      zip_file.writestr(link_info, link_script)

    # Add gsutil to the archive, if it's available. The gsutil in
    # depot_tools is modified to allow authentication using prodaccess.
    # TODO: If there's a gsutil in telemetry/third_party/, bootstrap_deps
    # will include it. Then there will be two copies of gsutil at the same
    # location in the archive. This can be confusing for users.
    gsutil_path = os.path.realpath(cloud_storage.FindGsutil())
    if cloud_storage.SupportsProdaccess(gsutil_path):
      gsutil_base_dir = os.path.join(os.path.dirname(gsutil_path), os.pardir)
      gsutil_dependencies = path_set.PathSet()
      gsutil_dependencies.add(os.path.dirname(gsutil_path))
      # Also add modules from depot_tools that are needed by gsutil.
      gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'boto'))
      gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'fancy_urllib'))
      gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'retry_decorator'))
      gsutil_dependencies -= FindExcludedFiles(
          set(gsutil_dependencies), options)

      # Also add upload.py to the archive from depot_tools, if it is available.
      # This allows us to post patches without requiring a full depot_tools
      # install. There's no real point in including upload.py if we do not
      # also have gsutil, which is why this is inside the gsutil block.
      gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'upload.py'))

      for dependency_path in gsutil_dependencies:
        path_in_archive = os.path.join(
            'telemetry', os.path.relpath(path.GetTelemetryDir(), base_dir),
            'third_party', os.path.relpath(dependency_path, gsutil_base_dir))
        zip_file.write(dependency_path, path_in_archive)
 def _InstallHorndis(self):
     if 'HoRNDIS' in subprocess.check_output(['kextstat']):
         return
     logging.info('Installing HoRNDIS...')
     pkg_path = os.path.join(path.GetTelemetryDir(), 'bin', 'mac',
                             'HoRNDIS-rel5.pkg')
     cloud_storage.GetIfChanged(pkg_path,
                                bucket=cloud_storage.PUBLIC_BUCKET)
     subprocess.check_call(
         ['sudo', 'installer', '-pkg', pkg_path, '-target', '/'])
def _InstallWinRing0():
    """WinRing0 is used for reading MSRs."""
    executable_dir = os.path.dirname(sys.executable)

    python_is_64_bit = sys.maxsize > 2**32
    dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll'
    dll_path = os.path.join(executable_dir, dll_file_name)

    os_is_64_bit = platform.machine().endswith('64')
    driver_file_name = 'WinRing0x64.sys' if os_is_64_bit else 'WinRing0.sys'
    driver_path = os.path.join(executable_dir, driver_file_name)

    # Check for WinRing0 and download if needed.
    if not (os.path.exists(dll_path) and os.path.exists(driver_path)):
        win_binary_dir = os.path.join(path.GetTelemetryDir(), 'bin', 'win',
                                      'AMD64')
        zip_path = os.path.join(win_binary_dir, 'winring0.zip')
        cloud_storage.GetIfChanged(zip_path,
                                   bucket=cloud_storage.PUBLIC_BUCKET)
        try:
            with zipfile.ZipFile(zip_path, 'r') as zip_file:
                error_message = (
                    'Failed to extract %s into %s. If python claims that '
                    'the zip file is locked, this may be a lie. The problem may be '
                    'that python does not have write permissions to the destination '
                    'directory.')
                # Install DLL.
                if not os.path.exists(dll_path):
                    try:
                        zip_file.extract(dll_file_name, executable_dir)
                    except:
                        logging.error(error_message %
                                      (dll_file_name, executable_dir))
                        raise

                # Install kernel driver.
                if not os.path.exists(driver_path):
                    try:
                        zip_file.extract(driver_file_name, executable_dir)
                    except:
                        logging.error(error_message %
                                      (driver_file_name, executable_dir))
                        raise
        finally:
            os.remove(zip_path)
Exemple #8
0
def _GetBinPath(binary_name, arch_name, platform_name):
    return os.path.join(path.GetTelemetryDir(), 'bin', platform_name,
                        arch_name, binary_name)
from telemetry.core import util
from telemetry.util import path

PUBLIC_BUCKET = 'chromium-telemetry'
PARTNER_BUCKET = 'chrome-partner-telemetry'
INTERNAL_BUCKET = 'chrome-telemetry'

BUCKET_ALIASES = {
    'public': PUBLIC_BUCKET,
    'partner': PARTNER_BUCKET,
    'internal': INTERNAL_BUCKET,
}

_GSUTIL_URL = 'http://storage.googleapis.com/pub/gsutil.tar.gz'
_DOWNLOAD_PATH = os.path.join(path.GetTelemetryDir(), 'third_party', 'gsutil')
# TODO(tbarzic): A workaround for http://crbug.com/386416 and
#     http://crbug.com/359293. See |_RunCommand|.
_CROS_GSUTIL_HOME_WAR = '/home/chromeos-test/'


class CloudStorageError(Exception):
    @staticmethod
    def _GetConfigInstructions(gsutil_path):
        if SupportsProdaccess(gsutil_path) and _FindExecutableInPath(
                'prodaccess'):
            return 'Run prodaccess to authenticate.'
        else:
            if util.IsRunningOnCrosDevice():
                gsutil_path = ('HOME=%s %s' %
                               (_CROS_GSUTIL_HOME_WAR, gsutil_path))
Exemple #10
0
def _GetBinPath(binary_name, platform_name):
    # TODO(tonyg): Add another nesting level for architecture_name.
    return os.path.join(path.GetTelemetryDir(), 'bin', platform_name,
                        binary_name)
Exemple #11
0
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import json
import os
import unittest

from telemetry.util import path
from telemetry.util import find_dependencies


_TELEMETRY_DEPS_PATH = os.path.join(
    path.GetTelemetryDir(), 'telemetry', 'TELEMETRY_DEPS')


def _GetCurrentTelemetryDependencies():
  parser = find_dependencies.FindDependenciesCommand.CreateParser()
  find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None)
  options, args = parser.parse_args([''])
  options.positional_args = args
  return find_dependencies.FindDependencies([], options=options)


def _GetRestrictedTelemetryDeps():
  with open(_TELEMETRY_DEPS_PATH, 'r') as f:
    telemetry_deps = json.load(f)

  # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain
  # the relative path in chromium/src/.
  def NormalizePath(p):