Exemple #1
0
    def ProcessCommandLineArgs(cls, parser, args, _):
        if args.verbosity >= 2:
            logging.getLogger().setLevel(logging.DEBUG)
        elif args.verbosity:
            logging.getLogger().setLevel(logging.INFO)
        else:
            logging.getLogger().setLevel(logging.WARNING)

        # We retry failures by default unless we're running a list of tests
        # explicitly.
        if not args.retry_limit and not args.positional_args:
            args.retry_limit = 3

        if args.test_filter and args.positional_args:
            parser.error('Cannot specify test names in positional args and use'
                         '--test-filter flag at the same time.')

        if args.no_browser:
            return

        if args.start_xvfb and xvfb.ShouldStartXvfb():
            cls.xvfb_process = xvfb.StartXvfb()
            # Work around Mesa issues on Linux. See
            # https://github.com/catapult-project/catapult/issues/3074
            args.browser_options.AppendExtraBrowserArgs('--disable-gpu')

        try:
            possible_browser = browser_finder.FindBrowser(args)
        except browser_finder_exceptions.BrowserFinderException, ex:
            parser.error(ex)
Exemple #2
0
def RunWct(base_dir,
           dep_dirs,
           persist=False,
           chrome_channel='stable',
           prefix=''):
    wct_bin = os.environ.get('WCT', 'wct')
    if os.system('which %s > /dev/null' % wct_bin):
        print 'FATAL ERROR: wct not found. Install it and add it to your path:'
        print 'cipd install -root ~/cipd infra/testing/wct/linux-amd64 prod'
        print 'export PATH=~/cipd:$PATH'
        return 1

    xvfb_process = None

    chrome_bin = run_dev_server_tests.GetLocalChromePath(None)
    if not chrome_bin:
        chrome_manager = binary_manager.BinaryManager(
            [run_dev_server_tests.CHROME_BINARIES_CONFIG])
        arch, os_name = dependency_util.GetOSAndArchForCurrentDesktopPlatform()
        chrome_bin = chrome_manager.FetchPathWithVersion(
            'chrome_%s' % chrome_channel, arch, os_name)[0]
        if not chrome_bin or os.system('which %s > /dev/null' % chrome_bin):
            print 'FATAL ERROR: chrome not found.'
            return 1

        if xvfb.ShouldStartXvfb():
            print 'Starting xvfb...'
            xvfb_process = xvfb.StartXvfb()

    user_data_dir = tempfile.mkdtemp()

    command = [wct_bin]
    command += ['-chrome', chrome_bin]
    command += ['-dir', user_data_dir]
    command += ['-base', base_dir]
    command += ['-prefix', prefix]
    if persist:
        command += ['-persist']
    for dep in dep_dirs:
        command += ['-dep', dep]
    logging.info('Starting WCT: %r', command)

    try:
        return subprocess.call(command)
    finally:
        if xvfb_process:
            xvfb_process.kill()
        try:
            shutil.rmtree(user_data_dir)
        except OSError as e:
            logging.error('Error cleaning up temp dir %r: %s', user_data_dir,
                          e)
Exemple #3
0
  def ProcessCommandLineArgs(cls, parser, args, _):
    # We retry failures by default unless we're running a list of tests
    # explicitly.
    if not args.retry_limit and not args.positional_args:
      args.retry_limit = 3

    if args.no_browser:
      return

    if args.start_xvfb and xvfb.ShouldStartXvfb():
      cls.xvfb_process = xvfb.StartXvfb()
    try:
      possible_browser = browser_finder.FindBrowser(args)
    except browser_finder_exceptions.BrowserFinderException, ex:
      parser.error(ex)
Exemple #4
0
    def ProcessCommandLineArgs(cls, parser, args, _):
        # We retry failures by default unless we're running a list of tests
        # explicitly.
        if not args.retry_limit and not args.positional_args:
            args.retry_limit = 3

        if args.no_browser:
            return

        if args.start_xvfb and xvfb.ShouldStartXvfb():
            cls.xvfb_process = xvfb.StartXvfb()
            # Work around Mesa issues on Linux. See
            # https://github.com/catapult-project/catapult/issues/3074
            args.browser_options.AppendExtraBrowserArgs('--disable-gpu')

        try:
            possible_browser = browser_finder.FindBrowser(args)
        except browser_finder_exceptions.BrowserFinderException, ex:
            parser.error(ex)
Exemple #5
0
def RunTests(args, chrome_path):
  """Runs tests and returns dev server return code.

  Returns _TIMEOUT_RETURNCODE if tests exceed args.timeout_sec.
  """
  user_data_dir = None
  xvfb_process = None
  chrome_process = None
  server_process = None
  timer = None
  test_start_time = time.time()
  try:
    user_data_dir = tempfile.mkdtemp()
    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)
    if xvfb.ShouldStartXvfb():
      print('Starting xvfb...')
      xvfb_process = xvfb.StartXvfb()
    chrome_command = [
        chrome_path,
        '--user-data-dir=%s' % user_data_dir,
        '--no-sandbox',
        '--no-experiments',
        '--no-first-run',
        '--noerrdialogs',
        '--window-size=1280,1024',
        '--enable-logging', '--v=1',
        '--enable-features=ForceWebRequestProxyForTest',
        '--enable-blink-features=CustomElementsV0,'
        'HTMLImports,ShadowDOMV0',
        '--force-device-scale-factor=1',
        ('http://localhost:%s/%s/tests.html?' % (port, args.tests)) +
        'headless=true&testTypeToRun=all',
    ]
    print('Starting Chrome at path %s...' % chrome_path)
    chrome_process = subprocess.Popen(
        chrome_command, stdout=sys.stdout, stderr=sys.stderr)
    print('Chrome process command:', ' '.join(chrome_command))
    print('Waiting for tests to finish...')

    def KillServer():
      print('Timeout reached. Killing dev server...')
      KillProcess(server_process)

    timer = threading.Timer(args.timeout_sec, KillServer)
    timer.start()
    server_out, server_err = server_process.communicate()
    timed_out = not timer.is_alive()
    timer.cancel()

    # There is a very unlikely case where you see server saying "ALL_PASSED"
    # but the test still saying "timed out". This usually happens because the
    # server takes about a second to exit after printing "ALL_PASSED", and it
    # can time out within that time. Looking at the server returncode can help
    # here. The timeout should be increased if we're hitting this case.
    print("Server return code:", server_process.returncode)

    logging.error('Server stdout:\n%s', server_out)
    logging.error('Server stderr:\n%s', server_err)

    if timed_out:
      print('Tests did not finish before', args.timeout_sec, 'seconds')
      return _TIMEOUT_RETURNCODE
    else:
      if server_process.returncode == 0:
        print("Tests passed in %.2f seconds." % (time.time() - test_start_time))
      else:
        logging.error('Tests failed!')
      return server_process.returncode

  finally:
    if timer:
      timer.cancel()
    if server_process and server_process.poll is None:
      # Dev server is still running. Kill it.
      print('Killing dev server...')
      KillProcess(server_process)
    if chrome_process:
      print('Killing Chrome...')
      KillProcess(chrome_process)
    # 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 user_data_dir:
      chrome_debug_logs = os.path.join(user_data_dir, 'chrome_debug.log')
      if os.path.exists(chrome_debug_logs):
        with open(chrome_debug_logs) as f:
          print('-------- chrome_debug.log --------')
          sys.stdout.write(f.read())
          print('-------- ---------------- --------')
          print('Chrome debug logs printed from', chrome_debug_logs)
      try:
        shutil.rmtree(user_data_dir)
      except OSError as e:
        logging.error('Error cleaning up temp dirs %s: %s', user_data_dir, e)
    if xvfb_process:
      KillProcess(xvfb_process)
Exemple #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.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)