Ejemplo n.º 1
0
    def communicate(self, input=None):  # pylint: disable=redefined-builtin
        """subprocess.Popen.communicate."""
        stdout, stderr = self._popen.communicate(input)
        if not self._max_stdout_len:
            return stdout, stderr

        with self._stdout_file:
            return utils.read_from_handle_truncated(
                self._stdout_file, self._max_stdout_len), stderr
Ejemplo n.º 2
0
    def fuzzer_stderr(self):
        """Returns the stderr of the fuzzer. Reads it first if it wasn't already
    read. Because ClusterFuzz terminates this process after seeing a stacktrace
    printed, make sure that printing this property is the last code a program
    expects to execute.
    """
        if self._fuzzer_stderr is not None:
            return self._fuzzer_stderr

        try:
            with open(self.stderr_file_path) as file_handle:
                stderr_data = utils.read_from_handle_truncated(
                    file_handle, MAX_OUTPUT_LEN)

            self._fuzzer_stderr = get_first_stacktrace(stderr_data)
        except IOError:
            self._fuzzer_stderr = ''
        return self._fuzzer_stderr
Ejemplo n.º 3
0
def undercoat_api_command(*args):
  """Make an API call to the undercoat binary."""
  bundle_dir = environment.get_value('FUCHSIA_RESOURCES_DIR')
  undercoat_path = os.path.join(bundle_dir, 'undercoat', 'undercoat')
  undercoat = new_process.ProcessRunner(undercoat_path, args)
  # The undercoat log is sent to stderr, which we capture to a tempfile
  undercoat_log = tempfile.TemporaryFile()
  result = undercoat.run_and_wait(stderr=undercoat_log)
  result.output = result.output.decode('utf-8')

  if result.return_code != 0:
    # Dump the undercoat log to assist in debugging
    log_data = utils.read_from_handle_truncated(undercoat_log, 1024 * 1024)
    logs.log_warn('Log output from undercoat: ' + log_data)

    # The API error message is returned on stdout
    raise UndercoatError(
        'Error running undercoat command %s: %s' % (args, result.output))

  return result