示例#1
0
def main():
    fix_encoding.fix_encoding()
    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
    parser.add_argument('-a',
                        '--all',
                        action='store_true',
                        help='allow non local connection')
    parser.add_argument('-l',
                        '--leak',
                        action='store_true',
                        help='leak logs instead of deleting on shutdown')
    args = parser.parse_args()
    root = tempfile.mkdtemp(prefix='start_servers')
    try:
        servers = LocalServers(args.all, root)
        dump_log = True
        try:
            servers.start()
            print('Logs:     %s' % root)
            print('Swarming: %s' % servers.swarming_server.url)
            print('Isolate : %s' % servers.isolate_server.url)
            servers.wait()
        except KeyboardInterrupt:
            print >> sys.stderr, '<Ctrl-C> received; stopping servers'
            dump_log = False
        finally:
            exit_code = servers.stop()
            if dump_log:
                servers.dump_log()
    finally:
        if not args.leak:
            shutil.rmtree(root)
    return exit_code
示例#2
0
def main():
  """Improvement over unittest.main()."""
  fix_encoding.fix_encoding()
  logging.basicConfig(
      level=logging.DEBUG if '-v' in sys.argv else logging.ERROR,
      format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
  if '-v' in sys.argv:
    unittest.TestCase.maxDiff = None
  # Use an unusual umask.
  os.umask(0070)
  fs.chdir(TESTS_DIR)
  unittest.main()
示例#3
0
def main():
  # Always make the current working directory the directory containing this
  # file. It simplifies assumptions.
  base_dir = os.path.dirname(THIS_FILE)
  os.chdir(base_dir)
  # Always create the logs dir first thing, before printing anything out.
  if not os.path.isdir('logs'):
    os.mkdir('logs')

  net.set_user_agent('swarming_bot/' + __version__)

  # This is necessary so os.path.join() works with unicode path. No kidding.
  # This must be done here as each of the command take wildly different code
  # path and this must be run in every case, as it causes really unexpected
  # issues otherwise, especially in module os.path.
  fix_encoding.fix_encoding()

  # This is extremely useful to debug hangs.
  signal_trace.register()

  if os.path.basename(THIS_FILE) == 'swarming_bot.zip':
    # Self-replicate itself right away as swarming_bot.1.zip and restart the bot
    # process as this copy. This enables LKGBC logic.
    print('Self replicating pid:%d.' % os.getpid(), file=sys.stderr)
    new_zip = os.path.join(base_dir, 'swarming_bot.1.zip')
    if os.path.isfile(new_zip):
      os.remove(new_zip)
    shutil.copyfile(THIS_FILE, new_zip)
    cmd = [new_zip] + sys.argv[1:]
    print('cmd: %s' % cmd, file=sys.stderr)
    return common.exec_python(cmd)

  # sys.argv[0] is the zip file itself.
  cmd = 'start_slave'
  args = []
  if len(sys.argv) > 1:
    cmd = sys.argv[1]
    args = sys.argv[2:]

  fn = getattr(sys.modules[__name__], 'CMD%s' % cmd, None)
  if fn:
    try:
      return fn(args)
    except ImportError:
      logging.exception('Failed to run %s', cmd)
      with zipfile.ZipFile(THIS_FILE, 'r') as f:
        logging.error('Files in %s:\n%s', THIS_FILE, f.namelist())
      return 1

  print('Unknown command %s' % cmd, file=sys.stderr)
  return 1
示例#4
0
def main():
  fix_encoding.fix_encoding()
  # It's necessary for relative paths in .isolate.
  os.chdir(APP_DIR)

  parser = optparse.OptionParser()
  parser.add_option('-S', '--swarming', help='Swarming server')
  parser.add_option('-I', '--isolate-server', help='Isolate server')
  parser.add_option('-d', '--dimensions', nargs=2, default=[], action='append')
  parser.add_option('-v', '--verbose', action='store_true', help='Logs more')
  options, args = parser.parse_args()

  if args:
    parser.error('Unsupported args: %s' % args)
  if not options.swarming:
    parser.error('--swarming required')
  if not options.isolate_server:
    parser.error('--isolate-server required')
  if not os.path.isfile(SWARMING_SCRIPT):
    parser.error('Invalid checkout, %s does not exist' % SWARMING_SCRIPT)

  logging.basicConfig(level=logging.DEBUG if options.verbose else logging.ERROR)
  extra_flags = ['--priority', '5', '--tags', 'smoke_test:1']
  for k, v in options.dimensions or [('os', 'Linux')]:
    extra_flags.extend(('-d', k, v))

  # Run all the tests in parallel.
  tests = get_all_tests()
  results = queue.Queue(maxsize=len(tests))

  for name, fn in sorted(tests.items()):
    logging.info('%s', name)
    t = threading.Thread(
        target=run_test, name=name,
        args=(results, options.swarming, options.isolate_server, extra_flags,
              name, fn))
    t.start()

  print('%d tests started' % len(tests))
  maxlen = max(len(name) for name in tests)
  for i in range(len(tests)):
    name, result, duration = results.get()
    print('[%d/%d] %-*s: %4.1fs: %s' %
        (i, len(tests), maxlen, name, duration, result))

  return 0
示例#5
0
def main():
    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
    parser.add_argument('server', help='Swarming server to connect bot to.')
    args = parser.parse_args()
    fix_encoding.fix_encoding()
    botdir = tempfile.mkdtemp(prefix='start_bot')
    try:
        bot = LocalBot(args.server, False, botdir)
        try:
            bot.start()
            bot.wait()
            bot.dump_log()
        except KeyboardInterrupt:
            print('<Ctrl-C> received; stopping bot', file=sys.stderr)
        finally:
            exit_code = bot.stop()
    finally:
        shutil.rmtree(botdir)
    return exit_code
示例#6
0
def run_tests(python3=False, plugins=None):
    """Discover unittests and run them using nose2"""
    hook_args(sys.argv)

    # plugins
    if plugins is None:
        plugins = []
    if python3:
        plugins.append('py3filter')

    # fix_encoding
    sys.path.insert(0, CLIENT_THIRD_PARTY_DIR)
    from depot_tools import fix_encoding
    fix_encoding.fix_encoding()

    # add nose2 plugin dir to path
    sys.path.insert(0, PLUGINS_DIR)
    result = discover(plugins=plugins, exit=False).result
    if not result.wasSuccessful():
        return 1
    return 0
示例#7
0
                                cwd=ROOT_DIR,
                                universal_newlines=True)
        stdout = proc.communicate()[0]
        self.assertEqual(1, proc.returncode)
        self.assertTrue('simple.py is missing' in stdout)

    def test_empty_and_renamed(self):
        a_isolate = os.path.join(self.tempdir, 'a.isolate')
        with open(a_isolate, 'wb') as f:
            f.write('{}')

        cmd = [
            sys.executable,
            'isolate.py',
            'check',
            '-s',
            os.path.join(self.tempdir, 'out.isolated'),
        ]
        subprocess.check_call(cmd + ['-i', a_isolate], cwd=ROOT_DIR)

        # Move the .isolate file aside and rerun the command with the new source but
        # same destination.
        b_isolate = os.path.join(self.tempdir, 'b.isolate')
        os.rename(a_isolate, b_isolate)
        subprocess.check_call(cmd + ['-i', b_isolate], cwd=ROOT_DIR)


if __name__ == '__main__':
    fix_encoding.fix_encoding()
    test_utils.main()
示例#8
0
        def check(x):
            self.assertEqual(logging.WARNING, x)

        self.mock(logging_utils, "set_console_level", check)

        def run_bot(error):
            self.assertEqual(None, error)
            return 0

        self.mock(bot_main, "run_bot", run_bot)

        class Singleton(object):
            # pylint: disable=no-self-argument
            def acquire(self2):
                return True

            def release(self2):
                self.fail()

        self.mock(bot_main, "SINGLETON", Singleton())

        self.assertEqual(0, bot_main.main([]))


if __name__ == "__main__":
    fix_encoding.fix_encoding()
    if "-v" in sys.argv:
        unittest.TestCase.maxDiff = None
    logging.basicConfig(level=logging.DEBUG if "-v" in sys.argv else logging.CRITICAL)
    unittest.main()
示例#9
0
def setup():
    fix_encoding.fix_encoding()
    # Use an unusual umask.
    os.umask(0o070)
    fs.chdir(TESTS_DIR)