Exemplo n.º 1
0
def _VerifyTargetExecutablesAreInBuildDirectory(commands):
  """Verifies that the target executables specified in the commands are inside
  the given build directory."""
  for command in commands:
    binary_path = _GetBinaryPath(command)
    binary_absolute_path = coverage_utils.GetFullPath(binary_path)
    assert binary_absolute_path.startswith(BUILD_DIR + os.sep), (
        'Target executable "%s" in command: "%s" is outside of '
        'the given build directory: "%s".' % (binary_path, command, BUILD_DIR))
Exemplo n.º 2
0
def _ConfigureLLVMCoverageTools(args):
    """Configures llvm coverage tools."""
    if args.coverage_tools_dir:
        llvm_bin_dir = coverage_utils.GetFullPath(args.coverage_tools_dir)
        global LLVM_COV_PATH
        global LLVM_PROFDATA_PATH
        LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
        LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
    else:
        update_clang_coverage_tools.DownloadCoverageToolsIfNeeded()

    coverage_tools_exist = (os.path.exists(LLVM_COV_PATH)
                            and os.path.exists(LLVM_PROFDATA_PATH))
    assert coverage_tools_exist, (
        'Cannot find coverage tools, please make sure '
        'both \'%s\' and \'%s\' exist.') % (LLVM_COV_PATH, LLVM_PROFDATA_PATH)
Exemplo n.º 3
0
def _ConfigureLLVMCoverageTools(args):
  """Configures llvm coverage tools."""
  if args.coverage_tools_dir:
    llvm_bin_dir = coverage_utils.GetFullPath(args.coverage_tools_dir)
    global LLVM_COV_PATH
    global LLVM_PROFDATA_PATH
    LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
    LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
  else:
    update.UpdatePackage('coverage_tools', coverage_utils.GetHostPlatform())

  if coverage_utils.GetHostPlatform() == 'win':
    LLVM_COV_PATH += '.exe'
    LLVM_PROFDATA_PATH += '.exe'

  coverage_tools_exist = (
      os.path.exists(LLVM_COV_PATH) and os.path.exists(LLVM_PROFDATA_PATH))
  assert coverage_tools_exist, ('Cannot find coverage tools, please make sure '
                                'both \'%s\' and \'%s\' exist.') % (
                                    LLVM_COV_PATH, LLVM_PROFDATA_PATH)
Exemplo n.º 4
0
def _ConfigureLLVMCoverageTools(args):
    """Configures llvm coverage tools."""
    if args.coverage_tools_dir:
        llvm_bin_dir = coverage_utils.GetFullPath(args.coverage_tools_dir)
        global LLVM_COV_PATH
        global LLVM_PROFDATA_PATH
        LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
        LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
    else:
        subprocess.check_call([
            sys.executable, 'tools/clang/scripts/update.py', '--package',
            'coverage_tools'
        ])

    if coverage_utils.GetHostPlatform() == 'win':
        LLVM_COV_PATH += '.exe'
        LLVM_PROFDATA_PATH += '.exe'

    coverage_tools_exist = (os.path.exists(LLVM_COV_PATH)
                            and os.path.exists(LLVM_PROFDATA_PATH))
    assert coverage_tools_exist, (
        'Cannot find coverage tools, please make sure '
        'both \'%s\' and \'%s\' exist.') % (LLVM_COV_PATH, LLVM_PROFDATA_PATH)
Exemplo n.º 5
0
def Main():
    """Execute tool commands."""

    # Change directory to source root to aid in relative paths calculations.
    os.chdir(SRC_ROOT_PATH)

    # Setup coverage binaries even when script is called with empty params. This
    # is used by coverage bot for initial setup.
    if len(sys.argv) == 1:
        subprocess.check_call(
            ['tools/clang/scripts/update.py', '--package', 'coverage_tools'])
        print(__doc__)
        return

    args = _ParseCommandArguments()
    coverage_utils.ConfigureLogging(verbose=args.verbose,
                                    log_file=args.log_file)
    _ConfigureLLVMCoverageTools(args)

    global BUILD_DIR
    BUILD_DIR = coverage_utils.GetFullPath(args.build_dir)

    global OUTPUT_DIR
    OUTPUT_DIR = coverage_utils.GetFullPath(args.output_dir)

    assert args.web_tests or args.command or args.profdata_file, (
        'Need to either provide commands to run using -c/--command option OR '
        'provide prof-data file as input using -p/--profdata-file option OR '
        'run web tests using -wt/--run-web-tests.')

    assert not args.command or (len(args.targets) == len(args.command)), (
        'Number of targets must be equal to the number of test commands.')

    assert os.path.exists(BUILD_DIR), ('Build directory: "%s" doesn\'t exist. '
                                       'Please run "gn gen" to generate.' %
                                       BUILD_DIR)

    _ValidateCurrentPlatformIsSupported()
    _ValidateBuildingWithClangCoverage()

    absolute_filter_paths = []
    if args.filters:
        absolute_filter_paths = _VerifyPathsAndReturnAbsolutes(args.filters)

    _SetupOutputDir()

    # Get .profdata file and list of binary paths.
    if args.web_tests:
        commands = [_GetCommandForWebTests(args.web_tests)]
        profdata_file_path = _CreateCoverageProfileDataForTargets(
            args.targets, commands, args.jobs)
        binary_paths = [_GetBinaryPathForWebTests()]
    elif args.command:
        for i in range(len(args.command)):
            assert not 'run_web_tests.py' in args.command[i], (
                'run_web_tests.py is not supported via --command argument. '
                'Please use --run-web-tests argument instead.')

        # A list of commands are provided. Run them to generate profdata file, and
        # create a list of binary paths from parsing commands.
        _VerifyTargetExecutablesAreInBuildDirectory(args.command)
        profdata_file_path = _CreateCoverageProfileDataForTargets(
            args.targets, args.command, args.jobs)
        binary_paths = [_GetBinaryPath(command) for command in args.command]
    else:
        # An input prof-data file is already provided. Just calculate binary paths.
        profdata_file_path = args.profdata_file
        binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)

    # If the checkout uses the hermetic xcode binaries, then otool must be
    # directly invoked. The indirection via /usr/bin/otool won't work unless
    # there's an actual system install of Xcode.
    otool_path = None
    if sys.platform == 'darwin':
        hermetic_otool_path = os.path.join(SRC_ROOT_PATH, 'build', 'mac_files',
                                           'xcode_binaries', 'Contents',
                                           'Developer', 'Toolchains',
                                           'XcodeDefault.xctoolchain', 'usr',
                                           'bin', 'otool')
        if os.path.exists(hermetic_otool_path):
            otool_path = hermetic_otool_path
    if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
        binary_paths.extend(
            coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR,
                                              otool_path))

    assert args.format == 'html' or args.format == 'text', (
        '%s is not a valid output format for "llvm-cov show". Only "text" and '
        '"html" formats are supported.' % (args.format))
    logging.info(
        'Generating code coverage report in %s (this can take a while '
        'depending on size of target!).' % (args.format))
    per_file_summary_data = _GeneratePerFileCoverageSummary(
        binary_paths, profdata_file_path, absolute_filter_paths,
        args.ignore_filename_regex)
    _GeneratePerFileLineByLineCoverageInFormat(binary_paths,
                                               profdata_file_path,
                                               absolute_filter_paths,
                                               args.ignore_filename_regex,
                                               args.format)
    component_mappings = None
    if not args.no_component_view:
        component_mappings = json.load(urllib2.urlopen(COMPONENT_MAPPING_URL))

    # Call prepare here.
    processor = coverage_utils.CoverageReportPostProcessor(
        OUTPUT_DIR,
        SRC_ROOT_PATH,
        per_file_summary_data,
        no_component_view=args.no_component_view,
        no_file_view=args.no_file_view,
        component_mappings=component_mappings)

    if args.format == 'html':
        processor.PrepareHtmlReport()
Exemplo n.º 6
0
def Main():
  """Execute tool commands."""
  # Setup coverage binaries even when script is called with empty params. This
  # is used by coverage bot for initial setup.
  if len(sys.argv) == 1:
    update_clang_coverage_tools.DownloadCoverageToolsIfNeeded()
    print(__doc__)
    return

  # Change directory to source root to aid in relative paths calculations.
  global SRC_ROOT_PATH
  SRC_ROOT_PATH = coverage_utils.GetFullPath(
      os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir))
  os.chdir(SRC_ROOT_PATH)

  args = _ParseCommandArguments()
  coverage_utils.ConfigureLogging(verbose=args.verbose, log_file=args.log_file)
  _ConfigureLLVMCoverageTools(args)

  global BUILD_DIR
  BUILD_DIR = coverage_utils.GetFullPath(args.build_dir)

  global OUTPUT_DIR
  OUTPUT_DIR = coverage_utils.GetFullPath(args.output_dir)

  assert args.web_tests or args.command or args.profdata_file, (
      'Need to either provide commands to run using -c/--command option OR '
      'provide prof-data file as input using -p/--profdata-file option OR '
      'run web tests using -wt/--run-web-tests.')

  assert not args.command or (len(args.targets) == len(args.command)), (
      'Number of targets must be equal to the number of test commands.')

  assert os.path.exists(BUILD_DIR), (
      'Build directory: "%s" doesn\'t exist. '
      'Please run "gn gen" to generate.' % BUILD_DIR)

  _ValidateCurrentPlatformIsSupported()
  _ValidateBuildingWithClangCoverage()

  absolute_filter_paths = []
  if args.filters:
    absolute_filter_paths = _VerifyPathsAndReturnAbsolutes(args.filters)

  _SetupOutputDir()

  # Get .profdata file and list of binary paths.
  if args.web_tests:
    commands = [_GetCommandForWebTests(args.web_tests)]
    profdata_file_path = _CreateCoverageProfileDataForTargets(
        args.targets, commands, args.jobs)
    binary_paths = [_GetBinaryPathForWebTests()]
  elif args.command:
    for i in range(len(args.command)):
      assert not 'run_web_tests.py' in args.command[i], (
          'run_web_tests.py is not supported via --command argument. '
          'Please use --run-web-tests argument instead.')

    # A list of commands are provided. Run them to generate profdata file, and
    # create a list of binary paths from parsing commands.
    _VerifyTargetExecutablesAreInBuildDirectory(args.command)
    profdata_file_path = _CreateCoverageProfileDataForTargets(
        args.targets, args.command, args.jobs)
    binary_paths = [_GetBinaryPath(command) for command in args.command]
  else:
    # An input prof-data file is already provided. Just calculate binary paths.
    profdata_file_path = args.profdata_file
    binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)

  binary_paths.extend(
      coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR))

  logging.info('Generating code coverage report in html (this can take a while '
               'depending on size of target!).')
  per_file_summary_data = _GeneratePerFileCoverageSummary(
      binary_paths, profdata_file_path, absolute_filter_paths,
      args.ignore_filename_regex)
  _GeneratePerFileLineByLineCoverageInHtml(binary_paths, profdata_file_path,
                                           absolute_filter_paths,
                                           args.ignore_filename_regex)
  component_mappings = None
  if not args.no_component_view:
    component_mappings = json.load(urllib2.urlopen(COMPONENT_MAPPING_URL))

  # Call prepare here.
  processor = coverage_utils.CoverageReportPostProcessor(
      OUTPUT_DIR,
      SRC_ROOT_PATH,
      per_file_summary_data,
      no_component_view=args.no_component_view,
      no_file_view=args.no_file_view,
      component_mappings=component_mappings)

  processor.PrepareHtmlReport()