예제 #1
0
  def test_run_and_get_output_timeout_exceeded(self):
    """Verifies the returned values of run_and_get_output() when timeout is set
    and the binary does not exit before it is hit.
    """
    temp_dir = tempfile.mkdtemp()
    fifo_path = os.path.join(temp_dir, 'fifo')
    os.mkfifo(fifo_path)

    class Data:
      fifo = None

    # Any write to the fifo will block until it is open for reading by cat,
    # hence write on a background thread.
    def _write_to_fifo():
      Data.fifo = open(fifo_path, 'w')
      print >> Data.fifo, 'abc'
      Data.fifo.flush()
    write_thread = threading.Thread(target=_write_to_fifo)
    write_thread.start()

    # The call to cat should read what is written to the fifo ('abc') and then
    # stall forever, as we don't close the fifo after writing.
    shell = LinuxShell('cat')
    args = [fifo_path]
    _, output, did_time_out = shell.run_and_get_output(args, timeout=1)

    write_thread.join()
    if Data.fifo:
      Data.fifo.close()

    # Verify that the process did time out and that the output was correctly
    # produced before that.
    self.assertEquals(True, did_time_out)
    self.assertEquals('abc', output.strip())
    shutil.rmtree(temp_dir)
예제 #2
0
  def test_run_and_get_output(self):
    """Verifies that run_and_get_output() correctly builds and passes the
    argument list to the binary.
    """
    shell = LinuxShell('echo')
    shell_args = ['--some-argument 42', 'unicornA', 'unicornB']
    return_code, output, did_time_out = shell.run_and_get_output(shell_args)

    self.assertEquals(0, return_code)
    self.assertEquals(' '.join(shell_args), output.strip())
    self.assertEquals(False, did_time_out)
예제 #3
0
  def test_run_and_get_output_timeout_met(self):
    """Verifies the returned values of run_and_get_output() when timeout is set
    but the binary exits before it is hit.
    """
    shell = LinuxShell('echo')
    shell_args = ['--some-argument 42', 'unicornA', 'unicornB']
    return_code, output, did_time_out = shell.run_and_get_output(shell_args,
                                                                 timeout=1)

    self.assertEquals(0, return_code)
    self.assertEquals(' '.join(shell_args), output.strip())
    self.assertEquals(False, did_time_out)
예제 #4
0
def configure_shell(config_args, shell_args):
    """
  Produces a shell abstraction configured using the parsed arguments defined in
  add_shell_arguments().

  Args:
    config_args: Parsed arguments added using add_shell_arguments().
    shell_args: Additional raw shell arguments to be passed to the shell. We
        need to take these into account as some parameters need to appear only
        once on the argument list (e.g. url-mappings) so we need to coalesce any
        overrides and the existing value into just one argument.

  Returns:
    A tuple of (shell, shell_args).

  Throws:
    ShellConfigurationException if shell abstraction could not be configured.
  """
    if config_args.android:
        verbose_pipe = sys.stdout if config_args.verbose else None

        shell = AndroidShell(config_args.adb_path,
                             config_args.target_device,
                             logcat_tags=config_args.logcat_tags,
                             verbose_pipe=verbose_pipe)
        device_status, error = shell.CheckDevice()
        if not device_status:
            raise ShellConfigurationException('Device check failed: ' + error)
        if config_args.shell_path:
            shell.InstallApk(config_args.shell_path)
    else:
        if not config_args.shell_path:
            raise ShellConfigurationException(
                'Can not run without a shell binary. '
                'Please pass --shell-path.')
        shell = LinuxShell(config_args.shell_path)
        if config_args.use_osmesa:
            shell_args.append(
                '--args-for=mojo:native_viewport_service --use-osmesa')

    shell_args = _apply_mappings(shell, shell_args, config_args.map_url,
                                 config_args.map_origin)

    if config_args.origin:
        if _is_web_url(config_args.origin):
            shell_args.append('--origin=' + config_args.origin)
        else:
            shell_args.extend(
                configure_local_origin(shell,
                                       config_args.origin,
                                       fixed_port=True))

    return shell, shell_args
예제 #5
0
def main():
    parser = argparse.ArgumentParser(
        description="A test runner for application "
        "tests.")

    parser.add_argument("--verbose",
                        help="be verbose (multiple times for more)",
                        default=0,
                        dest="verbose_count",
                        action="count")
    parser.add_argument("test_list_file",
                        type=file,
                        help="a file listing apptests to run")
    parser.add_argument("build_dir",
                        type=str,
                        help="the build output directory")
    args = parser.parse_args()

    InitLogging(args.verbose_count)
    config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
    paths = Paths(config)
    extra_args = []
    if config.target_os == Config.OS_ANDROID:
        shell = AndroidShell(paths.adb_path)
        device_status, error = shell.CheckDevice()
        if not device_status:
            print 'Device check failed: ' + error
            return 1
        shell.InstallApk(paths.target_mojo_shell_path)
        extra_args.extend(
            shell_arguments.ConfigureLocalOrigin(shell,
                                                 paths.build_dir,
                                                 fixed_port=True))
    else:
        shell = LinuxShell(paths.mojo_shell_path)

    gtest.set_color()

    test_list_globals = {"config": config}
    exec args.test_list_file in test_list_globals
    apptests_result = run_apptests(shell, extra_args,
                                   test_list_globals["tests"])
    return 0 if apptests_result else 1
예제 #6
0
def get_shell(shell_config, shell_args):
    """
  Produces a shell abstraction configured according to |shell_config|.

  Args:
    shell_config: Instance of shell_config.ShellConfig.
    shell_args: Additional raw shell arguments to be passed to the shell. We
        need to take these into account as some parameters need to appear only
        once on the argument list (e.g. url-mappings) so we need to coalesce any
        overrides and the existing value into just one argument.

  Returns:
    A tuple of (shell, shell_args). |shell| is the configured shell abstraction,
    |shell_args| is updated list of shell arguments.

  Throws:
    ShellConfigurationException if shell abstraction could not be configured.
  """
    if shell_config.android:
        shell = AndroidShell(shell_config.adb_path,
                             shell_config.target_device,
                             logcat_tags=shell_config.logcat_tags,
                             verbose=shell_config.verbose)

        device_status, error = shell.check_device()
        if not device_status:
            raise ShellConfigurationException('Device check failed: ' + error)
        if shell_config.shell_path:
            shell.install_apk(shell_config.shell_path)
    else:
        if not shell_config.shell_path:
            raise ShellConfigurationException(
                'Can not run without a shell binary. '
                'Please pass --shell-path.')
        shell = LinuxShell(shell_config.shell_path)
        if shell_config.use_osmesa:
            shell_args.append(
                '--args-for=mojo:native_viewport_service --use-osmesa')

    shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list,
                                 shell_config.map_origin_list,
                                 shell_config.reuse_servers)

    if shell_config.origin:
        if _is_web_url(shell_config.origin):
            shell_args.append('--origin=' + shell_config.origin)
        else:
            local_origin_port = _LOCAL_ORIGIN_PORT
            shell_args.extend(
                configure_local_origin(shell, shell_config.origin,
                                       local_origin_port,
                                       shell_config.reuse_servers))

    if shell_config.content_handlers:
        for (mime_type,
             content_handler_url) in shell_config.content_handlers.iteritems():
            shell_args = append_to_argument(
                shell_args, '--content-handlers=',
                '%s,%s' % (mime_type, content_handler_url))

    for dev_server_config in shell_config.dev_servers:
        shell_args = _configure_dev_server(shell, shell_args,
                                           dev_server_config,
                                           shell_config.reuse_servers,
                                           shell_config.verbose)

    return shell, shell_args
예제 #7
0
def get_shell(shell_config, shell_args):
  """
  Produces a shell abstraction configured according to |shell_config|.

  Args:
    shell_config: Instance of shell_config.ShellConfig.
    shell_args: Additional raw shell arguments to be passed to the shell. We
        need to take these into account as some parameters need to appear only
        once on the argument list (e.g. url-mappings) so we need to coalesce any
        overrides and the existing value into just one argument.

  Returns:
    A tuple of (shell, shell_args). |shell| is the configured shell abstraction,
    |shell_args| is updated list of shell arguments.

  Throws:
    ShellConfigurationException if shell abstraction could not be configured.
  """
  platform = 'android-arm' if shell_config.android else 'linux-x64'

  shell_path = shell_config.shell_path
  if not shell_path and shell_config.mojo_version:
    download_dir = os.path.join(paths.DEVTOOLS_ROOT, '_prebuilt')
    shell_path = download.download_shell(shell_config.mojo_version, platform,
                                         download_dir, shell_config.verbose)
  if shell_config.verbose:
    if shell_path:
      print('Using shell binary at ' + shell_path)
    else:
      print('No shell path given, only running on Android with pre-installed '
            'shell will be possible.')

  if shell_config.android:
    shell = AndroidShell(shell_config.adb_path, shell_config.target_device,
                         logcat_tags=shell_config.logcat_tags,
                         verbose=shell_config.verbose)

    device_status, error = shell.check_device()
    if not device_status:
      raise ShellConfigurationException('Device check failed: ' + error)
    if shell_path:
      shell.install_apk(shell_path)
  else:
    if not shell_path:
      raise ShellConfigurationException('Can not run without a shell binary. '
                                        'Please pass --mojo-version or '
                                        '--shell-path.')
    shell = LinuxShell(shell_path)
    if shell_config.use_osmesa:
      shell_args.append('--args-for=mojo:native_viewport_service --use-osmesa')

  shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list,
                               shell_config.map_origin_list,
                               shell_config.reuse_servers)

  # Configure origin for mojo: urls.
  if shell_config.origin:
    # If origin was set on the command line, this takes precedence.
    if _is_web_url(shell_config.origin):
      shell_args.append('--origin=' + shell_config.origin)
    else:
      local_origin_port = _LOCAL_ORIGIN_PORT
      shell_args.extend(configure_local_origin(shell, shell_config.origin,
                                               local_origin_port,
                                               shell_config.reuse_servers))
  elif shell_config.mojo_version:
    # Otherwise we infer the origin from the mojo_version.
    web_origin = "https://storage.googleapis.com/mojo/services/%s/%s" % (
        platform, shell_config.mojo_version)
    if shell_config.verbose:
      print('Inferring origin from `MOJO_VERSION` as: ' + web_origin)
    shell_args.append('--origin=' + web_origin)

  if shell_config.content_handlers:
    for (mime_type,
         content_handler_url) in shell_config.content_handlers.iteritems():
      shell_args = append_to_argument(shell_args, '--content-handlers=',
                                      '%s,%s' % (mime_type,
                                                 content_handler_url))

  for dev_server_config in shell_config.dev_servers:
    shell_args = _configure_dev_server(shell, shell_args, dev_server_config,
                                       shell_config.reuse_servers,
                                       shell_config.verbose)

  return shell, shell_args