Exemplo n.º 1
0
def Main(argv):
    pds = [
        dashboard_dev_server_config.DashboardDevServerConfig(),
        perf_insights_dev_server_config.PerfInsightsDevServerConfig(),
        tracing_dev_server_config.TracingDevServerConfig(),
        lighthouse_dev_server_config.LighthouseDevServerConfig(),
    ]

    args = _AddCommandLineArguments(pds, argv)

    if args.install_hooks:
        install.InstallHooks()

    app = DevServerApp(pds, args=args)

    server = httpserver.serve(app,
                              host='127.0.0.1',
                              port=args.port,
                              start_loop=False)
    _AddPleaseExitMixinToServer(server)
    # pylint: disable=no-member
    server.urlbase = 'http://127.0.0.1:%i' % server.server_port
    app.server = server

    sys.stderr.write('Now running on %s\n' % server.urlbase)

    return server.serve_forever()
Exemplo n.º 2
0
def Main(argv):
    parser = argparse.ArgumentParser(description='Run d8 tests.')
    parser.add_argument('--no-install-hooks',
                        dest='install_hooks',
                        action='store_false')
    parser.set_defaults(install_hooks=True)
    args = parser.parse_args(argv[1:])
    if args.install_hooks:
        install.InstallHooks()

    sys.exit(RunTests())
Exemplo n.º 3
0
def Main(argv):
  parser = argparse.ArgumentParser(
      description='Run python tests.')
  parser.add_argument(
    '--no-install-hooks', dest='install_hooks', action='store_false')
  parser.add_argument('filters', nargs='*')
  parser.set_defaults(install_hooks=True)
  args = parser.parse_args(argv[1:])
  if args.install_hooks:
    install.InstallHooks()

  runner = test_runner.TestRunner()
  runner.AddModule(tvcm)
  runner.AddModule(tracing_build)
  return runner.Run(args.filters)
Exemplo n.º 4
0
def Main(argv):
    parser = argparse.ArgumentParser(description='Run python tests.')
    parser.add_argument('--no-install-hooks',
                        dest='install_hooks',
                        action='store_false')
    parser.add_argument('filters', nargs='*')
    parser.set_defaults(install_hooks=True)
    args = parser.parse_args(argv[1:])
    if args.install_hooks:
        install.InstallHooks()

    suite = unittest.TestLoader().discover(os.path.dirname(__file__),
                                           pattern='*_unittest.py')
    result = unittest.TextTestRunner(verbosity=2).run(suite)
    if result.wasSuccessful():
        return 0
    else:
        return 1
Exemplo n.º 5
0
def Main(argv):
    pds = [
        perf_insights_dev_server_config.PerfInsightsDevServerConfig(),
        tracing_dev_server_config.TracingDevServerConfig(),
    ]

    args = _AddCommandLineArguments(pds, argv)

    if args.install_hooks:
        install.InstallHooks()

    app = CreateApp(pds, args)

    server = httpserver.serve(app,
                              host='127.0.0.1',
                              port=args.port,
                              start_loop=False)
    _AddPleaseExitMixinToServer(server)
    app.server = server

    sys.stderr.write('Now running on http://127.0.0.1:%i\n' %
                     server.server_port)

    return server.serve_forever()
Exemplo n.º 6
0
def Main(argv):
  try:
    parser = argparse.ArgumentParser(
        description='Run dev_server tests for a project.')
    parser.add_argument('--chrome_path', type=str,
                        help='Path to Chrome browser binary.')
    parser.add_argument('--no-use-local-chrome',
                        dest='use_local_chrome', action='store_false')
    parser.add_argument(
        '--no-install-hooks', dest='install_hooks', action='store_false')
    parser.add_argument('--tests', type=str,
                        help='Set of tests to run (tracing or perf_insights)')
    parser.add_argument('--channel', type=str, default='stable',
                        help='Chrome channel to run (stable or canary)')
    parser.set_defaults(install_hooks=True)
    parser.set_defaults(use_local_chrome=True)
    args = parser.parse_args(argv[1:])

    if args.install_hooks:
      install.InstallHooks()

    platform_data = PLATFORM_MAPPING[sys.platform]
    user_data_dir = tempfile.mkdtemp()
    tmpdir = None
    server_path = os.path.join(os.path.dirname(
        os.path.abspath(__file__)), os.pardir, 'bin', 'run_dev_server')
    # TODO(anniesullie): Make OS selection of port work on Windows. See #1235.
    if sys.platform == 'win32':
      port = DEFAULT_PORT
    else:
      port = '0'
    server_command = [server_path, '--no-install-hooks', '--port', port]
    if sys.platform.startswith('win'):
        server_command = ['python.exe'] + server_command
    print "Starting dev_server..."
    server_process = subprocess.Popen(
        server_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
        bufsize=1)
    time.sleep(1)
    if sys.platform != 'win32':
      output = server_process.stderr.readline()
      port = re.search(
          'Now running on http://127.0.0.1:([\d]+)', output).group(1)

    xvfb_process = None
    chrome_info = None
    if args.use_local_chrome:
      chrome_path = GetLocalChromePath(args.chrome_path)
      if not chrome_path:
        logging.error('Could not find path to chrome.')
        sys.exit(1)
      chrome_info = 'with command `%s`' % chrome_path
    else:
      channel = args.channel
      if sys.platform == 'linux2' and channel == 'canary':
        channel = 'dev'
      assert channel in ['stable', 'beta', 'dev', 'canary']
      tmpdir, version = DownloadChromium(channel)
      if platform_data.get('use_xfvb'):
        xvfb_process = StartXvfb()
      chrome_path = os.path.join(
          tmpdir, platform_data['chromepath'])
      os.chmod(chrome_path, os.stat(chrome_path).st_mode | stat.S_IEXEC)
      # On Mac, we need to update a file with the version in the path, and
      # the version we downloaded could be slightly different than what we
      # requested. Update it.
      if platform_data.get('version_path'):
        contents = os.listdir(
            os.path.join(tmpdir, platform_data['version_path']))
        for path in contents:
          if re.match('\d+\.\d+\.\d+\.\d+', path):
            version = path
      if platform_data.get('additional_paths'):
        for path in platform_data.get('additional_paths'):
          path = path.replace('%VERSION%', version)
          path = os.path.join(tmpdir, path)
          if os.path.exists(path):
            os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC)
      chrome_info = version
    chrome_command = [
        chrome_path,
        '--user-data-dir=%s' % user_data_dir,
        '--no-sandbox',
        '--no-experiments',
        '--no-first-run',
        '--noerrdialogs',
        '--window-size=1280,1024',
        ('http://localhost:%s/%s/tests.html?' % (port, args.tests)) +
            'headless=true&testTypeToRun=all',
    ]
    print "Starting Chrome %s..." % chrome_info
    chrome_process = subprocess.Popen(
        chrome_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    print "Waiting for tests to finish..."
    server_out, server_err = server_process.communicate()
    print "Killing Chrome..."
    if sys.platform == 'win32':
      # Use taskkill on Windows to make sure Chrome and all subprocesses are
      # killed.
      subprocess.call(['taskkill', '/F', '/T', '/PID', str(chrome_process.pid)])
    else:
      chrome_process.kill()
    if server_process.returncode != 0:
      logging.error('Tests failed!')
      logging.error('Server stderr:')
      logging.error(server_err)
      logging.error('Server stdout:')
      logging.error(server_out)
    else:
      print server_out
  finally:
    # Wait for Chrome to be killed before deleting temp Chrome dir. Only have
    # this timing issue on Windows.
    if sys.platform == 'win32':
      time.sleep(5)
    if tmpdir:
      try:
        shutil.rmtree(tmpdir)
        shutil.rmtree(user_data_dir)
      except OSError as e:
        logging.error('Error cleaning up temp dirs %s and %s: %s' % (
            tmpdir, user_data_dir, e))
    if xvfb_process:
      xvfb_process.kill()

  sys.exit(server_process.returncode)
Exemplo n.º 7
0
def Main(argv):
  parser = argparse.ArgumentParser(
      description='Run dev_server tests for a project.')
  parser.add_argument('--chrome_path', type=str,
                      help='Path to Chrome browser binary.')
  parser.add_argument('--no-use-local-chrome',
                      dest='use_local_chrome', action='store_false',
                      help='Use chrome binary fetched from cloud storage '
                      'instead of chrome available on the system.')
  parser.add_argument(
      '--no-install-hooks', dest='install_hooks', action='store_false')
  parser.add_argument('--tests', type=str,
                      help='Set of tests to run (tracing or perf_insights)')
  parser.add_argument('--channel', type=str, default='stable',
                      help='Chrome channel to run (stable or canary)')
  parser.add_argument('--presentation-json', type=str,
                      help='Recipe presentation-json output file path')
  parser.add_argument('--timeout-sec', type=float, default=float('inf'),
                      help='Timeout for running all tests, in seconds')
  parser.add_argument('--timeout-retries', type=int, default=0,
                      help='Number of times to retry if tests time out.'
                      'Default 0 (no retries)')
  parser.set_defaults(install_hooks=True)
  parser.set_defaults(use_local_chrome=True)
  args = parser.parse_args(argv[1:])

  # TODO(crbug.com/1132884) Test consistently fails with canary channel on Mac.
  if args.channel == 'canary' and sys.platform == 'darwin':
    print ('Skipping canary channel tests on MacOS')
    sys.exit(0)

  if args.install_hooks:
    install.InstallHooks()

  chrome_info = GetChromeInfo(args)
  print('Using chrome at path', chrome_info.path)
  if not args.use_local_chrome:
    print ('Chrome version', chrome_info.version, '| channel ', args.channel)
  attempts_left = max(0, args.timeout_retries) + 1
  return_code = None
  while attempts_left:
    print(attempts_left, 'attempts left. Running tests...')
    return_code = RunTests(args, chrome_info.path)
    if return_code == _TIMEOUT_RETURNCODE:
      attempts_left -= 1
      continue
    else:
      break
  else:
    logging.error('Tests timed out every time. Retried %d times.',
                  args.timeout_retries)
    return_code = 1
  if args.presentation_json:
    with open(args.presentation_json, 'w') as recipe_out:
      # Add a link to the buildbot status for the step saying which version
      # of Chrome the test ran on. The actual linking feature is not used,
      # but there isn't a way to just add text.
      link_name = 'Chrome Version %s' % chrome_info.version
      presentation_info = {'links': {link_name: CHROME_CONFIG_URL}}
      json.dump(presentation_info, recipe_out)
  sys.exit(return_code)
Exemplo n.º 8
0
def Main(argv):
    try:
        parser = argparse.ArgumentParser(
            description='Run dev_server tests for a project.')
        parser.add_argument('--chrome_path',
                            type=str,
                            help='Path to Chrome browser binary.')
        parser.add_argument('--no-use-local-chrome',
                            dest='use_local_chrome',
                            action='store_false')
        parser.add_argument('--no-install-hooks',
                            dest='install_hooks',
                            action='store_false')
        parser.add_argument(
            '--tests',
            type=str,
            help='Set of tests to run (tracing or perf_insights)')
        parser.add_argument('--channel',
                            type=str,
                            default='stable',
                            help='Chrome channel to run (stable or canary)')
        parser.add_argument('--presentation-json',
                            type=str,
                            help='Recipe presentation-json output file path')
        parser.set_defaults(install_hooks=True)
        parser.set_defaults(use_local_chrome=True)
        args = parser.parse_args(argv[1:])

        if args.install_hooks:
            install.InstallHooks()

        user_data_dir = tempfile.mkdtemp()
        tmpdir = None
        xvfb_process = None

        server_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   os.pardir, 'bin', 'run_dev_server')
        # TODO(anniesullie): Make OS selection of port work on Windows. See #1235.
        if sys.platform == 'win32':
            port = DEFAULT_PORT
        else:
            port = '0'
        server_command = [server_path, '--no-install-hooks', '--port', port]
        if sys.platform.startswith('win'):
            server_command = ['python.exe'] + server_command
        print "Starting dev_server..."
        server_process = subprocess.Popen(server_command,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          bufsize=1)
        time.sleep(1)
        if sys.platform != 'win32':
            output = server_process.stderr.readline()
            port = re.search(r'Now running on http://127.0.0.1:([\d]+)',
                             output).group(1)

        chrome_info = None
        if args.use_local_chrome:
            chrome_path = GetLocalChromePath(args.chrome_path)
            if not chrome_path:
                logging.error('Could not find path to chrome.')
                sys.exit(1)
            chrome_info = 'with command `%s`' % chrome_path
        else:
            channel = args.channel
            if sys.platform == 'linux2' and channel == 'canary':
                channel = 'dev'
            assert channel in ['stable', 'beta', 'dev', 'canary']

            print 'Fetching the %s chrome binary via the binary_manager.' % channel
            chrome_manager = binary_manager.BinaryManager(
                [CHROME_BINARIES_CONFIG])
            arch, os_name = dependency_util.GetOSAndArchForCurrentDesktopPlatform(
            )
            chrome_path, version = chrome_manager.FetchPathWithVersion(
                'chrome_%s' % channel, arch, os_name)
            if xvfb.ShouldStartXvfb():
                xvfb_process = xvfb.StartXvfb()
            chrome_info = 'version %s from channel %s' % (version, channel)
        chrome_command = [
            chrome_path,
            '--user-data-dir=%s' % user_data_dir,
            '--no-sandbox',
            '--no-experiments',
            '--no-first-run',
            '--noerrdialogs',
            '--window-size=1280,1024',
            ('http://localhost:%s/%s/tests.html?' % (port, args.tests)) +
            'headless=true&testTypeToRun=all',
        ]
        print "Starting Chrome %s..." % chrome_info
        chrome_process = subprocess.Popen(chrome_command,
                                          stdout=sys.stdout,
                                          stderr=sys.stderr)
        print 'chrome process command: %s' % ' '.join(chrome_command)
        print "Waiting for tests to finish..."
        server_out, server_err = server_process.communicate()
        print "Killing Chrome..."
        if sys.platform == 'win32':
            # Use taskkill on Windows to make sure Chrome and all subprocesses are
            # killed.
            subprocess.call(
                ['taskkill', '/F', '/T', '/PID',
                 str(chrome_process.pid)])
        else:
            chrome_process.kill()
        if server_process.returncode != 0:
            logging.error('Tests failed!')
            logging.error('Server stderr:')
            logging.error(server_err)
            logging.error('Server stdout:')
            logging.error(server_out)
        else:
            print server_out
        if args.presentation_json:
            with open(args.presentation_json, 'w') as recipe_out:
                # Add a link to the buildbot status for the step saying which version
                # of Chrome the test ran on. The actual linking feature is not used,
                # but there isn't a way to just add text.
                link_name = 'Chrome Version %s' % version
                presentation_info = {'links': {link_name: CHROME_CONFIG_URL}}
                json.dump(presentation_info, recipe_out)
    finally:
        # Wait for Chrome to be killed before deleting temp Chrome dir. Only have
        # this timing issue on Windows.
        if sys.platform == 'win32':
            time.sleep(5)
        if tmpdir:
            try:
                shutil.rmtree(tmpdir)
                shutil.rmtree(user_data_dir)
            except OSError as e:
                logging.error('Error cleaning up temp dirs %s and %s: %s',
                              tmpdir, user_data_dir, e)
        if xvfb_process:
            xvfb_process.kill()

    sys.exit(server_process.returncode)