Beispiel #1
0
    def run_test(self, driver_input):
        output = []
        error = []
        crash = False
        timeout = False
        actual_uri = None
        actual_checksum = None
        self._clear_output_image()
        start_time = time.time()

        uri = self._port.filename_to_uri(driver_input.filename)
        cmd = self._test_shell_command(uri, driver_input.timeout,
                                       driver_input.image_hash)
        (line, crash) = self._write_command_and_read_line(input=cmd)

        while not crash and line.rstrip() != "#EOF":
            # Make sure we haven't crashed.
            if line == '' and self.poll() is not None:
                # This is hex code 0xc000001d, which is used for abrupt
                # termination. This happens if we hit ctrl+c from the prompt
                # and we happen to be waiting on DRT.
                # sdoyon: Not sure for which OS and in what circumstances the
                # above code is valid. What works for me under Linux to detect
                # ctrl+c is for the subprocess returncode to be negative
                # SIGINT. And that agrees with the subprocess documentation.
                if (-1073741510 == self._proc.returncode
                        or -signal.SIGINT == self._proc.returncode):
                    raise KeyboardInterrupt
                crash = True
                break

            # Don't include #URL lines in our output
            if line.startswith("#URL:"):
                actual_uri = line.rstrip()[5:]
                if uri != actual_uri:
                    # GURL capitalizes the drive letter of a file URL.
                    if (not re.search("^file:///[a-z]:", uri)
                            or uri.lower() != actual_uri.lower()):
                        _log.fatal("Test got out of sync:\n|%s|\n|%s|" %
                                   (uri, actual_uri))
                        raise AssertionError("test out of sync")
            elif line.startswith("#MD5:"):
                actual_checksum = line.rstrip()[5:]
            elif line.startswith("#TEST_TIMED_OUT"):
                timeout = True
                # Test timed out, but we still need to read until #EOF.
            elif actual_uri:
                output.append(line)
            else:
                error.append(line)

            (line, crash) = self._write_command_and_read_line(input=None)

        run_time = time.time() - start_time
        output_image = self._output_image_with_retry()
        assert output_image is not None
        return base.DriverOutput(''.join(output), output_image,
                                 actual_checksum, crash, run_time, timeout,
                                 ''.join(error))
Beispiel #2
0
    def run_test(self, driver_input):
        uri = self._port.filename_to_uri_for_test_command(
            driver_input.filename)
        if uri.startswith("file:///"):
            command = uri[7:]
        else:
            command = uri

        if driver_input.image_hash:
            command += "'" + driver_input.image_hash
        command += "\n"

        start_time = time.time()
        self._server_process.write(command)

        text = None
        image = None
        actual_image_hash = None
        audio = None
        deadline = time.time() + int(driver_input.timeout) / 1000.0

        # First block is either text or audio
        block = self._read_block(deadline)
        if block.content_type == 'audio/wav':
            audio = block.decoded_content
        else:
            text = block.decoded_content

        # Now read an optional second block of image data
        block = self._read_block(deadline)
        if block.content and block.content_type == 'image/png':
            image = block.decoded_content
            actual_image_hash = block.content_hash

        error_lines = self._server_process.error.splitlines()
        # FIXME: This is a hack.  It is unclear why sometimes
        # we do not get any error lines from the server_process
        # probably we are not flushing stderr.
        if error_lines and error_lines[-1] == "#EOF":
            error_lines.pop()  # Remove the expected "#EOF"
        error = "\n".join(error_lines)
        # FIXME: This seems like the wrong section of code to be doing
        # this reset in.
        self._server_process.error = ""
        return base.DriverOutput(text,
                                 image,
                                 actual_image_hash,
                                 audio,
                                 crash=self._server_process.crashed,
                                 test_time=time.time() - start_time,
                                 timeout=self._server_process.timed_out,
                                 error=error)
Beispiel #3
0
    def run_test(self, driver_input):
        uri = self._port.filename_to_uri(driver_input.filename)
        if uri.startswith("file:///"):
            command = uri[7:]
        else:
            command = uri

        if driver_input.image_hash:
            command += "'" + driver_input.image_hash
        command += "\n"

        start_time = time.time()
        self._server_process.write(command)

        have_seen_content_type = False
        actual_image_hash = None
        output = str()  # Use a byte array for output, even though it should be UTF-8.
        image = str()

        timeout = int(driver_input.timeout) / 1000.0
        deadline = time.time() + timeout
        line = self._server_process.read_line(timeout)
        while (not self._server_process.timed_out
               and not self._server_process.crashed
               and line.rstrip() != "#EOF"):
            if (line.startswith('Content-Type:') and not
                have_seen_content_type):
                have_seen_content_type = True
            else:
                # Note: Text output from DumpRenderTree is always UTF-8.
                # However, some tests (e.g. webarchives) spit out binary
                # data instead of text.  So to make things simple, we
                # always treat the output as binary.
                output += line
            line = self._server_process.read_line(timeout)
            timeout = deadline - time.time()

        # Now read a second block of text for the optional image data
        remaining_length = -1
        HASH_HEADER = 'ActualHash: '
        LENGTH_HEADER = 'Content-Length: '
        line = self._server_process.read_line(timeout)
        while (not self._server_process.timed_out
               and not self._server_process.crashed
               and line.rstrip() != "#EOF"):
            if line.startswith(HASH_HEADER):
                actual_image_hash = line[len(HASH_HEADER):].strip()
            elif line.startswith('Content-Type:'):
                pass
            elif line.startswith(LENGTH_HEADER):
                timeout = deadline - time.time()
                content_length = int(line[len(LENGTH_HEADER):])
                image = self._server_process.read(timeout, content_length)
            timeout = deadline - time.time()
            line = self._server_process.read_line(timeout)

        error_lines = self._server_process.error.splitlines()
        # FIXME: This is a hack.  It is unclear why sometimes
        # we do not get any error lines from the server_process
        # probably we are not flushing stderr.
        if error_lines and error_lines[-1] == "#EOF":
            error_lines.pop()  # Remove the expected "#EOF"
        error = "\n".join(error_lines)
        # FIXME: This seems like the wrong section of code to be doing
        # this reset in.
        self._server_process.error = ""
        return base.DriverOutput(output, image, actual_image_hash,
                                 self._server_process.crashed,
                                 time.time() - start_time,
                                 self._server_process.timed_out,
                                 error)
Beispiel #4
0
 def _expected_driver_output(self):
     return base.DriverOutput(self._port.expected_text(self._filename),
                              self._port.expected_image(self._filename),
                              self._port.expected_checksum(self._filename))