Exemplo n.º 1
0
def main():
  parser = parallel_execution.OptionParser(
      usage='%prog [options] script.py', version=__version__)
  parser.add_option(
      '--serial', action='store_true',
      help='Runs the task serially, to be used when debugging problems since '
           'it\'s slow')
  parser.add_option(
      '--repeat', type='int', default=1,
      help='Runs the task multiple time on each bot, meant to be used as a '
           'load test')
  options, args = parser.parse_args()

  if len(args) != 1:
    parser.error(
        'Must pass one python script to run. Use --help for more details')

  if not options.priority:
    parser.error(
        'Please provide the --priority option. Either use a very low number\n'
        'so the task completes as fast as possible, or an high number so the\n'
        'task only runs when the bot is idle.')

  # 1. Query the bots list.
  bots = get_bot_list(options.swarming, options.dimensions, False)
  print('Found %d bots to process' % len(bots))
  if not bots:
    return 1

  dead_bots = get_bot_list(options.swarming, options.dimensions, True)
  if dead_bots:
    print('Warning: found %d dead bots' % len(dead_bots))

  # 2. Archive the script to run.
  isolated_hash = archive(options.isolate_server, args[0])
  print('Running %s' % isolated_hash)

  # 3. Trigger the tasks.
  name = os.path.basename(args[0])
  if options.serial:
    return run_serial(
        options.swarming,
        options.isolate_server,
        str(options.priority),
        str(options.deadline),
        options.repeat,
        isolated_hash,
        name,
        bots)

  return run_parallel(
      options.swarming,
      options.isolate_server,
      str(options.priority),
      str(options.deadline),
      options.repeat,
      isolated_hash,
      name,
      bots)
Exemplo n.º 2
0
def main():
  parser = parallel_execution.OptionParser(
              usage='%prog [options]', version=__version__)
  parser.add_option(
      '--logs',
      help='Destination where to store the failure logs (recommended!)')
  parser.add_option('-o', '--os', help='Run tests only on this OS')
  parser.add_option(
      '-t', '--test', action='append',
      help='Run only these test, can be specified multiple times')
  parser.add_option(
      '--no-idempotent', action='store_true',
      help='Do not use --idempotent to detect flaky tests')
  options, args = parser.parse_args()
  if args:
    parser.error('Unsupported argument %s' % args)

  oses = ['Linux', 'Mac', 'Windows']
  tests = [
      os.path.relpath(i, ROOT_DIR)
      for i in (
      glob.glob(os.path.join(ROOT_DIR, 'tests', '*_test.py')) +
      glob.glob(os.path.join(ROOT_DIR, 'googletest', 'tests', '*_test.py')))
  ]
  valid_tests = sorted(map(os.path.basename, tests))
  assert len(valid_tests) == len(set(valid_tests)), (
      'Can\'t have 2 tests with the same base name')

  if options.test:
    for t in options.test:
      if not t in valid_tests:
        parser.error(
            '--test %s is unknown. Valid values are:\n%s' % (
              t, '\n'.join('  ' + i for i in valid_tests)))
    filters = tuple(os.path.sep + t for t in options.test)
    tests = [t for t in tests if t.endswith(filters)]

  if options.os:
    if options.os not in oses:
      parser.error(
          '--os %s is unknown. Valid values are %s' % (
            options.os, ', '.join(sorted(oses))))
    oses = [options.os]

  if sys.platform in ('win32', 'cygwin'):
    # If we are on Windows, don't generate the tests for Linux and Mac since
    # they use symlinks and we can't create symlinks on windows.
    oses = ['Windows']
    if options.os != 'win32':
      print('Linux and Mac tests skipped since running on Windows.')

  return run_swarming_tests_on_swarming(
      options.swarming,
      options.isolate_server,
      options.priority,
      oses,
      tests,
      options.logs,
      options.no_idempotent)
Exemplo n.º 3
0
def main():
    parser = parallel_execution.OptionParser(
        usage='%prog [options] (script.py|isolated hash) '
        '-- [script.py arguments]',
        version=__version__)
    parser.add_option(
        '--serial',
        action='store_true',
        help='Runs the task serially, to be used when debugging problems since '
        'it\'s slow')
    parser.add_option('--batches',
                      type='int',
                      default=0,
                      help='Runs a task in parallel |batches| at a time.')
    parser.add_option('--tags',
                      action='append',
                      default=[],
                      metavar='FOO:BAR',
                      help='Tags to assign to the task.')
    parser.add_option(
        '--repeat',
        type='int',
        default=1,
        help='Runs the task multiple time on each bot, meant to be used as a '
        'load test')
    parser.add_option('--name',
                      help='Name to use when providing an isolated hash')
    options, args = parser.parse_args()

    if len(args) < 1:
        parser.error(
            'Must pass one python script to run. Use --help for more details')

    if not options.priority:
        parser.error(
            'Please provide the --priority option. Either use a very low number\n'
            'so the task completes as fast as possible, or an high number so the\n'
            'task only runs when the bot is idle.')

    # 1. Archive the script to run.
    if not os.path.exists(args[0]):
        if not options.name:
            parser.error('Please provide --name when using an isolated hash.')
        if len(args[0]) not in (40, 64):
            parser.error('Hash wrong length %d (%r)' %
                         (len(args.hash), args[0]))
        for i, c in enumerate(args[0]):
            if c not in string.hexdigits:
                parser.error('Hash character invalid\n'
                             ' %s\n' % args[0] + ' ' + '-' * i + '^\n')

        isolated_hash = args[0]
        name = options.name
    else:
        isolated_hash = archive(options.isolate_server, args[0])
        name = os.path.basename(args[0])

    print('Running %s' % isolated_hash)

    # 2. Query the bots list.
    bots, quarantined_bots, dead_bots = get_bot_list(options.swarming,
                                                     options.dimensions)
    print('Found %d bots to process' % len(bots))
    if quarantined_bots:
        print('Warning: found %d quarantined bots' % len(quarantined_bots))
    if dead_bots:
        print('Warning: found %d dead bots' % len(dead_bots))
    if not bots:
        return 1

    # 3. Trigger the tasks.
    if options.batches > 0:
        return run_batches(options.swarming, options.isolate_server,
                           options.dimensions, options.tags, options.env,
                           str(options.priority), str(options.deadline),
                           options.batches, options.repeat, isolated_hash,
                           name, bots, args[1:])

    if options.serial:
        return run_serial(options.swarming, options.isolate_server,
                          options.dimensions, options.tags, options.env,
                          str(options.priority), str(options.deadline),
                          options.repeat, isolated_hash, name, bots, args[1:])

    return run_parallel(options.swarming, options.isolate_server,
                        options.dimensions, options.env, str(options.priority),
                        str(options.deadline), options.repeat, isolated_hash,
                        name, bots, args[1:])