def isolate_test_cases(
    cmd, test_cases, jobs, isolated_file, isolate_file,
    root_dir, reldir, variables, trace_blacklist):
  assert os.path.isabs(root_dir) and os.path.isdir(root_dir), root_dir

  logname = isolated_file + '.log'
  basename = isolated_file.rsplit('.', 1)[0]
  cwd_dir = os.path.join(root_dir, reldir)
  # Do the actual tracing.
  results = trace_test_cases.trace_test_cases(
      cmd, cwd_dir, test_cases, jobs, logname)
  api = trace_inputs.get_api()
  blacklist = trace_inputs.gen_blacklist(trace_blacklist)
  logs = dict(
      (i.pop('trace'), i) for i in api.parse_log(logname, blacklist, None))
  exception = None
  try:
    inputs = []
    for items in results:
      item = items[-1]
      assert item['valid']
      # Load the results;
      log_dict = logs[item['tracename']]
      if log_dict.get('exception'):
        exception = exception or log_dict['exception']
        logging.error('Got exception: %s', exception)
        continue
      files = log_dict['results'].strip_root(root_dir).files
      tracked, touched = isolate.split_touched(files)
      value = isolate.generate_isolate(
          tracked,
          [],
          touched,
          root_dir,
          variables,
          reldir,
          blacklist)
      # item['test_case'] could be an invalid file name.
      out = basename + '.' + item['tracename'] + '.isolate'
      with open(out, 'w') as f:
        isolate.pretty_print(value, f)
      inputs.append(out)

    # Merges back. Note that it is possible to blow up the command line
    # argument length here but writing the files is still useful. Convert to
    # importing the module instead if necessary.
    merge_cmd = [
      sys.executable,
      os.path.join(ROOT_DIR, 'isolate_merge.py'),
      isolate_file,
      '-o', isolate_file,
    ]
    merge_cmd.extend(inputs)
    logging.info(merge_cmd)
    proc = subprocess.Popen(merge_cmd)
    proc.communicate()
    return proc.returncode
  finally:
    if exception:
      raise exception[0], exception[1], exception[2]
Exemplo n.º 2
0
def isolate_test_cases(cmd, test_cases, jobs, isolated_file, isolate_file,
                       root_dir, reldir, variables, trace_blacklist):
    assert os.path.isabs(root_dir) and os.path.isdir(root_dir), root_dir

    logname = isolated_file + '.log'
    basename = isolated_file.rsplit('.', 1)[0]
    cwd_dir = os.path.join(root_dir, reldir)
    # Do the actual tracing.
    results = trace_test_cases.trace_test_cases(cmd, cwd_dir, test_cases, jobs,
                                                logname)
    api = trace_inputs.get_api()
    blacklist = trace_inputs.gen_blacklist(trace_blacklist)
    logs = dict(
        (i.pop('trace'), i) for i in api.parse_log(logname, blacklist, None))
    exception = None
    try:
        inputs = []
        for items in results:
            item = items[-1]
            assert item['valid']
            # Load the results;
            log_dict = logs[item['tracename']]
            if log_dict.get('exception'):
                exception = exception or log_dict['exception']
                logging.error('Got exception: %s', exception)
                continue
            files = log_dict['results'].strip_root(root_dir).files
            tracked, touched = isolate.split_touched(files)
            value = isolate.generate_isolate(tracked, [], touched, root_dir,
                                             variables, reldir, blacklist)
            # item['test_case'] could be an invalid file name.
            out = basename + '.' + item['tracename'] + '.isolate'
            with open(out, 'w') as f:
                isolate.pretty_print(value, f)
            inputs.append(out)

        # Merges back. Note that it is possible to blow up the command line
        # argument length here but writing the files is still useful. Convert to
        # importing the module instead if necessary.
        merge_cmd = [
            sys.executable,
            os.path.join(ROOT_DIR, 'isolate_merge.py'),
            isolate_file,
            '-o',
            isolate_file,
        ]
        merge_cmd.extend(inputs)
        logging.info(merge_cmd)
        proc = subprocess.Popen(merge_cmd)
        proc.communicate()
        return proc.returncode
    finally:
        if exception:
            raise exception[0], exception[1], exception[2]
def main():
  """CLI frontend to validate arguments."""
  run_isolated.disable_buffering()
  parser = run_test_cases.OptionParserTestCases(
      usage='%prog <options> [gtest]')
  parser.format_description = lambda *_: parser.description
  parser.add_option(
      '-o', '--out',
      help='output file, defaults to <executable>.test_cases')
  parser.add_option(
      '-r', '--root-dir',
      help='Root directory under which file access should be noted')
  parser.add_option(
      '--trace-blacklist', action='append', default=[],
      help='List of regexp to use as blacklist filter')
  # TODO(maruel): Add support for options.timeout.
  parser.remove_option('--timeout')
  options, args = parser.parse_args()

  if not args:
    parser.error(
        'Please provide the executable line to run, if you need fancy things '
        'like xvfb, start this script from *inside* xvfb, it\'ll be much faster'
        '.')

  cmd = run_isolated.fix_python_path(args)
  cmd[0] = os.path.abspath(cmd[0])
  if not os.path.isfile(cmd[0]):
    parser.error('Tracing failed for: %s\nIt doesn\'t exit' % ' '.join(cmd))

  if not options.out:
    options.out = '%s.test_cases' % cmd[-1]
  options.out = os.path.abspath(options.out)
  if options.root_dir:
    options.root_dir = os.path.abspath(options.root_dir)
  logname = options.out + '.log'

  test_cases = parser.process_gtest_options(cmd, os.getcwd(), options)

  # Then run them.
  print('Tracing...')
  results = trace_test_cases(
      cmd,
      os.getcwd(),
      test_cases,
      options.jobs,
      logname)
  print('Reading trace logs...')
  blacklist = trace_inputs.gen_blacklist(options.trace_blacklist)
  write_details(logname, options.out, options.root_dir, blacklist, results)
  return 0
Exemplo n.º 4
0
def main():
    """CLI frontend to validate arguments."""
    tools.disable_buffering()
    parser = run_test_cases.OptionParserTestCases(
        usage='%prog <options> [gtest]')
    parser.format_description = lambda *_: parser.description
    parser.add_option('-o',
                      '--out',
                      help='output file, defaults to <executable>.test_cases')
    parser.add_option(
        '-r',
        '--root-dir',
        help='Root directory under which file access should be noted')
    parser.add_option('--trace-blacklist',
                      action='append',
                      default=[],
                      help='List of regexp to use as blacklist filter')
    # TODO(maruel): Add support for options.timeout.
    parser.remove_option('--timeout')
    options, args = parser.parse_args()

    if not args:
        parser.error(
            'Please provide the executable line to run, if you need fancy things '
            'like xvfb, start this script from *inside* xvfb, it\'ll be much faster'
            '.')

    cmd = tools.fix_python_path(args)
    cmd[0] = os.path.abspath(cmd[0])
    if not os.path.isfile(cmd[0]):
        parser.error('Tracing failed for: %s\nIt doesn\'t exit' %
                     ' '.join(cmd))

    if not options.out:
        options.out = '%s.test_cases' % cmd[-1]
    options.out = os.path.abspath(options.out)
    if options.root_dir:
        options.root_dir = os.path.abspath(options.root_dir)
    logname = options.out + '.log'

    test_cases = parser.process_gtest_options(cmd, os.getcwd(), options)

    # Then run them.
    print('Tracing...')
    results = trace_test_cases(cmd, os.getcwd(), test_cases, options.jobs,
                               logname)
    print('Reading trace logs...')
    blacklist = trace_inputs.gen_blacklist(options.trace_blacklist)
    write_details(logname, options.out, options.root_dir, blacklist, results)
    return 0