[GTK] run-gtk-tests should use webkitpy.port.gtk and webkitpy.port.xvfbdriver
authorclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2016 16:32:32 +0000 (16:32 +0000)
committerclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2016 16:32:32 +0000 (16:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160736

Reviewed by Carlos Garcia Campos.

This plugs run-gtk-tests into the webkitpy testing infrastructure.
As a benefit of this, run-gtk-tests now can be executed over any of
the existing supported gtk test display servers (xvfb, weston-over-xvfb,
or native xorg). A new command line switch --wayland is added for
run-gtk-tests.

* Scripts/run-gtk-tests:
(TestRunner.__init__): Remove the --display command line switch, its not longer useful.
Add a --wayland command line switch.
(TestRunner._start_accessibility_daemons):
(TestRunner):
(TestRunner.__init__):
(TestRunner._run_xvfb): Deleted.
(TestRunner._create_driver):
(TestRunner._setup_testing_environment): Delete the environment variable definitions that
are now done by driver._setup_environ_for_test().
(TestRunner._tear_down_testing_environment):
* Scripts/webkitpy/port/driver.py:
(Driver.__init__): Define self._server_name in the constructor of the base class.
It is used by several functions, so it makes sense to store once the value here.
(Driver._setup_environ_for_test): Factorize setting the environment for a given test.
(Driver._start): Get the environment from self._setup_environ_for_test()
* Scripts/webkitpy/port/driver_unittest.py:
(DriverTest):
(DriverTest.test_setup_environ_for_test): Add unittest for driver._setup_environ_for_test()
* Scripts/webkitpy/port/gtk.py: Move the inspection of the env var USE_NATIVE_XDISPLAY to the constructor.
(GtkPort.__init__):
(GtkPort._driver_class):
* Scripts/webkitpy/port/westondriver.py: Define and use self._setup_environ_for_test()
(WestonDriver._setup_environ_for_test):
(WestonDriver._start):
* Scripts/webkitpy/port/xorgdriver.py: Define and use self._setup_environ_for_test()
(XorgDriver._setup_environ_for_test):
(XorgDriver._start):
* Scripts/webkitpy/port/xvfbdriver.py: Define and use self._setup_environ_for_test()
(XvfbDriver._setup_environ_for_test):
(XvfbDriver._start):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205014 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/run-gtk-tests
Tools/Scripts/webkitpy/port/driver.py
Tools/Scripts/webkitpy/port/driver_unittest.py
Tools/Scripts/webkitpy/port/gtk.py
Tools/Scripts/webkitpy/port/westondriver.py
Tools/Scripts/webkitpy/port/xorgdriver.py
Tools/Scripts/webkitpy/port/xvfbdriver.py

index 992e0f2..59529fd 100644 (file)
@@ -1,3 +1,48 @@
+2016-08-26  Carlos Alberto Lopez Perez  <clopez@igalia.com>
+
+        [GTK] run-gtk-tests should use webkitpy.port.gtk and webkitpy.port.xvfbdriver
+        https://bugs.webkit.org/show_bug.cgi?id=160736
+
+        Reviewed by Carlos Garcia Campos.
+
+        This plugs run-gtk-tests into the webkitpy testing infrastructure.
+        As a benefit of this, run-gtk-tests now can be executed over any of
+        the existing supported gtk test display servers (xvfb, weston-over-xvfb,
+        or native xorg). A new command line switch --wayland is added for
+        run-gtk-tests.
+
+        * Scripts/run-gtk-tests:
+        (TestRunner.__init__): Remove the --display command line switch, its not longer useful.
+        Add a --wayland command line switch.
+        (TestRunner._start_accessibility_daemons):
+        (TestRunner):
+        (TestRunner.__init__):
+        (TestRunner._run_xvfb): Deleted.
+        (TestRunner._create_driver):
+        (TestRunner._setup_testing_environment): Delete the environment variable definitions that
+        are now done by driver._setup_environ_for_test().
+        (TestRunner._tear_down_testing_environment):
+        * Scripts/webkitpy/port/driver.py:
+        (Driver.__init__): Define self._server_name in the constructor of the base class.
+        It is used by several functions, so it makes sense to store once the value here.
+        (Driver._setup_environ_for_test): Factorize setting the environment for a given test.
+        (Driver._start): Get the environment from self._setup_environ_for_test()
+        * Scripts/webkitpy/port/driver_unittest.py:
+        (DriverTest):
+        (DriverTest.test_setup_environ_for_test): Add unittest for driver._setup_environ_for_test()
+        * Scripts/webkitpy/port/gtk.py: Move the inspection of the env var USE_NATIVE_XDISPLAY to the constructor.
+        (GtkPort.__init__):
+        (GtkPort._driver_class):
+        * Scripts/webkitpy/port/westondriver.py: Define and use self._setup_environ_for_test()
+        (WestonDriver._setup_environ_for_test):
+        (WestonDriver._start):
+        * Scripts/webkitpy/port/xorgdriver.py: Define and use self._setup_environ_for_test()
+        (XorgDriver._setup_environ_for_test):
+        (XorgDriver._start):
+        * Scripts/webkitpy/port/xvfbdriver.py: Define and use self._setup_environ_for_test()
+        (XvfbDriver._setup_environ_for_test):
+        (XvfbDriver._start):
+
 2016-08-26  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [EFL][GTK] REGRESSION(204877): Fix the clean build
index 0980736..b198c13 100755 (executable)
@@ -30,6 +30,7 @@ sys.path.append(os.path.join(top_level_directory, "Tools", "jhbuild"))
 sys.path.append(os.path.join(top_level_directory, "Tools", "gtk"))
 import common
 import jhbuildutils
+from webkitpy.common.host import Host
 
 class SkippedTest:
     ENTIRE_SUITE = None
@@ -97,6 +98,8 @@ class TestRunner:
 
         self._build_type = "Debug" if self._options.debug else "Release"
         common.set_build_types((self._build_type,))
+        self._port = Host().port_factory.get("gtk")
+        self._driver = self._create_driver()
 
         self._programs_path = common.binary_build_path()
         self._tests = self._get_tests(tests)
@@ -179,33 +182,21 @@ class TestRunner:
 
         return True
 
-    def _run_xvfb(self):
-        self._xvfb = None
-        if not self._options.use_xvfb:
-            return True
-
-        self._test_env["DISPLAY"] = self._options.display
-
-        try:
-            self._xvfb = subprocess.Popen(["Xvfb", self._options.display, "-screen", "0", "800x600x24", "-nolisten", "tcp"],
-                                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        except Exception as e:
-            sys.stderr.write("Failed to run Xvfb: %s\n" % e)
-            sys.stderr.flush()
-            return False
-
-        return True
+    def _create_driver(self, port_options=[]):
+        if self._options.use_wayland:
+            self._port._wayland = True
+        else:
+            self._port._nativexorg = not self._options.use_xvfb
+        driver = self._port.create_driver(worker_number=0, no_timeout=True)._make_driver(pixel_tests=False)
+        if not driver.check_driver(self._port):
+            raise RuntimeError("Failed to check driver %s" %driver.__class__.__name__)
+        return driver
 
     def _setup_testing_environment(self):
-        self._test_env = os.environ
-        self._test_env['GSETTINGS_BACKEND'] = 'memory'
+        self._test_env = self._driver._setup_environ_for_test()
         self._test_env["TEST_WEBKIT_API_WEBKIT2_RESOURCES_PATH"] = common.top_level_path("Tools", "TestWebKitAPI", "Tests", "WebKit2")
         self._test_env["TEST_WEBKIT_API_WEBKIT2_INJECTED_BUNDLE_PATH"] = common.library_build_path()
         self._test_env["WEBKIT_EXEC_PATH"] = self._programs_path
-        self._test_env["OWR_USE_TEST_SOURCES"] = '1'
-
-        if not self._run_xvfb():
-            return False
 
         # If we cannot start the accessibility daemons, we can just skip the accessibility tests.
         if not self._start_accessibility_daemons():
@@ -218,8 +209,8 @@ class TestRunner:
             self._spi_registryd.terminate()
         if self._spi_bus_launcher:
             self._spi_bus_launcher.terminate()
-        if self._xvfb:
-            self._xvfb.terminate()
+        if self._driver:
+            self._driver.stop()
 
     def _test_cases_to_skip(self, test_program):
         if self._options.skipped_action != 'skip':
@@ -462,8 +453,6 @@ if __name__ == "__main__":
     option_parser.add_option('-v', '--verbose',
                              action='store_true', dest='verbose',
                              help='Run gtester in verbose mode')
-    option_parser.add_option('--display', action='store', dest='display', default=':55',
-                             help='Display to run Xvfb')
     option_parser.add_option('--skipped', action='store', dest='skipped_action',
                              choices=['skip', 'ignore', 'only'], default='skip',
                              metavar='skip|ignore|only',
@@ -473,6 +462,9 @@ if __name__ == "__main__":
                              help='Time in seconds until a test times out')
     option_parser.add_option('--no-xvfb', action='store_false', dest='use_xvfb', default=True,
                              help='Do not run tests under Xvfb')
+    option_parser.add_option('--wayland', action='store_true', dest='use_wayland', default=False,
+                             help='Run the layout tests inside a (virtualized) weston')
     options, args = option_parser.parse_args()
 
-    sys.exit(TestRunner(options, args).run_tests())
+    runner = TestRunner(options, args)
+    sys.exit(runner.run_tests())
index a88a2f0..3b75a72 100644 (file)
@@ -154,6 +154,8 @@ class Driver(object):
         # instead scope these locally in run_test.
         self.error_from_test = str()
         self.err_seen_eof = False
+
+        self._server_name = self._port.driver_name()
         self._server_process = None
 
         self._measurements = {}
@@ -346,6 +348,11 @@ class Driver(object):
             environment = self._profiler.adjusted_environment(environment)
         return environment
 
+    def _setup_environ_for_test(self):
+        environment = self._port.setup_environ_for_server(self._server_name)
+        environment = self._setup_environ_for_driver(environment)
+        return environment
+
     def _start(self, pixel_tests, per_test_args):
         self.stop()
         # Each driver process should be using individual directories under _driver_tempdir (which is deleted when stopping),
@@ -357,12 +364,10 @@ class Driver(object):
         if user_cache_directory:
             self._port._filesystem.maybe_make_directory(user_cache_directory)
             self._driver_user_cache_directory = user_cache_directory
-        server_name = self._port.driver_name()
-        environment = self._port.setup_environ_for_server(server_name)
-        environment = self._setup_environ_for_driver(environment)
+        environment = self._setup_environ_for_test()
         self._crashed_process_name = None
         self._crashed_pid = None
-        self._server_process = self._port._server_process_constructor(self._port, server_name, self.cmd_line(pixel_tests, per_test_args), environment)
+        self._server_process = self._port._server_process_constructor(self._port, self._server_name, self.cmd_line(pixel_tests, per_test_args), environment)
         self._server_process.start()
 
     def _run_post_start_tasks(self):
index 3ff0017..625055f 100644 (file)
@@ -32,6 +32,7 @@ from webkitpy.common.system.systemhost_mock import MockSystemHost
 
 from webkitpy.port import Port, Driver, DriverOutput
 from webkitpy.port.server_process_mock import MockServerProcess
+from webkitpy.thirdparty.mock import patch
 
 # FIXME: remove the dependency on TestWebKitPort
 from webkitpy.port.port_testcase import TestWebKitPort
@@ -311,3 +312,15 @@ class DriverTest(unittest.TestCase):
         environment[variable] = base_value
         driver._append_environment_variable_path(environment, variable, path)
         self.assertEqual(environment[variable], base_value + os.pathsep + path)
+
+    def test_setup_environ_for_test(self):
+        environment_user = {}
+        environment_user['WEBKIT_OUTPUTDIR'] = '/opt/webkit/WebKitBuild/Release'
+        environment_user['FOO'] = 'BAR'
+        with patch('os.environ', environment_user):
+            port = self.make_port()
+            driver = Driver(port, None, pixel_tests=False)
+            environment_driver_test = driver._setup_environ_for_test()
+            self.assertNotIn('FOO', environment_driver_test)
+            self.assertIn('WEBKIT_OUTPUTDIR', environment_driver_test)
+            self.assertEqual(environment_user['WEBKIT_OUTPUTDIR'], environment_driver_test['WEBKIT_OUTPUTDIR'])
index 3d80a0b..c8a96a7 100644 (file)
@@ -53,6 +53,9 @@ class GtkPort(Port):
         super(GtkPort, self).__init__(*args, **kwargs)
         self._pulseaudio_sanitizer = PulseAudioSanitizer()
         self._wayland = self.get_option("wayland")
+        self._nativexorg = False
+        if os.environ.get("USE_NATIVE_XDISPLAY"):
+            self._nativexorg = True
 
         if self.get_option("leaks"):
             self._leakdetector = LeakDetectorValgrind(self._executive, self._filesystem, self.results_directory())
@@ -79,7 +82,7 @@ class GtkPort(Port):
     def _driver_class(self):
         if self._wayland:
             return WestonDriver
-        if os.environ.get("USE_NATIVE_XDISPLAY"):
+        if self._nativexorg:
             return XorgDriver
         return XvfbDriver
 
index ed81a50..168496c 100644 (file)
@@ -54,16 +54,10 @@ class WestonDriver(Driver):
         self._startup_delay_secs = 1.0
         self._xvfbdriver = XvfbDriver(*args, **kwargs)
 
-    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)
-
-        driver_environment = self._port.setup_environ_for_server(driver_name)
+    def _setup_environ_for_test(self):
+        self._driver_directory = self._port.host.filesystem.mkdtemp(prefix='%s-' % self._server_name)
+        driver_environment = self._port.setup_environ_for_server(self._server_name)
         driver_environment['DISPLAY'] = ":%d" % self._xvfbdriver._xvfb_run(driver_environment)
-
         weston_socket = 'WKTesting-weston-%032x' % random.getrandbits(128)
         weston_command = ['weston', '--socket=%s' % weston_socket, '--width=1024', '--height=768', '--use-pixman']
         if self._port._should_use_jhbuild():
@@ -75,20 +69,21 @@ class WestonDriver(Driver):
         time.sleep(self._startup_delay_secs)
 
         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']
+        return driver_environment
 
+    def _start(self, pixel_tests, per_test_args):
+        self.stop()
         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 = self._port._server_process_constructor(self._port, self._server_name, self.cmd_line(pixel_tests, per_test_args), self._setup_environ_for_test())
         self._server_process.start()
 
     def stop(self):
index 5a46240..ffc3f1b 100644 (file)
@@ -44,15 +44,10 @@ class XorgDriver(Driver):
                 return False
         return True
 
-    def _start(self, pixel_tests, per_test_args):
-        super(XorgDriver, self).stop()
-
-        server_name = self._port.driver_name()
-        self._driver_tempdir = self._port.host.filesystem.mkdtemp(prefix='%s-' % server_name)
-
+    def _setup_environ_for_test(self):
         # setup_environ_for_server() already takes care of copying the
         # XAUTHORITY environment variable
-        server_environment = self._port.setup_environ_for_server(server_name)
+        server_environment = self._port.setup_environ_for_server(self._server_name)
         server_environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
         server_environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
         # Currently on WebKit2, there is no API for setting the application
@@ -60,8 +55,14 @@ class XorgDriver(Driver):
         # cleaned afterwards, so we set it to inside the temporary folder by
         # prepending XDG_CACHE_HOME with DUMPRENDERTREE_TEMP.
         server_environment['XDG_CACHE_HOME'] = self._port.host.filesystem.join(str(self._driver_tempdir), 'appcache')
+        return server_environment
+
+    def _start(self, pixel_tests, per_test_args):
+        super(XorgDriver, self).stop()
+
+        self._driver_tempdir = self._port.host.filesystem.mkdtemp(prefix='%s-' % self._server_name)
 
         self._crashed_process_name = None
         self._crashed_pid = None
-        self._server_process = self._port._server_process_constructor(self._port, server_name, self.cmd_line(pixel_tests, per_test_args), server_environment)
+        self._server_process = self._port._server_process_constructor(self._port, self._server_name, self.cmd_line(pixel_tests, per_test_args), self._setup_environ_for_test())
         self._server_process.start()
index e7fdbed..4072639 100644 (file)
@@ -92,16 +92,13 @@ class XvfbDriver(Driver):
     def _xvfb_screen_depth(self):
         return os.environ.get('XVFB_SCREEN_DEPTH', '24')
 
-    def _start(self, pixel_tests, per_test_args):
-        self.stop()
-
-        server_name = self._port.driver_name()
-        environment = self._port.setup_environ_for_server(server_name)
+    def _setup_environ_for_test(self):
+        environment = self._port.setup_environ_for_server(self._server_name)
         display_id = self._xvfb_run(environment)
 
         # We must do this here because the DISPLAY number depends on _worker_number
         environment['DISPLAY'] = ":%d" % display_id
-        self._driver_tempdir = self._port.host.filesystem.mkdtemp(prefix='%s-' % self._port.driver_name())
+        self._driver_tempdir = self._port.host.filesystem.mkdtemp(prefix='%s-' % self._server_name)
         environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
         environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
 
@@ -110,10 +107,13 @@ class XvfbDriver(Driver):
         # cleaned afterwards, so we set it to inside the temporary folder by
         # prepending XDG_CACHE_HOME with DUMPRENDERTREE_TEMP.
         environment['XDG_CACHE_HOME'] = self._port.host.filesystem.join(str(self._driver_tempdir), 'appcache')
+        return environment
 
+    def _start(self, pixel_tests, per_test_args):
+        self.stop()
         self._crashed_process_name = None
         self._crashed_pid = None
-        self._server_process = self._port._server_process_constructor(self._port, server_name, self.cmd_line(pixel_tests, per_test_args), environment)
+        self._server_process = self._port._server_process_constructor(self._port, self._server_name, self.cmd_line(pixel_tests, per_test_args), self._setup_environ_for_test())
         self._server_process.start()
 
     def stop(self):