2010-11-12 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Nov 2010 02:00:51 +0000 (02:00 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Nov 2010 02:00:51 +0000 (02:00 +0000)
        Reviewed by James Robinson.

        Attempt yet again to land the fix for bug 49360 (respecting
        set-webkit-configuration). We need to handle the cases where
        trying to run webkit-build-directory to find out where the
        default configuration might be fails (that shows up on some
        Chromium bots that apparently don't have perl installed).

        https://bugs.webkit.org/show_bug.cgi?id=49360

        * Scripts/webkitpy/layout_tests/port/config.py:
        * Scripts/webkitpy/layout_tests/port/config_standalone.py: Added.
        * Scripts/webkitpy/layout_tests/port/config_unittest.py:

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

WebKitTools/ChangeLog
WebKitTools/Scripts/webkitpy/layout_tests/port/config.py
WebKitTools/Scripts/webkitpy/layout_tests/port/config_standalone.py [new file with mode: 0644]
WebKitTools/Scripts/webkitpy/layout_tests/port/config_unittest.py

index f9e5641707fd09dd96f33a3675b96e3d4a282bc4..60cb2e64823baf7b7bf8bd60d34e24df4bac2de2 100644 (file)
@@ -1,3 +1,19 @@
+2010-11-12  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by James Robinson.
+
+        Attempt yet again to land the fix for bug 49360 (respecting
+        set-webkit-configuration). We need to handle the cases where
+        trying to run webkit-build-directory to find out where the
+        default configuration might be fails (that shows up on some
+        Chromium bots that apparently don't have perl installed).
+
+        https://bugs.webkit.org/show_bug.cgi?id=49360
+
+        * Scripts/webkitpy/layout_tests/port/config.py:
+        * Scripts/webkitpy/layout_tests/port/config_standalone.py: Added.
+        * Scripts/webkitpy/layout_tests/port/config_unittest.py:
+
 2010-11-12  Mihai Parparita  <mihaip@chromium.org>
 
         Reviewed by Adam Barth.
index 4a0de96346ab4cab8706cdf79ce25b1d17e582fb..cad5e370027ea244184c132eab079f0f51d4484b 100644 (file)
 import os
 
 from webkitpy.common.system import logutils
+from webkitpy.common.system import executive
 
 
 _log = logutils.get_logger(__file__)
 
 #
-# This is used to record if we've already hit the filesystem to look
+# FIXME: This is used to record if we've already hit the filesystem to look
 # for a default configuration. We cache this to speed up the unit tests,
-# but this can be reset with clear_cached_configuration().
+# but this can be reset with clear_cached_configuration(). This should be
+# replaced with us consistently using MockConfigs() for tests that don't
+# hit the filesystem at all and provide a reliable value.
 #
-_determined_configuration = None
+_have_determined_configuration = False
+_configuration = "Release"
 
 
 def clear_cached_configuration():
-    global _determined_configuration
-    _determined_configuration = -1
+    global _have_determined_configuration, _configuration
+    _have_determined_configuration = False
+    _configuration = "Release"
 
 
 class Config(object):
@@ -137,8 +142,11 @@ class Config(object):
 
     def _determine_configuration(self):
         # This mirrors the logic in webkitdirs.pm:determineConfiguration().
-        global _determined_configuration
-        if _determined_configuration == -1:
+        #
+        # FIXME: See the comment at the top of the file regarding unit tests
+        # and our use of global mutable static variables.
+        global _have_determined_configuration, _configuration
+        if not _have_determined_configuration:
             contents = self._read_configuration()
             if not contents:
                 contents = "Release"
@@ -146,13 +154,17 @@ class Config(object):
                 contents = "Release"
             if contents == "Development":
                 contents = "Debug"
-            _determined_configuration = contents
-        return _determined_configuration
+            _configuration = contents
+            _have_determined_configuration = True
+        return _configuration
 
     def _read_configuration(self):
-        configuration_path = self._filesystem.join(self.build_directory(None),
-                                                   "Configuration")
-        if not self._filesystem.exists(configuration_path):
+        try:
+            configuration_path = self._filesystem.join(self.build_directory(None),
+                                                       "Configuration")
+            if not self._filesystem.exists(configuration_path):
+                return None
+        except (OSError, executive.ScriptError):
             return None
 
         return self._filesystem.read_text_file(configuration_path).rstrip()
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/port/config_standalone.py b/WebKitTools/Scripts/webkitpy/layout_tests/port/config_standalone.py
new file mode 100644 (file)
index 0000000..3dec3b9
--- /dev/null
@@ -0,0 +1,70 @@
+# Copyright (C) 2010 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.
+
+"""FIXME: This script is used by
+config_unittest.test_default_configuration__standalone() to read the
+default configuration to work around any possible caching / reset bugs. See
+https://bugs.webkit.org/show_bug?id=49360 for the motivation. We can remove
+this test when we remove the global configuration cache in config.py."""
+
+import os
+import unittest
+import sys
+
+
+# Ensure that webkitpy is in PYTHONPATH.
+this_dir = os.path.abspath(sys.path[0])
+up = os.path.dirname
+script_dir = up(up(up(this_dir)))
+if script_dir not in sys.path:
+    sys.path.append(script_dir)
+
+from webkitpy.common.system import executive
+from webkitpy.common.system import executive_mock
+from webkitpy.common.system import filesystem
+from webkitpy.common.system import filesystem_mock
+
+import config
+
+
+def main(argv=None):
+    if not argv:
+        argv = sys.argv
+
+    if len(argv) == 3 and argv[1] == '--mock':
+        e = executive_mock.MockExecutive2(output='foo')
+        fs = filesystem_mock.MockFileSystem({'foo/Configuration': argv[2]})
+    else:
+        e = executive.Executive()
+        fs = filesystem.FileSystem()
+
+    c = config.Config(e, fs)
+    print c.default_configuration()
+
+if __name__ == '__main__':
+    main()
index ed5ab8b7304e05dea47198f9e4472fcc580d65eb..9bea014420070698efa6805c741d23d0daaa3cf4 100644 (file)
@@ -27,6 +27,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import os
+import sys
 import unittest
 
 from webkitpy.common.system import executive
@@ -41,14 +42,15 @@ class ConfigTest(unittest.TestCase):
     def tearDown(self):
         config.clear_cached_configuration()
 
-    def make_config(self, output='', files={}, exit_code=0):
-        e = executive_mock.MockExecutive2(output=output, exit_code=exit_code)
+    def make_config(self, output='', files={}, exit_code=0, exception=None):
+        e = executive_mock.MockExecutive2(output=output, exit_code=exit_code,
+                                          exception=exception)
         fs = filesystem_mock.MockFileSystem(files)
         return config.Config(e, fs)
 
     def assert_configuration(self, contents, expected):
         # This tests that a configuration file containing
-        # _contents_ endsd up being interpreted as _expected_.
+        # _contents_ ends up being interpreted as _expected_.
         c = self.make_config('foo', {'foo/Configuration': contents})
         self.assertEqual(c.default_configuration(), expected)
 
@@ -119,6 +121,41 @@ class ConfigTest(unittest.TestCase):
         self.assert_configuration('Unknown', 'Unknown')
         oc.restore_output()
 
+    def test_default_configuration__standalone(self):
+        # FIXME: This test runs a standalone python script to test
+        # reading the default configuration to work around any possible
+        # caching / reset bugs. See https://bugs.webkit.org/show_bug?id=49360
+        # for the motivation. We can remove this test when we remove the
+        # global configuration cache in config.py.
+        e = executive.Executive()
+        fs = filesystem.FileSystem()
+        c = config.Config(e, fs)
+        script = c.path_from_webkit_base('WebKitTools', 'Scripts',
+            'webkitpy', 'layout_tests', 'port', 'config_standalone.py')
+
+        # Note: don't use 'Release' here, since that's the normal default.
+        expected = 'Debug'
+
+        args = [sys.executable, script, '--mock', expected]
+        actual = e.run_command(args).rstrip()
+        self.assertEqual(actual, expected)
+
+    def test_default_configuration__no_perl(self):
+        # We need perl to run webkit-build-directory to find out where the
+        # default configuration file is. See what happens if perl isn't
+        # installed. (We should get the default value, 'Release').
+        c = self.make_config(exception=OSError)
+        actual = c.default_configuration()
+        self.assertEqual(actual, 'Release')
+
+    def test_default_configuration__scripterror(self):
+        # We run webkit-build-directory to find out where the default
+        # configuration file is. See what happens if that script fails.
+        # (We should get the default value, 'Release').
+        c = self.make_config(exception=executive.ScriptError())
+        actual = c.default_configuration()
+        self.assertEqual(actual, 'Release')
+
     def test_path_from_webkit_base(self):
         # FIXME: We use a real filesystem here. Should this move to a
         # mocked one?