Title: [153439] trunk/Tools
Revision
153439
Author
zandober...@gmail.com
Date
2013-07-29 13:09:26 -0700 (Mon, 29 Jul 2013)

Log Message

[GTK] Add WestonDriver, use it when appropriate
https://bugs.webkit.org/show_bug.cgi?id=119100

Reviewed by Dirk Pranke.

Introduce the WestonDriver, a Driver-implementing class that sets up an instance of Weston, the Wayland compositor,
and sets up an environment that enables the test runner to run inside it.

The design very much mimics the XvfbDriver class. It is currently used by the GTK port when the WAYLAND_DISPLAY
environment variable is set, that is when NRWT is being run under a Wayland display.

* Scripts/webkitpy/port/base.py:
(Port.to.setup_environ_for_server): Also copy the XDG_RUNTIME_DIR env from the original environment for Linux-using ports.
* Scripts/webkitpy/port/gtk.py:
(GtkPort):
(GtkPort._driver_class): Make the method memoized - the display type is not going to change during the testing, so we
should only check once for the presence of the WAYLAND_DISPLAY env and determine the proper driver class to use based on that.
(GtkPort.check_sys_deps): Call the static check_driver method on the class as returned by the _driver_class method
instead of hard-coding the XvfbDriver class in the check.
* Scripts/webkitpy/port/westondriver.py: Added.
(WestonDriver):
(WestonDriver.check_driver): Similarly to XvfbDriver, this checks for existance of the weston executable.
(WestonDriver.__init__): Again, like in XvfbDriver, we use a small delay between launching the Weston display and launching the driver.
(WestonDriver._start): Sets up the driver-specific temporary directory, launches the Weston display, sets up the environment for the
driver and then launches the driver in said environment, using the driver's Weston display.
(WestonDriver.stop): Cleans up the Weston instance and the temporary directory.
(WestonDriver._ensure_driver_tmpdir_subdirectory): A helper function that creates a subdirectory in the driver's temporary directory
and returns the absolute path to it.
* Scripts/webkitpy/port/xvfbdriver.py:
(XvfbDriver.check_driver): Renamed from check_xvfb.
(XvfbDriver._start): Access the FileSystem object through the Port's Host object, instead of the Port's private member.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (153438 => 153439)


--- trunk/Tools/ChangeLog	2013-07-29 19:25:17 UTC (rev 153438)
+++ trunk/Tools/ChangeLog	2013-07-29 20:09:26 UTC (rev 153439)
@@ -1,3 +1,37 @@
+2013-07-29  Zan Dobersek  <zdober...@igalia.com>
+
+        [GTK] Add WestonDriver, use it when appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=119100
+
+        Reviewed by Dirk Pranke.
+
+        Introduce the WestonDriver, a Driver-implementing class that sets up an instance of Weston, the Wayland compositor,
+        and sets up an environment that enables the test runner to run inside it.
+
+        The design very much mimics the XvfbDriver class. It is currently used by the GTK port when the WAYLAND_DISPLAY
+        environment variable is set, that is when NRWT is being run under a Wayland display.
+
+        * Scripts/webkitpy/port/base.py:
+        (Port.to.setup_environ_for_server): Also copy the XDG_RUNTIME_DIR env from the original environment for Linux-using ports.
+        * Scripts/webkitpy/port/gtk.py:
+        (GtkPort):
+        (GtkPort._driver_class): Make the method memoized - the display type is not going to change during the testing, so we
+        should only check once for the presence of the WAYLAND_DISPLAY env and determine the proper driver class to use based on that.
+        (GtkPort.check_sys_deps): Call the static check_driver method on the class as returned by the _driver_class method
+        instead of hard-coding the XvfbDriver class in the check.
+        * Scripts/webkitpy/port/westondriver.py: Added.
+        (WestonDriver):
+        (WestonDriver.check_driver): Similarly to XvfbDriver, this checks for existance of the weston executable.
+        (WestonDriver.__init__): Again, like in XvfbDriver, we use a small delay between launching the Weston display and launching the driver.
+        (WestonDriver._start): Sets up the driver-specific temporary directory, launches the Weston display, sets up the environment for the
+        driver and then launches the driver in said environment, using the driver's Weston display.
+        (WestonDriver.stop): Cleans up the Weston instance and the temporary directory.
+        (WestonDriver._ensure_driver_tmpdir_subdirectory): A helper function that creates a subdirectory in the driver's temporary directory
+        and returns the absolute path to it.
+        * Scripts/webkitpy/port/xvfbdriver.py:
+        (XvfbDriver.check_driver): Renamed from check_xvfb.
+        (XvfbDriver._start): Access the FileSystem object through the Port's Host object, instead of the Port's private member.
+
 2013-07-29  Mario Sanchez Prada  <mario.pr...@samsung.com>
 
         [ATK] Implement attributesOfChildren() for AccessibilityUIElement

Modified: trunk/Tools/Scripts/webkitpy/port/base.py (153438 => 153439)


--- trunk/Tools/Scripts/webkitpy/port/base.py	2013-07-29 19:25:17 UTC (rev 153438)
+++ trunk/Tools/Scripts/webkitpy/port/base.py	2013-07-29 20:09:26 UTC (rev 153439)
@@ -881,6 +881,7 @@
             'LD_LIBRARY_PATH',
             'DBUS_SESSION_BUS_ADDRESS',
             'XDG_DATA_DIRS',
+            'XDG_RUNTIME_DIR',
 
             # Darwin:
             'DYLD_LIBRARY_PATH',

Modified: trunk/Tools/Scripts/webkitpy/port/gtk.py (153438 => 153439)


--- trunk/Tools/Scripts/webkitpy/port/gtk.py	2013-07-29 19:25:17 UTC (rev 153438)
+++ trunk/Tools/Scripts/webkitpy/port/gtk.py	2013-07-29 20:09:26 UTC (rev 153439)
@@ -29,10 +29,12 @@
 import os
 import subprocess
 
+from webkitpy.common.memoized import memoized
 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
 from webkitpy.port.base import Port
 from webkitpy.port.pulseaudio_sanitizer import PulseAudioSanitizer
 from webkitpy.port.xvfbdriver import XvfbDriver
+from webkitpy.port.westondriver import WestonDriver
 
 
 class GtkPort(Port):
@@ -48,7 +50,10 @@
     def _port_flag_for_scripts(self):
         return "--gtk"
 
+    @memoized
     def _driver_class(self):
+        if os.environ.get("WAYLAND_DISPLAY"):
+            return WestonDriver
         return XvfbDriver
 
     def default_timeout_ms(self):
@@ -128,7 +133,7 @@
         self._run_script("run-launcher", run_launcher_args)
 
     def check_sys_deps(self, needs_http):
-        return super(GtkPort, self).check_sys_deps(needs_http) and XvfbDriver.check_xvfb(self)
+        return super(GtkPort, self).check_sys_deps(needs_http) and self._driver_class().check_driver(self)
 
     def _get_gdb_output(self, coredump_path):
         cmd = ['gdb', '-ex', 'thread apply all bt 1024', '--batch', str(self._path_to_driver()), coredump_path]

Added: trunk/Tools/Scripts/webkitpy/port/westondriver.py (0 => 153439)


--- trunk/Tools/Scripts/webkitpy/port/westondriver.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/port/westondriver.py	2013-07-29 20:09:26 UTC (rev 153439)
@@ -0,0 +1,97 @@
+# Copyright (C) 2013 Zan Dobersek <zandober...@gmail.com>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the Google name nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+import os
+import random
+import time
+
+from webkitpy.port.server_process import ServerProcess
+from webkitpy.port.driver import Driver
+
+_log = logging.getLogger(__name__)
+
+
+class WestonDriver(Driver):
+    @staticmethod
+    def check_driver(port):
+        weston_found = port.host.executive.run_command(['which', 'weston'], return_exit_code=True) is 0
+        if not weston_found:
+            _log.error("No weston found. Cannot run layout tests.")
+        return weston_found
+
+    def __init__(self, *args, **kwargs):
+        Driver.__init__(self, *args, **kwargs)
+        self._startup_delay_secs = 1.0
+
+    def _start(self, pixel_tests, per_test_args):
+        self.stop()
+
+        driver_name = self._port.driver_name()
+        self._driver_directory = self._port.host.filesystem.mkdtemp(prefix='%s-' % driver_name)
+
+        weston_socket = 'WKTesting-weston-%032x' % random.getrandbits(128)
+        weston_command = ['weston', '--socket=%s' % weston_socket, '--width=800', '--height=600']
+        with open(os.devnull, 'w') as devnull:
+            self._weston_process = self._port.host.executive.popen(weston_command, stderr=devnull)
+
+        # Give Weston a bit of time to set itself up.
+        time.sleep(self._startup_delay_secs)
+
+        driver_environment = self._port.setup_environ_for_server(driver_name)
+        driver_environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
+
+        # Currently on WebKit2, there is no API for setting the application cache directory.
+        # Each worker should have its own and it should be cleaned afterwards, when the worker stops.
+        driver_environment['XDG_CACHE_HOME'] = self._ensure_driver_tmpdir_subdirectory('appcache')
+        driver_environment['DUMPRENDERTREE_TEMP'] = self._ensure_driver_tmpdir_subdirectory('drt-temp')
+
+        driver_environment['WAYLAND_DISPLAY'] = weston_socket
+        driver_environment['GDK_BACKEND'] = 'wayland'
+        if driver_environment.get('DISPLAY'):
+            del driver_environment['DISPLAY']
+
+        self._crashed_process_name = None
+        self._crashed_pid = None
+        self._server_process = self._port._server_process_constructor(self._port, driver_name, self.cmd_line(pixel_tests, per_test_args), driver_environment)
+        self._server_process.start()
+
+    def stop(self):
+        super(WestonDriver, self).stop()
+        if getattr(self, '_weston_process', None):
+            # The Weston process is terminated instead of killed, giving the Weston a chance to clean up after itself.
+            self._weston_process.terminate()
+            self._weston_process = None
+        if getattr(self, '_driver_directory', None):
+            self._port.host.filesystem.rmtree(str(self._driver_directory))
+
+    def _ensure_driver_tmpdir_subdirectory(self, subdirectory):
+        assert getattr(self, '_driver_directory', None)
+        directory_path = self._port.host.filesystem.join(str(self._driver_directory), subdirectory)
+        self._port.host.filesystem.maybe_make_directory(directory_path)
+        return directory_path

Modified: trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py (153438 => 153439)


--- trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py	2013-07-29 19:25:17 UTC (rev 153438)
+++ trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py	2013-07-29 20:09:26 UTC (rev 153439)
@@ -40,7 +40,7 @@
 
 class XvfbDriver(Driver):
     @staticmethod
-    def check_xvfb(port):
+    def check_driver(port):
         xvfb_found = port.host.executive.run_command(['which', 'Xvfb'], return_exit_code=True) is 0
         if not xvfb_found:
             _log.error("No Xvfb found. Cannot run layout tests.")
@@ -86,7 +86,7 @@
         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._driver_tempdir = self._port._filesystem.mkdtemp(prefix='%s-' % self._port.driver_name())
+        self._driver_tempdir = self._port.host.filesystem.mkdtemp(prefix='%s-' % self._port.driver_name())
         environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
         environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to