Beispiel #1
0
    def _CreateTempRepo(self, dir_name, relative_build_dir, branch):
        """Clones a temporary git repository out of the current working dir.

    Args:
      dir_name: Name for the temporary repository directory
      relative_build_dir: Path to the build dir in the current working dir to
          clone build args from.
      branch: Branch to checkout in the new repository. None will keep checked
          out the same branch as the local repo.
    Returns:
      Path to the build directory of the new repository.
    """
        cwd = os.getcwd()

        repo_dir = tempfile.mkdtemp(suffix='-%s' % dir_name)
        src_dir = os.path.join(repo_dir, 'pdfium')

        self.git.CloneLocal(os.getcwd(), src_dir)

        if branch is not None:
            os.chdir(src_dir)
            self.git.Checkout(branch)

        os.chdir(repo_dir)
        PrintErr('Syncing...')

        cmd = [
            'gclient', 'config', '--unmanaged',
            'https://pdfium.googlesource.com/pdfium.git'
        ]
        if self.args.cache_dir:
            cmd.append('--cache-dir=%s' % self.args.cache_dir)
        RunCommandPropagateErr(cmd, exit_status_on_error=1)

        RunCommandPropagateErr(['gclient', 'sync', '--force'],
                               exit_status_on_error=1)

        PrintErr('Done.')

        build_dir = os.path.join(src_dir, relative_build_dir)
        os.makedirs(build_dir)
        os.chdir(src_dir)

        source_gn_args = os.path.join(cwd, relative_build_dir, 'args.gn')
        dest_gn_args = os.path.join(build_dir, 'args.gn')
        shutil.copy(source_gn_args, dest_gn_args)

        RunCommandPropagateErr(['gn', 'gen', relative_build_dir],
                               exit_status_on_error=1)

        os.chdir(cwd)

        return build_dir
Beispiel #2
0
    def RunSingleTestCase(self, run_label, build_dir, test_case):
        """Profiles a single test case.

    Args:
      run_label: String to differentiate this version of the code in output
          files from other versions.
      build_dir: String with path to build directory
      test_case: Path to the test case.

    Returns:
      The measured profiling value for that test case.
    """
        command = [
            self.safe_measure_script_path, test_case,
            '--build-dir=%s' % build_dir
        ]

        if self.args.interesting_section:
            command.append('--interesting-section')

        if self.args.profiler:
            command.append('--profiler=%s' % self.args.profiler)

        profile_file_path = self._GetProfileFilePath(run_label, test_case)
        if profile_file_path:
            command.append('--output-path=%s' % profile_file_path)

        if self.args.png_dir:
            command.append('--png')

        if self.args.pages:
            command.extend(['--pages', self.args.pages])

        output = RunCommandPropagateErr(command)

        if output is None:
            return None

        if self.args.png_dir:
            self._MoveImages(test_case, run_label)

        # Get the time number as output, making sure it's just a number
        output = output.strip()
        if re.match('^[0-9]+$', output):
            return int(output)

        return None
Beispiel #3
0
  def _BuildCurrentBranch(self, build_dir):
    """Synchronizes and builds the current version of pdfium.

    Args:
      build_dir: String with path to build directory
    """
    PrintErr('Syncing...')
    RunCommandPropagateErr(['gclient', 'sync', '--force'],
                           exit_status_on_error=1)
    PrintErr('Done.')

    PrintErr('Building...')
    cmd = ['ninja', '-C', build_dir, 'pdfium_test']
    if GetBooleanGnArg('use_goma', build_dir):
      cmd.extend(['-j', '250'])
    RunCommandPropagateErr(cmd, stdout_has_errors=True, exit_status_on_error=1)
    PrintErr('Done.')
Beispiel #4
0
  def RunSingleTestCase(self, run_label, build_dir, test_case):
    """Profiles a single test case.

    Args:
      run_label: String to differentiate this version of the code in output
          files from other versions.
      build_dir: String with path to build directory
      test_case: Path to the test case.

    Returns:
      The measured profiling value for that test case.
    """
    command = [self.safe_measure_script_path, test_case,
               '--build-dir=%s' % build_dir]

    if self.args.interesting_section:
      command.append('--interesting-section')

    if self.args.profiler:
      command.append('--profiler=%s' % self.args.profiler)

    profile_file_path = self._GetProfileFilePath(run_label, test_case)
    if profile_file_path:
      command.append('--output-path=%s' % profile_file_path)

    if self.args.png_dir:
      command.append('--png')

    if self.args.pages:
      command.extend(['--pages', self.args.pages])

    output = RunCommandPropagateErr(command)

    if output is None:
      return None

    if self.args.png_dir:
      self._MoveImages(test_case, run_label)

    # Get the time number as output, making sure it's just a number
    output = output.strip()
    if re.match('^[0-9]+$', output):
      return int(output)

    return None
Beispiel #5
0
  def StashPush(self):
    """Stashes uncommitted changes."""
    output = RunCommandPropagateErr(['git', 'stash', '--include-untracked'],
                                    exit_status_on_error=1)
    if 'No local changes to save' in output:
      return False

    self.stashed += 1
    return True
 def __FreezeFile(self, file):
     RunCommandPropagateErr(['cp', file, self.safe_script_dir],
                            exit_status_on_error=1)
Beispiel #7
0
  def _IncrementalRun(self, last_revision_covered):
    """Incremental run, compare against last checkpoint and update it.

    Args:
      last_revision_covered: String with hash for last checkpoint.

    Returns:
      Exit code for the script.
    """
    current = self.git.GetCurrentBranchHash()

    PrintWithTime('Incremental run, current is %s, last is %s' %
                  (current, last_revision_covered))

    if not os.path.exists(self.context.run_output_dir):
      os.makedirs(self.context.run_output_dir)

    if current == last_revision_covered:
      PrintWithTime('No changes seen, finishing job')
      output_info = {
          'metadata':
              self._BuildRunMetadata(last_revision_covered, current, False)
      }
      self._WriteRawJson(output_info)
      return 0

    # Run compare
    cmd = [
        'testing/tools/safetynet_compare.py', '--this-repo',
        '--machine-readable',
        '--branch-before=%s' % last_revision_covered,
        '--output-dir=%s' % self.context.run_output_dir
    ]
    cmd.extend(self.args.input_paths)

    json_output = RunCommandPropagateErr(cmd)

    if json_output is None:
      return 1

    output_info = json.loads(json_output)

    run_metadata = self._BuildRunMetadata(last_revision_covered, current, True)
    output_info.setdefault('metadata', {}).update(run_metadata)
    self._WriteRawJson(output_info)

    PrintConclusionsDictHumanReadable(
        output_info,
        colored=(not self.args.output_to_log and not self.args.no_color),
        key='after')

    status = 0

    if output_info['summary']['improvement']:
      PrintWithTime('Improvement detected.')
      status = 4

    if output_info['summary']['regression']:
      PrintWithTime('Regression detected.')
      status = 3

    if status == 0:
      PrintWithTime('Nothing detected.')

    self._WriteCheckpoint(current)

    return status
Beispiel #8
0
 def CloneLocal(self, source_repo, new_repo):
   RunCommandPropagateErr(['git', 'clone', source_repo, new_repo],
                          exit_status_on_error=1)
Beispiel #9
0
 def BranchExists(self, branch_name):
   """Return whether a branch with the given name exists."""
   output = RunCommandPropagateErr(
       ['git', 'rev-parse', '--verify', branch_name])
   return output is not None
Beispiel #10
0
 def IsCurrentBranchClean(self):
   output = RunCommandPropagateErr(['git', 'status', '--porcelain'],
                                   exit_status_on_error=1)
   return not output
Beispiel #11
0
 def GetCurrentBranchHash(self):
   return RunCommandPropagateErr(['git', 'rev-parse', 'HEAD'],
                                 exit_status_on_error=1).strip()
Beispiel #12
0
 def GetCurrentBranchName(self):
   """Returns a string with the current branch name."""
   return RunCommandPropagateErr(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
                                 exit_status_on_error=1).strip()
Beispiel #13
0
 def StashPopAll(self):
   """Pops as many changes as this instance stashed."""
   while self.stashed > 0:
     RunCommandPropagateErr(['git', 'stash', 'pop'], exit_status_on_error=1)
     self.stashed -= 1
Beispiel #14
0
 def FetchOriginMaster(self):
   """Fetches new changes on origin/main."""
   RunCommandPropagateErr(['git', 'fetch', 'origin', 'main'],
                          exit_status_on_error=1)
Beispiel #15
0
 def Checkout(self, branch):
   """Checks out a branch."""
   RunCommandPropagateErr(['git', 'checkout', branch], exit_status_on_error=1)