NRWT's HTTP servers should support additional directories for resources
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Feb 2012 22:39:57 +0000 (22:39 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Feb 2012 22:39:57 +0000 (22:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78528

Reviewed by Eric Seidel.

This functionality will be used by the Chromium-Android port.

* Scripts/webkitpy/layout_tests/port/base.py:
(Port.to.start_http_server):
* Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
(LayoutTestApacheHttpd.__init__):
* Scripts/webkitpy/layout_tests/servers/http_server.py:
(Lighttpd.__init__):
(Lighttpd._prepare_config):

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

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/executive_mock.py
Tools/Scripts/webkitpy/layout_tests/port/base.py
Tools/Scripts/webkitpy/layout_tests/port/test.py
Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py
Tools/Scripts/webkitpy/layout_tests/servers/http_server.py
Tools/Scripts/webkitpy/layout_tests/servers/http_server_unittest.py [new file with mode: 0644]

index de4e931..b467680 100644 (file)
@@ -1,3 +1,20 @@
+2012-02-13  Adam Barth  <abarth@webkit.org>
+
+        NRWT's HTTP servers should support additional directories for resources
+        https://bugs.webkit.org/show_bug.cgi?id=78528
+
+        Reviewed by Eric Seidel.
+
+        This functionality will be used by the Chromium-Android port.
+
+        * Scripts/webkitpy/layout_tests/port/base.py:
+        (Port.to.start_http_server):
+        * Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
+        (LayoutTestApacheHttpd.__init__):
+        * Scripts/webkitpy/layout_tests/servers/http_server.py:
+        (Lighttpd.__init__):
+        (Lighttpd._prepare_config):
+
 2012-02-13  Ami Fischman  <fischman@chromium.org>
 
         Add fischman as committer.
index f698235..9ed5048 100644 (file)
@@ -32,8 +32,16 @@ from webkitpy.common.system.deprecated_logging import log
 from webkitpy.common.system.executive import ScriptError
 
 
+class MockProcess(object):
+    def __init__(self):
+        self.pid = 42
+
+
 # FIXME: This should be unified with MockExecutive2
 class MockExecutive(object):
+    PIPE = "MOCK PIPE"
+    STDOUT = "MOCK STDOUT"
+
     @staticmethod
     def ignore_error(error):
         pass
@@ -81,6 +89,10 @@ class MockExecutive(object):
     def cpu_count(self):
         return 2
 
+    def popen(self, *args, **kwargs):
+        # FIXME: Implement logging when self._should_log is set.
+        return MockProcess()
+
 
 class MockExecutive2(object):
     @staticmethod
index 6c40d05..69dd5b5 100755 (executable)
@@ -750,16 +750,16 @@ class Port(object):
         method."""
         pass
 
-    def start_http_server(self):
+    def start_http_server(self, additional_dirs=None):
         """Start a web server. Raise an error if it can't start or is already running.
 
         Ports can stub this out if they don't need a web server to be running."""
         assert not self._http_server, 'Already running an http server.'
 
         if self._uses_apache():
-            server = apache_http_server.LayoutTestApacheHttpd(self, self.results_directory())
+            server = apache_http_server.LayoutTestApacheHttpd(self, self.results_directory(), additional_dirs=additional_dirs)
         else:
-            server = http_server.Lighttpd(self, self.results_directory())
+            server = http_server.Lighttpd(self, self.results_directory(), additional_dirs=additional_dirs)
 
         server.start()
         self._http_server = server
index 6535efd..b3aecfd 100644 (file)
@@ -428,6 +428,15 @@ class TestPort(Port):
     def release_http_lock(self):
         pass
 
+    def _path_to_lighttpd(self):
+        return "/usr/sbin/lighttpd"
+
+    def _path_to_lighttpd_modules(self):
+        return "/usr/lib/lighttpd"
+
+    def _path_to_lighttpd_php(self):
+        return "/usr/bin/php-cgi"
+
     def path_to_test_expectations_file(self):
         return self._expectations_path
 
index 4f6f980..a09aa33 100644 (file)
@@ -43,7 +43,7 @@ _log = logging.getLogger(__name__)
 
 class LayoutTestApacheHttpd(http_server_base.HttpServerBase):
 
-    def __init__(self, port_obj, output_dir):
+    def __init__(self, port_obj, output_dir, additional_dirs=None):
         """Args:
           port_obj: handle to the platform-specific routines
           output_dir: the absolute path to the layout test result directory
@@ -87,6 +87,14 @@ class LayoutTestApacheHttpd(http_server_base.HttpServerBase):
             '-c', "\'PidFile %s'" % self._pid_file,
             '-k', "start"]
 
+        if additional_dirs:
+            for alias, path in additional_dirs.iteritems():
+                start_cmd += ['-c', "\'Alias %s \"%s\"\'" % (alias, path),
+                        # Disable CGI handler for additional dirs.
+                        '-c', "\'<Location %s>\'" % alias,
+                        '-c', "\'RemoveHandler .cgi .pl\'",
+                        '-c', "\'</Location>\'"]
+
         stop_cmd = [executable,
             '-f', "\"%s\"" % self._get_apache_config_file_path(test_dir, output_dir),
             '-c', "\'PidFile %s'" % self._pid_file,
index 701e7bd..1f14e0d 100755 (executable)
@@ -43,7 +43,8 @@ _log = logging.getLogger(__name__)
 class Lighttpd(http_server_base.HttpServerBase):
 
     def __init__(self, port_obj, output_dir, background=False, port=None,
-                 root=None, run_background=None, layout_tests_dir=None):
+                 root=None, run_background=None, additional_dirs=None,
+                 layout_tests_dir=None):
         """Args:
           output_dir: the absolute path to the layout test result directory
         """
@@ -54,6 +55,7 @@ class Lighttpd(http_server_base.HttpServerBase):
         self._port = port
         self._root = root
         self._run_background = run_background
+        self._additional_dirs = additional_dirs
         self._layout_tests_dir = layout_tests_dir
 
         self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % self._name)
@@ -124,6 +126,10 @@ class Lighttpd(http_server_base.HttpServerBase):
         f.write(('alias.url = ( "/js-test-resources" => "%s" )\n\n') %
                     (self._js_test_resource))
 
+        if self._additional_dirs:
+            for alias, path in self._additional_dirs.iteritems():
+                f.write(('alias.url += ( "%s" => "%s" )\n\n') % (alias, path))
+
         # Setup a link to where the media resources are stored.
         f.write(('alias.url += ( "/media-resources" => "%s" )\n\n') %
                     (self._media_resource))
@@ -189,7 +195,7 @@ class Lighttpd(http_server_base.HttpServerBase):
             try:
                 self._remove_log_files(self._output_dir, log_prefix)
             except OSError, e:
-                _log.warning('Failed to remove old %s %s files' % self._name, log_prefix)
+                _log.warning('Failed to remove old %s %s files' % (self._name, log_prefix))
 
     def _spawn_process(self):
         _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd))
diff --git a/Tools/Scripts/webkitpy/layout_tests/servers/http_server_unittest.py b/Tools/Scripts/webkitpy/layout_tests/servers/http_server_unittest.py
new file mode 100644 (file)
index 0000000..a037a37
--- /dev/null
@@ -0,0 +1,59 @@
+# Copyright (C) 2012 Google Inc. All rights reserved.
+#
+# 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 name of Google Inc. 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 unittest
+import re
+
+from webkitpy.common.host_mock import MockHost
+from webkitpy.layout_tests.port import test
+from webkitpy.layout_tests.servers.http_server import Lighttpd
+from webkitpy.layout_tests.servers.http_server_base import ServerError
+
+
+class TestHttpServer(unittest.TestCase):
+    def test_start_cmd(self):
+        host = MockHost()
+        test_port = test.TestPort(host)
+        host.filesystem.write_text_file(
+            "/mock-checkout/Tools/Scripts/webkitpy/layout_tests/servers/lighttpd.conf", "Mock Config\n")
+        host.filesystem.write_text_file(
+            "/usr/lib/lighttpd/liblightcomp.dylib", "Mock dylib")
+
+        server = Lighttpd(test_port, "/mock/output_dir",
+                          additional_dirs={
+                              "/mock/one-additional-dir": "/mock-checkout/one-additional-dir",
+                              "/mock/another-additional-dir": "/mock-checkout/one-additional-dir"})
+        self.assertRaises(ServerError, server.start)
+
+        config_file = host.filesystem.read_text_file("/mock/output_dir/lighttpd.conf")
+        self.assertEquals(re.findall(r"alias.url.+", config_file), [
+            'alias.url = ( "/js-test-resources" => "/test.checkout/LayoutTests/fast/js/resources" )',
+            'alias.url += ( "/mock/one-additional-dir" => "/mock-checkout/one-additional-dir" )',
+            'alias.url += ( "/mock/another-additional-dir" => "/mock-checkout/one-additional-dir" )',
+            'alias.url += ( "/media-resources" => "/test.checkout/LayoutTests/media" )',
+        ])