Ejemplo n.º 1
0
    def test_basic(self):
        cmd = [
            sys.executable, '-c',
            'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"'
        ]
        host = SystemHost()
        factory = PortFactory(host)
        port = factory.get()
        now = time.time()
        proc = server_process.ServerProcess(port, 'python', cmd)
        proc.write('')

        self.assertEquals(proc.poll(), None)
        self.assertFalse(proc.has_crashed())

        # check that doing a read after an expired deadline returns
        # nothing immediately.
        line = proc.read_stdout_line(now - 1)
        self.assertEquals(line, None)

        line = proc.read_stdout_line(now + 1.0)
        self.assertEquals(line.strip(), "stdout")

        line = proc.read_stderr_line(now + 1.0)
        self.assertEquals(line.strip(), "stderr")

        proc.stop()
    def test_basic(self):
        cmd = [
            sys.executable, '-c',
            'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"'
        ]
        host = SystemHost()
        factory = PortFactory(host)
        port = factory.get()
        now = time.time()
        proc = server_process.ServerProcess(port, 'python', cmd)
        proc.write('')

        self.assertEquals(proc.poll(), None)
        self.assertFalse(proc.has_crashed())

        # check that doing a read after an expired deadline returns
        # nothing immediately.
        line = proc.read_stdout_line(now - 1)
        self.assertEquals(line, None)

        # FIXME: This part appears to be flaky. line should always be non-None.
        # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280
        line = proc.read_stdout_line(now + 1.0)
        if line:
            self.assertEquals(line.strip(), "stdout")

        line = proc.read_stderr_line(now + 1.0)
        if line:
            self.assertEquals(line.strip(), "stderr")

        proc.stop(0)
Ejemplo n.º 3
0
 def start(self):
     server_name = self._port.driver_name()
     environment = self._port.setup_environ_for_server(server_name)
     environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
     # FIXME: We're assuming that WebKitTestRunner checks this DumpRenderTree-named environment variable.
     environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
     self._server_process = server_process.ServerProcess(
         self._port, server_name, self.cmd_line(), environment)
Ejemplo n.º 4
0
    def _start_image_diff_process(self, expected_contents, actual_contents, tolerance=None):
        command = self._image_diff_command(tolerance)
        environment = self.setup_environ_for_server('ImageDiff')
        process = server_process.ServerProcess(self, 'ImageDiff', command, environment)

        process.write('Content-Length: %d\n%sContent-Length: %d\n%s' % (
            len(actual_contents), actual_contents,
            len(expected_contents), expected_contents))
        return process
Ejemplo n.º 5
0
 def _android_server_process_constructor(port, server_name, cmd_line, env=None, more_logging=False):
     # We need universal_newlines=True, because 'adb shell' for some unknown reason
     # does newline conversion of unix-style LF into win-style CRLF (and we need
     # to convert that back). This can cause headaches elsewhere because
     # server_process' stdout and stderr are now unicode file-like objects,
     # not binary file-like objects like all of the other ports are.
     # FIXME: crbug.com/496983.
     return server_process.ServerProcess(port, server_name, cmd_line, env,
                                         universal_newlines=True, treat_no_data_as_crash=True, more_logging=more_logging)
Ejemplo n.º 6
0
 def _android_server_process_constructor(port,
                                         server_name,
                                         cmd_line,
                                         env=None):
     return server_process.ServerProcess(port,
                                         server_name,
                                         cmd_line,
                                         env,
                                         universal_newlines=True,
                                         treat_no_data_as_crash=True)
Ejemplo n.º 7
0
 def start(self):
     command = []
     # FIXME: We should not be grabbing at self._port._options.wrapper directly.
     command += self._command_wrapper(self._port._options.wrapper)
     command += [self._port._path_to_driver(), '-']
     if self._image_path:
         command.append('--pixel-tests')
     environment = os.environ
     environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
     self._server_process = server_process.ServerProcess(
         self._port, "DumpRenderTree", command, environment)
Ejemplo n.º 8
0
 def _android_server_process_constructor(port,
                                         server_name,
                                         cmd_line,
                                         env=None,
                                         more_logging=False):
     return server_process.ServerProcess(port,
                                         server_name,
                                         cmd_line,
                                         env,
                                         treat_no_data_as_crash=True,
                                         more_logging=more_logging)
Ejemplo n.º 9
0
 def _start(self, pixel_tests, per_test_args):
     server_name = self._port.driver_name()
     environment = self._port.setup_environ_for_server(server_name)
     environment['DYLD_LIBRARY_PATH'] = self._port._build_path()
     environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
     # FIXME: We're assuming that WebKitTestRunner checks this DumpRenderTree-named environment variable.
     environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
     environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
     self._crashed_process_name = None
     self._crashed_pid = None
     self._server_process = server_process.ServerProcess(
         self._port, server_name, self.cmd_line(pixel_tests, per_test_args),
         environment)
Ejemplo n.º 10
0
    def _diff_image_request(self, expected_filename, actual_filename, tolerance):
        command = [self._path_to_image_diff(), '--tolerance', str(tolerance)]
        sp = server_process.ServerProcess(self, 'ImageDiff', command)

        actual_length = os.stat(actual_filename).st_size
        with open(actual_filename) as file:
            actual_file = file.read()
        expected_length = os.stat(expected_filename).st_size
        with open(expected_filename) as file:
            expected_file = file.read()
        sp.write('Content-Length: %d\n%sContent-Length: %d\n%s' %
                 (actual_length, actual_file, expected_length, expected_file))

        return sp
Ejemplo n.º 11
0
    def _start_image_diff_process(self, expected_contents, actual_contents):
        # FIXME: There needs to be a more sane way of handling default
        # values for options so that you can distinguish between a default
        # value of None and a default value that wasn't set.
        if self.get_option('tolerance') is not None:
            tolerance = self.get_option('tolerance')
        else:
            tolerance = 0.1
        command = [self._path_to_image_diff(), '--tolerance', str(tolerance)]
        process = server_process.ServerProcess(self, 'ImageDiff', command)

        process.write('Content-Length: %d\n%sContent-Length: %d\n%s' %
                      (len(actual_contents), actual_contents,
                       len(expected_contents), expected_contents))
        return process
Ejemplo n.º 12
0
 def start(self):
     display_id = self._worker_number + 1
     run_xvfb = [
         "Xvfb",
         ":%d" % (display_id), "-screen", "0", "800x600x24", "-nolisten",
         "tcp"
     ]
     devnull = open(os.devnull, 'w')
     self._xvfb_process = subprocess.Popen(run_xvfb, stderr=devnull)
     devnull.close()
     server_name = self._port.driver_name()
     environment = self._port.setup_environ_for_server(server_name)
     # We must do this here because the DISPLAY number depends on _worker_number
     environment['DISPLAY'] = ":%d" % (display_id)
     self._server_process = server_process.ServerProcess(
         self._port, server_name, self.cmd_line(), environment)
Ejemplo n.º 13
0
    def _diff_image_request(self, expected_filename, actual_filename):
        # FIXME: either expose the tolerance argument as a command-line
        # parameter, or make it go away and aways use exact matches.
        command = [self._path_to_image_diff(), '--tolerance', '0.1']
        sp = server_process.ServerProcess(self, 'ImageDiff', command)

        actual_length = os.stat(actual_filename).st_size
        with open(actual_filename) as file:
            actual_file = file.read()
        expected_length = os.stat(expected_filename).st_size
        with open(expected_filename) as file:
            expected_file = file.read()
        sp.write('Content-Length: %d\n%sContent-Length: %d\n%s' %
                 (actual_length, actual_file, expected_length, expected_file))

        return sp
Ejemplo n.º 14
0
 def start(self):
     environment = self._port.setup_environ_for_server()
     environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
     environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
     self._server_process = server_process.ServerProcess(self._port,
         "DumpRenderTree", self.cmd_line(), environment)
Ejemplo n.º 15
0
    def _start_once(self, pixel_tests, per_test_args):
        super(ChromiumAndroidDriver, self)._start(pixel_tests, per_test_args)

        self._port._run_adb_command(['logcat', '-c'])
        self._port._run_adb_command(
            ['shell', 'echo'] +
            self._drt_cmd_line(pixel_tests, per_test_args) +
            ['>', COMMAND_LINE_FILE])
        start_result = self._port._run_adb_command([
            'shell', 'am', 'start', '-e', 'RunInSubThread', '-n',
            DRT_ACTIVITY_FULL_NAME
        ])
        if start_result.find('Exception') != -1:
            _log.error(
                'Failed to start DumpRenderTree application. Exception:\n' +
                start_result)
            return False

        seconds = 0
        while (not self._file_exists_on_device(self._in_fifo_path)
               or not self._file_exists_on_device(self._out_fifo_path)
               or not self._file_exists_on_device(self._err_fifo_path)):
            time.sleep(1)
            seconds += 1
            if seconds >= DRT_START_STOP_TIMEOUT_SECS:
                return False

        # Read back the shell prompt to ensure adb shell ready.
        deadline = time.time() + DRT_START_STOP_TIMEOUT_SECS
        self._server_process.start()
        self._read_prompt(deadline)
        _log.debug('Interactive shell started')

        # Start a process to read from the stdout fifo of the DumpRenderTree app and print to stdout.
        _log.debug('Redirecting stdout to ' + self._out_fifo_path)
        self._read_stdout_process = server_process.ServerProcess(
            self._port,
            'ReadStdout',
            self._port._adb_command + ['shell', 'cat', self._out_fifo_path],
            universal_newlines=True)
        self._read_stdout_process.start()

        # Start a process to read from the stderr fifo of the DumpRenderTree app and print to stdout.
        _log.debug('Redirecting stderr to ' + self._err_fifo_path)
        self._read_stderr_process = server_process.ServerProcess(
            self._port,
            'ReadStderr',
            self._port._adb_command + ['shell', 'cat', self._err_fifo_path],
            universal_newlines=True)
        self._read_stderr_process.start()

        _log.debug('Redirecting stdin to ' + self._in_fifo_path)
        self._server_process.write('cat >%s\n' % self._in_fifo_path)

        # Combine the stdout and stderr pipes into self._server_process.
        self._server_process.replace_outputs(
            self._read_stdout_process._proc.stdout,
            self._read_stderr_process._proc.stdout)

        # Start a thread to kill the pipe reading/writing processes on deadlock of the fifos during startup.
        normal_startup_event = threading.Event()
        threading.Thread(target=self._deadlock_detector,
                         args=([
                             self._server_process, self._read_stdout_process,
                             self._read_stderr_process
                         ], normal_startup_event)).start()

        output = ''
        line = self._server_process.read_stdout_line(deadline)
        while not self._server_process.timed_out and not self.has_crashed(
        ) and line.rstrip() != '#READY':
            output += line
            line = self._server_process.read_stdout_line(deadline)

        if self._server_process.timed_out and not self.has_crashed():
            # DumpRenderTree crashes during startup, or when the deadlock detector detected
            # deadlock and killed the fifo reading/writing processes.
            _log.error('Failed to start DumpRenderTree: \n%s' % output)
            return False
        else:
            # Inform the deadlock detector that the startup is successful without deadlock.
            normal_startup_event.set()
            return True